提交 e8399d55 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

worker: Add RTC::ProducerListener and RTC::ConsumerListener classes

上级 44a1248a
# TODO in mediasoup v2 (server-side)
* When a producer is locally closed, the remote `RtpListener.RemoveProducer()` is not called. The question is: how to tell the transport of the producer about this?
- Yes, double listeners...
* Does `PRODUCER_SEND` makes sense? why not just requiring RTP parameters (and mapping) in the constructor?
* Does `CONSUMER_ENABLE` makes sense? IMHO it's better to keep the Consumer just in JS and call `CREATE_CONSUMER` (by passing `rtpParameters` and `transportId`) once enabled for reception in JS.
......
......@@ -121,11 +121,11 @@ class Peer extends EnhancedEventEmitter
if (this._closed)
return;
this._closed = true;
// Send a notification.
this._sendNotification('closed', { appData });
this._closed = true;
this.emit('@close');
this.safeEmit('close', 'local', appData);
......
......@@ -4,6 +4,7 @@
#include "common.hpp"
#include "Channel/Notifier.hpp"
#include "Channel/Request.hpp"
#include "RTC/ConsumerListener.hpp"
#include "RTC/RTCP/CompoundPacket.hpp"
#include "RTC/RTCP/FeedbackRtpNack.hpp"
#include "RTC/RTCP/ReceiverReport.hpp"
......@@ -20,20 +21,9 @@ namespace RTC
{
class Consumer
{
public:
/**
* RTC::Peer is the Listener.
*/
class Listener
{
public:
virtual void OnConsumerClosed(Consumer* consumer) = 0;
virtual void OnConsumerFullFrameRequired(Consumer* consumer) = 0;
};
public:
Consumer(
Listener* listener,
RTC::ConsumerListener* listener,
Channel::Notifier* notifier,
uint32_t consumerId,
RTC::Media::Kind kind,
......@@ -66,7 +56,7 @@ namespace RTC
private:
// Passed by argument.
Listener* listener{ nullptr };
RTC::ConsumerListener* listener{ nullptr };
Channel::Notifier* notifier{ nullptr };
RTC::Transport* transport{ nullptr };
// Allocated by this.
......
#ifndef MS_RTC_CONSUMER_LISTENER_HPP
#define MS_RTC_CONSUMER_LISTENER_HPP
#include "RTC/RtpPacket.hpp"
namespace RTC
{
// Avoid cyclic #include problem by declaring classes instead of including
// the corresponding header files.
class Consumer;
class ConsumerListener
{
public:
virtual void OnConsumerClosed(RTC::Consumer* consumer) = 0;
virtual void OnConsumerFullFrameRequired(RTC::Consumer* consumer) = 0;
};
} // namespace RTC
#endif
......@@ -4,6 +4,7 @@
#include "common.hpp"
#include "Channel/Notifier.hpp"
#include "Channel/Request.hpp"
#include "RTC/ProducerListener.hpp"
#include "RTC/RTCP/CompoundPacket.hpp"
#include "RTC/RTCP/Feedback.hpp"
#include "RTC/RTCP/ReceiverReport.hpp"
......@@ -12,6 +13,7 @@
#include "RTC/RtpStreamRecv.hpp"
#include "RTC/Transport.hpp"
#include <json/json.h>
#include <unordered_set>
#include <map>
#include <string>
......@@ -19,17 +21,6 @@ namespace RTC
{
class Producer : public RtpStreamRecv::Listener
{
public:
/**
* RTC::Peer is the Listener.
*/
class Listener
{
public:
virtual void OnProducerClosed(RTC::Producer* producer) = 0;
virtual void OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) = 0;
};
private:
struct RtpMapping
{
......@@ -46,7 +37,7 @@ namespace RTC
public:
Producer(
Listener* listener,
RTC::ProducerListener* listener,
Channel::Notifier* notifier,
uint32_t producerId,
RTC::Media::Kind kind,
......@@ -86,7 +77,8 @@ namespace RTC
private:
// Passed by argument.
Listener* listener{ nullptr };
// std::unordered_set<
RTC::ProducerListener* listener{ nullptr };
Channel::Notifier* notifier{ nullptr };
RTC::Transport* transport{ nullptr };
// Allocated by this.
......
#ifndef MS_RTC_PRODUCER_LISTENER_HPP
#define MS_RTC_PRODUCER_LISTENER_HPP
#include "RTC/RtpPacket.hpp"
namespace RTC
{
// Avoid cyclic #include problem by declaring classes instead of including
// the corresponding header files.
class Producer;
class ProducerListener
{
public:
virtual void OnProducerClosed(RTC::Producer* producer) = 0;
virtual void OnProducerRtpParameters(RTC::Producer* producer) = 0;
virtual void OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) = 0;
};
} // namespace RTC
#endif
......@@ -4,8 +4,10 @@
#include "common.hpp"
#include "Channel/Notifier.hpp"
#include "Channel/Request.hpp"
#include "RTC/Consumer.hpp"
#include "RTC/Producer.hpp"
#include "RTC/ProducerListener.hpp"
#include "RTC/Consumer.hpp"
#include "RTC/ConsumerListener.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/Transport.hpp"
// TODO: Let's see.
......@@ -21,8 +23,8 @@
namespace RTC
{
class Router : public RTC::Transport::Listener,
public RTC::Producer::Listener,
public RTC::Consumer::Listener,
public RTC::ProducerListener,
public RTC::ConsumerListener,
public Timer::Listener
{
public:
......@@ -64,6 +66,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::Producer::Listener. */
public:
void OnProducerClosed(RTC::Producer* producer) override;
void OnProducerRtpParameters(RTC::Producer* producer) override;
void OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) override;
/* Pure virtual methods inherited from RTC::Consumer::Listener. */
......
......@@ -106,12 +106,14 @@
'include/Channel/Request.hpp',
'include/Channel/UnixStreamSocket.hpp',
'include/RTC/Consumer.hpp',
'include/RTC/ConsumerListener.hpp',
'include/RTC/DtlsTransport.hpp',
'include/RTC/IceCandidate.hpp',
'include/RTC/IceServer.hpp',
'include/RTC/NackGenerator.hpp',
'include/RTC/Parameters.hpp',
'include/RTC/Producer.hpp',
'include/RTC/ProducerListener.hpp',
'include/RTC/Router.hpp',
'include/RTC/RtpDictionaries.hpp',
'include/RTC/RtpListener.hpp',
......
......@@ -18,7 +18,7 @@ namespace RTC
/* Instance methods. */
Consumer::Consumer(
Listener* listener,
RTC::ConsumerListener* listener,
Channel::Notifier* notifier,
uint32_t consumerId,
RTC::Media::Kind kind,
......
......@@ -13,7 +13,7 @@ namespace RTC
/* Instance methods. */
Producer::Producer(
Listener* listener,
ProducerListener* listener,
Channel::Notifier* notifier,
uint32_t producerId,
RTC::Media::Kind kind,
......@@ -100,21 +100,6 @@ namespace RTC
switch (request->methodId)
{
case Channel::Request::MethodId::PRODUCER_CLOSE:
{
#ifdef MS_LOG_DEV
uint32_t producerId = this->producerId;
#endif
Destroy();
MS_DEBUG_DEV("Producer closed [producerId:%" PRIu32 "]", producerId);
request->Accept();
break;
}
case Channel::Request::MethodId::PRODUCER_DUMP:
{
auto json = ToJson();
......@@ -179,6 +164,8 @@ namespace RTC
CreateRtpStream(encoding);
}
this->listener->OnProducerRtpParameters(this);
request->Accept();
break;
......
......@@ -363,6 +363,7 @@ namespace RTC
}
transport->Destroy();
request->Accept();
break;
}
......@@ -420,6 +421,7 @@ namespace RTC
}
producer->Destroy();
request->Accept();
break;
}
......@@ -479,6 +481,7 @@ namespace RTC
}
consumer->Destroy();
request->Accept();
break;
}
......@@ -636,6 +639,19 @@ namespace RTC
this->mapProducerAudioLevelContainer.erase(producer);
}
void Router::OnProducerRtpParameters(RTC::Producer* producer)
{
MS_TRACE();
MS_ASSERT(producer->GetParameters(), "Producer has no parameters");
MS_ASSERT(
this->mapProducerConsumers.find(producer) == this->mapProducerConsumers.end(),
"Producer already in mapProducerConsumers");
// Ensure the entry will exist even with an empty array.
this->mapProducerConsumers[producer];
}
void Router::OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet)
{
MS_TRACE();
......
......@@ -394,21 +394,6 @@ namespace RTC
switch (request->methodId)
{
case Channel::Request::MethodId::TRANSPORT_CLOSE:
{
#ifdef MS_LOG_DEV
uint32_t transportId = this->transportId;
#endif
Destroy();
MS_DEBUG_DEV("Transport closed [transportId:%" PRIu32 "]", transportId);
request->Accept();
break;
}
case Channel::Request::MethodId::TRANSPORT_DUMP:
{
auto json = ToJson();
......
......@@ -232,6 +232,7 @@ void Worker::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::R
}
router->Destroy();
request->Accept();
break;
}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论