Unverified 提交 237fd62f authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

Woerker: Add RTC::Shared singleton for RTC entities (#953)

上级 461e0af0
# Changelog # Changelog
### NEXT
* `Worker`: Add `RTC::Shared` singleton for RTC entities (PR #953).
### 3.11.3 ### 3.11.3
* `ChannelMessageHandlers`: Make `RegisterHandler()` not remove the existing handler if another one with same `id` is given (PR #952). * `ChannelMessageHandlers`: Make `RegisterHandler()` not remove the existing handler if another one with same `id` is given (PR #952).
......
...@@ -13,15 +13,17 @@ namespace Channel ...@@ -13,15 +13,17 @@ namespace Channel
class ChannelNotifier class ChannelNotifier
{ {
public: public:
static void ClassInit(Channel::ChannelSocket* channel); explicit ChannelNotifier(Channel::ChannelSocket* channel);
static void Emit(uint64_t targetId, const char* event);
static void Emit(const std::string& targetId, const char* event);
static void Emit(const std::string& targetId, const char* event, json& data);
static void Emit(const std::string& targetId, const char* event, const std::string& data);
public: public:
void Emit(uint64_t targetId, const char* event);
void Emit(const std::string& targetId, const char* event);
void Emit(const std::string& targetId, const char* event, json& data);
void Emit(const std::string& targetId, const char* event, const std::string& data);
private:
// Passed by argument. // Passed by argument.
thread_local static Channel::ChannelSocket* channel; Channel::ChannelSocket* channel{ nullptr };
}; };
} // namespace Channel } // namespace Channel
......
#ifndef MS_CHANNEL_MESSAGE_HANDLERS_HPP #ifndef MS_CHANNEL_MESSAGE_REGISTRATOR_HPP
#define MS_CHANNEL_MESSAGE_HANDLERS_HPP #define MS_CHANNEL_MESSAGE_REGISTRATOR_HPP
#include "common.hpp" #include "common.hpp"
#include "Channel/ChannelSocket.hpp" #include "Channel/ChannelSocket.hpp"
...@@ -8,28 +8,31 @@ ...@@ -8,28 +8,31 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <string> #include <string>
class ChannelMessageHandlers class ChannelMessageRegistrator
{ {
public: public:
static void FillJson(json& jsonObject); explicit ChannelMessageRegistrator();
static void RegisterHandler( ~ChannelMessageRegistrator();
public:
void FillJson(json& jsonObject);
void RegisterHandler(
const std::string& id, const std::string& id,
Channel::ChannelSocket::RequestHandler* channelRequestHandler, Channel::ChannelSocket::RequestHandler* channelRequestHandler,
PayloadChannel::PayloadChannelSocket::RequestHandler* payloadChannelRequestHandler, PayloadChannel::PayloadChannelSocket::RequestHandler* payloadChannelRequestHandler,
PayloadChannel::PayloadChannelSocket::NotificationHandler* payloadChannelNotificationHandler); PayloadChannel::PayloadChannelSocket::NotificationHandler* payloadChannelNotificationHandler);
static void UnregisterHandler(const std::string& id); void UnregisterHandler(const std::string& id);
static Channel::ChannelSocket::RequestHandler* GetChannelRequestHandler(const std::string& id); Channel::ChannelSocket::RequestHandler* GetChannelRequestHandler(const std::string& id);
static PayloadChannel::PayloadChannelSocket::RequestHandler* GetPayloadChannelRequestHandler( PayloadChannel::PayloadChannelSocket::RequestHandler* GetPayloadChannelRequestHandler(
const std::string& id); const std::string& id);
static PayloadChannel::PayloadChannelSocket::NotificationHandler* GetPayloadChannelNotificationHandler( PayloadChannel::PayloadChannelSocket::NotificationHandler* GetPayloadChannelNotificationHandler(
const std::string& id); const std::string& id);
private: private:
thread_local static absl::flat_hash_map<std::string, Channel::ChannelSocket::RequestHandler*> absl::flat_hash_map<std::string, Channel::ChannelSocket::RequestHandler*> mapChannelRequestHandlers;
mapChannelRequestHandlers; absl::flat_hash_map<std::string, PayloadChannel::PayloadChannelSocket::RequestHandler*>
thread_local static absl::flat_hash_map<std::string, PayloadChannel::PayloadChannelSocket::RequestHandler*>
mapPayloadChannelRequestHandlers; mapPayloadChannelRequestHandlers;
thread_local static absl::flat_hash_map<std::string, PayloadChannel::PayloadChannelSocket::NotificationHandler*> absl::flat_hash_map<std::string, PayloadChannel::PayloadChannelSocket::NotificationHandler*>
mapPayloadChannelNotificationHandlers; mapPayloadChannelNotificationHandlers;
}; };
......
...@@ -13,25 +13,26 @@ namespace PayloadChannel ...@@ -13,25 +13,26 @@ namespace PayloadChannel
class PayloadChannelNotifier class PayloadChannelNotifier
{ {
public: public:
static void ClassInit(PayloadChannel::PayloadChannelSocket* payloadChannel); explicit PayloadChannelNotifier(PayloadChannel::PayloadChannelSocket* payloadChannel);
static void Emit(
const std::string& targetId, const char* event, const uint8_t* payload, size_t payloadLen); public:
static void Emit( void Emit(const std::string& targetId, const char* event, const uint8_t* payload, size_t payloadLen);
void Emit(
const std::string& targetId, const std::string& targetId,
const char* event, const char* event,
json& data, json& data,
const uint8_t* payload, const uint8_t* payload,
size_t payloadLen); size_t payloadLen);
static void Emit( void Emit(
const std::string& targetId, const std::string& targetId,
const char* event, const char* event,
const std::string& data, const std::string& data,
const uint8_t* payload, const uint8_t* payload,
size_t payloadLen); size_t payloadLen);
public: private:
// Passed by argument. // Passed by argument.
thread_local static PayloadChannel::PayloadChannelSocket* payloadChannel; PayloadChannel::PayloadChannelSocket* payloadChannel{ nullptr };
}; };
} // namespace PayloadChannel } // namespace PayloadChannel
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define MS_RTC_ACTIVE_SPEAKER_OBSERVER_HPP #define MS_RTC_ACTIVE_SPEAKER_OBSERVER_HPP
#include "RTC/RtpObserver.hpp" #include "RTC/RtpObserver.hpp"
#include "RTC/Shared.hpp"
#include "handles/Timer.hpp" #include "handles/Timer.hpp"
#include <absl/container/flat_hash_map.h> #include <absl/container/flat_hash_map.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
...@@ -69,7 +70,8 @@ namespace RTC ...@@ -69,7 +70,8 @@ namespace RTC
static const size_t RelativeSpeachActivitiesLen{ 3u }; static const size_t RelativeSpeachActivitiesLen{ 3u };
public: public:
ActiveSpeakerObserver(const std::string& id, RTC::RtpObserver::Listener* listener, json& data); ActiveSpeakerObserver(
RTC::Shared* shared, const std::string& id, RTC::RtpObserver::Listener* listener, json& data);
~ActiveSpeakerObserver() override; ~ActiveSpeakerObserver() override;
public: public:
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define MS_RTC_AUDIO_LEVEL_OBSERVER_HPP #define MS_RTC_AUDIO_LEVEL_OBSERVER_HPP
#include "RTC/RtpObserver.hpp" #include "RTC/RtpObserver.hpp"
#include "RTC/Shared.hpp"
#include "handles/Timer.hpp" #include "handles/Timer.hpp"
#include <absl/container/flat_hash_map.h> #include <absl/container/flat_hash_map.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
...@@ -20,7 +21,8 @@ namespace RTC ...@@ -20,7 +21,8 @@ namespace RTC
}; };
public: public:
AudioLevelObserver(const std::string& id, RTC::RtpObserver::Listener* listener, json& data); AudioLevelObserver(
RTC::Shared* shared, const std::string& id, RTC::RtpObserver::Listener* listener, json& data);
~AudioLevelObserver() override; ~AudioLevelObserver() override;
public: public:
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include "RTC/RtpStream.hpp" #include "RTC/RtpStream.hpp"
#include "RTC/RtpStreamSend.hpp" #include "RTC/RtpStreamSend.hpp"
#include "RTC/Shared.hpp"
#include <absl/container/flat_hash_set.h> #include <absl/container/flat_hash_set.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <string> #include <string>
...@@ -60,6 +61,7 @@ namespace RTC ...@@ -60,6 +61,7 @@ namespace RTC
public: public:
Consumer( Consumer(
RTC::Shared* shared,
const std::string& id, const std::string& id,
const std::string& producerId, const std::string& producerId,
RTC::Consumer::Listener* listener, RTC::Consumer::Listener* listener,
...@@ -178,6 +180,7 @@ namespace RTC ...@@ -178,6 +180,7 @@ namespace RTC
protected: protected:
// Passed by argument. // Passed by argument.
RTC::Shared* shared{ nullptr };
RTC::Consumer::Listener* listener{ nullptr }; RTC::Consumer::Listener* listener{ nullptr };
RTC::Media::Kind kind; RTC::Media::Kind kind;
RTC::RtpParameters rtpParameters; RTC::RtpParameters rtpParameters;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "PayloadChannel/PayloadChannelRequest.hpp" #include "PayloadChannel/PayloadChannelRequest.hpp"
#include "PayloadChannel/PayloadChannelSocket.hpp" #include "PayloadChannel/PayloadChannelSocket.hpp"
#include "RTC/SctpDictionaries.hpp" #include "RTC/SctpDictionaries.hpp"
#include "RTC/Shared.hpp"
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <string> #include <string>
...@@ -47,6 +48,7 @@ namespace RTC ...@@ -47,6 +48,7 @@ namespace RTC
public: public:
DataConsumer( DataConsumer(
RTC::Shared* shared,
const std::string& id, const std::string& id,
const std::string& dataProducerId, const std::string& dataProducerId,
RTC::SctpAssociation* sctpAssociation, RTC::SctpAssociation* sctpAssociation,
...@@ -81,6 +83,7 @@ namespace RTC ...@@ -81,6 +83,7 @@ namespace RTC
void SctpAssociationConnected(); void SctpAssociationConnected();
void SctpAssociationClosed(); void SctpAssociationClosed();
void SctpAssociationBufferedAmount(uint32_t bufferedAmount); void SctpAssociationBufferedAmount(uint32_t bufferedAmount);
void SctpAssociationSendBufferFull();
void DataProducerClosed(); void DataProducerClosed();
void SendMessage(uint32_t ppid, const uint8_t* msg, size_t len, onQueuedCallback* = nullptr); void SendMessage(uint32_t ppid, const uint8_t* msg, size_t len, onQueuedCallback* = nullptr);
...@@ -99,6 +102,7 @@ namespace RTC ...@@ -99,6 +102,7 @@ namespace RTC
private: private:
// Passed by argument. // Passed by argument.
RTC::Shared* shared{ nullptr };
RTC::SctpAssociation* sctpAssociation{ nullptr }; RTC::SctpAssociation* sctpAssociation{ nullptr };
RTC::DataConsumer::Listener* listener{ nullptr }; RTC::DataConsumer::Listener* listener{ nullptr };
size_t maxMessageSize{ 0u }; size_t maxMessageSize{ 0u };
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "PayloadChannel/PayloadChannelSocket.hpp" #include "PayloadChannel/PayloadChannelSocket.hpp"
#include "RTC/RTCP/Packet.hpp" #include "RTC/RTCP/Packet.hpp"
#include "RTC/SctpDictionaries.hpp" #include "RTC/SctpDictionaries.hpp"
#include "RTC/Shared.hpp"
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <string> #include <string>
...@@ -36,7 +37,11 @@ namespace RTC ...@@ -36,7 +37,11 @@ namespace RTC
public: public:
DataProducer( DataProducer(
const std::string& id, size_t maxMessageSize, RTC::DataProducer::Listener* listener, json& data); RTC::Shared* shared,
const std::string& id,
size_t maxMessageSize,
RTC::DataProducer::Listener* listener,
json& data);
virtual ~DataProducer(); virtual ~DataProducer();
public: public:
...@@ -66,6 +71,7 @@ namespace RTC ...@@ -66,6 +71,7 @@ namespace RTC
private: private:
// Passed by argument. // Passed by argument.
RTC::Shared* shared{ nullptr };
size_t maxMessageSize{ 0u }; size_t maxMessageSize{ 0u };
RTC::DataProducer::Listener* listener{ nullptr }; RTC::DataProducer::Listener* listener{ nullptr };
// Others. // Others.
......
#ifndef MS_RTC_DIRECT_TRANSPORT_HPP #ifndef MS_RTC_DIRECT_TRANSPORT_HPP
#define MS_RTC_DIRECT_TRANSPORT_HPP #define MS_RTC_DIRECT_TRANSPORT_HPP
#include "RTC/Shared.hpp"
#include "RTC/Transport.hpp" #include "RTC/Transport.hpp"
namespace RTC namespace RTC
...@@ -8,7 +9,8 @@ namespace RTC ...@@ -8,7 +9,8 @@ namespace RTC
class DirectTransport : public RTC::Transport class DirectTransport : public RTC::Transport
{ {
public: public:
DirectTransport(const std::string& id, RTC::Transport::Listener* listener, json& data); DirectTransport(
RTC::Shared* shared, const std::string& id, RTC::Transport::Listener* listener, json& data);
~DirectTransport() override; ~DirectTransport() override;
public: public:
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "RTC/Consumer.hpp" #include "RTC/Consumer.hpp"
#include "RTC/RtpStreamSend.hpp" #include "RTC/RtpStreamSend.hpp"
#include "RTC/SeqManager.hpp" #include "RTC/SeqManager.hpp"
#include "RTC/Shared.hpp"
namespace RTC namespace RTC
{ {
...@@ -11,6 +12,7 @@ namespace RTC ...@@ -11,6 +12,7 @@ namespace RTC
{ {
public: public:
PipeConsumer( PipeConsumer(
RTC::Shared* shared,
const std::string& id, const std::string& id,
const std::string& producerId, const std::string& producerId,
RTC::Consumer::Listener* listener, RTC::Consumer::Listener* listener,
......
#ifndef MS_RTC_PIPE_TRANSPORT_HPP #ifndef MS_RTC_PIPE_TRANSPORT_HPP
#define MS_RTC_PIPE_TRANSPORT_HPP #define MS_RTC_PIPE_TRANSPORT_HPP
#include "RTC/Shared.hpp"
#include "RTC/SrtpSession.hpp" #include "RTC/SrtpSession.hpp"
#include "RTC/Transport.hpp" #include "RTC/Transport.hpp"
#include "RTC/TransportTuple.hpp" #include "RTC/TransportTuple.hpp"
...@@ -23,7 +24,8 @@ namespace RTC ...@@ -23,7 +24,8 @@ namespace RTC
static size_t srtpMasterLength; static size_t srtpMasterLength;
public: public:
PipeTransport(const std::string& id, RTC::Transport::Listener* listener, json& data); PipeTransport(
RTC::Shared* shared, const std::string& id, RTC::Transport::Listener* listener, json& data);
~PipeTransport() override; ~PipeTransport() override;
public: public:
......
#ifndef MS_RTC_PLAIN_TRANSPORT_HPP #ifndef MS_RTC_PLAIN_TRANSPORT_HPP
#define MS_RTC_PLAIN_TRANSPORT_HPP #define MS_RTC_PLAIN_TRANSPORT_HPP
#include "RTC/Shared.hpp"
#include "RTC/SrtpSession.hpp" #include "RTC/SrtpSession.hpp"
#include "RTC/Transport.hpp" #include "RTC/Transport.hpp"
#include "RTC/TransportTuple.hpp" #include "RTC/TransportTuple.hpp"
...@@ -23,7 +24,8 @@ namespace RTC ...@@ -23,7 +24,8 @@ namespace RTC
static absl::flat_hash_map<RTC::SrtpSession::CryptoSuite, std::string> srtpCryptoSuite2String; static absl::flat_hash_map<RTC::SrtpSession::CryptoSuite, std::string> srtpCryptoSuite2String;
public: public:
PlainTransport(const std::string& id, RTC::Transport::Listener* listener, json& data); PlainTransport(
RTC::Shared* shared, const std::string& id, RTC::Transport::Listener* listener, json& data);
~PlainTransport() override; ~PlainTransport() override;
public: public:
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "RTC/RtpHeaderExtensionIds.hpp" #include "RTC/RtpHeaderExtensionIds.hpp"
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include "RTC/RtpStreamRecv.hpp" #include "RTC/RtpStreamRecv.hpp"
#include "RTC/Shared.hpp"
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -92,7 +93,7 @@ namespace RTC ...@@ -92,7 +93,7 @@ namespace RTC
}; };
public: public:
Producer(const std::string& id, RTC::Producer::Listener* listener, json& data); Producer(RTC::Shared* shared, const std::string& id, RTC::Producer::Listener* listener, json& data);
virtual ~Producer(); virtual ~Producer();
public: public:
...@@ -172,6 +173,7 @@ namespace RTC ...@@ -172,6 +173,7 @@ namespace RTC
private: private:
// Passed by argument. // Passed by argument.
RTC::Shared* shared{ nullptr };
RTC::Producer::Listener* listener{ nullptr }; RTC::Producer::Listener* listener{ nullptr };
// Allocated by this. // Allocated by this.
absl::flat_hash_map<uint32_t, RTC::RtpStreamRecv*> mapSsrcRtpStream; absl::flat_hash_map<uint32_t, RTC::RtpStreamRecv*> mapSsrcRtpStream;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "RTC/RtpObserver.hpp" #include "RTC/RtpObserver.hpp"
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include "RTC/RtpStream.hpp" #include "RTC/RtpStream.hpp"
#include "RTC/Shared.hpp"
#include "RTC/Transport.hpp" #include "RTC/Transport.hpp"
#include "RTC/WebRtcServer.hpp" #include "RTC/WebRtcServer.hpp"
#include <absl/container/flat_hash_map.h> #include <absl/container/flat_hash_map.h>
...@@ -39,7 +40,7 @@ namespace RTC ...@@ -39,7 +40,7 @@ namespace RTC
}; };
public: public:
explicit Router(const std::string& id, Listener* listener); explicit Router(RTC::Shared* shared, const std::string& id, Listener* listener);
virtual ~Router(); virtual ~Router();
public: public:
...@@ -111,9 +112,11 @@ namespace RTC ...@@ -111,9 +112,11 @@ namespace RTC
public: public:
// Passed by argument. // Passed by argument.
const std::string id; const std::string id;
Listener* listener{ nullptr };
private: private:
// Passed by argument.
RTC::Shared* shared{ nullptr };
Listener* listener{ nullptr };
// Allocated by this. // Allocated by this.
absl::flat_hash_map<std::string, RTC::Transport*> mapTransports; absl::flat_hash_map<std::string, RTC::Transport*> mapTransports;
absl::flat_hash_map<std::string, RTC::RtpObserver*> mapRtpObservers; absl::flat_hash_map<std::string, RTC::RtpObserver*> mapRtpObservers;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "common.hpp" #include "common.hpp"
#include "RTC/Producer.hpp" #include "RTC/Producer.hpp"
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include "RTC/Shared.hpp"
#include <string> #include <string>
namespace RTC namespace RTC
...@@ -25,7 +26,7 @@ namespace RTC ...@@ -25,7 +26,7 @@ namespace RTC
}; };
public: public:
RtpObserver(const std::string& id, RTC::RtpObserver::Listener* listener); RtpObserver(RTC::Shared* shared, const std::string& id, RTC::RtpObserver::Listener* listener);
virtual ~RtpObserver(); virtual ~RtpObserver();
public: public:
...@@ -55,9 +56,14 @@ namespace RTC ...@@ -55,9 +56,14 @@ namespace RTC
public: public:
// Passed by argument. // Passed by argument.
const std::string id; const std::string id;
RTC::RtpObserver::Listener* listener{ nullptr };
protected:
// Passed by argument.
RTC::Shared* shared{ nullptr };
private: private:
// Passed by argument.
RTC::RtpObserver::Listener* listener{ nullptr };
// Others. // Others.
bool paused{ false }; bool paused{ false };
}; };
......
#ifndef MS_RTC_SHARED_HPP
#define MS_RTC_SHARED_HPP
#include "ChannelMessageRegistrator.hpp"
#include "Channel/ChannelNotifier.hpp"
#include "PayloadChannel/PayloadChannelNotifier.hpp"
namespace RTC
{
class Shared
{
public:
explicit Shared(
ChannelMessageRegistrator* channelMessageRegistrator,
Channel::ChannelNotifier* channelNotifier,
PayloadChannel::PayloadChannelNotifier* payloadChannelNotifier);
~Shared();
public:
ChannelMessageRegistrator* channelMessageRegistrator{ nullptr };
Channel::ChannelNotifier* channelNotifier{ nullptr };
PayloadChannel::PayloadChannelNotifier* payloadChannelNotifier{ nullptr };
};
} // namespace RTC
#endif
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "RTC/Consumer.hpp" #include "RTC/Consumer.hpp"
#include "RTC/RtpStreamSend.hpp" #include "RTC/RtpStreamSend.hpp"
#include "RTC/SeqManager.hpp" #include "RTC/SeqManager.hpp"
#include "RTC/Shared.hpp"
namespace RTC namespace RTC
{ {
...@@ -11,6 +12,7 @@ namespace RTC ...@@ -11,6 +12,7 @@ namespace RTC
{ {
public: public:
SimpleConsumer( SimpleConsumer(
RTC::Shared* shared,
const std::string& id, const std::string& id,
const std::string& producerId, const std::string& producerId,
RTC::Consumer::Listener* listener, RTC::Consumer::Listener* listener,
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "RTC/Consumer.hpp" #include "RTC/Consumer.hpp"
#include "RTC/RtpStreamSend.hpp" #include "RTC/RtpStreamSend.hpp"
#include "RTC/SeqManager.hpp" #include "RTC/SeqManager.hpp"
#include "RTC/Shared.hpp"
namespace RTC namespace RTC
{ {
...@@ -12,6 +13,7 @@ namespace RTC ...@@ -12,6 +13,7 @@ namespace RTC
{ {
public: public:
SimulcastConsumer( SimulcastConsumer(
RTC::Shared* shared,
const std::string& id, const std::string& id,
const std::string& producerId, const std::string& producerId,
RTC::Consumer::Listener* listener, RTC::Consumer::Listener* listener,
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "RTC/Consumer.hpp" #include "RTC/Consumer.hpp"
#include "RTC/RtpStreamSend.hpp" #include "RTC/RtpStreamSend.hpp"
#include "RTC/SeqManager.hpp" #include "RTC/SeqManager.hpp"
#include "RTC/Shared.hpp"
#include <map> #include <map>
namespace RTC namespace RTC
...@@ -13,6 +14,7 @@ namespace RTC ...@@ -13,6 +14,7 @@ namespace RTC
{ {
public: public:
SvcConsumer( SvcConsumer(
RTC::Shared* shared,
const std::string& id, const std::string& id,
const std::string& producerId, const std::string& producerId,
RTC::Consumer::Listener* listener, RTC::Consumer::Listener* listener,
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include "RTC/SctpAssociation.hpp" #include "RTC/SctpAssociation.hpp"
#include "RTC/SctpListener.hpp" #include "RTC/SctpListener.hpp"
#include "RTC/Shared.hpp"
#ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
#include "RTC/SenderBandwidthEstimator.hpp" #include "RTC/SenderBandwidthEstimator.hpp"
#endif #endif
...@@ -119,7 +120,7 @@ namespace RTC ...@@ -119,7 +120,7 @@ namespace RTC
}; };
public: public:
Transport(const std::string& id, Listener* listener, json& data); Transport(RTC::Shared* shared, const std::string& id, Listener* listener, json& data);
virtual ~Transport(); virtual ~Transport();
public: public:
...@@ -290,6 +291,7 @@ namespace RTC ...@@ -290,6 +291,7 @@ namespace RTC
const std::string id; const std::string id;
protected: protected:
RTC::Shared* shared{ nullptr };
size_t maxMessageSize{ 262144u }; size_t maxMessageSize{ 262144u };
// Allocated by this. // Allocated by this.
RTC::SctpAssociation* sctpAssociation{ nullptr }; RTC::SctpAssociation* sctpAssociation{ nullptr };
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "Channel/ChannelRequest.hpp" #include "Channel/ChannelRequest.hpp"
#include "RTC/IceCandidate.hpp" #include "RTC/IceCandidate.hpp"
#include "RTC/Shared.hpp"
#include "RTC/StunPacket.hpp" #include "RTC/StunPacket.hpp"
#include "RTC/TcpConnection.hpp" #include "RTC/TcpConnection.hpp"
#include "RTC/TcpServer.hpp" #include "RTC/TcpServer.hpp"
...@@ -47,7 +48,7 @@ namespace RTC ...@@ -47,7 +48,7 @@ namespace RTC
}; };
public: public:
WebRtcServer(const std::string& id, json& data); WebRtcServer(RTC::Shared* shared, const std::string& id, json& data);
~WebRtcServer(); ~WebRtcServer();
public: public:
...@@ -97,6 +98,8 @@ namespace RTC ...@@ -97,6 +98,8 @@ namespace RTC
const std::string id; const std::string id;
private: private:
// Passed by argument.
RTC::Shared* shared{ nullptr };
// Vector of UdpSockets and TcpServers in the user given order. // Vector of UdpSockets and TcpServers in the user given order.
std::vector<UdpSocketOrTcpServer> udpSocketOrTcpServers; std::vector<UdpSocketOrTcpServer> udpSocketOrTcpServers;
// Set of WebRtcTransports. // Set of WebRtcTransports.
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#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/Shared.hpp"
#include "RTC/SrtpSession.hpp" #include "RTC/SrtpSession.hpp"
#include "RTC/StunPacket.hpp" #include "RTC/StunPacket.hpp"
#include "RTC/TcpConnection.hpp" #include "RTC/TcpConnection.hpp"
...@@ -49,8 +50,10 @@ namespace RTC ...@@ -49,8 +50,10 @@ namespace RTC
}; };
public: public:
WebRtcTransport(const std::string& id, RTC::Transport::Listener* listener, json& data);
WebRtcTransport( WebRtcTransport(
RTC::Shared* shared, const std::string& id, RTC::Transport::Listener* listener, json& data);
WebRtcTransport(
RTC::Shared* shared,
const std::string& id, const std::string& id,
RTC::Transport::Listener* listener, RTC::Transport::Listener* listener,
WebRtcTransportListener* webRtcTransportListener, WebRtcTransportListener* webRtcTransportListener,
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "PayloadChannel/PayloadChannelRequest.hpp" #include "PayloadChannel/PayloadChannelRequest.hpp"
#include "PayloadChannel/PayloadChannelSocket.hpp" #include "PayloadChannel/PayloadChannelSocket.hpp"
#include "RTC/Router.hpp" #include "RTC/Router.hpp"
#include "RTC/Shared.hpp"
#include "RTC/WebRtcServer.hpp" #include "RTC/WebRtcServer.hpp"
#include "handles/SignalsHandler.hpp" #include "handles/SignalsHandler.hpp"
#include <absl/container/flat_hash_map.h> #include <absl/container/flat_hash_map.h>
...@@ -68,6 +69,7 @@ private: ...@@ -68,6 +69,7 @@ private:
PayloadChannel::PayloadChannelSocket* payloadChannel{ nullptr }; PayloadChannel::PayloadChannelSocket* payloadChannel{ nullptr };
// Allocated by this. // Allocated by this.
SignalsHandler* signalsHandler{ nullptr }; SignalsHandler* signalsHandler{ nullptr };
RTC::Shared* shared{ nullptr };
absl::flat_hash_map<std::string, RTC::WebRtcServer*> mapWebRtcServers; absl::flat_hash_map<std::string, RTC::WebRtcServer*> mapWebRtcServers;
absl::flat_hash_map<std::string, RTC::Router*> mapRouters; absl::flat_hash_map<std::string, RTC::Router*> mapRouters;
// Others. // Others.
......
...@@ -49,7 +49,7 @@ common_sources = [ ...@@ -49,7 +49,7 @@ common_sources = [
'src/MediaSoupErrors.cpp', 'src/MediaSoupErrors.cpp',
'src/Settings.cpp', 'src/Settings.cpp',
'src/Worker.cpp', 'src/Worker.cpp',
'src/ChannelMessageHandlers.cpp', 'src/ChannelMessageRegistrator.cpp',
'src/Utils/Crypto.cpp', 'src/Utils/Crypto.cpp',
'src/Utils/File.cpp', 'src/Utils/File.cpp',
'src/Utils/IP.cpp', 'src/Utils/IP.cpp',
...@@ -97,6 +97,7 @@ common_sources = [ ...@@ -97,6 +97,7 @@ common_sources = [
'src/RTC/SctpListener.cpp', 'src/RTC/SctpListener.cpp',
'src/RTC/SenderBandwidthEstimator.cpp', 'src/RTC/SenderBandwidthEstimator.cpp',
'src/RTC/SeqManager.cpp', 'src/RTC/SeqManager.cpp',
'src/RTC/Shared.cpp',
'src/RTC/SimpleConsumer.cpp', 'src/RTC/SimpleConsumer.cpp',
'src/RTC/SimulcastConsumer.cpp', 'src/RTC/SimulcastConsumer.cpp',
'src/RTC/SrtpSession.cpp', 'src/RTC/SrtpSession.cpp',
......
...@@ -6,68 +6,52 @@ ...@@ -6,68 +6,52 @@
namespace Channel namespace Channel
{ {
/* Class variables. */ ChannelNotifier::ChannelNotifier(Channel::ChannelSocket* channel) : channel(channel)
thread_local Channel::ChannelSocket* ChannelNotifier::channel{ nullptr };
/* Static methods. */
void ChannelNotifier::ClassInit(Channel::ChannelSocket* channel)
{ {
MS_TRACE(); MS_TRACE();
ChannelNotifier::channel = channel;
} }
void ChannelNotifier::Emit(uint64_t targetId, const char* event) void ChannelNotifier::Emit(uint64_t targetId, const char* event)
{ {
MS_TRACE(); MS_TRACE();
MS_ASSERT(ChannelNotifier::channel, "channel unset");
json jsonNotification = json::object(); json jsonNotification = json::object();
jsonNotification["targetId"] = targetId; jsonNotification["targetId"] = targetId;
jsonNotification["event"] = event; jsonNotification["event"] = event;
ChannelNotifier::channel->Send(jsonNotification); this->channel->Send(jsonNotification);
} }
void ChannelNotifier::Emit(const std::string& targetId, const char* event) void ChannelNotifier::Emit(const std::string& targetId, const char* event)
{ {
MS_TRACE(); MS_TRACE();
MS_ASSERT(ChannelNotifier::channel, "channel unset");
json jsonNotification = json::object(); json jsonNotification = json::object();
jsonNotification["targetId"] = targetId; jsonNotification["targetId"] = targetId;
jsonNotification["event"] = event; jsonNotification["event"] = event;
ChannelNotifier::channel->Send(jsonNotification); this->channel->Send(jsonNotification);
} }
void ChannelNotifier::Emit(const std::string& targetId, const char* event, json& data) void ChannelNotifier::Emit(const std::string& targetId, const char* event, json& data)
{ {
MS_TRACE(); MS_TRACE();
MS_ASSERT(ChannelNotifier::channel, "channel unset");
json jsonNotification = json::object(); json jsonNotification = json::object();
jsonNotification["targetId"] = targetId; jsonNotification["targetId"] = targetId;
jsonNotification["event"] = event; jsonNotification["event"] = event;
jsonNotification["data"] = data; jsonNotification["data"] = data;
ChannelNotifier::channel->Send(jsonNotification); this->channel->Send(jsonNotification);
} }
void ChannelNotifier::Emit(const std::string& targetId, const char* event, const std::string& data) void ChannelNotifier::Emit(const std::string& targetId, const char* event, const std::string& data)
{ {
MS_TRACE(); MS_TRACE();
MS_ASSERT(ChannelNotifier::channel, "channel unset");
std::string notification("{\"targetId\":\""); std::string notification("{\"targetId\":\"");
notification.append(targetId); notification.append(targetId);
...@@ -77,6 +61,6 @@ namespace Channel ...@@ -77,6 +61,6 @@ namespace Channel
notification.append(data); notification.append(data);
notification.append("}"); notification.append("}");
ChannelNotifier::channel->Send(notification); this->channel->Send(notification);
} }
} // namespace Channel } // namespace Channel
#define MS_CLASS "ChannelMessageHandlers" #define MS_CLASS "ChannelMessageRegistrator"
// #define MS_LOG_DEV_LEVEL 3 // #define MS_LOG_DEV_LEVEL 3
#include "ChannelMessageHandlers.hpp" #include "ChannelMessageRegistrator.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
/* Class variables. */ ChannelMessageRegistrator::ChannelMessageRegistrator()
{
MS_TRACE();
}
thread_local absl::flat_hash_map<std::string, Channel::ChannelSocket::RequestHandler*> ChannelMessageRegistrator::~ChannelMessageRegistrator()
ChannelMessageHandlers::mapChannelRequestHandlers; {
thread_local absl::flat_hash_map<std::string, PayloadChannel::PayloadChannelSocket::RequestHandler*> MS_TRACE();
ChannelMessageHandlers::mapPayloadChannelRequestHandlers;
thread_local absl::flat_hash_map<std::string, PayloadChannel::PayloadChannelSocket::NotificationHandler*>
ChannelMessageHandlers::mapPayloadChannelNotificationHandlers;
/* Class methods. */ this->mapChannelRequestHandlers.clear();
this->mapPayloadChannelRequestHandlers.clear();
this->mapPayloadChannelNotificationHandlers.clear();
}
void ChannelMessageHandlers::FillJson(json& jsonObject) void ChannelMessageRegistrator::FillJson(json& jsonObject)
{ {
MS_TRACE(); MS_TRACE();
...@@ -24,7 +27,7 @@ void ChannelMessageHandlers::FillJson(json& jsonObject) ...@@ -24,7 +27,7 @@ void ChannelMessageHandlers::FillJson(json& jsonObject)
jsonObject["channelRequestHandlers"] = json::array(); jsonObject["channelRequestHandlers"] = json::array();
auto jsonChannelRequestHandlersIt = jsonObject.find("channelRequestHandlers"); auto jsonChannelRequestHandlersIt = jsonObject.find("channelRequestHandlers");
for (const auto& kv : ChannelMessageHandlers::mapChannelRequestHandlers) for (const auto& kv : this->mapChannelRequestHandlers)
{ {
const auto& handlerId = kv.first; const auto& handlerId = kv.first;
...@@ -35,7 +38,7 @@ void ChannelMessageHandlers::FillJson(json& jsonObject) ...@@ -35,7 +38,7 @@ void ChannelMessageHandlers::FillJson(json& jsonObject)
jsonObject["payloadChannelRequestHandlers"] = json::array(); jsonObject["payloadChannelRequestHandlers"] = json::array();
auto jsonPayloadChannelRequestHandlersIt = jsonObject.find("payloadChannelRequestHandlers"); auto jsonPayloadChannelRequestHandlersIt = jsonObject.find("payloadChannelRequestHandlers");
for (const auto& kv : ChannelMessageHandlers::mapPayloadChannelRequestHandlers) for (const auto& kv : this->mapPayloadChannelRequestHandlers)
{ {
const auto& handlerId = kv.first; const auto& handlerId = kv.first;
...@@ -47,7 +50,7 @@ void ChannelMessageHandlers::FillJson(json& jsonObject) ...@@ -47,7 +50,7 @@ void ChannelMessageHandlers::FillJson(json& jsonObject)
auto jsonPayloadChannelNotificationHandlersIt = auto jsonPayloadChannelNotificationHandlersIt =
jsonObject.find("payloadChannelNotificationHandlers"); jsonObject.find("payloadChannelNotificationHandlers");
for (const auto& kv : ChannelMessageHandlers::mapPayloadChannelNotificationHandlers) for (const auto& kv : this->mapPayloadChannelNotificationHandlers)
{ {
const auto& handlerId = kv.first; const auto& handlerId = kv.first;
...@@ -55,7 +58,7 @@ void ChannelMessageHandlers::FillJson(json& jsonObject) ...@@ -55,7 +58,7 @@ void ChannelMessageHandlers::FillJson(json& jsonObject)
} }
} }
void ChannelMessageHandlers::RegisterHandler( void ChannelMessageRegistrator::RegisterHandler(
const std::string& id, const std::string& id,
Channel::ChannelSocket::RequestHandler* channelRequestHandler, Channel::ChannelSocket::RequestHandler* channelRequestHandler,
PayloadChannel::PayloadChannelSocket::RequestHandler* payloadChannelRequestHandler, PayloadChannel::PayloadChannelSocket::RequestHandler* payloadChannelRequestHandler,
...@@ -65,74 +68,69 @@ void ChannelMessageHandlers::RegisterHandler( ...@@ -65,74 +68,69 @@ void ChannelMessageHandlers::RegisterHandler(
if (channelRequestHandler != nullptr) if (channelRequestHandler != nullptr)
{ {
if ( if (this->mapChannelRequestHandlers.find(id) != this->mapChannelRequestHandlers.end())
ChannelMessageHandlers::mapChannelRequestHandlers.find(id) !=
ChannelMessageHandlers::mapChannelRequestHandlers.end())
{ {
MS_THROW_ERROR("Channel request handler with ID %s already exists", id.c_str()); MS_THROW_ERROR("Channel request handler with ID %s already exists", id.c_str());
} }
ChannelMessageHandlers::mapChannelRequestHandlers[id] = channelRequestHandler; this->mapChannelRequestHandlers[id] = channelRequestHandler;
} }
if (payloadChannelRequestHandler != nullptr) if (payloadChannelRequestHandler != nullptr)
{ {
if ( if (this->mapPayloadChannelRequestHandlers.find(id) != this->mapPayloadChannelRequestHandlers.end())
ChannelMessageHandlers::mapPayloadChannelRequestHandlers.find(id) !=
ChannelMessageHandlers::mapPayloadChannelRequestHandlers.end())
{ {
if (channelRequestHandler != nullptr) if (channelRequestHandler != nullptr)
{ {
ChannelMessageHandlers::mapChannelRequestHandlers.erase(id); this->mapChannelRequestHandlers.erase(id);
} }
MS_THROW_ERROR("PayloadChannel request handler with ID %s already exists", id.c_str()); MS_THROW_ERROR("PayloadChannel request handler with ID %s already exists", id.c_str());
} }
ChannelMessageHandlers::mapPayloadChannelRequestHandlers[id] = payloadChannelRequestHandler; this->mapPayloadChannelRequestHandlers[id] = payloadChannelRequestHandler;
} }
if (payloadChannelNotificationHandler != nullptr) if (payloadChannelNotificationHandler != nullptr)
{ {
if ( if (
ChannelMessageHandlers::mapPayloadChannelNotificationHandlers.find(id) != this->mapPayloadChannelNotificationHandlers.find(id) !=
ChannelMessageHandlers::mapPayloadChannelNotificationHandlers.end()) this->mapPayloadChannelNotificationHandlers.end())
{ {
if (channelRequestHandler != nullptr) if (channelRequestHandler != nullptr)
{ {
ChannelMessageHandlers::mapChannelRequestHandlers.erase(id); this->mapChannelRequestHandlers.erase(id);
} }
if (payloadChannelRequestHandler != nullptr) if (payloadChannelRequestHandler != nullptr)
{ {
ChannelMessageHandlers::mapPayloadChannelRequestHandlers.erase(id); this->mapPayloadChannelRequestHandlers.erase(id);
} }
MS_THROW_ERROR("PayloadChannel notification handler with ID %s already exists", id.c_str()); MS_THROW_ERROR("PayloadChannel notification handler with ID %s already exists", id.c_str());
} }
ChannelMessageHandlers::mapPayloadChannelNotificationHandlers[id] = this->mapPayloadChannelNotificationHandlers[id] = payloadChannelNotificationHandler;
payloadChannelNotificationHandler;
} }
} }
void ChannelMessageHandlers::UnregisterHandler(const std::string& id) void ChannelMessageRegistrator::UnregisterHandler(const std::string& id)
{ {
MS_TRACE(); MS_TRACE();
ChannelMessageHandlers::mapChannelRequestHandlers.erase(id); this->mapChannelRequestHandlers.erase(id);
ChannelMessageHandlers::mapPayloadChannelRequestHandlers.erase(id); this->mapPayloadChannelRequestHandlers.erase(id);
ChannelMessageHandlers::mapPayloadChannelNotificationHandlers.erase(id); this->mapPayloadChannelNotificationHandlers.erase(id);
} }
Channel::ChannelSocket::RequestHandler* ChannelMessageHandlers::GetChannelRequestHandler( Channel::ChannelSocket::RequestHandler* ChannelMessageRegistrator::GetChannelRequestHandler(
const std::string& id) const std::string& id)
{ {
MS_TRACE(); MS_TRACE();
auto it = ChannelMessageHandlers::mapChannelRequestHandlers.find(id); auto it = this->mapChannelRequestHandlers.find(id);
if (it != ChannelMessageHandlers::mapChannelRequestHandlers.end()) if (it != this->mapChannelRequestHandlers.end())
{ {
return it->second; return it->second;
} }
...@@ -142,14 +140,14 @@ Channel::ChannelSocket::RequestHandler* ChannelMessageHandlers::GetChannelReques ...@@ -142,14 +140,14 @@ Channel::ChannelSocket::RequestHandler* ChannelMessageHandlers::GetChannelReques
} }
} }
PayloadChannel::PayloadChannelSocket::RequestHandler* ChannelMessageHandlers::GetPayloadChannelRequestHandler( PayloadChannel::PayloadChannelSocket::RequestHandler* ChannelMessageRegistrator::GetPayloadChannelRequestHandler(
const std::string& id) const std::string& id)
{ {
MS_TRACE(); MS_TRACE();
auto it = ChannelMessageHandlers::mapPayloadChannelRequestHandlers.find(id); auto it = this->mapPayloadChannelRequestHandlers.find(id);
if (it != ChannelMessageHandlers::mapPayloadChannelRequestHandlers.end()) if (it != this->mapPayloadChannelRequestHandlers.end())
{ {
return it->second; return it->second;
} }
...@@ -159,14 +157,14 @@ PayloadChannel::PayloadChannelSocket::RequestHandler* ChannelMessageHandlers::Ge ...@@ -159,14 +157,14 @@ PayloadChannel::PayloadChannelSocket::RequestHandler* ChannelMessageHandlers::Ge
} }
} }
PayloadChannel::PayloadChannelSocket::NotificationHandler* ChannelMessageHandlers:: PayloadChannel::PayloadChannelSocket::NotificationHandler* ChannelMessageRegistrator::
GetPayloadChannelNotificationHandler(const std::string& id) GetPayloadChannelNotificationHandler(const std::string& id)
{ {
MS_TRACE(); MS_TRACE();
auto it = ChannelMessageHandlers::mapPayloadChannelNotificationHandlers.find(id); auto it = this->mapPayloadChannelNotificationHandlers.find(id);
if (it != ChannelMessageHandlers::mapPayloadChannelNotificationHandlers.end()) if (it != this->mapPayloadChannelNotificationHandlers.end())
{ {
return it->second; return it->second;
} }
......
...@@ -6,17 +6,10 @@ ...@@ -6,17 +6,10 @@
namespace PayloadChannel namespace PayloadChannel
{ {
/* Class variables. */ PayloadChannelNotifier::PayloadChannelNotifier(PayloadChannel::PayloadChannelSocket* payloadChannel)
: payloadChannel(payloadChannel)
thread_local PayloadChannel::PayloadChannelSocket* PayloadChannelNotifier::payloadChannel{ nullptr };
/* Static methods. */
void PayloadChannelNotifier::ClassInit(PayloadChannel::PayloadChannelSocket* payloadChannel)
{ {
MS_TRACE(); MS_TRACE();
PayloadChannelNotifier::payloadChannel = payloadChannel;
} }
void PayloadChannelNotifier::Emit( void PayloadChannelNotifier::Emit(
...@@ -24,8 +17,6 @@ namespace PayloadChannel ...@@ -24,8 +17,6 @@ namespace PayloadChannel
{ {
MS_TRACE(); MS_TRACE();
MS_ASSERT(PayloadChannelNotifier::payloadChannel, "payloadChannel unset");
std::string notification("{\"targetId\":\""); std::string notification("{\"targetId\":\"");
notification.append(targetId); notification.append(targetId);
...@@ -33,7 +24,7 @@ namespace PayloadChannel ...@@ -33,7 +24,7 @@ namespace PayloadChannel
notification.append(event); notification.append(event);
notification.append("\"}"); notification.append("\"}");
PayloadChannelNotifier::payloadChannel->Send(notification, payload, payloadLen); this->payloadChannel->Send(notification, payload, payloadLen);
} }
void PayloadChannelNotifier::Emit( void PayloadChannelNotifier::Emit(
...@@ -41,14 +32,12 @@ namespace PayloadChannel ...@@ -41,14 +32,12 @@ namespace PayloadChannel
{ {
MS_TRACE(); MS_TRACE();
MS_ASSERT(PayloadChannelNotifier::payloadChannel, "payloadChannel unset");
json jsonNotification = json::object(); json jsonNotification = json::object();
jsonNotification["targetId"] = targetId; jsonNotification["targetId"] = targetId;
jsonNotification["event"] = event; jsonNotification["event"] = event;
jsonNotification["data"] = data; jsonNotification["data"] = data;
PayloadChannelNotifier::payloadChannel->Send(jsonNotification, payload, payloadLen); this->payloadChannel->Send(jsonNotification, payload, payloadLen);
} }
} // namespace PayloadChannel } // namespace PayloadChannel
#define MS_CLASS "RTC::ActiveSpeakerObserver" #define MS_CLASS "RTC::ActiveSpeakerObserver"
#include "RTC/ActiveSpeakerObserver.hpp" #include "RTC/ActiveSpeakerObserver.hpp"
#include "ChannelMessageHandlers.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "Channel/ChannelNotifier.hpp"
#include "RTC/RtpDictionaries.hpp" #include "RTC/RtpDictionaries.hpp"
namespace RTC namespace RTC
...@@ -97,8 +95,8 @@ namespace RTC ...@@ -97,8 +95,8 @@ namespace RTC
} }
ActiveSpeakerObserver::ActiveSpeakerObserver( ActiveSpeakerObserver::ActiveSpeakerObserver(
const std::string& id, RTC::RtpObserver::Listener* listener, json& data) RTC::Shared* shared, const std::string& id, RTC::RtpObserver::Listener* listener, json& data)
: RTC::RtpObserver(id, listener) : RTC::RtpObserver(shared, id, listener)
{ {
MS_TRACE(); MS_TRACE();
...@@ -121,7 +119,7 @@ namespace RTC ...@@ -121,7 +119,7 @@ namespace RTC
this->periodicTimer->Start(interval, interval); this->periodicTimer->Start(interval, interval);
// NOTE: This may throw. // NOTE: This may throw.
ChannelMessageHandlers::RegisterHandler( this->shared->channelMessageRegistrator->RegisterHandler(
this->id, this->id,
/*channelRequestHandler*/ this, /*channelRequestHandler*/ this,
/*payloadChannelRequestHandler*/ nullptr, /*payloadChannelRequestHandler*/ nullptr,
...@@ -132,7 +130,7 @@ namespace RTC ...@@ -132,7 +130,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
ChannelMessageHandlers::UnregisterHandler(this->id); this->shared->channelMessageRegistrator->UnregisterHandler(this->id);
delete this->periodicTimer; delete this->periodicTimer;
...@@ -280,7 +278,7 @@ namespace RTC ...@@ -280,7 +278,7 @@ namespace RTC
json data = json::object(); json data = json::object();
data["producerId"] = this->dominantId; data["producerId"] = this->dominantId;
Channel::ChannelNotifier::Emit(this->id, "dominantspeaker", data); this->shared->channelNotifier->Emit(this->id, "dominantspeaker", data);
} }
} }
......
...@@ -2,11 +2,9 @@ ...@@ -2,11 +2,9 @@
// #define MS_LOG_DEV_LEVEL 3 // #define MS_LOG_DEV_LEVEL 3
#include "RTC/AudioLevelObserver.hpp" #include "RTC/AudioLevelObserver.hpp"
#include "ChannelMessageHandlers.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "Channel/ChannelNotifier.hpp"
#include "RTC/RtpDictionaries.hpp" #include "RTC/RtpDictionaries.hpp"
#include <cmath> // std::lround() #include <cmath> // std::lround()
#include <map> #include <map>
...@@ -16,8 +14,8 @@ namespace RTC ...@@ -16,8 +14,8 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
AudioLevelObserver::AudioLevelObserver( AudioLevelObserver::AudioLevelObserver(
const std::string& id, RTC::RtpObserver::Listener* listener, json& data) RTC::Shared* shared, const std::string& id, RTC::RtpObserver::Listener* listener, json& data)
: RTC::RtpObserver(id, listener) : RTC::RtpObserver(shared, id, listener)
{ {
MS_TRACE(); MS_TRACE();
...@@ -65,7 +63,7 @@ namespace RTC ...@@ -65,7 +63,7 @@ namespace RTC
this->periodicTimer->Start(this->interval, this->interval); this->periodicTimer->Start(this->interval, this->interval);
// NOTE: This may throw. // NOTE: This may throw.
ChannelMessageHandlers::RegisterHandler( this->shared->channelMessageRegistrator->RegisterHandler(
this->id, this->id,
/*channelRequestHandler*/ this, /*channelRequestHandler*/ this,
/*payloadChannelRequestHandler*/ nullptr, /*payloadChannelRequestHandler*/ nullptr,
...@@ -76,7 +74,7 @@ namespace RTC ...@@ -76,7 +74,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
ChannelMessageHandlers::UnregisterHandler(this->id); this->shared->channelMessageRegistrator->UnregisterHandler(this->id);
delete this->periodicTimer; delete this->periodicTimer;
} }
...@@ -143,7 +141,7 @@ namespace RTC ...@@ -143,7 +141,7 @@ namespace RTC
{ {
this->silence = true; this->silence = true;
Channel::ChannelNotifier::Emit(this->id, "silence"); this->shared->channelNotifier->Emit(this->id, "silence");
} }
} }
...@@ -195,13 +193,13 @@ namespace RTC ...@@ -195,13 +193,13 @@ namespace RTC
jsonEntry["volume"] = rit->first; jsonEntry["volume"] = rit->first;
} }
Channel::ChannelNotifier::Emit(this->id, "volumes", data); this->shared->channelNotifier->Emit(this->id, "volumes", data);
} }
else if (!this->silence) else if (!this->silence)
{ {
this->silence = true; this->silence = true;
Channel::ChannelNotifier::Emit(this->id, "silence"); this->shared->channelNotifier->Emit(this->id, "silence");
} }
} }
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "DepLibUV.hpp" #include "DepLibUV.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Channel/ChannelNotifier.hpp"
#include <iterator> // std::ostream_iterator #include <iterator> // std::ostream_iterator
#include <sstream> // std::ostringstream #include <sstream> // std::ostringstream
...@@ -14,12 +13,13 @@ namespace RTC ...@@ -14,12 +13,13 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
Consumer::Consumer( Consumer::Consumer(
RTC::Shared* shared,
const std::string& id, const std::string& id,
const std::string& producerId, const std::string& producerId,
Listener* listener, Listener* listener,
json& data, json& data,
RTC::RtpParameters::Type type) RTC::RtpParameters::Type type)
: id(id), producerId(producerId), listener(listener), type(type) : id(id), producerId(producerId), shared(shared), listener(listener), type(type)
{ {
MS_TRACE(); MS_TRACE();
...@@ -419,7 +419,7 @@ namespace RTC ...@@ -419,7 +419,7 @@ namespace RTC
if (wasActive) if (wasActive)
UserOnPaused(); UserOnPaused();
Channel::ChannelNotifier::Emit(this->id, "producerpause"); this->shared->channelNotifier->Emit(this->id, "producerpause");
} }
void Consumer::ProducerResumed() void Consumer::ProducerResumed()
...@@ -436,7 +436,7 @@ namespace RTC ...@@ -436,7 +436,7 @@ namespace RTC
if (IsActive()) if (IsActive())
UserOnResumed(); UserOnResumed();
Channel::ChannelNotifier::Emit(this->id, "producerresume"); this->shared->channelNotifier->Emit(this->id, "producerresume");
} }
void Consumer::ProducerRtpStreamScores(const std::vector<uint8_t>* scores) void Consumer::ProducerRtpStreamScores(const std::vector<uint8_t>* scores)
...@@ -457,7 +457,7 @@ namespace RTC ...@@ -457,7 +457,7 @@ namespace RTC
MS_DEBUG_DEV("Producer closed [consumerId:%s]", this->id.c_str()); MS_DEBUG_DEV("Producer closed [consumerId:%s]", this->id.c_str());
Channel::ChannelNotifier::Emit(this->id, "producerclose"); this->shared->channelNotifier->Emit(this->id, "producerclose");
this->listener->OnConsumerProducerClosed(this); this->listener->OnConsumerProducerClosed(this);
} }
...@@ -479,7 +479,7 @@ namespace RTC ...@@ -479,7 +479,7 @@ namespace RTC
if (isRtx) if (isRtx)
data["info"]["isRtx"] = true; data["info"]["isRtx"] = true;
Channel::ChannelNotifier::Emit(this->id, "trace", data); this->shared->channelNotifier->Emit(this->id, "trace", data);
} }
else if (this->traceEventTypes.rtp) else if (this->traceEventTypes.rtp)
{ {
...@@ -494,7 +494,7 @@ namespace RTC ...@@ -494,7 +494,7 @@ namespace RTC
if (isRtx) if (isRtx)
data["info"]["isRtx"] = true; data["info"]["isRtx"] = true;
Channel::ChannelNotifier::Emit(this->id, "trace", data); this->shared->channelNotifier->Emit(this->id, "trace", data);
} }
} }
...@@ -512,7 +512,7 @@ namespace RTC ...@@ -512,7 +512,7 @@ namespace RTC
data["direction"] = "in"; data["direction"] = "in";
data["info"]["ssrc"] = ssrc; data["info"]["ssrc"] = ssrc;
Channel::ChannelNotifier::Emit(this->id, "trace", data); this->shared->channelNotifier->Emit(this->id, "trace", data);
} }
void Consumer::EmitTraceEventFirType(uint32_t ssrc) const void Consumer::EmitTraceEventFirType(uint32_t ssrc) const
...@@ -529,7 +529,7 @@ namespace RTC ...@@ -529,7 +529,7 @@ namespace RTC
data["direction"] = "in"; data["direction"] = "in";
data["info"]["ssrc"] = ssrc; data["info"]["ssrc"] = ssrc;
Channel::ChannelNotifier::Emit(this->id, "trace", data); this->shared->channelNotifier->Emit(this->id, "trace", data);
} }
void Consumer::EmitTraceEventNackType() const void Consumer::EmitTraceEventNackType() const
...@@ -546,6 +546,6 @@ namespace RTC ...@@ -546,6 +546,6 @@ namespace RTC
data["direction"] = "in"; data["direction"] = "in";
data["info"] = json::object(); data["info"] = json::object();
Channel::ChannelNotifier::Emit(this->id, "trace", data); this->shared->channelNotifier->Emit(this->id, "trace", data);
} }
} // namespace RTC } // namespace RTC
...@@ -2,12 +2,10 @@ ...@@ -2,12 +2,10 @@
// #define MS_LOG_DEV_LEVEL 3 // #define MS_LOG_DEV_LEVEL 3
#include "RTC/DataConsumer.hpp" #include "RTC/DataConsumer.hpp"
#include "ChannelMessageHandlers.hpp"
#include "DepLibUV.hpp" #include "DepLibUV.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "Channel/ChannelNotifier.hpp"
#include "RTC/SctpAssociation.hpp" #include "RTC/SctpAssociation.hpp"
#include <stdexcept> #include <stdexcept>
...@@ -16,14 +14,15 @@ namespace RTC ...@@ -16,14 +14,15 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
DataConsumer::DataConsumer( DataConsumer::DataConsumer(
RTC::Shared* shared,
const std::string& id, const std::string& id,
const std::string& dataProducerId, const std::string& dataProducerId,
RTC::SctpAssociation* sctpAssociation, RTC::SctpAssociation* sctpAssociation,
RTC::DataConsumer::Listener* listener, RTC::DataConsumer::Listener* listener,
json& data, json& data,
size_t maxMessageSize) size_t maxMessageSize)
: id(id), dataProducerId(dataProducerId), sctpAssociation(sctpAssociation), listener(listener), : id(id), dataProducerId(dataProducerId), shared(shared), sctpAssociation(sctpAssociation),
maxMessageSize(maxMessageSize) listener(listener), maxMessageSize(maxMessageSize)
{ {
MS_TRACE(); MS_TRACE();
...@@ -67,7 +66,7 @@ namespace RTC ...@@ -67,7 +66,7 @@ namespace RTC
this->protocol = jsonProtocolIt->get<std::string>(); this->protocol = jsonProtocolIt->get<std::string>();
// NOTE: This may throw. // NOTE: This may throw.
ChannelMessageHandlers::RegisterHandler( this->shared->channelMessageRegistrator->RegisterHandler(
this->id, this->id,
/*channelRequestHandler*/ this, /*channelRequestHandler*/ this,
/*payloadChannelRequestHandler*/ this, /*payloadChannelRequestHandler*/ this,
...@@ -78,7 +77,7 @@ namespace RTC ...@@ -78,7 +77,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
ChannelMessageHandlers::UnregisterHandler(this->id); this->shared->channelMessageRegistrator->UnregisterHandler(this->id);
} }
void DataConsumer::FillJson(json& jsonObject) const void DataConsumer::FillJson(json& jsonObject) const
...@@ -355,10 +354,17 @@ namespace RTC ...@@ -355,10 +354,17 @@ namespace RTC
data.append(std::to_string(this->bufferedAmount)); data.append(std::to_string(this->bufferedAmount));
data.append("}"); data.append("}");
Channel::ChannelNotifier::Emit(this->id, "bufferedamountlow", data); this->shared->channelNotifier->Emit(this->id, "bufferedamountlow", data);
} }
} }
void DataConsumer::SctpAssociationSendBufferFull()
{
MS_TRACE();
this->shared->channelNotifier->Emit(this->id, "sctpsendbufferfull");
}
// The caller (Router) is supposed to proceed with the deletion of this DataConsumer // The caller (Router) is supposed to proceed with the deletion of this DataConsumer
// right after calling this method. Otherwise ugly things may happen. // right after calling this method. Otherwise ugly things may happen.
void DataConsumer::DataProducerClosed() void DataConsumer::DataProducerClosed()
...@@ -369,7 +375,7 @@ namespace RTC ...@@ -369,7 +375,7 @@ namespace RTC
MS_DEBUG_DEV("DataProducer closed [dataConsumerId:%s]", this->id.c_str()); MS_DEBUG_DEV("DataProducer closed [dataConsumerId:%s]", this->id.c_str());
Channel::ChannelNotifier::Emit(this->id, "dataproducerclose"); this->shared->channelNotifier->Emit(this->id, "dataproducerclose");
this->listener->OnDataConsumerDataProducerClosed(this); this->listener->OnDataConsumerDataProducerClosed(this);
} }
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// #define MS_LOG_DEV_LEVEL 3 // #define MS_LOG_DEV_LEVEL 3
#include "RTC/DataProducer.hpp" #include "RTC/DataProducer.hpp"
#include "ChannelMessageHandlers.hpp"
#include "DepLibUV.hpp" #include "DepLibUV.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
...@@ -14,8 +13,12 @@ namespace RTC ...@@ -14,8 +13,12 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
DataProducer::DataProducer( DataProducer::DataProducer(
const std::string& id, size_t maxMessageSize, RTC::DataProducer::Listener* listener, json& data) RTC::Shared* shared,
: id(id), maxMessageSize(maxMessageSize), listener(listener) const std::string& id,
size_t maxMessageSize,
RTC::DataProducer::Listener* listener,
json& data)
: id(id), shared(shared), maxMessageSize(maxMessageSize), listener(listener)
{ {
MS_TRACE(); MS_TRACE();
...@@ -59,7 +62,7 @@ namespace RTC ...@@ -59,7 +62,7 @@ namespace RTC
this->protocol = jsonProtocolIt->get<std::string>(); this->protocol = jsonProtocolIt->get<std::string>();
// NOTE: This may throw. // NOTE: This may throw.
ChannelMessageHandlers::RegisterHandler( this->shared->channelMessageRegistrator->RegisterHandler(
this->id, this->id,
/*channelRequestHandler*/ this, /*channelRequestHandler*/ this,
/*payloadChannelRequestHandler*/ nullptr, /*payloadChannelRequestHandler*/ nullptr,
...@@ -70,7 +73,7 @@ namespace RTC ...@@ -70,7 +73,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
ChannelMessageHandlers::UnregisterHandler(this->id); this->shared->channelMessageRegistrator->UnregisterHandler(this->id);
} }
void DataProducer::FillJson(json& jsonObject) const void DataProducer::FillJson(json& jsonObject) const
......
...@@ -2,23 +2,22 @@ ...@@ -2,23 +2,22 @@
// #define MS_LOG_DEV_LEVEL 3 // #define MS_LOG_DEV_LEVEL 3
#include "RTC/DirectTransport.hpp" #include "RTC/DirectTransport.hpp"
#include "ChannelMessageHandlers.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "PayloadChannel/PayloadChannelNotifier.hpp"
namespace RTC namespace RTC
{ {
/* Instance methods. */ /* Instance methods. */
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
DirectTransport::DirectTransport(const std::string& id, RTC::Transport::Listener* listener, json& data) DirectTransport::DirectTransport(
: RTC::Transport::Transport(id, listener, data) RTC::Shared* shared, const std::string& id, RTC::Transport::Listener* listener, json& data)
: RTC::Transport::Transport(shared, id, listener, data)
{ {
MS_TRACE(); MS_TRACE();
// NOTE: This may throw. // NOTE: This may throw.
ChannelMessageHandlers::RegisterHandler( this->shared->channelMessageRegistrator->RegisterHandler(
this->id, this->id,
/*channelRequestHandler*/ this, /*channelRequestHandler*/ this,
/*payloadChannelRequestHandler*/ this, /*payloadChannelRequestHandler*/ this,
...@@ -29,7 +28,7 @@ namespace RTC ...@@ -29,7 +28,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
ChannelMessageHandlers::UnregisterHandler(this->id); this->shared->channelMessageRegistrator->UnregisterHandler(this->id);
} }
void DirectTransport::FillJson(json& jsonObject) const void DirectTransport::FillJson(json& jsonObject) const
...@@ -126,7 +125,7 @@ namespace RTC ...@@ -126,7 +125,7 @@ namespace RTC
size_t len = packet->GetSize(); size_t len = packet->GetSize();
// Notify the Node DirectTransport. // Notify the Node DirectTransport.
PayloadChannel::PayloadChannelNotifier::Emit(consumer->id, "rtp", data, len); this->shared->payloadChannelNotifier->Emit(consumer->id, "rtp", data, len);
if (cb) if (cb)
{ {
...@@ -146,7 +145,7 @@ namespace RTC ...@@ -146,7 +145,7 @@ namespace RTC
size_t len = packet->GetSize(); size_t len = packet->GetSize();
// Notify the Node DirectTransport. // Notify the Node DirectTransport.
PayloadChannel::PayloadChannelNotifier::Emit(this->id, "rtcp", data, len); this->shared->payloadChannelNotifier->Emit(this->id, "rtcp", data, len);
// Increase send transmission. // Increase send transmission.
RTC::Transport::DataSent(len); RTC::Transport::DataSent(len);
...@@ -162,7 +161,7 @@ namespace RTC ...@@ -162,7 +161,7 @@ namespace RTC
size_t len = packet->GetSize(); size_t len = packet->GetSize();
// Notify the Node DirectTransport. // Notify the Node DirectTransport.
PayloadChannel::PayloadChannelNotifier::Emit(this->id, "rtcp", data, len); this->shared->payloadChannelNotifier->Emit(this->id, "rtcp", data, len);
// Increase send transmission. // Increase send transmission.
RTC::Transport::DataSent(len); RTC::Transport::DataSent(len);
...@@ -178,7 +177,7 @@ namespace RTC ...@@ -178,7 +177,7 @@ namespace RTC
data["ppid"] = ppid; data["ppid"] = ppid;
PayloadChannel::PayloadChannelNotifier::Emit(dataConsumer->id, "message", data, msg, len); this->shared->payloadChannelNotifier->Emit(dataConsumer->id, "message", data, msg, len);
// Increase send transmission. // Increase send transmission.
RTC::Transport::DataSent(len); RTC::Transport::DataSent(len);
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// #define MS_LOG_DEV_LEVEL 3 // #define MS_LOG_DEV_LEVEL 3
#include "RTC/PipeConsumer.hpp" #include "RTC/PipeConsumer.hpp"
#include "ChannelMessageHandlers.hpp"
#include "DepLibUV.hpp" #include "DepLibUV.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
...@@ -13,8 +12,12 @@ namespace RTC ...@@ -13,8 +12,12 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
PipeConsumer::PipeConsumer( PipeConsumer::PipeConsumer(
const std::string& id, const std::string& producerId, RTC::Consumer::Listener* listener, json& data) RTC::Shared* shared,
: RTC::Consumer::Consumer(id, producerId, listener, data, RTC::RtpParameters::Type::PIPE) const std::string& id,
const std::string& producerId,
RTC::Consumer::Listener* listener,
json& data)
: RTC::Consumer::Consumer(shared, id, producerId, listener, data, RTC::RtpParameters::Type::PIPE)
{ {
MS_TRACE(); MS_TRACE();
...@@ -31,7 +34,7 @@ namespace RTC ...@@ -31,7 +34,7 @@ namespace RTC
CreateRtpStreams(); CreateRtpStreams();
// NOTE: This may throw. // NOTE: This may throw.
ChannelMessageHandlers::RegisterHandler( this->shared->channelMessageRegistrator->RegisterHandler(
this->id, this->id,
/*channelRequestHandler*/ this, /*channelRequestHandler*/ this,
/*payloadChannelRequestHandler*/ nullptr, /*payloadChannelRequestHandler*/ nullptr,
...@@ -42,7 +45,7 @@ namespace RTC ...@@ -42,7 +45,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
ChannelMessageHandlers::UnregisterHandler(this->id); this->shared->channelMessageRegistrator->UnregisterHandler(this->id);
for (auto* rtpStream : this->rtpStreams) for (auto* rtpStream : this->rtpStreams)
{ {
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// #define MS_LOG_DEV_LEVEL 3 // #define MS_LOG_DEV_LEVEL 3
#include "RTC/PipeTransport.hpp" #include "RTC/PipeTransport.hpp"
#include "ChannelMessageHandlers.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Utils.hpp" #include "Utils.hpp"
...@@ -23,8 +22,9 @@ namespace RTC ...@@ -23,8 +22,9 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
PipeTransport::PipeTransport(const std::string& id, RTC::Transport::Listener* listener, json& data) PipeTransport::PipeTransport(
: RTC::Transport::Transport(id, listener, data) RTC::Shared* shared, const std::string& id, RTC::Transport::Listener* listener, json& data)
: RTC::Transport::Transport(shared, id, listener, data)
{ {
MS_TRACE(); MS_TRACE();
...@@ -96,7 +96,7 @@ namespace RTC ...@@ -96,7 +96,7 @@ namespace RTC
this->udpSocket = new RTC::UdpSocket(this, this->listenIp.ip); this->udpSocket = new RTC::UdpSocket(this, this->listenIp.ip);
// NOTE: This may throw. // NOTE: This may throw.
ChannelMessageHandlers::RegisterHandler( this->shared->channelMessageRegistrator->RegisterHandler(
this->id, this->id,
/*channelRequestHandler*/ this, /*channelRequestHandler*/ this,
/*payloadChannelRequestHandler*/ this, /*payloadChannelRequestHandler*/ this,
...@@ -117,7 +117,7 @@ namespace RTC ...@@ -117,7 +117,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
ChannelMessageHandlers::UnregisterHandler(this->id); this->shared->channelMessageRegistrator->UnregisterHandler(this->id);
delete this->udpSocket; delete this->udpSocket;
this->udpSocket = nullptr; this->udpSocket = nullptr;
......
...@@ -2,11 +2,9 @@ ...@@ -2,11 +2,9 @@
// #define MS_LOG_DEV_LEVEL 3 // #define MS_LOG_DEV_LEVEL 3
#include "RTC/PlainTransport.hpp" #include "RTC/PlainTransport.hpp"
#include "ChannelMessageHandlers.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "Channel/ChannelNotifier.hpp"
namespace RTC namespace RTC
{ {
...@@ -47,8 +45,8 @@ namespace RTC ...@@ -47,8 +45,8 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
PlainTransport::PlainTransport(const std::string& id, RTC::Transport::Listener* listener, json& data) PlainTransport::PlainTransport(RTC::Shared* shared, const std::string& id, RTC::Transport::Listener* listener, json& data)
: RTC::Transport::Transport(id, listener, data) : RTC::Transport::Transport(shared, id, listener, data)
{ {
MS_TRACE(); MS_TRACE();
...@@ -186,7 +184,7 @@ namespace RTC ...@@ -186,7 +184,7 @@ namespace RTC
} }
// NOTE: This may throw. // NOTE: This may throw.
ChannelMessageHandlers::RegisterHandler( this->shared->channelMessageRegistrator->RegisterHandler(
this->id, this->id,
/*channelRequestHandler*/ this, /*channelRequestHandler*/ this,
/*payloadChannelRequestHandler*/ this, /*payloadChannelRequestHandler*/ this,
...@@ -208,7 +206,7 @@ namespace RTC ...@@ -208,7 +206,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
ChannelMessageHandlers::UnregisterHandler(this->id); this->shared->channelMessageRegistrator->UnregisterHandler(this->id);
delete this->udpSocket; delete this->udpSocket;
this->udpSocket = nullptr; this->udpSocket = nullptr;
...@@ -943,7 +941,7 @@ namespace RTC ...@@ -943,7 +941,7 @@ namespace RTC
this->tuple->FillJson(data["tuple"]); this->tuple->FillJson(data["tuple"]);
Channel::ChannelNotifier::Emit(this->id, "tuple", data); this->shared->channelNotifier->Emit(this->id, "tuple", data);
RTC::Transport::Connected(); RTC::Transport::Connected();
} }
...@@ -1010,7 +1008,7 @@ namespace RTC ...@@ -1010,7 +1008,7 @@ namespace RTC
this->tuple->FillJson(data["tuple"]); this->tuple->FillJson(data["tuple"]);
Channel::ChannelNotifier::Emit(this->id, "tuple", data); this->shared->channelNotifier->Emit(this->id, "tuple", data);
RTC::Transport::Connected(); RTC::Transport::Connected();
} }
...@@ -1038,7 +1036,7 @@ namespace RTC ...@@ -1038,7 +1036,7 @@ namespace RTC
this->rtcpTuple->FillJson(data["rtcpTuple"]); this->rtcpTuple->FillJson(data["rtcpTuple"]);
Channel::ChannelNotifier::Emit(this->id, "rtcptuple", data); this->shared->channelNotifier->Emit(this->id, "rtcptuple", data);
} }
// If RTCP-mux verify that the packet's tuple matches our RTP tuple. // If RTCP-mux verify that the packet's tuple matches our RTP tuple.
else if (this->rtcpMux && !this->tuple->Compare(tuple)) else if (this->rtcpMux && !this->tuple->Compare(tuple))
...@@ -1100,7 +1098,7 @@ namespace RTC ...@@ -1100,7 +1098,7 @@ namespace RTC
this->tuple->FillJson(data["tuple"]); this->tuple->FillJson(data["tuple"]);
Channel::ChannelNotifier::Emit(this->id, "tuple", data); this->shared->channelNotifier->Emit(this->id, "tuple", data);
RTC::Transport::Connected(); RTC::Transport::Connected();
} }
......
...@@ -2,12 +2,10 @@ ...@@ -2,12 +2,10 @@
// #define MS_LOG_DEV_LEVEL 3 // #define MS_LOG_DEV_LEVEL 3
#include "RTC/Producer.hpp" #include "RTC/Producer.hpp"
#include "ChannelMessageHandlers.hpp"
#include "DepLibUV.hpp" #include "DepLibUV.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "Channel/ChannelNotifier.hpp"
#include "RTC/Codecs/Tools.hpp" #include "RTC/Codecs/Tools.hpp"
#include "RTC/RTCP/FeedbackPs.hpp" #include "RTC/RTCP/FeedbackPs.hpp"
#include "RTC/RTCP/FeedbackRtp.hpp" #include "RTC/RTCP/FeedbackRtp.hpp"
...@@ -29,8 +27,9 @@ namespace RTC ...@@ -29,8 +27,9 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
Producer::Producer(const std::string& id, RTC::Producer::Listener* listener, json& data) Producer::Producer(
: id(id), listener(listener) RTC::Shared* shared, const std::string& id, RTC::Producer::Listener* listener, json& data)
: id(id), shared(shared), listener(listener)
{ {
MS_TRACE(); MS_TRACE();
...@@ -316,7 +315,7 @@ namespace RTC ...@@ -316,7 +315,7 @@ namespace RTC
} }
// NOTE: This may throw. // NOTE: This may throw.
ChannelMessageHandlers::RegisterHandler( this->shared->channelMessageRegistrator->RegisterHandler(
this->id, this->id,
/*channelRequestHandler*/ this, /*channelRequestHandler*/ this,
/*payloadChannelRequestHandler*/ nullptr, /*payloadChannelRequestHandler*/ nullptr,
...@@ -327,7 +326,7 @@ namespace RTC ...@@ -327,7 +326,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
ChannelMessageHandlers::UnregisterHandler(this->id); this->shared->channelMessageRegistrator->UnregisterHandler(this->id);
// Delete all streams. // Delete all streams.
for (auto& kv : this->mapSsrcRtpStream) for (auto& kv : this->mapSsrcRtpStream)
...@@ -1497,7 +1496,7 @@ namespace RTC ...@@ -1497,7 +1496,7 @@ namespace RTC
data["flip"] = this->videoOrientation.flip; data["flip"] = this->videoOrientation.flip;
data["rotation"] = this->videoOrientation.rotation; data["rotation"] = this->videoOrientation.rotation;
Channel::ChannelNotifier::Emit(this->id, "videoorientationchange", data); this->shared->channelNotifier->Emit(this->id, "videoorientationchange", data);
} }
} }
} }
...@@ -1527,7 +1526,7 @@ namespace RTC ...@@ -1527,7 +1526,7 @@ namespace RTC
jsonEntry["score"] = rtpStream->GetScore(); jsonEntry["score"] = rtpStream->GetScore();
} }
Channel::ChannelNotifier::Emit(this->id, "score", data); this->shared->channelNotifier->Emit(this->id, "score", data);
} }
inline void Producer::EmitTraceEventRtpAndKeyFrameTypes(RTC::RtpPacket* packet, bool isRtx) const inline void Producer::EmitTraceEventRtpAndKeyFrameTypes(RTC::RtpPacket* packet, bool isRtx) const
...@@ -1547,7 +1546,7 @@ namespace RTC ...@@ -1547,7 +1546,7 @@ namespace RTC
if (isRtx) if (isRtx)
data["info"]["isRtx"] = true; data["info"]["isRtx"] = true;
Channel::ChannelNotifier::Emit(this->id, "trace", data); this->shared->channelNotifier->Emit(this->id, "trace", data);
} }
else if (this->traceEventTypes.rtp) else if (this->traceEventTypes.rtp)
{ {
...@@ -1562,7 +1561,7 @@ namespace RTC ...@@ -1562,7 +1561,7 @@ namespace RTC
if (isRtx) if (isRtx)
data["info"]["isRtx"] = true; data["info"]["isRtx"] = true;
Channel::ChannelNotifier::Emit(this->id, "trace", data); this->shared->channelNotifier->Emit(this->id, "trace", data);
} }
} }
...@@ -1580,7 +1579,7 @@ namespace RTC ...@@ -1580,7 +1579,7 @@ namespace RTC
data["direction"] = "out"; data["direction"] = "out";
data["info"]["ssrc"] = ssrc; data["info"]["ssrc"] = ssrc;
Channel::ChannelNotifier::Emit(this->id, "trace", data); this->shared->channelNotifier->Emit(this->id, "trace", data);
} }
inline void Producer::EmitTraceEventFirType(uint32_t ssrc) const inline void Producer::EmitTraceEventFirType(uint32_t ssrc) const
...@@ -1597,7 +1596,7 @@ namespace RTC ...@@ -1597,7 +1596,7 @@ namespace RTC
data["direction"] = "out"; data["direction"] = "out";
data["info"]["ssrc"] = ssrc; data["info"]["ssrc"] = ssrc;
Channel::ChannelNotifier::Emit(this->id, "trace", data); this->shared->channelNotifier->Emit(this->id, "trace", data);
} }
inline void Producer::EmitTraceEventNackType() const inline void Producer::EmitTraceEventNackType() const
...@@ -1614,7 +1613,7 @@ namespace RTC ...@@ -1614,7 +1613,7 @@ namespace RTC
data["direction"] = "out"; data["direction"] = "out";
data["info"] = json::object(); data["info"] = json::object();
Channel::ChannelNotifier::Emit(this->id, "trace", data); this->shared->channelNotifier->Emit(this->id, "trace", data);
} }
inline void Producer::OnRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) inline void Producer::OnRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore)
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// #define MS_LOG_DEV_LEVEL 3 // #define MS_LOG_DEV_LEVEL 3
#include "RTC/Router.hpp" #include "RTC/Router.hpp"
#include "ChannelMessageHandlers.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Utils.hpp" #include "Utils.hpp"
...@@ -17,12 +16,13 @@ namespace RTC ...@@ -17,12 +16,13 @@ namespace RTC
{ {
/* Instance methods. */ /* Instance methods. */
Router::Router(const std::string& id, Listener* listener) : id(id), listener(listener) Router::Router(RTC::Shared* shared, const std::string& id, Listener* listener)
: id(id), shared(shared), listener(listener)
{ {
MS_TRACE(); MS_TRACE();
// NOTE: This may throw. // NOTE: This may throw.
ChannelMessageHandlers::RegisterHandler( this->shared->channelMessageRegistrator->RegisterHandler(
this->id, this->id,
/*channelRequestHandler*/ this, /*channelRequestHandler*/ this,
/*payloadChannelRequestHandler*/ nullptr, /*payloadChannelRequestHandler*/ nullptr,
...@@ -33,7 +33,7 @@ namespace RTC ...@@ -33,7 +33,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
ChannelMessageHandlers::UnregisterHandler(this->id); this->shared->channelMessageRegistrator->UnregisterHandler(this->id);
// Close all Transports. // Close all Transports.
for (auto& kv : this->mapTransports) for (auto& kv : this->mapTransports)
...@@ -196,7 +196,8 @@ namespace RTC ...@@ -196,7 +196,8 @@ namespace RTC
SetNewTransportIdFromData(request->data, transportId); SetNewTransportIdFromData(request->data, transportId);
// This may throw. // This may throw.
auto* webRtcTransport = new RTC::WebRtcTransport(transportId, this, request->data); auto* webRtcTransport =
new RTC::WebRtcTransport(this->shared, transportId, this, request->data);
// Insert into the map. // Insert into the map.
this->mapTransports[transportId] = webRtcTransport; this->mapTransports[transportId] = webRtcTransport;
...@@ -281,8 +282,8 @@ namespace RTC ...@@ -281,8 +282,8 @@ namespace RTC
webRtcServer->GetIceCandidates(enableUdp, enableTcp, preferUdp, preferTcp); webRtcServer->GetIceCandidates(enableUdp, enableTcp, preferUdp, preferTcp);
// This may throw. // This may throw.
auto* webRtcTransport = auto* webRtcTransport = new RTC::WebRtcTransport(
new RTC::WebRtcTransport(transportId, this, webRtcServer, iceCandidates, request->data); this->shared, transportId, this, webRtcServer, iceCandidates, request->data);
// Insert into the map. // Insert into the map.
this->mapTransports[transportId] = webRtcTransport; this->mapTransports[transportId] = webRtcTransport;
...@@ -306,7 +307,8 @@ namespace RTC ...@@ -306,7 +307,8 @@ namespace RTC
// This may throw // This may throw
SetNewTransportIdFromData(request->data, transportId); SetNewTransportIdFromData(request->data, transportId);
auto* plainTransport = new RTC::PlainTransport(transportId, this, request->data); auto* plainTransport =
new RTC::PlainTransport(this->shared, transportId, this, request->data);
// Insert into the map. // Insert into the map.
this->mapTransports[transportId] = plainTransport; this->mapTransports[transportId] = plainTransport;
...@@ -329,7 +331,7 @@ namespace RTC ...@@ -329,7 +331,7 @@ namespace RTC
// This may throw // This may throw
SetNewTransportIdFromData(request->data, transportId); SetNewTransportIdFromData(request->data, transportId);
auto* pipeTransport = new RTC::PipeTransport(transportId, this, request->data); auto* pipeTransport = new RTC::PipeTransport(this->shared, transportId, this, request->data);
// Insert into the map. // Insert into the map.
this->mapTransports[transportId] = pipeTransport; this->mapTransports[transportId] = pipeTransport;
...@@ -352,7 +354,8 @@ namespace RTC ...@@ -352,7 +354,8 @@ namespace RTC
// This may throw // This may throw
SetNewTransportIdFromData(request->data, transportId); SetNewTransportIdFromData(request->data, transportId);
auto* directTransport = new RTC::DirectTransport(transportId, this, request->data); auto* directTransport =
new RTC::DirectTransport(this->shared, transportId, this, request->data);
// Insert into the map. // Insert into the map.
this->mapTransports[transportId] = directTransport; this->mapTransports[transportId] = directTransport;
...@@ -376,7 +379,7 @@ namespace RTC ...@@ -376,7 +379,7 @@ namespace RTC
SetNewRtpObserverIdFromData(request->data, rtpObserverId); SetNewRtpObserverIdFromData(request->data, rtpObserverId);
auto* activeSpeakerObserver = auto* activeSpeakerObserver =
new RTC::ActiveSpeakerObserver(rtpObserverId, this, request->data); new RTC::ActiveSpeakerObserver(this->shared, rtpObserverId, this, request->data);
// Insert into the map. // Insert into the map.
this->mapRtpObservers[rtpObserverId] = activeSpeakerObserver; this->mapRtpObservers[rtpObserverId] = activeSpeakerObserver;
...@@ -395,7 +398,8 @@ namespace RTC ...@@ -395,7 +398,8 @@ namespace RTC
// This may throw // This may throw
SetNewRtpObserverIdFromData(request->data, rtpObserverId); SetNewRtpObserverIdFromData(request->data, rtpObserverId);
auto* audioLevelObserver = new RTC::AudioLevelObserver(rtpObserverId, this, request->data); auto* audioLevelObserver =
new RTC::AudioLevelObserver(this->shared, rtpObserverId, this, request->data);
// Insert into the map. // Insert into the map.
this->mapRtpObservers[rtpObserverId] = audioLevelObserver; this->mapRtpObservers[rtpObserverId] = audioLevelObserver;
......
...@@ -9,8 +9,8 @@ namespace RTC ...@@ -9,8 +9,8 @@ namespace RTC
{ {
/* Instance methods. */ /* Instance methods. */
RtpObserver::RtpObserver(const std::string& id, RTC::RtpObserver::Listener* listener) RtpObserver::RtpObserver(RTC::Shared* shared, const std::string& id, RTC::RtpObserver::Listener* listener)
: id(id), listener(listener) : id(id), shared(shared), listener(listener)
{ {
MS_TRACE(); MS_TRACE();
} }
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "DepUsrSCTP.hpp" #include "DepUsrSCTP.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Channel/ChannelNotifier.hpp"
#include <cstdlib> // std::malloc(), std::free() #include <cstdlib> // std::malloc(), std::free()
#include <cstring> // std::memset(), std::memcpy() #include <cstring> // std::memset(), std::memcpy()
#include <string> #include <string>
...@@ -470,7 +469,7 @@ namespace RTC ...@@ -470,7 +469,7 @@ namespace RTC
if (sctpSendBufferFull) if (sctpSendBufferFull)
{ {
Channel::ChannelNotifier::Emit(dataConsumer->id, "sctpsendbufferfull"); dataConsumer->SctpAssociationSendBufferFull();
} }
} }
else if (cb) else if (cb)
......
#define MS_CLASS "Shared"
// #define MS_LOG_DEV_LEVEL 3
#include "RTC/Shared.hpp"
#include "Logger.hpp"
namespace RTC
{
Shared::Shared(
ChannelMessageRegistrator* channelMessageRegistrator,
Channel::ChannelNotifier* channelNotifier,
PayloadChannel::PayloadChannelNotifier* payloadChannelNotifier)
: channelMessageRegistrator(channelMessageRegistrator), channelNotifier(channelNotifier),
payloadChannelNotifier(payloadChannelNotifier)
{
MS_TRACE();
}
Shared::~Shared()
{
MS_TRACE();
delete this->channelMessageRegistrator;
delete this->channelNotifier;
delete this->payloadChannelNotifier;
}
} // namespace RTC
...@@ -2,11 +2,9 @@ ...@@ -2,11 +2,9 @@
// #define MS_LOG_DEV_LEVEL 3 // #define MS_LOG_DEV_LEVEL 3
#include "RTC/SimpleConsumer.hpp" #include "RTC/SimpleConsumer.hpp"
#include "ChannelMessageHandlers.hpp"
#include "DepLibUV.hpp" #include "DepLibUV.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Channel/ChannelNotifier.hpp"
#include "RTC/Codecs/Tools.hpp" #include "RTC/Codecs/Tools.hpp"
namespace RTC namespace RTC
...@@ -14,8 +12,12 @@ namespace RTC ...@@ -14,8 +12,12 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
SimpleConsumer::SimpleConsumer( SimpleConsumer::SimpleConsumer(
const std::string& id, const std::string& producerId, RTC::Consumer::Listener* listener, json& data) RTC::Shared* shared,
: RTC::Consumer::Consumer(id, producerId, listener, data, RTC::RtpParameters::Type::SIMPLE) const std::string& id,
const std::string& producerId,
RTC::Consumer::Listener* listener,
json& data)
: RTC::Consumer::Consumer(shared, id, producerId, listener, data, RTC::RtpParameters::Type::SIMPLE)
{ {
MS_TRACE(); MS_TRACE();
...@@ -53,7 +55,7 @@ namespace RTC ...@@ -53,7 +55,7 @@ namespace RTC
} }
// NOTE: This may throw. // NOTE: This may throw.
ChannelMessageHandlers::RegisterHandler( this->shared->channelMessageRegistrator->RegisterHandler(
this->id, this->id,
/*channelRequestHandler*/ this, /*channelRequestHandler*/ this,
/*payloadChannelRequestHandler*/ nullptr, /*payloadChannelRequestHandler*/ nullptr,
...@@ -64,7 +66,7 @@ namespace RTC ...@@ -64,7 +66,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
ChannelMessageHandlers::UnregisterHandler(this->id); this->shared->channelMessageRegistrator->UnregisterHandler(this->id);
delete this->rtpStream; delete this->rtpStream;
} }
...@@ -621,7 +623,7 @@ namespace RTC ...@@ -621,7 +623,7 @@ namespace RTC
FillJsonScore(data); FillJsonScore(data);
Channel::ChannelNotifier::Emit(this->id, "score", data); this->shared->channelNotifier->Emit(this->id, "score", data);
} }
inline void SimpleConsumer::OnRtpStreamScore( inline void SimpleConsumer::OnRtpStreamScore(
......
...@@ -2,12 +2,10 @@ ...@@ -2,12 +2,10 @@
// #define MS_LOG_DEV_LEVEL 3 // #define MS_LOG_DEV_LEVEL 3
#include "RTC/SimulcastConsumer.hpp" #include "RTC/SimulcastConsumer.hpp"
#include "ChannelMessageHandlers.hpp"
#include "DepLibUV.hpp" #include "DepLibUV.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "Channel/ChannelNotifier.hpp"
#include "RTC/Codecs/Tools.hpp" #include "RTC/Codecs/Tools.hpp"
namespace RTC namespace RTC
...@@ -22,8 +20,13 @@ namespace RTC ...@@ -22,8 +20,13 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
SimulcastConsumer::SimulcastConsumer( SimulcastConsumer::SimulcastConsumer(
const std::string& id, const std::string& producerId, RTC::Consumer::Listener* listener, json& data) RTC::Shared* shared,
: RTC::Consumer::Consumer(id, producerId, listener, data, RTC::RtpParameters::Type::SIMULCAST) const std::string& id,
const std::string& producerId,
RTC::Consumer::Listener* listener,
json& data)
: RTC::Consumer::Consumer(
shared, id, producerId, listener, data, RTC::RtpParameters::Type::SIMULCAST)
{ {
MS_TRACE(); MS_TRACE();
...@@ -122,7 +125,7 @@ namespace RTC ...@@ -122,7 +125,7 @@ namespace RTC
CreateRtpStream(); CreateRtpStream();
// NOTE: This may throw. // NOTE: This may throw.
ChannelMessageHandlers::RegisterHandler( this->shared->channelMessageRegistrator->RegisterHandler(
this->id, this->id,
/*channelRequestHandler*/ this, /*channelRequestHandler*/ this,
/*payloadChannelRequestHandler*/ nullptr, /*payloadChannelRequestHandler*/ nullptr,
...@@ -133,7 +136,7 @@ namespace RTC ...@@ -133,7 +136,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
ChannelMessageHandlers::UnregisterHandler(this->id); this->shared->channelMessageRegistrator->UnregisterHandler(this->id);
delete this->rtpStream; delete this->rtpStream;
} }
...@@ -1458,7 +1461,7 @@ namespace RTC ...@@ -1458,7 +1461,7 @@ namespace RTC
FillJsonScore(data); FillJsonScore(data);
Channel::ChannelNotifier::Emit(this->id, "score", data); this->shared->channelNotifier->Emit(this->id, "score", data);
} }
inline void SimulcastConsumer::EmitLayersChange() const inline void SimulcastConsumer::EmitLayersChange() const
...@@ -1483,7 +1486,7 @@ namespace RTC ...@@ -1483,7 +1486,7 @@ namespace RTC
data = nullptr; data = nullptr;
} }
Channel::ChannelNotifier::Emit(this->id, "layerschange", data); this->shared->channelNotifier->Emit(this->id, "layerschange", data);
} }
inline RTC::RtpStream* SimulcastConsumer::GetProducerCurrentRtpStream() const inline RTC::RtpStream* SimulcastConsumer::GetProducerCurrentRtpStream() const
......
...@@ -2,12 +2,10 @@ ...@@ -2,12 +2,10 @@
// #define MS_LOG_DEV_LEVEL 3 // #define MS_LOG_DEV_LEVEL 3
#include "RTC/SvcConsumer.hpp" #include "RTC/SvcConsumer.hpp"
#include "ChannelMessageHandlers.hpp"
#include "DepLibUV.hpp" #include "DepLibUV.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "Channel/ChannelNotifier.hpp"
#include "RTC/Codecs/Tools.hpp" #include "RTC/Codecs/Tools.hpp"
namespace RTC namespace RTC
...@@ -20,8 +18,12 @@ namespace RTC ...@@ -20,8 +18,12 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
SvcConsumer::SvcConsumer( SvcConsumer::SvcConsumer(
const std::string& id, const std::string& producerId, RTC::Consumer::Listener* listener, json& data) RTC::Shared* shared,
: RTC::Consumer::Consumer(id, producerId, listener, data, RTC::RtpParameters::Type::SVC) const std::string& id,
const std::string& producerId,
RTC::Consumer::Listener* listener,
json& data)
: RTC::Consumer::Consumer(shared, id, producerId, listener, data, RTC::RtpParameters::Type::SVC)
{ {
MS_TRACE(); MS_TRACE();
...@@ -105,7 +107,7 @@ namespace RTC ...@@ -105,7 +107,7 @@ namespace RTC
CreateRtpStream(); CreateRtpStream();
// NOTE: This may throw. // NOTE: This may throw.
ChannelMessageHandlers::RegisterHandler( this->shared->channelMessageRegistrator->RegisterHandler(
this->id, this->id,
/*channelRequestHandler*/ this, /*channelRequestHandler*/ this,
/*payloadChannelRequestHandler*/ nullptr, /*payloadChannelRequestHandler*/ nullptr,
...@@ -116,7 +118,7 @@ namespace RTC ...@@ -116,7 +118,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
ChannelMessageHandlers::UnregisterHandler(this->id); this->shared->channelMessageRegistrator->UnregisterHandler(this->id);
delete this->rtpStream; delete this->rtpStream;
} }
...@@ -1076,7 +1078,7 @@ namespace RTC ...@@ -1076,7 +1078,7 @@ namespace RTC
FillJsonScore(data); FillJsonScore(data);
Channel::ChannelNotifier::Emit(this->id, "score", data); this->shared->channelNotifier->Emit(this->id, "score", data);
} }
inline void SvcConsumer::EmitLayersChange() const inline void SvcConsumer::EmitLayersChange() const
...@@ -1101,7 +1103,7 @@ namespace RTC ...@@ -1101,7 +1103,7 @@ namespace RTC
data = nullptr; data = nullptr;
} }
Channel::ChannelNotifier::Emit(this->id, "layerschange", data); this->shared->channelNotifier->Emit(this->id, "layerschange", data);
} }
inline void SvcConsumer::OnRtpStreamScore( inline void SvcConsumer::OnRtpStreamScore(
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "Channel/ChannelNotifier.hpp"
#include "PayloadChannel/PayloadChannelNotifier.hpp"
#include "RTC/BweType.hpp" #include "RTC/BweType.hpp"
#include "RTC/PipeConsumer.hpp" #include "RTC/PipeConsumer.hpp"
#include "RTC/RTCP/FeedbackPs.hpp" #include "RTC/RTCP/FeedbackPs.hpp"
...@@ -32,9 +30,9 @@ namespace RTC ...@@ -32,9 +30,9 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
Transport::Transport(const std::string& id, Listener* listener, json& data) Transport::Transport(RTC::Shared* shared, const std::string& id, Listener* listener, json& data)
: id(id), listener(listener), recvRtxTransmission(1000u), sendRtxTransmission(1000u), : id(id), shared(shared), listener(listener), recvRtxTransmission(1000u),
sendProbationTransmission(100u) sendRtxTransmission(1000u), sendProbationTransmission(100u)
{ {
MS_TRACE(); MS_TRACE();
...@@ -675,7 +673,7 @@ namespace RTC ...@@ -675,7 +673,7 @@ namespace RTC
SetNewProducerIdFromData(request->data, producerId); SetNewProducerIdFromData(request->data, producerId);
// This may throw. // This may throw.
auto* producer = new RTC::Producer(producerId, this, request->data); auto* producer = new RTC::Producer(this->shared, producerId, this, request->data);
// Insert the Producer into the RtpListener. // Insert the Producer into the RtpListener.
// This may throw. If so, delete the Producer and throw. // This may throw. If so, delete the Producer and throw.
...@@ -862,7 +860,8 @@ namespace RTC ...@@ -862,7 +860,8 @@ namespace RTC
case RTC::RtpParameters::Type::SIMPLE: case RTC::RtpParameters::Type::SIMPLE:
{ {
// This may throw. // This may throw.
consumer = new RTC::SimpleConsumer(consumerId, producerId, this, request->data); consumer =
new RTC::SimpleConsumer(this->shared, consumerId, producerId, this, request->data);
break; break;
} }
...@@ -870,7 +869,8 @@ namespace RTC ...@@ -870,7 +869,8 @@ namespace RTC
case RTC::RtpParameters::Type::SIMULCAST: case RTC::RtpParameters::Type::SIMULCAST:
{ {
// This may throw. // This may throw.
consumer = new RTC::SimulcastConsumer(consumerId, producerId, this, request->data); consumer =
new RTC::SimulcastConsumer(this->shared, consumerId, producerId, this, request->data);
break; break;
} }
...@@ -878,7 +878,8 @@ namespace RTC ...@@ -878,7 +878,8 @@ namespace RTC
case RTC::RtpParameters::Type::SVC: case RTC::RtpParameters::Type::SVC:
{ {
// This may throw. // This may throw.
consumer = new RTC::SvcConsumer(consumerId, producerId, this, request->data); consumer =
new RTC::SvcConsumer(this->shared, consumerId, producerId, this, request->data);
break; break;
} }
...@@ -886,7 +887,8 @@ namespace RTC ...@@ -886,7 +887,8 @@ namespace RTC
case RTC::RtpParameters::Type::PIPE: case RTC::RtpParameters::Type::PIPE:
{ {
// This may throw. // This may throw.
consumer = new RTC::PipeConsumer(consumerId, producerId, this, request->data); consumer =
new RTC::PipeConsumer(this->shared, consumerId, producerId, this, request->data);
break; break;
} }
...@@ -1092,8 +1094,8 @@ namespace RTC ...@@ -1092,8 +1094,8 @@ namespace RTC
SetNewDataProducerIdFromData(request->data, dataProducerId); SetNewDataProducerIdFromData(request->data, dataProducerId);
// This may throw. // This may throw.
auto* dataProducer = auto* dataProducer = new RTC::DataProducer(
new RTC::DataProducer(dataProducerId, this->maxMessageSize, this, request->data); this->shared, dataProducerId, this->maxMessageSize, this, request->data);
// Verify the type of the DataProducer. // Verify the type of the DataProducer.
switch (dataProducer->GetType()) switch (dataProducer->GetType())
...@@ -1198,7 +1200,13 @@ namespace RTC ...@@ -1198,7 +1200,13 @@ namespace RTC
// This may throw. // This may throw.
auto* dataConsumer = new RTC::DataConsumer( auto* dataConsumer = new RTC::DataConsumer(
dataConsumerId, dataProducerId, this->sctpAssociation, this, request->data, this->maxMessageSize); this->shared,
dataConsumerId,
dataProducerId,
this->sctpAssociation,
this,
request->data,
this->maxMessageSize);
// Verify the type of the DataConsumer. // Verify the type of the DataConsumer.
switch (dataConsumer->GetType()) switch (dataConsumer->GetType())
...@@ -2404,7 +2412,7 @@ namespace RTC ...@@ -2404,7 +2412,7 @@ namespace RTC
packet->FillJson(data["info"]); packet->FillJson(data["info"]);
Channel::ChannelNotifier::Emit(this->id, "trace", data); this->shared->channelNotifier->Emit(this->id, "trace", data);
} }
inline void Transport::EmitTraceEventBweType( inline void Transport::EmitTraceEventBweType(
...@@ -2438,7 +2446,7 @@ namespace RTC ...@@ -2438,7 +2446,7 @@ namespace RTC
break; break;
} }
Channel::ChannelNotifier::Emit(this->id, "trace", data); this->shared->channelNotifier->Emit(this->id, "trace", data);
} }
inline void Transport::OnProducerPaused(RTC::Producer* producer) inline void Transport::OnProducerPaused(RTC::Producer* producer)
...@@ -2761,7 +2769,7 @@ namespace RTC ...@@ -2761,7 +2769,7 @@ namespace RTC
data["sctpState"] = "connecting"; data["sctpState"] = "connecting";
Channel::ChannelNotifier::Emit(this->id, "sctpstatechange", data); this->shared->channelNotifier->Emit(this->id, "sctpstatechange", data);
} }
inline void Transport::OnSctpAssociationConnected(RTC::SctpAssociation* /*sctpAssociation*/) inline void Transport::OnSctpAssociationConnected(RTC::SctpAssociation* /*sctpAssociation*/)
...@@ -2784,7 +2792,7 @@ namespace RTC ...@@ -2784,7 +2792,7 @@ namespace RTC
data["sctpState"] = "connected"; data["sctpState"] = "connected";
Channel::ChannelNotifier::Emit(this->id, "sctpstatechange", data); this->shared->channelNotifier->Emit(this->id, "sctpstatechange", data);
} }
inline void Transport::OnSctpAssociationFailed(RTC::SctpAssociation* /*sctpAssociation*/) inline void Transport::OnSctpAssociationFailed(RTC::SctpAssociation* /*sctpAssociation*/)
...@@ -2807,7 +2815,7 @@ namespace RTC ...@@ -2807,7 +2815,7 @@ namespace RTC
data["sctpState"] = "failed"; data["sctpState"] = "failed";
Channel::ChannelNotifier::Emit(this->id, "sctpstatechange", data); this->shared->channelNotifier->Emit(this->id, "sctpstatechange", data);
} }
inline void Transport::OnSctpAssociationClosed(RTC::SctpAssociation* /*sctpAssociation*/) inline void Transport::OnSctpAssociationClosed(RTC::SctpAssociation* /*sctpAssociation*/)
...@@ -2830,7 +2838,7 @@ namespace RTC ...@@ -2830,7 +2838,7 @@ namespace RTC
data["sctpState"] = "closed"; data["sctpState"] = "closed";
Channel::ChannelNotifier::Emit(this->id, "sctpstatechange", data); this->shared->channelNotifier->Emit(this->id, "sctpstatechange", data);
} }
inline void Transport::OnSctpAssociationSendData( inline void Transport::OnSctpAssociationSendData(
......
...@@ -2,11 +2,9 @@ ...@@ -2,11 +2,9 @@
// #define MS_LOG_DEV_LEVEL 3 // #define MS_LOG_DEV_LEVEL 3
#include "RTC/WebRtcServer.hpp" #include "RTC/WebRtcServer.hpp"
#include "ChannelMessageHandlers.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "Channel/ChannelNotifier.hpp"
#include <cmath> // std::pow() #include <cmath> // std::pow()
namespace RTC namespace RTC
...@@ -29,7 +27,8 @@ namespace RTC ...@@ -29,7 +27,8 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
WebRtcServer::WebRtcServer(const std::string& id, json& data) : id(id) WebRtcServer::WebRtcServer(RTC::Shared* shared, const std::string& id, json& data)
: id(id), shared(shared)
{ {
MS_TRACE(); MS_TRACE();
...@@ -139,7 +138,7 @@ namespace RTC ...@@ -139,7 +138,7 @@ namespace RTC
} }
// NOTE: This may throw. // NOTE: This may throw.
ChannelMessageHandlers::RegisterHandler( this->shared->channelMessageRegistrator->RegisterHandler(
this->id, this->id,
/*channelRequestHandler*/ this, /*channelRequestHandler*/ this,
/*payloadChannelRequestHandler*/ nullptr, /*payloadChannelRequestHandler*/ nullptr,
...@@ -167,7 +166,7 @@ namespace RTC ...@@ -167,7 +166,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
ChannelMessageHandlers::UnregisterHandler(this->id); this->shared->channelMessageRegistrator->UnregisterHandler(this->id);
for (auto& item : this->udpSocketOrTcpServers) for (auto& item : this->udpSocketOrTcpServers)
{ {
......
...@@ -2,11 +2,9 @@ ...@@ -2,11 +2,9 @@
// #define MS_LOG_DEV_LEVEL 3 // #define MS_LOG_DEV_LEVEL 3
#include "RTC/WebRtcTransport.hpp" #include "RTC/WebRtcTransport.hpp"
#include "ChannelMessageHandlers.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "Channel/ChannelNotifier.hpp"
#include <cmath> // std::pow() #include <cmath> // std::pow()
namespace RTC namespace RTC
...@@ -29,8 +27,9 @@ namespace RTC ...@@ -29,8 +27,9 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
WebRtcTransport::WebRtcTransport(const std::string& id, RTC::Transport::Listener* listener, json& data) WebRtcTransport::WebRtcTransport(
: RTC::Transport::Transport(id, listener, data) RTC::Shared* shared, const std::string& id, RTC::Transport::Listener* listener, json& data)
: RTC::Transport::Transport(shared, id, listener, data)
{ {
MS_TRACE(); MS_TRACE();
...@@ -206,7 +205,7 @@ namespace RTC ...@@ -206,7 +205,7 @@ namespace RTC
this->dtlsTransport = new RTC::DtlsTransport(this); this->dtlsTransport = new RTC::DtlsTransport(this);
// NOTE: This may throw. // NOTE: This may throw.
ChannelMessageHandlers::RegisterHandler( this->shared->channelMessageRegistrator->RegisterHandler(
this->id, this->id,
/*channelRequestHandler*/ this, /*channelRequestHandler*/ this,
/*payloadChannelRequestHandler*/ this, /*payloadChannelRequestHandler*/ this,
...@@ -248,12 +247,13 @@ namespace RTC ...@@ -248,12 +247,13 @@ namespace RTC
* This constructor is used when the WebRtcTransport uses a WebRtcServer. * This constructor is used when the WebRtcTransport uses a WebRtcServer.
*/ */
WebRtcTransport::WebRtcTransport( WebRtcTransport::WebRtcTransport(
RTC::Shared* shared,
const std::string& id, const std::string& id,
RTC::Transport::Listener* listener, RTC::Transport::Listener* listener,
WebRtcTransportListener* webRtcTransportListener, WebRtcTransportListener* webRtcTransportListener,
std::vector<RTC::IceCandidate>& iceCandidates, std::vector<RTC::IceCandidate>& iceCandidates,
json& data) json& data)
: RTC::Transport::Transport(id, listener, data), : RTC::Transport::Transport(shared, id, listener, data),
webRtcTransportListener(webRtcTransportListener), iceCandidates(iceCandidates) webRtcTransportListener(webRtcTransportListener), iceCandidates(iceCandidates)
{ {
MS_TRACE(); MS_TRACE();
...@@ -274,7 +274,7 @@ namespace RTC ...@@ -274,7 +274,7 @@ namespace RTC
this->webRtcTransportListener->OnWebRtcTransportCreated(this); this->webRtcTransportListener->OnWebRtcTransportCreated(this);
// NOTE: This may throw. // NOTE: This may throw.
ChannelMessageHandlers::RegisterHandler( this->shared->channelMessageRegistrator->RegisterHandler(
this->id, this->id,
/*channelRequestHandler*/ this, /*channelRequestHandler*/ this,
/*payloadChannelRequestHandler*/ this, /*payloadChannelRequestHandler*/ this,
...@@ -300,7 +300,7 @@ namespace RTC ...@@ -300,7 +300,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
ChannelMessageHandlers::UnregisterHandler(this->id); this->shared->channelMessageRegistrator->UnregisterHandler(this->id);
// Must delete the DTLS transport first since it will generate a DTLS alert // Must delete the DTLS transport first since it will generate a DTLS alert
// to be sent. // to be sent.
...@@ -1304,7 +1304,7 @@ namespace RTC ...@@ -1304,7 +1304,7 @@ namespace RTC
this->iceServer->GetSelectedTuple()->FillJson(data["iceSelectedTuple"]); this->iceServer->GetSelectedTuple()->FillJson(data["iceSelectedTuple"]);
Channel::ChannelNotifier::Emit(this->id, "iceselectedtuplechange", data); this->shared->channelNotifier->Emit(this->id, "iceselectedtuplechange", data);
} }
inline void WebRtcTransport::OnIceServerConnected(const RTC::IceServer* /*iceServer*/) inline void WebRtcTransport::OnIceServerConnected(const RTC::IceServer* /*iceServer*/)
...@@ -1318,7 +1318,7 @@ namespace RTC ...@@ -1318,7 +1318,7 @@ namespace RTC
data["iceState"] = "connected"; data["iceState"] = "connected";
Channel::ChannelNotifier::Emit(this->id, "icestatechange", data); this->shared->channelNotifier->Emit(this->id, "icestatechange", data);
// If ready, run the DTLS handler. // If ready, run the DTLS handler.
MayRunDtlsTransport(); MayRunDtlsTransport();
...@@ -1341,7 +1341,7 @@ namespace RTC ...@@ -1341,7 +1341,7 @@ namespace RTC
data["iceState"] = "completed"; data["iceState"] = "completed";
Channel::ChannelNotifier::Emit(this->id, "icestatechange", data); this->shared->channelNotifier->Emit(this->id, "icestatechange", data);
// If ready, run the DTLS handler. // If ready, run the DTLS handler.
MayRunDtlsTransport(); MayRunDtlsTransport();
...@@ -1364,7 +1364,7 @@ namespace RTC ...@@ -1364,7 +1364,7 @@ namespace RTC
data["iceState"] = "disconnected"; data["iceState"] = "disconnected";
Channel::ChannelNotifier::Emit(this->id, "icestatechange", data); this->shared->channelNotifier->Emit(this->id, "icestatechange", data);
// If DTLS was already connected, notify the parent class. // If DTLS was already connected, notify the parent class.
if (this->dtlsTransport->GetState() == RTC::DtlsTransport::DtlsState::CONNECTED) if (this->dtlsTransport->GetState() == RTC::DtlsTransport::DtlsState::CONNECTED)
...@@ -1384,7 +1384,7 @@ namespace RTC ...@@ -1384,7 +1384,7 @@ namespace RTC
data["dtlsState"] = "connecting"; data["dtlsState"] = "connecting";
Channel::ChannelNotifier::Emit(this->id, "dtlsstatechange", data); this->shared->channelNotifier->Emit(this->id, "dtlsstatechange", data);
} }
inline void WebRtcTransport::OnDtlsTransportConnected( inline void WebRtcTransport::OnDtlsTransportConnected(
...@@ -1428,7 +1428,7 @@ namespace RTC ...@@ -1428,7 +1428,7 @@ namespace RTC
data["dtlsState"] = "connected"; data["dtlsState"] = "connected";
data["dtlsRemoteCert"] = remoteCert; data["dtlsRemoteCert"] = remoteCert;
Channel::ChannelNotifier::Emit(this->id, "dtlsstatechange", data); this->shared->channelNotifier->Emit(this->id, "dtlsstatechange", data);
// Tell the parent class. // Tell the parent class.
RTC::Transport::Connected(); RTC::Transport::Connected();
...@@ -1453,7 +1453,7 @@ namespace RTC ...@@ -1453,7 +1453,7 @@ namespace RTC
data["dtlsState"] = "failed"; data["dtlsState"] = "failed";
Channel::ChannelNotifier::Emit(this->id, "dtlsstatechange", data); this->shared->channelNotifier->Emit(this->id, "dtlsstatechange", data);
} }
inline void WebRtcTransport::OnDtlsTransportClosed(const RTC::DtlsTransport* /*dtlsTransport*/) inline void WebRtcTransport::OnDtlsTransportClosed(const RTC::DtlsTransport* /*dtlsTransport*/)
...@@ -1467,7 +1467,7 @@ namespace RTC ...@@ -1467,7 +1467,7 @@ namespace RTC
data["dtlsState"] = "closed"; data["dtlsState"] = "closed";
Channel::ChannelNotifier::Emit(this->id, "dtlsstatechange", data); this->shared->channelNotifier->Emit(this->id, "dtlsstatechange", data);
// Tell the parent class. // Tell the parent class.
RTC::Transport::Disconnected(); RTC::Transport::Disconnected();
......
...@@ -2,13 +2,14 @@ ...@@ -2,13 +2,14 @@
// #define MS_LOG_DEV_LEVEL 3 // #define MS_LOG_DEV_LEVEL 3
#include "Worker.hpp" #include "Worker.hpp"
#include "ChannelMessageHandlers.hpp" #include "ChannelMessageRegistrator.hpp"
#include "DepLibUV.hpp" #include "DepLibUV.hpp"
#include "DepUsrSCTP.hpp" #include "DepUsrSCTP.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Settings.hpp" #include "Settings.hpp"
#include "Channel/ChannelNotifier.hpp" #include "Channel/ChannelNotifier.hpp"
#include "PayloadChannel/PayloadChannelNotifier.hpp"
/* Instance methods. */ /* Instance methods. */
...@@ -23,9 +24,15 @@ Worker::Worker(::Channel::ChannelSocket* channel, PayloadChannel::PayloadChannel ...@@ -23,9 +24,15 @@ Worker::Worker(::Channel::ChannelSocket* channel, PayloadChannel::PayloadChannel
// Set us as PayloadChannel's listener. // Set us as PayloadChannel's listener.
this->payloadChannel->SetListener(this); this->payloadChannel->SetListener(this);
// Set the signals handler. // Set the SignalHandler.
this->signalsHandler = new SignalsHandler(this); this->signalsHandler = new SignalsHandler(this);
// Set up the RTC::Shared singleton.
this->shared = new RTC::Shared(
/*channelMessageRegistrator*/ new ChannelMessageRegistrator(),
/*channelNotifier*/ new Channel::ChannelNotifier(this->channel),
/*payloadChannelNotifier*/ new PayloadChannel::PayloadChannelNotifier(this->payloadChannel));
#ifdef MS_EXECUTABLE #ifdef MS_EXECUTABLE
{ {
// Add signals to handle. // Add signals to handle.
...@@ -38,7 +45,7 @@ Worker::Worker(::Channel::ChannelSocket* channel, PayloadChannel::PayloadChannel ...@@ -38,7 +45,7 @@ Worker::Worker(::Channel::ChannelSocket* channel, PayloadChannel::PayloadChannel
DepUsrSCTP::CreateChecker(); DepUsrSCTP::CreateChecker();
// Tell the Node process that we are running. // Tell the Node process that we are running.
Channel::ChannelNotifier::Emit(Logger::pid, "running"); this->shared->channelNotifier->Emit(Logger::pid, "running");
MS_DEBUG_DEV("starting libuv loop"); MS_DEBUG_DEV("starting libuv loop");
DepLibUV::RunLoop(); DepLibUV::RunLoop();
...@@ -83,6 +90,9 @@ void Worker::Close() ...@@ -83,6 +90,9 @@ void Worker::Close()
} }
this->mapWebRtcServers.clear(); this->mapWebRtcServers.clear();
// Delete the RTC::Shared singleton.
delete this->shared;
// Close the Checker instance in DepUsrSCTP. // Close the Checker instance in DepUsrSCTP.
DepUsrSCTP::CloseChecker(); DepUsrSCTP::CloseChecker();
...@@ -126,7 +136,7 @@ void Worker::FillJson(json& jsonObject) const ...@@ -126,7 +136,7 @@ void Worker::FillJson(json& jsonObject) const
jsonObject["channelMessageHandlers"] = json::object(); jsonObject["channelMessageHandlers"] = json::object();
auto jsonChannelMessageHandlersIt = jsonObject.find("channelMessageHandlers"); auto jsonChannelMessageHandlersIt = jsonObject.find("channelMessageHandlers");
ChannelMessageHandlers::FillJson(*jsonChannelMessageHandlersIt); this->shared->channelMessageRegistrator->FillJson(*jsonChannelMessageHandlersIt);
} }
void Worker::FillJsonResourceUsage(json& jsonObject) const void Worker::FillJsonResourceUsage(json& jsonObject) const
...@@ -318,7 +328,7 @@ inline void Worker::HandleRequest(Channel::ChannelRequest* request) ...@@ -318,7 +328,7 @@ inline void Worker::HandleRequest(Channel::ChannelRequest* request)
SetNewWebRtcServerIdFromData(request->data, webRtcServerId); SetNewWebRtcServerIdFromData(request->data, webRtcServerId);
auto* webRtcServer = new RTC::WebRtcServer(webRtcServerId, request->data); auto* webRtcServer = new RTC::WebRtcServer(this->shared, webRtcServerId, request->data);
this->mapWebRtcServers[webRtcServerId] = webRtcServer; this->mapWebRtcServers[webRtcServerId] = webRtcServer;
...@@ -376,7 +386,7 @@ inline void Worker::HandleRequest(Channel::ChannelRequest* request) ...@@ -376,7 +386,7 @@ inline void Worker::HandleRequest(Channel::ChannelRequest* request)
MS_THROW_ERROR("%s [method:%s]", error.what(), request->method.c_str()); MS_THROW_ERROR("%s [method:%s]", error.what(), request->method.c_str());
} }
auto* router = new RTC::Router(routerId, this); auto* router = new RTC::Router(this->shared, routerId, this);
this->mapRouters[routerId] = router; this->mapRouters[routerId] = router;
...@@ -417,7 +427,8 @@ inline void Worker::HandleRequest(Channel::ChannelRequest* request) ...@@ -417,7 +427,8 @@ inline void Worker::HandleRequest(Channel::ChannelRequest* request)
{ {
try try
{ {
auto* handler = ChannelMessageHandlers::GetChannelRequestHandler(request->handlerId); auto* handler =
this->shared->channelMessageRegistrator->GetChannelRequestHandler(request->handlerId);
if (handler == nullptr) if (handler == nullptr)
{ {
...@@ -465,7 +476,8 @@ inline void Worker::HandleRequest(PayloadChannel::PayloadChannelRequest* request ...@@ -465,7 +476,8 @@ inline void Worker::HandleRequest(PayloadChannel::PayloadChannelRequest* request
try try
{ {
auto* handler = ChannelMessageHandlers::GetPayloadChannelRequestHandler(request->handlerId); auto* handler =
this->shared->channelMessageRegistrator->GetPayloadChannelRequestHandler(request->handlerId);
if (handler == nullptr) if (handler == nullptr)
{ {
...@@ -493,8 +505,8 @@ inline void Worker::HandleNotification(PayloadChannel::PayloadChannelNotificatio ...@@ -493,8 +505,8 @@ inline void Worker::HandleNotification(PayloadChannel::PayloadChannelNotificatio
try try
{ {
auto* handler = auto* handler = this->shared->channelMessageRegistrator->GetPayloadChannelNotificationHandler(
ChannelMessageHandlers::GetPayloadChannelNotificationHandler(notification->handlerId); notification->handlerId);
if (handler == nullptr) if (handler == nullptr)
{ {
......
...@@ -12,9 +12,7 @@ ...@@ -12,9 +12,7 @@
#include "Settings.hpp" #include "Settings.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "Worker.hpp" #include "Worker.hpp"
#include "Channel/ChannelNotifier.hpp"
#include "Channel/ChannelSocket.hpp" #include "Channel/ChannelSocket.hpp"
#include "PayloadChannel/PayloadChannelNotifier.hpp"
#include "PayloadChannel/PayloadChannelSocket.hpp" #include "PayloadChannel/PayloadChannelSocket.hpp"
#include "RTC/DtlsTransport.hpp" #include "RTC/DtlsTransport.hpp"
#include "RTC/SrtpSession.hpp" #include "RTC/SrtpSession.hpp"
...@@ -166,8 +164,6 @@ extern "C" int mediasoup_worker_run( ...@@ -166,8 +164,6 @@ extern "C" int mediasoup_worker_run(
Utils::Crypto::ClassInit(); Utils::Crypto::ClassInit();
RTC::DtlsTransport::ClassInit(); RTC::DtlsTransport::ClassInit();
RTC::SrtpSession::ClassInit(); RTC::SrtpSession::ClassInit();
Channel::ChannelNotifier::ClassInit(channel.get());
PayloadChannel::PayloadChannelNotifier::ClassInit(payloadChannel.get());
#ifdef MS_EXECUTABLE #ifdef MS_EXECUTABLE
// Ignore some signals. // Ignore some signals.
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论