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

Code cleanup

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