Unverified 提交 4d0ea75c authored 作者: Nazar Mokrynskyi's avatar Nazar Mokrynskyi 提交者: GitHub

Merge pull request #878 from nazar-pc/unify-request-notification-handling

Refactor request and notification handlers to conform to the same API
......@@ -51,15 +51,22 @@ namespace Channel
class ChannelSocket : public ConsumerSocket::Listener
{
public:
class Listener
class RequestHandler
{
public:
virtual ~RequestHandler() = default;
public:
virtual void HandleRequest(Channel::ChannelRequest* request) = 0;
};
class Listener : public RequestHandler
{
public:
virtual ~Listener() = default;
public:
virtual void OnChannelRequest(
Channel::ChannelSocket* channel, Channel::ChannelRequest* request) = 0;
virtual void OnChannelClosed(Channel::ChannelSocket* channel) = 0;
virtual void OnChannelClosed(Channel::ChannelSocket* channel) = 0;
};
public:
......
......@@ -54,18 +54,30 @@ namespace PayloadChannel
class PayloadChannelSocket : public ConsumerSocket::Listener
{
public:
class Listener
class RequestHandler
{
public:
virtual ~RequestHandler() = default;
public:
virtual void HandleRequest(PayloadChannel::PayloadChannelRequest* request) = 0;
};
class NotificationHandler
{
public:
virtual ~NotificationHandler() = default;
public:
virtual void HandleNotification(PayloadChannel::Notification* notification) = 0;
};
class Listener : public RequestHandler, public NotificationHandler
{
public:
virtual ~Listener() = default;
public:
virtual void OnPayloadChannelNotification(
PayloadChannel::PayloadChannelSocket* payloadChannel,
PayloadChannel::Notification* notification) = 0;
virtual void OnPayloadChannelRequest(
PayloadChannel::PayloadChannelSocket* payloadChannel,
PayloadChannel::PayloadChannelRequest* request) = 0;
virtual void OnPayloadChannelClosed(PayloadChannel::PayloadChannelSocket* payloadChannel) = 0;
};
......
......@@ -3,6 +3,7 @@
#include "common.hpp"
#include "Channel/ChannelRequest.hpp"
#include "Channel/ChannelSocket.hpp"
#include "RTC/RTCP/CompoundPacket.hpp"
#include "RTC/RTCP/FeedbackPs.hpp"
#include "RTC/RTCP/FeedbackPsFir.hpp"
......@@ -23,7 +24,7 @@ using json = nlohmann::json;
namespace RTC
{
class Consumer
class Consumer : Channel::ChannelSocket::RequestHandler
{
public:
class Listener
......@@ -70,7 +71,6 @@ namespace RTC
virtual void FillJson(json& jsonObject) const;
virtual void FillJsonStats(json& jsonArray) const = 0;
virtual void FillJsonScore(json& jsonObject) const = 0;
virtual void HandleRequest(Channel::ChannelRequest* request);
RTC::Media::Kind GetKind() const
{
return this->kind;
......@@ -155,6 +155,10 @@ namespace RTC
virtual uint32_t GetTransmissionRate(uint64_t nowMs) = 0;
virtual float GetRtt() const = 0;
/* Methods inherited from Channel::ChannelSocket::RequestHandler. */
public:
void HandleRequest(Channel::ChannelRequest* request) override;
protected:
void EmitTraceEventRtpAndKeyFrameTypes(RTC::RtpPacket* packet, bool isRtx = false) const;
void EmitTraceEventKeyFrameType(RTC::RtpPacket* packet, bool isRtx = false) const;
......
......@@ -3,14 +3,17 @@
#include "common.hpp"
#include "Channel/ChannelRequest.hpp"
#include "Channel/ChannelSocket.hpp"
#include "PayloadChannel/PayloadChannelRequest.hpp"
#include "PayloadChannel/PayloadChannelSocket.hpp"
#include "RTC/SctpDictionaries.hpp"
#include <nlohmann/json.hpp>
#include <string>
namespace RTC
{
class DataConsumer
class DataConsumer : Channel::ChannelSocket::RequestHandler,
PayloadChannel::PayloadChannelSocket::RequestHandler
{
protected:
using onQueuedCallback = const std::function<void(bool queued, bool sctpSendBufferFull)>;
......@@ -50,8 +53,6 @@ namespace RTC
public:
void FillJson(json& jsonObject) const;
void FillJsonStats(json& jsonArray) const;
void HandleRequest(Channel::ChannelRequest* request);
void HandleRequest(PayloadChannel::PayloadChannelRequest* request);
Type GetType() const
{
return this->type;
......@@ -78,6 +79,14 @@ namespace RTC
void DataProducerClosed();
void SendMessage(uint32_t ppid, const uint8_t* msg, size_t len, onQueuedCallback* = nullptr);
/* Methods inherited from Channel::ChannelSocket::RequestHandler. */
public:
void HandleRequest(Channel::ChannelRequest* request) override;
/* Methods inherited from PayloadChannel::PayloadChannelSocket::RequestHandler. */
public:
void HandleRequest(PayloadChannel::PayloadChannelRequest* request) override;
public:
// Passed by argument.
const std::string id;
......
......@@ -3,13 +3,14 @@
#include "common.hpp"
#include "Channel/ChannelRequest.hpp"
#include "Channel/ChannelSocket.hpp"
#include "RTC/SctpDictionaries.hpp"
#include <nlohmann/json.hpp>
#include <string>
namespace RTC
{
class DataProducer
class DataProducer : Channel::ChannelSocket::RequestHandler
{
public:
class Listener
......@@ -36,7 +37,6 @@ namespace RTC
public:
void FillJson(json& jsonObject) const;
void FillJsonStats(json& jsonArray) const;
void HandleRequest(Channel::ChannelRequest* request) const;
Type GetType() const
{
return this->type;
......@@ -47,6 +47,10 @@ namespace RTC
}
void ReceiveMessage(uint32_t ppid, const uint8_t* msg, size_t len);
/* Methods inherited from Channel::ChannelSocket::RequestHandler. */
public:
void HandleRequest(Channel::ChannelRequest* request) override;
public:
// Passed by argument.
const std::string id;
......
......@@ -14,7 +14,6 @@ namespace RTC
public:
void FillJson(json& jsonObject) const override;
void FillJsonStats(json& jsonArray) override;
void HandleRequest(Channel::ChannelRequest* request) override;
void HandleNotification(PayloadChannel::Notification* notification) override;
private:
......@@ -35,6 +34,10 @@ namespace RTC
void RecvStreamClosed(uint32_t ssrc) override;
void SendStreamClosed(uint32_t ssrc) override;
/* Methods inherited from Channel::ChannelSocket::RequestHandler. */
public:
void HandleRequest(Channel::ChannelRequest* request) override;
private:
// Allocated by this.
uint8_t* buffer{ nullptr };
......
......@@ -21,7 +21,6 @@ namespace RTC
void FillJson(json& jsonObject) const override;
void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::ChannelRequest* request) override;
void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) override;
......@@ -44,6 +43,10 @@ namespace RTC
uint32_t GetTransmissionRate(uint64_t nowMs) override;
float GetRtt() const override;
/* Methods inherited from Channel::ChannelSocket::RequestHandler. */
public:
void HandleRequest(Channel::ChannelRequest* request) override;
private:
void UserOnTransportConnected() override;
void UserOnTransportDisconnected() override;
......
......@@ -29,9 +29,12 @@ namespace RTC
public:
void FillJson(json& jsonObject) const override;
void FillJsonStats(json& jsonArray) override;
void HandleRequest(Channel::ChannelRequest* request) override;
void HandleNotification(PayloadChannel::Notification* notification) override;
/* Methods inherited from Channel::ChannelSocket::RequestHandler. */
public:
void HandleRequest(Channel::ChannelRequest* request) override;
private:
bool IsConnected() const override;
bool HasSrtp() const;
......
......@@ -29,9 +29,12 @@ namespace RTC
public:
void FillJson(json& jsonObject) const override;
void FillJsonStats(json& jsonArray) override;
void HandleRequest(Channel::ChannelRequest* request) override;
void HandleNotification(PayloadChannel::Notification* notification) override;
/* Methods inherited from Channel::ChannelSocket::RequestHandler. */
public:
void HandleRequest(Channel::ChannelRequest* request) override;
private:
bool IsConnected() const override;
bool HasSrtp() const;
......
......@@ -3,6 +3,7 @@
#include "common.hpp"
#include "Channel/ChannelRequest.hpp"
#include "Channel/ChannelSocket.hpp"
#include "RTC/KeyFrameRequestManager.hpp"
#include "RTC/RTCP/CompoundPacket.hpp"
#include "RTC/RTCP/Packet.hpp"
......@@ -20,7 +21,9 @@ using json = nlohmann::json;
namespace RTC
{
class Producer : public RTC::RtpStreamRecv::Listener, public RTC::KeyFrameRequestManager::Listener
class Producer : public RTC::RtpStreamRecv::Listener,
public RTC::KeyFrameRequestManager::Listener,
Channel::ChannelSocket::RequestHandler
{
public:
class Listener
......@@ -91,7 +94,6 @@ namespace RTC
public:
void FillJson(json& jsonObject) const;
void FillJsonStats(json& jsonArray) const;
void HandleRequest(Channel::ChannelRequest* request);
RTC::Media::Kind GetKind() const
{
return this->kind;
......@@ -126,6 +128,10 @@ namespace RTC
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t nowMs);
void RequestKeyFrame(uint32_t mappedSsrc);
/* Methods inherited from Channel::ChannelSocket::RequestHandler. */
public:
void HandleRequest(Channel::ChannelRequest* request) override;
private:
RTC::RtpStreamRecv* GetRtpStream(RTC::RtpPacket* packet);
RTC::RtpStreamRecv* CreateRtpStream(
......
......@@ -23,7 +23,10 @@ using json = nlohmann::json;
namespace RTC
{
class Router : public RTC::Transport::Listener
class Router : public RTC::Transport::Listener,
Channel::ChannelSocket::RequestHandler,
PayloadChannel::PayloadChannelSocket::RequestHandler,
PayloadChannel::PayloadChannelSocket::NotificationHandler
{
public:
class Listener
......@@ -42,9 +45,18 @@ namespace RTC
public:
void FillJson(json& jsonObject) const;
void HandleRequest(Channel::ChannelRequest* request);
void HandleRequest(PayloadChannel::PayloadChannelRequest* request);
void HandleNotification(PayloadChannel::Notification* notification);
/* Methods inherited from Channel::ChannelSocket::RequestHandler. */
public:
void HandleRequest(Channel::ChannelRequest* request) override;
/* Methods inherited from PayloadChannel::PayloadChannelSocket::RequestHandler. */
public:
void HandleRequest(PayloadChannel::PayloadChannelRequest* request) override;
/* Methods inherited from PayloadChannel::PayloadChannelSocket::NotificationHandler. */
public:
void HandleNotification(PayloadChannel::Notification* notification) override;
private:
void SetNewTransportIdFromInternal(json& internal, std::string& transportId) const;
......
......@@ -21,7 +21,6 @@ namespace RTC
void FillJson(json& jsonObject) const override;
void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::ChannelRequest* request) override;
bool IsActive() const override
{
// clang-format off
......@@ -54,6 +53,10 @@ namespace RTC
uint32_t GetTransmissionRate(uint64_t nowMs) override;
float GetRtt() const override;
/* Methods inherited from Channel::ChannelSocket::RequestHandler. */
public:
void HandleRequest(Channel::ChannelRequest* request) override;
private:
void UserOnTransportConnected() override;
void UserOnTransportDisconnected() override;
......
......@@ -22,7 +22,6 @@ namespace RTC
void FillJson(json& jsonObject) const override;
void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::ChannelRequest* request) override;
RTC::Consumer::Layers GetPreferredLayers() const override
{
RTC::Consumer::Layers layers;
......@@ -70,6 +69,10 @@ namespace RTC
uint32_t GetTransmissionRate(uint64_t nowMs) override;
float GetRtt() const override;
/* Methods inherited from Channel::ChannelSocket::RequestHandler. */
public:
void HandleRequest(Channel::ChannelRequest* request) override;
private:
void UserOnTransportConnected() override;
void UserOnTransportDisconnected() override;
......
......@@ -23,7 +23,6 @@ namespace RTC
void FillJson(json& jsonObject) const override;
void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::ChannelRequest* request) override;
RTC::Consumer::Layers GetPreferredLayers() const override
{
RTC::Consumer::Layers layers;
......@@ -65,6 +64,10 @@ namespace RTC
uint32_t GetTransmissionRate(uint64_t nowMs) override;
float GetRtt() const override;
/* Methods inherited from Channel::ChannelSocket::RequestHandler. */
public:
void HandleRequest(Channel::ChannelRequest* request) override;
private:
void UserOnTransportConnected() override;
void UserOnTransportDisconnected() override;
......
......@@ -5,6 +5,7 @@
#include "common.hpp"
#include "DepLibUV.hpp"
#include "Channel/ChannelRequest.hpp"
#include "Channel/ChannelSocket.hpp"
#include "PayloadChannel/Notification.hpp"
#include "PayloadChannel/PayloadChannelRequest.hpp"
#include "RTC/Consumer.hpp"
......
......@@ -20,7 +20,8 @@ namespace RTC
class WebRtcServer : public RTC::UdpSocket::Listener,
public RTC::TcpServer::Listener,
public RTC::TcpConnection::Listener,
public RTC::WebRtcTransport::WebRtcTransportListener
public RTC::WebRtcTransport::WebRtcTransportListener,
Channel::ChannelSocket::RequestHandler
{
private:
struct ListenInfo
......@@ -51,10 +52,13 @@ namespace RTC
public:
void FillJson(json& jsonObject) const;
void HandleRequest(Channel::ChannelRequest* request);
std::vector<RTC::IceCandidate> GetIceCandidates(
bool enableUdp, bool enableTcp, bool preferUdp, bool preferTcp);
/* Methods inherited from Channel::ChannelSocket::RequestHandler. */
public:
void HandleRequest(Channel::ChannelRequest* request) override;
private:
std::string GetLocalIceUsernameFragmentFromReceivedStunPacket(RTC::StunPacket* packet) const;
void OnPacketReceived(RTC::TransportTuple* tuple, const uint8_t* data, size_t len);
......
......@@ -61,13 +61,16 @@ namespace RTC
public:
void FillJson(json& jsonObject) const override;
void FillJsonStats(json& jsonArray) override;
void HandleRequest(Channel::ChannelRequest* request) override;
void HandleNotification(PayloadChannel::Notification* notification) override;
void ProcessStunPacketFromWebRtcServer(RTC::TransportTuple* tuple, RTC::StunPacket* packet);
void ProcessNonStunPacketFromWebRtcServer(
RTC::TransportTuple* tuple, const uint8_t* data, size_t len);
void RemoveTuple(RTC::TransportTuple* tuple);
/* Methods inherited from Channel::ChannelSocket::RequestHandler. */
public:
void HandleRequest(Channel::ChannelRequest* request) override;
private:
bool IsConnected() const override;
void MayRunDtlsTransport();
......
......@@ -34,19 +34,24 @@ private:
void SetNewRouterIdFromInternal(json& internal, std::string& routerId) const;
RTC::Router* GetRouterFromInternal(json& internal) const;
/* Methods inherited from Channel::lUnixStreamSocket::Listener. */
/* Methods inherited from Channel::ChannelSocket::RequestHandler. */
public:
void HandleRequest(Channel::ChannelRequest* request) override;
/* Methods inherited from Channel::ChannelSocket::Listener. */
public:
void OnChannelRequest(Channel::ChannelSocket* channel, Channel::ChannelRequest* request) override;
void OnChannelClosed(Channel::ChannelSocket* channel) override;
/* Methods inherited from PayloadChannel::lUnixStreamSocket::Listener. */
/* Methods inherited from PayloadChannel::PayloadChannelSocket::RequestHandler. */
public:
void HandleRequest(PayloadChannel::PayloadChannelRequest* request) override;
/* Methods inherited from PayloadChannel::PayloadChannelSocket::NotificationHandler. */
public:
void HandleNotification(PayloadChannel::Notification* notification) override;
/* Methods inherited from PayloadChannel::PayloadChannelSocket::Listener. */
public:
void OnPayloadChannelNotification(
PayloadChannel::PayloadChannelSocket* payloadChannel,
PayloadChannel::Notification* notification) override;
void OnPayloadChannelRequest(
PayloadChannel::PayloadChannelSocket* payloadChannel,
PayloadChannel::PayloadChannelRequest* request) override;
void OnPayloadChannelClosed(PayloadChannel::PayloadChannelSocket* payloadChannel) override;
/* Methods inherited from SignalsHandler::Listener. */
......
......@@ -181,7 +181,7 @@ namespace Channel
// Notify the listener.
try
{
this->listener->OnChannelRequest(this, request);
this->listener->HandleRequest(request);
}
catch (const MediaSoupTypeError& error)
{
......@@ -246,7 +246,7 @@ namespace Channel
// Notify the listener.
try
{
this->listener->OnChannelRequest(this, request);
this->listener->HandleRequest(request);
}
catch (const MediaSoupTypeError& error)
{
......
......@@ -212,7 +212,7 @@ namespace PayloadChannel
// Notify the listener.
try
{
this->listener->OnPayloadChannelRequest(this, request);
this->listener->HandleRequest(request);
}
catch (const MediaSoupTypeError& error)
{
......@@ -246,7 +246,7 @@ namespace PayloadChannel
// Notify the listener.
try
{
this->listener->OnPayloadChannelNotification(this, notification);
this->listener->HandleNotification(notification);
}
catch (const MediaSoupError& error)
{
......@@ -381,7 +381,7 @@ namespace PayloadChannel
// Notify the listener.
try
{
this->listener->OnPayloadChannelNotification(this, this->ongoingNotification);
this->listener->HandleNotification(this->ongoingNotification);
}
catch (const MediaSoupError& error)
{
......@@ -399,7 +399,7 @@ namespace PayloadChannel
// Notify the listener.
try
{
this->listener->OnPayloadChannelRequest(this, this->ongoingRequest);
this->listener->HandleRequest(this->ongoingRequest);
}
catch (const MediaSoupTypeError& error)
{
......
......@@ -110,7 +110,7 @@ namespace RTC
jsonObject["bytesReceived"] = this->bytesReceived;
}
void DataProducer::HandleRequest(Channel::ChannelRequest* request) const
void DataProducer::HandleRequest(Channel::ChannelRequest* request)
{
MS_TRACE();
......
......@@ -253,7 +253,7 @@ RTC::Router* Worker::GetRouterFromInternal(json& internal) const
return router;
}
inline void Worker::OnChannelRequest(Channel::ChannelSocket* /*channel*/, Channel::ChannelRequest* request)
inline void Worker::HandleRequest(Channel::ChannelRequest* request)
{
MS_TRACE();
......@@ -458,8 +458,7 @@ inline void Worker::OnChannelClosed(Channel::ChannelSocket* /*socket*/)
Close();
}
inline void Worker::OnPayloadChannelNotification(
PayloadChannel::PayloadChannelSocket* /*payloadChannel*/, PayloadChannel::Notification* notification)
inline void Worker::HandleNotification(PayloadChannel::Notification* notification)
{
MS_TRACE();
......@@ -481,9 +480,7 @@ inline void Worker::OnPayloadChannelNotification(
}
}
inline void Worker::OnPayloadChannelRequest(
PayloadChannel::PayloadChannelSocket* /*payloadChannel*/,
PayloadChannel::PayloadChannelRequest* request)
inline void Worker::HandleRequest(PayloadChannel::PayloadChannelRequest* request)
{
MS_TRACE();
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论