提交 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) # 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 `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. * 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 ...@@ -121,11 +121,11 @@ class Peer extends EnhancedEventEmitter
if (this._closed) if (this._closed)
return; return;
this._closed = true;
// Send a notification. // Send a notification.
this._sendNotification('closed', { appData }); this._sendNotification('closed', { appData });
this._closed = true;
this.emit('@close'); this.emit('@close');
this.safeEmit('close', 'local', appData); this.safeEmit('close', 'local', appData);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "common.hpp" #include "common.hpp"
#include "Channel/Notifier.hpp" #include "Channel/Notifier.hpp"
#include "Channel/Request.hpp" #include "Channel/Request.hpp"
#include "RTC/ConsumerListener.hpp"
#include "RTC/RTCP/CompoundPacket.hpp" #include "RTC/RTCP/CompoundPacket.hpp"
#include "RTC/RTCP/FeedbackRtpNack.hpp" #include "RTC/RTCP/FeedbackRtpNack.hpp"
#include "RTC/RTCP/ReceiverReport.hpp" #include "RTC/RTCP/ReceiverReport.hpp"
...@@ -20,20 +21,9 @@ namespace RTC ...@@ -20,20 +21,9 @@ namespace RTC
{ {
class Consumer class Consumer
{ {
public:
/**
* RTC::Peer is the Listener.
*/
class Listener
{
public:
virtual void OnConsumerClosed(Consumer* consumer) = 0;
virtual void OnConsumerFullFrameRequired(Consumer* consumer) = 0;
};
public: public:
Consumer( Consumer(
Listener* listener, RTC::ConsumerListener* listener,
Channel::Notifier* notifier, Channel::Notifier* notifier,
uint32_t consumerId, uint32_t consumerId,
RTC::Media::Kind kind, RTC::Media::Kind kind,
...@@ -66,7 +56,7 @@ namespace RTC ...@@ -66,7 +56,7 @@ namespace RTC
private: private:
// Passed by argument. // Passed by argument.
Listener* listener{ nullptr }; RTC::ConsumerListener* listener{ nullptr };
Channel::Notifier* notifier{ nullptr }; Channel::Notifier* notifier{ nullptr };
RTC::Transport* transport{ nullptr }; RTC::Transport* transport{ nullptr };
// Allocated by this. // 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 @@ ...@@ -4,6 +4,7 @@
#include "common.hpp" #include "common.hpp"
#include "Channel/Notifier.hpp" #include "Channel/Notifier.hpp"
#include "Channel/Request.hpp" #include "Channel/Request.hpp"
#include "RTC/ProducerListener.hpp"
#include "RTC/RTCP/CompoundPacket.hpp" #include "RTC/RTCP/CompoundPacket.hpp"
#include "RTC/RTCP/Feedback.hpp" #include "RTC/RTCP/Feedback.hpp"
#include "RTC/RTCP/ReceiverReport.hpp" #include "RTC/RTCP/ReceiverReport.hpp"
...@@ -12,6 +13,7 @@ ...@@ -12,6 +13,7 @@
#include "RTC/RtpStreamRecv.hpp" #include "RTC/RtpStreamRecv.hpp"
#include "RTC/Transport.hpp" #include "RTC/Transport.hpp"
#include <json/json.h> #include <json/json.h>
#include <unordered_set>
#include <map> #include <map>
#include <string> #include <string>
...@@ -19,17 +21,6 @@ namespace RTC ...@@ -19,17 +21,6 @@ namespace RTC
{ {
class Producer : public RtpStreamRecv::Listener 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: private:
struct RtpMapping struct RtpMapping
{ {
...@@ -46,7 +37,7 @@ namespace RTC ...@@ -46,7 +37,7 @@ namespace RTC
public: public:
Producer( Producer(
Listener* listener, RTC::ProducerListener* listener,
Channel::Notifier* notifier, Channel::Notifier* notifier,
uint32_t producerId, uint32_t producerId,
RTC::Media::Kind kind, RTC::Media::Kind kind,
...@@ -86,7 +77,8 @@ namespace RTC ...@@ -86,7 +77,8 @@ namespace RTC
private: private:
// Passed by argument. // Passed by argument.
Listener* listener{ nullptr }; // std::unordered_set<
RTC::ProducerListener* listener{ nullptr };
Channel::Notifier* notifier{ nullptr }; Channel::Notifier* notifier{ nullptr };
RTC::Transport* transport{ nullptr }; RTC::Transport* transport{ nullptr };
// Allocated by this. // 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 @@ ...@@ -4,8 +4,10 @@
#include "common.hpp" #include "common.hpp"
#include "Channel/Notifier.hpp" #include "Channel/Notifier.hpp"
#include "Channel/Request.hpp" #include "Channel/Request.hpp"
#include "RTC/Consumer.hpp"
#include "RTC/Producer.hpp" #include "RTC/Producer.hpp"
#include "RTC/ProducerListener.hpp"
#include "RTC/Consumer.hpp"
#include "RTC/ConsumerListener.hpp"
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include "RTC/Transport.hpp" #include "RTC/Transport.hpp"
// TODO: Let's see. // TODO: Let's see.
...@@ -21,8 +23,8 @@ ...@@ -21,8 +23,8 @@
namespace RTC namespace RTC
{ {
class Router : public RTC::Transport::Listener, class Router : public RTC::Transport::Listener,
public RTC::Producer::Listener, public RTC::ProducerListener,
public RTC::Consumer::Listener, public RTC::ConsumerListener,
public Timer::Listener public Timer::Listener
{ {
public: public:
...@@ -64,6 +66,7 @@ namespace RTC ...@@ -64,6 +66,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::Producer::Listener. */ /* Pure virtual methods inherited from RTC::Producer::Listener. */
public: public:
void OnProducerClosed(RTC::Producer* producer) override; void OnProducerClosed(RTC::Producer* producer) override;
void OnProducerRtpParameters(RTC::Producer* producer) override;
void OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) override; void OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) override;
/* Pure virtual methods inherited from RTC::Consumer::Listener. */ /* Pure virtual methods inherited from RTC::Consumer::Listener. */
......
...@@ -106,12 +106,14 @@ ...@@ -106,12 +106,14 @@
'include/Channel/Request.hpp', 'include/Channel/Request.hpp',
'include/Channel/UnixStreamSocket.hpp', 'include/Channel/UnixStreamSocket.hpp',
'include/RTC/Consumer.hpp', 'include/RTC/Consumer.hpp',
'include/RTC/ConsumerListener.hpp',
'include/RTC/DtlsTransport.hpp', 'include/RTC/DtlsTransport.hpp',
'include/RTC/IceCandidate.hpp', 'include/RTC/IceCandidate.hpp',
'include/RTC/IceServer.hpp', 'include/RTC/IceServer.hpp',
'include/RTC/NackGenerator.hpp', 'include/RTC/NackGenerator.hpp',
'include/RTC/Parameters.hpp', 'include/RTC/Parameters.hpp',
'include/RTC/Producer.hpp', 'include/RTC/Producer.hpp',
'include/RTC/ProducerListener.hpp',
'include/RTC/Router.hpp', 'include/RTC/Router.hpp',
'include/RTC/RtpDictionaries.hpp', 'include/RTC/RtpDictionaries.hpp',
'include/RTC/RtpListener.hpp', 'include/RTC/RtpListener.hpp',
......
...@@ -18,7 +18,7 @@ namespace RTC ...@@ -18,7 +18,7 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
Consumer::Consumer( Consumer::Consumer(
Listener* listener, RTC::ConsumerListener* listener,
Channel::Notifier* notifier, Channel::Notifier* notifier,
uint32_t consumerId, uint32_t consumerId,
RTC::Media::Kind kind, RTC::Media::Kind kind,
......
...@@ -13,7 +13,7 @@ namespace RTC ...@@ -13,7 +13,7 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
Producer::Producer( Producer::Producer(
Listener* listener, ProducerListener* listener,
Channel::Notifier* notifier, Channel::Notifier* notifier,
uint32_t producerId, uint32_t producerId,
RTC::Media::Kind kind, RTC::Media::Kind kind,
...@@ -100,21 +100,6 @@ namespace RTC ...@@ -100,21 +100,6 @@ namespace RTC
switch (request->methodId) 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: case Channel::Request::MethodId::PRODUCER_DUMP:
{ {
auto json = ToJson(); auto json = ToJson();
...@@ -179,6 +164,8 @@ namespace RTC ...@@ -179,6 +164,8 @@ namespace RTC
CreateRtpStream(encoding); CreateRtpStream(encoding);
} }
this->listener->OnProducerRtpParameters(this);
request->Accept(); request->Accept();
break; break;
......
...@@ -363,6 +363,7 @@ namespace RTC ...@@ -363,6 +363,7 @@ namespace RTC
} }
transport->Destroy(); transport->Destroy();
request->Accept();
break; break;
} }
...@@ -420,6 +421,7 @@ namespace RTC ...@@ -420,6 +421,7 @@ namespace RTC
} }
producer->Destroy(); producer->Destroy();
request->Accept();
break; break;
} }
...@@ -479,6 +481,7 @@ namespace RTC ...@@ -479,6 +481,7 @@ namespace RTC
} }
consumer->Destroy(); consumer->Destroy();
request->Accept();
break; break;
} }
...@@ -636,6 +639,19 @@ namespace RTC ...@@ -636,6 +639,19 @@ namespace RTC
this->mapProducerAudioLevelContainer.erase(producer); 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) void Router::OnProducerRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet)
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -394,21 +394,6 @@ namespace RTC ...@@ -394,21 +394,6 @@ namespace RTC
switch (request->methodId) 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: case Channel::Request::MethodId::TRANSPORT_DUMP:
{ {
auto json = ToJson(); auto json = ToJson();
......
...@@ -232,6 +232,7 @@ void Worker::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::R ...@@ -232,6 +232,7 @@ void Worker::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::R
} }
router->Destroy(); router->Destroy();
request->Accept();
break; break;
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论