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

Cosmetic improvements in Consumer.cpp/.hpp

上级 64f1335d
...@@ -94,13 +94,12 @@ namespace RTC ...@@ -94,13 +94,12 @@ 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 seqNum{ 0 }; uint16_t rtpLastSeq{ 0 };
uint16_t seqNumBase{ 0 }; uint16_t rtpBaseSeq{ 0 };
uint16_t seqNumPreviousBase{ 0 }; uint16_t rtpPreviousBaseSeq{ 0 };
uint32_t rtpTimestamp{ 0 }; uint32_t rtpLastTimestamp{ 0 };
uint32_t rtpTimestampBase{ 0 }; uint32_t rtpBaseTimestamp{ 0 };
uint32_t rtpTimestampPreviousBase{ 0 }; uint32_t rtpPreviousBaseTimestamp{ 0 };
uint32_t lastReceivedSsrc{ 0 };
bool syncRequired{ true }; bool syncRequired{ true };
// RTP profiles. // RTP profiles.
std::set<RTC::RtpEncodingParameters::Profile> profiles; std::set<RTC::RtpEncodingParameters::Profile> profiles;
......
...@@ -24,11 +24,11 @@ namespace RTC ...@@ -24,11 +24,11 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
// Initialize sequence number. // Initialize RTP sequence number.
this->seqNum = static_cast<uint16_t>(Utils::Crypto::GetRandomUInt(0x00FF, 0xFFFF)); this->rtpLastSeq = static_cast<uint16_t>(Utils::Crypto::GetRandomUInt(0x00FF, 0xFFFF));
// Initialize RTP timestamp. // Initialize RTP timestamp.
this->rtpTimestamp = Utils::Crypto::GetRandomUInt(0x00FF, 0xFFFF); 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)
...@@ -351,66 +351,63 @@ namespace RTC ...@@ -351,66 +351,63 @@ namespace RTC
{ {
isSyncPacket = true; isSyncPacket = true;
this->seqNumPreviousBase = this->seqNum; this->rtpPreviousBaseSeq = this->rtpLastSeq;
this->seqNumBase = packet->GetSequenceNumber(); this->rtpBaseSeq = packet->GetSequenceNumber();
this->rtpTimestampPreviousBase = this->rtpTimestamp; this->rtpPreviousBaseTimestamp = this->rtpLastTimestamp;
this->rtpTimestampBase = packet->GetTimestamp(); this->rtpBaseTimestamp = packet->GetTimestamp();
this->syncRequired = false; this->syncRequired = false;
MS_DEBUG_TAG(rtp, "re-syncing Consumer stream [seqNum:%" PRIu16 "]", this->seqNum); MS_DEBUG_TAG(rtp, "re-syncing Consumer stream [rtpLastSeq:%" PRIu16 "]", this->rtpLastSeq);
}
else
{
MS_ASSERT(this->lastReceivedSsrc == packet->GetSsrc(), "new SSRC requires re-syncing");
} }
if (isSyncPacket) if (isSyncPacket)
{ {
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtp, rtp,
"before re-syncing [seqNum:%" PRIu16 ", rtpTimestamp:%" PRIu32 "]", "before re-syncing [rtpLastSeq:%" PRIu16 ", rtpLastTimestamp:%" PRIu32 "]",
this->seqNum, this->rtpLastSeq,
this->rtpTimestamp); this->rtpLastTimestamp);
} }
this->rtpTimestamp = // Calculate latest RTP seq number to be sent.
(packet->GetTimestamp() - this->rtpTimestampBase) + this->rtpTimestampPreviousBase + 1; this->rtpLastSeq = packet->GetSequenceNumber() - this->rtpBaseSeq + this->rtpPreviousBaseSeq + 1;
this->seqNum = (packet->GetSequenceNumber() - this->seqNumBase) + this->seqNumPreviousBase + 1; // Calculate latest RTP timestamp to be sent.
this->rtpLastTimestamp =
packet->GetTimestamp() - this->rtpBaseTimestamp + this->rtpPreviousBaseTimestamp + 1;
// Save the received SSRC. // Save the received SSRC.
this->lastReceivedSsrc = packet->GetSsrc(); auto origSsrc = packet->GetSsrc();
// Save the received sequence number. // Save the received sequence number.
auto seqNum = packet->GetSequenceNumber(); auto origSeq = packet->GetSequenceNumber();
// Save the received timestamp. // Save the received timestamp.
auto rtpTimestamp = packet->GetTimestamp(); auto origTimestamp = packet->GetTimestamp();
// Rewrite packet SSRC. // Rewrite packet SSRC.
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->seqNum); packet->SetSequenceNumber(this->rtpLastSeq);
// Rewrite packet timestamp. // Rewrite packet timestamp.
packet->SetTimestamp(this->rtpTimestamp); packet->SetTimestamp(this->rtpLastTimestamp);
if (isSyncPacket) if (isSyncPacket)
{ {
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtp, rtp,
"sending sync packet [ssrc:%" PRIu32 ", seq:%" PRIu16 ", ts:%" PRIu32 "sending sync packet [ssrc:%" PRIu32 ", seq:%" PRIu16 ", ts:%" PRIu32
"] from original [ssrc:%" PRIu32 ", seq:%" PRIu16 ", ts:%" PRIu32 ", profile:%s]", ", profile:%s] from original [seq:%" PRIu16 ", ts:%" PRIu32 "]",
packet->GetSsrc(), packet->GetSsrc(),
packet->GetSequenceNumber(), packet->GetSequenceNumber(),
packet->GetTimestamp(), packet->GetTimestamp(),
this->lastReceivedSsrc, RTC::RtpEncodingParameters::profile2String[profile].c_str(),
seqNum, origSeq,
rtpTimestamp, origTimestamp);
RTC::RtpEncodingParameters::profile2String[profile].c_str());
} }
// Process the packet. // Process the packet.
...@@ -424,27 +421,26 @@ namespace RTC ...@@ -424,27 +421,26 @@ namespace RTC
} }
else else
{ {
MS_DEBUG_TAG( MS_WARN_TAG(
rtp, rtp,
"failed to send packet [ssrc:%" PRIu32 ", seq:%" PRIu16 ", ts:%" PRIu32 "failed to send packet [ssrc:%" PRIu32 ", seq:%" PRIu16 ", ts:%" PRIu32
"], from original [ssrc:%" PRIu32 ", seq:%" PRIu16 ", ts:%" PRIu32 ", profile:%s]", ", profile:%s] from original [seq:%" PRIu16 ", ts:%" PRIu32 "]",
packet->GetSsrc(), packet->GetSsrc(),
packet->GetSequenceNumber(), packet->GetSequenceNumber(),
packet->GetTimestamp(), packet->GetTimestamp(),
this->lastReceivedSsrc, RTC::RtpEncodingParameters::profile2String[profile].c_str(),
seqNum, origSeq,
rtpTimestamp, origTimestamp);
RTC::RtpEncodingParameters::profile2String[profile].c_str());
} }
// Restore packet SSRC. // Restore packet SSRC.
packet->SetSsrc(this->lastReceivedSsrc); packet->SetSsrc(origSsrc);
// Restore the original sequence number. // Restore the original sequence number.
packet->SetSequenceNumber(seqNum); packet->SetSequenceNumber(origSeq);
// Restore the original timestamp. // Restore the original timestamp.
packet->SetTimestamp(rtpTimestamp); packet->SetTimestamp(origTimestamp);
} }
void Consumer::GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now) void Consumer::GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now)
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论