提交 507f8cca authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

RtpBuffer: initial implementation (not finished yet)

上级 e6ce9ebe
#ifndef MS_RTC_RTP_BUFFER_H
#define MS_RTC_RTP_BUFFER_H
#include "common.h"
#include "RTC/RtpPacket.h"
#include <vector>
#define MS_RTP_PACKET_MAX_SIZE 65536
namespace RTC
{
class RtpBuffer
{
public:
struct Item
{
uint8_t raw[MS_RTP_PACKET_MAX_SIZE];
RTC::RtpPacket* packet = nullptr;
};
public:
RtpBuffer(size_t capability);
virtual ~RtpBuffer();
void Add(RTC::RtpPacket* packet);
private:
std::vector<Item> items;
size_t pos = 0;
bool full = false;
};
}
#endif
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "common.h" #include "common.h"
#include "RTC/RtpDictionaries.h" #include "RTC/RtpDictionaries.h"
#include "RTC/RtpPacket.h" #include "RTC/RtpPacket.h"
#include "RTC/RtpBuffer.h"
#include "RTC/RTCP/ReceiverReport.h" #include "RTC/RTCP/ReceiverReport.h"
#include "RTC/RTCP/Feedback.h" #include "RTC/RTCP/Feedback.h"
#include "Channel/Request.h" #include "Channel/Request.h"
...@@ -65,6 +66,7 @@ namespace RTC ...@@ -65,6 +66,7 @@ namespace RTC
RTC::Transport* transport = nullptr; RTC::Transport* transport = nullptr;
// Allocated by this. // Allocated by this.
RTC::RtpParameters* rtpParameters = nullptr; RTC::RtpParameters* rtpParameters = nullptr;
RTC::RtpBuffer* rtpBuffer = nullptr;
// Others. // Others.
bool rtpRawEventEnabled = false; bool rtpRawEventEnabled = false;
bool rtpObjectEventEnabled = false; bool rtpObjectEventEnabled = false;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
'src/RTC/IceServer.cpp', 'src/RTC/IceServer.cpp',
'src/RTC/Peer.cpp', 'src/RTC/Peer.cpp',
'src/RTC/Room.cpp', 'src/RTC/Room.cpp',
'src/RTC/RtpBuffer.cpp',
'src/RTC/RtpListener.cpp', 'src/RTC/RtpListener.cpp',
'src/RTC/RtpPacket.cpp', 'src/RTC/RtpPacket.cpp',
'src/RTC/RtpReceiver.cpp', 'src/RTC/RtpReceiver.cpp',
...@@ -107,6 +108,7 @@ ...@@ -107,6 +108,7 @@
'include/RTC/Parameters.h', 'include/RTC/Parameters.h',
'include/RTC/Peer.h', 'include/RTC/Peer.h',
'include/RTC/Room.h', 'include/RTC/Room.h',
'include/RTC/RtpBuffer.h',
'include/RTC/RtpDictionaries.h', 'include/RTC/RtpDictionaries.h',
'include/RTC/RtpListener.h', 'include/RTC/RtpListener.h',
'include/RTC/RtpPacket.h', 'include/RTC/RtpPacket.h',
......
#define MS_CLASS "RTC::RtpBuffer"
#include "RTC/RtpBuffer.h"
#include "Logger.h"
namespace RTC
{
/* Instance methods. */
RtpBuffer::RtpBuffer(size_t capability) :
items(capability)
{
MS_TRACE();
}
RtpBuffer::~RtpBuffer()
{
MS_TRACE();
// Delete cloned packets.
for (auto& item : this->items)
{
if (item.packet)
delete item.packet;
}
}
void RtpBuffer::Add(RTC::RtpPacket* packet)
{
MS_TRACE();
Item* item = std::addressof(this->items[this->pos]);
// Delete previous RTP packet (if any).
if (item->packet)
delete item->packet;
// Clone the given RTP packet and store it.
item->packet = packet->Clone(item->raw);
this->pos = (this->pos + 1) % this->items.size();
if (!this->full && this->pos == 0)
this->full = true;
}
}
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "MediaSoupError.h" #include "MediaSoupError.h"
#include "Logger.h" #include "Logger.h"
#define RTP_BUFFER_SIZE 100
namespace RTC namespace RTC
{ {
/* Instance methods. */ /* Instance methods. */
...@@ -17,6 +19,9 @@ namespace RTC ...@@ -17,6 +19,9 @@ namespace RTC
notifier(notifier) notifier(notifier)
{ {
MS_TRACE(); MS_TRACE();
// Create the RtpBuffer instance.
this->rtpBuffer = new RTC::RtpBuffer(RTP_BUFFER_SIZE);
} }
RtpReceiver::~RtpReceiver() RtpReceiver::~RtpReceiver()
...@@ -35,6 +40,9 @@ namespace RTC ...@@ -35,6 +40,9 @@ namespace RTC
if (this->rtpParameters) if (this->rtpParameters)
delete this->rtpParameters; delete this->rtpParameters;
if (this->rtpBuffer)
delete this->rtpBuffer;
// Notify. // Notify.
event_data[k_class] = "RtpReceiver"; event_data[k_class] = "RtpReceiver";
this->notifier->Emit(this->rtpReceiverId, "close", event_data); this->notifier->Emit(this->rtpReceiverId, "close", event_data);
...@@ -240,6 +248,10 @@ namespace RTC ...@@ -240,6 +248,10 @@ namespace RTC
this->notifier->EmitWithBinary(this->rtpReceiverId, "rtpobject", event_data, packet->GetPayload(), packet->GetPayloadLength()); this->notifier->EmitWithBinary(this->rtpReceiverId, "rtpobject", event_data, packet->GetPayload(), packet->GetPayloadLength());
} }
// Store in the buffer
// TODO: Must check what kind of packet we are storing, right?
this->rtpBuffer->Add(packet);
} }
void RtpReceiver::FillRtpParameters() void RtpReceiver::FillRtpParameters()
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论