提交 6c1402fd authored 作者: José Luis Millán's avatar José Luis Millán

Use SeqManager when needed

上级 ffb4b514
......@@ -5,6 +5,7 @@
#include "RTC/Codecs/PayloadDescriptorHandler.hpp"
#include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/SeqManager.hpp"
/* RFC 7741
* VP8 Payload Descriptor
......@@ -42,7 +43,7 @@ namespace RTC
~PayloadDescriptor() = default;
void Dump() const;
// Rewrite the buffer with the given pictureId and tl0PicutreIndex values.
// Rewrite the buffer with the given pictureId and tl0PictureIndex values.
void Encode(uint8_t* data, uint16_t pictureId, uint8_t tl0PictureIndex);
void Restore(uint8_t* data);
......@@ -78,12 +79,8 @@ namespace RTC
void SyncRequired() override;
public:
uint16_t pictureId{ 0 };
uint16_t pictureIdBase{ 0 };
uint16_t pictureIdPreviousBase{ 0 };
uint8_t tl0PictureIndex{ 0 };
uint8_t tl0PictureIndexBase{ 0 };
uint8_t tl0PictureIndexPreviousBase{ 0 };
SeqManager<uint16_t> pictureIdManager;
SeqManager<uint8_t> tl0PictureIndexManager;
bool syncRequired{ false };
};
......
......@@ -13,6 +13,7 @@
#include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/RtpStreamSend.hpp"
#include "RTC/SeqManager.hpp"
#include "RTC/Transport.hpp"
#include <json/json.h>
#include <set>
......@@ -95,12 +96,8 @@ namespace RTC
RTC::RtpDataCounter transmittedCounter;
RTC::RtpDataCounter retransmittedCounter;
// RTP sequence number and timestamp.
uint16_t rtpLastSeq{ 0 };
uint16_t rtpBaseSeq{ 0 };
uint16_t rtpPreviousBaseSeq{ 0 };
uint32_t rtpLastTimestamp{ 0 };
uint32_t rtpBaseTimestamp{ 0 };
uint32_t rtpPreviousBaseTimestamp{ 0 };
RTC::SeqManager<uint16_t> rtpSeqManager;
RTC::SeqManager<uint32_t> rtpTimestampManager;
bool syncRequired{ true };
std::unique_ptr<RTC::Codecs::EncodingContext> encodingContext;
......
......@@ -165,25 +165,18 @@ namespace RTC
// Check whether pictureId and tl0PictureIndex sync is required.
if (context->syncRequired)
{
context->pictureIdPreviousBase = context->pictureId;
context->pictureIdBase = this->payloadDescriptor->pictureId;
context->tl0PictureIndexPreviousBase = context->tl0PictureIndex;
context->tl0PictureIndexBase = this->payloadDescriptor->tl0PictureIndex;
context->pictureIdManager.Sync(this->payloadDescriptor->pictureId);
context->tl0PictureIndexManager.Sync(this->payloadDescriptor->tl0PictureIndex);
context->syncRequired = false;
}
// Update pictureId and tl0PictureIndex values.
context->pictureId = (this->payloadDescriptor->pictureId - context->pictureIdBase) +
context->pictureIdPreviousBase + 1;
context->tl0PictureIndex =
(this->payloadDescriptor->tl0PictureIndex - context->tl0PictureIndexBase) +
context->tl0PictureIndexPreviousBase + 1;
uint16_t pictureId;
uint8_t tl0PictureIndex;
auto pictureId = context->pictureId;
auto tl0PictureIndex = context->tl0PictureIndex;
context->pictureIdManager.Input(this->payloadDescriptor->pictureId, pictureId);
context->tl0PictureIndexManager.Input(this->payloadDescriptor->tl0PictureIndex, tl0PictureIndex);
this->payloadDescriptor->Encode(data, pictureId, tl0PictureIndex);
};
......
......@@ -24,12 +24,6 @@ namespace RTC
{
MS_TRACE();
// Initialize RTP sequence number.
this->rtpLastSeq = static_cast<uint16_t>(Utils::Crypto::GetRandomUInt(0x00FF, 0xFFFF));
// Initialize RTP timestamp.
this->rtpLastTimestamp = Utils::Crypto::GetRandomUInt(0x00FF, 0xFFFF);
// Set the RTCP report generation interval.
if (this->kind == RTC::Media::Kind::AUDIO)
this->maxRtcpInterval = RTC::RTCP::MaxAudioIntervalMs;
......@@ -351,35 +345,21 @@ namespace RTC
{
isSyncPacket = true;
this->rtpPreviousBaseSeq = this->rtpLastSeq;
this->rtpBaseSeq = packet->GetSequenceNumber();
this->rtpPreviousBaseTimestamp = this->rtpLastTimestamp;
this->rtpBaseTimestamp = packet->GetTimestamp();
this->rtpSeqManager.Sync(packet->GetSequenceNumber());
this->rtpTimestampManager.Sync(packet->GetTimestamp());
this->syncRequired = false;
if (this->encodingContext)
this->encodingContext->SyncRequired();
MS_DEBUG_TAG(rtp, "re-syncing Consumer stream [rtpLastSeq:%" PRIu16 "]", this->rtpLastSeq);
}
if (isSyncPacket)
{
MS_DEBUG_TAG(
rtp,
"before re-syncing [rtpLastSeq:%" PRIu16 ", rtpLastTimestamp:%" PRIu32 "]",
this->rtpLastSeq,
this->rtpLastTimestamp);
}
// Calculate latest RTP seq number to be sent.
this->rtpLastSeq = packet->GetSequenceNumber() - this->rtpBaseSeq + this->rtpPreviousBaseSeq + 1;
// Update RTP seq number and timestamp.
uint16_t rtpSeq;
uint32_t rtpTimestamp;
// Calculate latest RTP timestamp to be sent.
this->rtpLastTimestamp =
packet->GetTimestamp() - this->rtpBaseTimestamp + this->rtpPreviousBaseTimestamp + 1;
this->rtpSeqManager.Input(packet->GetSequenceNumber(), rtpSeq);
this->rtpTimestampManager.Input(packet->GetTimestamp(), rtpTimestamp);
// Save the received SSRC.
auto origSsrc = packet->GetSsrc();
......@@ -394,10 +374,10 @@ namespace RTC
packet->SetSsrc(this->rtpParameters.encodings[0].ssrc);
// Rewrite packet sequence number.
packet->SetSequenceNumber(this->rtpLastSeq);
packet->SetSequenceNumber(rtpSeq);
// Rewrite packet timestamp.
packet->SetTimestamp(this->rtpLastTimestamp);
packet->SetTimestamp(rtpTimestamp);
// Rewrite payload if needed.
if (this->encodingContext)
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论