提交 555e433d authored 作者: Nazar Mokrynskyi's avatar Nazar Mokrynskyi

Move `Producer` notification handling from `DirectTransport` to `Producer` itself

上级 23e26f80
......@@ -40,10 +40,6 @@ namespace RTC
/* Methods inherited from PayloadChannel::PayloadChannelSocket::NotificationHandler. */
public:
void HandleNotification(PayloadChannel::Notification* notification) override;
private:
// Allocated by this.
uint8_t* buffer{ nullptr };
};
} // namespace RTC
......
......@@ -4,6 +4,7 @@
#include "common.hpp"
#include "Channel/ChannelRequest.hpp"
#include "Channel/ChannelSocket.hpp"
#include "PayloadChannel/PayloadChannelSocket.hpp"
#include "RTC/KeyFrameRequestManager.hpp"
#include "RTC/RTCP/CompoundPacket.hpp"
#include "RTC/RTCP/Packet.hpp"
......@@ -23,7 +24,8 @@ namespace RTC
{
class Producer : public RTC::RtpStreamRecv::Listener,
public RTC::KeyFrameRequestManager::Listener,
public Channel::ChannelSocket::RequestHandler
public Channel::ChannelSocket::RequestHandler,
public PayloadChannel::PayloadChannelSocket::NotificationHandler
{
public:
class Listener
......@@ -32,8 +34,10 @@ namespace RTC
virtual ~Listener() = default;
public:
virtual void OnProducerPaused(RTC::Producer* producer) = 0;
virtual void OnProducerResumed(RTC::Producer* producer) = 0;
virtual void OnProducerReceiveData(RTC::Producer* producer, size_t len) = 0;
virtual void OnProducerReceiveRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) = 0;
virtual void OnProducerPaused(RTC::Producer* producer) = 0;
virtual void OnProducerResumed(RTC::Producer* producer) = 0;
virtual void OnProducerNewRtpStream(
RTC::Producer* producer, RTC::RtpStream* rtpStream, uint32_t mappedSsrc) = 0;
virtual void OnProducerRtpStreamScore(
......@@ -132,6 +136,10 @@ namespace RTC
public:
void HandleRequest(Channel::ChannelRequest* request) override;
/* Methods inherited from PayloadChannel::PayloadChannelSocket::NotificationHandler. */
public:
void HandleNotification(PayloadChannel::Notification* notification) override;
private:
RTC::RtpStreamRecv* GetRtpStream(RTC::RtpPacket* packet);
RTC::RtpStreamRecv* CreateRtpStream(
......@@ -188,6 +196,7 @@ namespace RTC
bool videoOrientationDetected{ false };
struct VideoOrientation videoOrientation;
struct TraceEventTypes traceEventTypes;
uint8_t* buffer{ nullptr };
};
} // namespace RTC
......
......@@ -191,6 +191,14 @@ namespace RTC
/* Pure virtual methods inherited from RTC::Producer::Listener. */
public:
void OnProducerReceiveData(RTC::Producer* /*producer*/, size_t len) override
{
this->DataReceived(len);
}
void OnProducerReceiveRtpPacket(RTC::Producer* /*producer*/, RTC::RtpPacket* packet) override
{
this->ReceiveRtpPacket(packet);
}
void OnProducerPaused(RTC::Producer* producer) override;
void OnProducerResumed(RTC::Producer* producer) override;
void OnProducerNewRtpStream(
......
......@@ -20,8 +20,6 @@ namespace RTC
DirectTransport::~DirectTransport()
{
MS_TRACE();
delete[] this->buffer;
}
void DirectTransport::FillJson(json& jsonObject) const
......@@ -91,37 +89,10 @@ namespace RTC
case PayloadChannel::Notification::EventId::PRODUCER_SEND:
{
const auto* data = notification->payload;
auto len = notification->payloadLen;
// Increase receive transmission.
RTC::Transport::DataReceived(len);
if (len > RTC::MtuSize + 100)
{
MS_WARN_TAG(rtp, "given RTP packet exceeds maximum size [len:%zu]", len);
return;
}
// If this is the first time to reveive a RTP packet then allocate the receiving buffer now.
if (!this->buffer)
this->buffer = new uint8_t[RTC::MtuSize + 100];
// Copy the received packet into this buffer so it can be expanded later.
std::memcpy(this->buffer, data, static_cast<size_t>(len));
RTC::RtpPacket* packet = RTC::RtpPacket::Parse(this->buffer, len);
if (!packet)
{
MS_WARN_TAG(rtp, "received data is not a valid RTP packet");
return;
}
// This may throw.
RTC::Producer* producer = GetProducerFromInternal(notification->internal);
// Pass the packet to the parent transport.
RTC::Transport::ReceiveRtpPacket(packet);
producer->HandleNotification(notification);
break;
}
......
......@@ -332,6 +332,8 @@ namespace RTC
// Delete the KeyFrameRequestManager.
delete this->keyFrameRequestManager;
delete[] this->buffer;
}
void Producer::FillJson(json& jsonObject) const
......@@ -605,6 +607,56 @@ namespace RTC
}
}
void Producer::HandleNotification(PayloadChannel::Notification* notification)
{
MS_TRACE();
switch (notification->eventId)
{
case PayloadChannel::Notification::EventId::PRODUCER_SEND:
{
const auto* data = notification->payload;
auto len = notification->payloadLen;
// Increase receive transmission.
this->listener->OnProducerReceiveData(this, len);
if (len > RTC::MtuSize + 100)
{
MS_WARN_TAG(rtp, "given RTP packet exceeds maximum size [len:%zu]", len);
break;
}
// If this is the first time to receive a RTP packet then allocate the receiving buffer now.
if (!this->buffer)
this->buffer = new uint8_t[RTC::MtuSize + 100];
// Copy the received packet into this buffer so it can be expanded later.
std::memcpy(this->buffer, data, static_cast<size_t>(len));
RTC::RtpPacket* packet = RTC::RtpPacket::Parse(this->buffer, len);
if (!packet)
{
MS_WARN_TAG(rtp, "received data is not a valid RTP packet");
break;
}
// Pass the packet to the parent transport.
this->listener->OnProducerReceiveRtpPacket(this, packet);
break;
}
default:
{
MS_ERROR("unknown event '%s'", notification->event.c_str());
}
}
}
Producer::ReceiveRtpPacketResult Producer::ReceiveRtpPacket(RTC::RtpPacket* packet)
{
MS_TRACE();
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论