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

Remove old RtpBuffer implementation (let's work on RtpStream)

上级 3dd89a71
#ifndef MS_RTC_RTP_BUFFER_H
#define MS_RTC_RTP_BUFFER_H
#include "common.h"
#include "RTC/RtpPacket.h"
#include <vector>
#include <list>
namespace RTC
{
class RtpBuffer
{
private:
struct StorageItem
{
uint8_t store[65536];
};
public:
RtpBuffer(size_t size);
~RtpBuffer();
bool Add(RTC::RtpPacket* packet);
private:
std::vector<StorageItem> storage;
typedef std::list<RTC::RtpPacket*> Packets;
Packets packets;
};
}
#endif
......@@ -31,7 +31,6 @@
'src/RTC/IceServer.cpp',
'src/RTC/Peer.cpp',
'src/RTC/Room.cpp',
'src/RTC/RtpBuffer.cpp',
'src/RTC/RtpListener.cpp',
'src/RTC/RtpPacket.cpp',
'src/RTC/RtpReceiver.cpp',
......@@ -108,7 +107,6 @@
'include/RTC/Parameters.h',
'include/RTC/Peer.h',
'include/RTC/Room.h',
'include/RTC/RtpBuffer.h',
'include/RTC/RtpDictionaries.h',
'include/RTC/RtpListener.h',
'include/RTC/RtpPacket.h',
......
// TODO: https://tools.ietf.org/html/rfc3550#appendix-A.1
#define MS_CLASS "RTC::RtpBuffer"
#include "RTC/RtpBuffer.h"
#include "Logger.h"
namespace RTC
{
/* Instance methods. */
RtpBuffer::RtpBuffer(size_t size) :
storage(size)
{
MS_TRACE();
}
RtpBuffer::~RtpBuffer()
{
MS_TRACE();
// Delete cloned packets.
for (auto& packet : this->packets)
{
delete packet;
}
}
bool RtpBuffer::Add(RTC::RtpPacket* packet)
{
MS_TRACE();
MS_WARN("BEGIN | seq_number: %" PRIu16, packet->GetSequenceNumber());
// If empty do it easy.
if (this->packets.size() == 0)
{
MS_WARN(" empty packet list");
auto store = this->storage[0].store;
auto cloned_packet = packet->Clone(store);
this->packets.push_back(cloned_packet);
MS_WARN("END | seq_number: %" PRIu16, packet->GetSequenceNumber());
return true;
}
// Otherwise, do the stuff.
Packets::iterator new_it;
uint8_t* store = nullptr;
auto it_r = this->packets.rbegin();
for (; it_r != this->packets.rend(); it_r++)
{
auto current_packet = *it_r;
if (packet->GetSequenceNumber() > current_packet->GetSequenceNumber())
{
// Get a forward iterator pointing to the same element.
auto it = it_r.base();
new_it = this->packets.insert(it, nullptr);
// Exit the loop.
break;
}
}
// If the packet was older than anything in the storate, just ignore it.
if (it_r == this->packets.rend())
{
// TODO: Wrong, this will drop all the received packets once sequence_number
// reaches 65535
MS_WARN(" packet is older than anything in the storage, ignoring it");
MS_WARN("END | seq_number: %" PRIu16, packet->GetSequenceNumber());
return false;
}
MS_WARN(" packets.size:%zu, storage.size:%zu", this->packets.size(), this->storage.size());
// If the storage is not full use the next free area.
if (this->packets.size() - 1 < this->storage.size())
{
MS_WARN(" storage not full");
// Store points to the next free mem area.
store = this->storage[this->packets.size() - 1].store;
}
// Otherwise remove the first packet list entry and replace its storage area.
else
{
auto first_packet = *(this->packets.begin());
MS_WARN(" storage full, deleting first list packet with seq_number: %" PRIu16, first_packet->GetSequenceNumber());
// Store points to the store used by the first packet.
store = (uint8_t*)first_packet->GetRaw();
// Free the first packet.
delete first_packet;
// Remove the first element in the list.
this->packets.pop_front();
}
// Update the new list entry so it points to the cloned packed.
*new_it = packet->Clone(store);
MS_WARN("END | seq_number: %" PRIu16, packet->GetSequenceNumber());
MS_WARN("<DUMP>");
for (auto& packet : this->packets)
{
MS_WARN(" - seq_number: %" PRIu16, packet->GetSequenceNumber());
}
MS_WARN("</DUMP>\n");
return true;
}
}
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论