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

Code cleanup

上级 4f52d2b8
# TODO in mediasoup v2 (server-side)
* `Producer`: Clearn RTX mapping when streams are updated/modified.
* `RtpListener`: Remove `ptTable` (period) and add `ridTable`.
* Remove `producer.on('rtprawpacket')` and, instead, create a special `RtpConsumer` or something like that.
......
......@@ -43,6 +43,7 @@ namespace RTC
void SourcePause();
void SourceResume();
void SourceRtpParametersUpdated();
void SetPreferredProfile(const RTC::RtpEncodingParameters::Profile profile);
void Disable();
bool IsEnabled() const;
const RTC::RtpParameters& GetParameters() const;
......@@ -53,7 +54,6 @@ namespace RTC
void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report);
uint32_t GetTransmissionRate(uint64_t now);
void RequestFullFrame();
void SetPreferredProfile(const RTC::RtpEncodingParameters::Profile profile);
private:
void FillSupportedCodecPayloadTypes();
......@@ -126,19 +126,6 @@ namespace RTC
{
return this->transmittedCounter.GetRate(now) + this->retransmittedCounter.GetRate(now);
}
inline void Consumer::SetPreferredProfile(const RTC::RtpEncodingParameters::Profile profile)
{
if (this->preferredProfile == profile)
return;
this->preferredProfile = profile;
// TODO: Set it dynamically dynamic.
this->effectiveProfile = profile;
this->syncRequired = true;
RequestFullFrame();
}
} // namespace RTC
#endif
......@@ -39,10 +39,9 @@ namespace RTC
void SetRtx(uint8_t payloadType, uint32_t ssrc);
bool HasRtx() const;
void RtxEncode(RtpPacket* packet);
void Reset();
void ClearRetransmissionBuffer();
private:
void ClearBuffer();
void StorePacket(RTC::RtpPacket* packet);
/* Pure virtual methods inherited from RtpStream. */
......
......@@ -159,9 +159,7 @@ namespace RTC
MS_DEBUG_DEV("Consumer paused [consumerId:%" PRIu32 "]", this->consumerId);
if (IsEnabled() && !this->sourcePaused)
{
this->rtpStream->Reset();
}
this->rtpStream->ClearRetransmissionBuffer();
}
void Consumer::Resume()
......@@ -195,9 +193,7 @@ namespace RTC
this->notifier->Emit(this->consumerId, "sourcepaused");
if (IsEnabled() && !this->paused)
{
this->rtpStream->Reset();
}
this->rtpStream->ClearRetransmissionBuffer();
}
void Consumer::SourceResume()
......@@ -214,9 +210,7 @@ namespace RTC
this->notifier->Emit(this->consumerId, "sourceresumed");
if (IsEnabled() && !this->paused)
{
RequestFullFrame();
}
}
void Consumer::SourceRtpParametersUpdated()
......@@ -227,6 +221,28 @@ namespace RTC
return;
this->syncRequired = true;
this->rtpStream->ClearRetransmissionBuffer();
}
void Consumer::SetPreferredProfile(const RTC::RtpEncodingParameters::Profile profile)
{
MS_TRACE();
if (this->preferredProfile == profile)
return;
this->preferredProfile = profile;
// TODO: Set it dynamically.
this->effectiveProfile = profile;
if (IsEnabled() && !IsPaused())
{
this->syncRequired = true;
this->rtpStream->ClearRetransmissionBuffer();
RequestFullFrame();
}
}
/**
......@@ -284,6 +300,17 @@ namespace RTC
// Check whether sequence number and timestamp sync is required.
if (this->syncRequired)
{
// TODO
MS_ERROR("------------ syncRequired IS TRUE !!!!!");
// TODO
MS_ERROR(
"--- [profile:%s, effectiveProfile:%s, ssrc:%" PRIu32 ", packet->seq:%" PRIu16 "]",
RTC::RtpEncodingParameters::profile2String[profile].c_str(),
RTC::RtpEncodingParameters::profile2String[this->effectiveProfile].c_str(),
packet->GetSsrc(),
packet->GetSequenceNumber());
this->seqNum += 1;
auto now = static_cast<uint32_t>(DepLibUV::GetTime());
......@@ -326,6 +353,17 @@ namespace RTC
// Update transmitted RTP data counter.
this->transmittedCounter.Update(packet);
}
else
{
// TODO
MS_ERROR(
"--- rtpStream->ReceivePacket() failed [profile:%s, effectiveProfile:%s, ssrc:%" PRIu32
", packet->seq:%" PRIu16 "]",
RTC::RtpEncodingParameters::profile2String[profile].c_str(),
RTC::RtpEncodingParameters::profile2String[this->effectiveProfile].c_str(),
ssrc,
this->lastRecvSeqNum);
}
// Restore packet SSRC.
packet->SetSsrc(ssrc);
......@@ -494,8 +532,8 @@ namespace RTC
MS_DEBUG_TAG(
rtx,
"sending rtx packet [ssrc: %" PRIu32 " seqnr: %" PRIu16
"] recovering original [ssrc: %" PRIu32 " seqnr: %" PRIu16 "]",
"sending rtx packet [ssrc: %" PRIu32 ", seq: %" PRIu16
"] recovering original [ssrc: %" PRIu32 ", seq: %" PRIu16 "]",
rtxPacket->GetSsrc(),
rtxPacket->GetSequenceNumber(),
packet->GetSsrc(),
......@@ -506,7 +544,7 @@ namespace RTC
rtxPacket = packet;
MS_DEBUG_TAG(
rtx,
"retransmitting packet [ssrc: %" PRIu32 " seqnr: %" PRIu16 "]",
"retransmitting packet [ssrc: %" PRIu32 ", seq: %" PRIu16 "]",
rtxPacket->GetSsrc(),
rtxPacket->GetSequenceNumber());
}
......
......@@ -364,6 +364,9 @@ namespace RTC
auto packet = new RtpPacket(
header, extensionHeader, payload, this->payloadLength, this->payloadPadding, this->size);
// Clone seq32.
packet->seq32 = this->seq32;
// Parse RFC 5285 extension header.
packet->ParseExtensions();
......
......@@ -28,7 +28,7 @@ namespace RTC
MS_TRACE();
// Clear the RTP buffer.
ClearBuffer();
ClearRetransmissionBuffer();
}
Json::Value RtpStreamSend::ToJson() const
......@@ -137,6 +137,7 @@ namespace RTC
auto bufferItReverse = this->buffer.rbegin();
uint32_t bufferFirstSeq32 = (*bufferIt).seq32;
uint32_t bufferLastSeq32 = (*bufferItReverse).seq32;
bool inRange = true;
// Requested packet range not found.
if (firstSeq32 > bufferLastSeq32 || lastSeq32 < bufferFirstSeq32)
......@@ -150,20 +151,32 @@ namespace RTC
// Try again.
if (firstSeq32 > bufferLastSeq32 || lastSeq32 < bufferFirstSeq32)
{
MS_WARN_TAG(rtx, "requested packet range not in the buffer");
return;
firstSeq32 += RtpSeqMod;
lastSeq32 += RtpSeqMod;
inRange = false;
}
}
// Otherwise just return.
else
{
MS_WARN_TAG(rtx, "requested packet range not in the buffer");
return;
inRange = false;
}
}
if (!inRange)
{
MS_WARN_TAG(
rtx,
"requested packet range not in the buffer [seq:%" PRIu16 ", seq32:%" PRIu32
", bufferFirstSeq32:%" PRIu32 ", bufferLastSeq32:%" PRIu32 "]",
seq,
firstSeq32,
bufferFirstSeq32,
bufferLastSeq32);
return;
}
// Look for each requested packet.
uint64_t now = DepLibUV::GetTime();
uint32_t rtt = (this->rtt != 0u ? this->rtt : DefaultRtt);
......@@ -316,24 +329,7 @@ namespace RTC
return report;
}
void RtpStreamSend::Reset()
{
MS_TRACE();
// By setting started to 0, on next packet the RtpStream will call
// InitSeq(seq).
this->started = false;
// Also reset RtpStreamSend own members.
this->receivedBytes = 0;
this->lastPacketTimeMs = 0;
this->lastPacketRtpTimestamp = 0;
// Clear the buffer.
ClearBuffer();
}
void RtpStreamSend::ClearBuffer()
void RtpStreamSend::ClearRetransmissionBuffer()
{
MS_TRACE();
......@@ -444,7 +440,7 @@ namespace RTC
MS_TRACE();
// Clear the RTP buffer.
ClearBuffer();
ClearRetransmissionBuffer();
}
void RtpStreamSend::SetRtx(uint8_t payloadType, uint32_t ssrc)
......
......@@ -772,7 +772,7 @@ namespace RTC
{
MS_WARN_TAG(
rtcp,
"no Consumer found for received NACK Feedback packet "
"no Consumer found for received Feedback packet "
"[sender ssrc:%" PRIu32 ", media ssrc:%" PRIu32 "]",
feedback->GetMediaSsrc(),
feedback->GetMediaSsrc());
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论