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

Use SeqManager when needed

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