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