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

Improve fullframe requests handling

上级 50f27f2d
# TODO in mediasoup v2 (server-side)
* Set a proper value for Producer::FullFrameRequestBlockTimeout (currently 1 second).
* Should RtpStream::InitSeq() reset `received` to 0? We do it but it may break RTCP reports in both RtpStreamRecv and RtpStreamSend.
- NOTE: We have removed `received = 0` from `InitSeq()`, so we still send RTCP SenderReports on paused Consumers.
- Also check whether expectedPrior and receivedPrior should just belong to RtpStreamRecv rather than RtpStream (yes).
* When a video Consumer is paused and later resumed, it requests a Full Frame to the Producer. The sending browser does receive the PLI and (obviously) sends a full frame. The problem is that the `RtpStreamSend` of the Consumer ignores that full frame due to "bad sequence number":
```
mediasoup:ERROR:mediasoup-worker [id:vdcuccoq#1] RTC::Consumer::SendRtpPacket() | ---- paused !!! +2ms
mediasoup:ERROR:mediasoup-worker [id:vdcuccoq#1] RTC::Consumer::SendRtpPacket() | ---- paused !!! +1ms
mediasoup:ERROR:mediasoup-worker [id:vdcuccoq#1] RTC::Consumer::SendRtpPacket() | ---- paused !!! +0ms
mediasoup:ERROR:mediasoup-worker [id:vdcuccoq#1] RTC::Consumer::HandleRequest() | ---- CONSUMER REQUESTING FULL FRAME ---- +0ms
mediasoup:ERROR:mediasoup-worker [id:vdcuccoq#1] RTC::Consumer::HandleRequest() | ---- CONSUMER REQUESTING FULL FRAME ---- +0ms
mediasoup:ERROR:mediasoup-worker [id:vdcuccoq#1] RTC::Consumer::SendRtpPacket() | ---- ok go go RTP :) +18ms
mediasoup:WARN:mediasoup-worker [id:vdcuccoq#1] RTC::RtpStream::UpdateSeq() | bad sequence number, ignoring packet [ssrc:1945391646, seq:13041] +19s
mediasoup:WARN:mediasoup-worker [id:vdcuccoq#1] RTC::RtpStream::ReceivePacket() | invalid packet [ssrc:1945391646, seq:13041] +0ms
mediasoup:ERROR:mediasoup-worker [id:vdcuccoq#1] RTC::Consumer::SendRtpPacket() | ---- ok go go RTP :) +1ms
mediasoup:WARN:mediasoup-worker [id:vdcuccoq#1] RTC::RtpStream::UpdateSeq() | too bad sequence number, re-syncing RTP [ssrc:1945391646, seq:13042] +1ms
mediasoup:ERROR:mediasoup-worker [id:vdcuccoq#1] RTC::Consumer::SendRtpPacket() | ---- ok go go RTP :) +11ms
mediasoup:ERROR:mediasoup-worker [id:vdcuccoq#1] RTC::Consumer::SendRtpPacket() | ---- ok go go RTP :) +1ms
mediasoup:ERROR:mediasoup-worker [id:vdcuccoq#1] RTC::Consumer::SendRtpPacket() | ---- ok go go RTP :) +0ms
mediasoup:ERROR:mediasoup-worker [id:vdcuccoq#1] RTC::Consumer::SendRtpPacket() | ---- ok go go RTP :) +0ms
```
In fact, if the `RtpStreamSend` does not return false, the video automatically works, so we must refactor the `RtpStream::UpdateSeq()` method.
* Add a `fullFrrameRequestBlockTimer` and a `isFullFrameRequested` flag in `Producer`, so `Producer::RequestFullFrame()` check it and decides whether ask for a full frame to its streams or not.
* Add a `fullFrameRequestBlockTimer` and a `isFullFrameRequested` flag in `Producer`, so `Producer::RequestFullFrame()` check it and decides whether ask for a full frame to its streams or not.
* If a worker Consumer is paused (or sourcePaused), should the RTCP checks or report generations behave differently?
......
......@@ -157,10 +157,7 @@ namespace RTC
if (!IsEnabled())
return;
for (auto& listener : this->listeners)
{
listener->OnConsumerFullFrameRequired(this);
}
RequestFullFrame();
}
} // namespace RTC
......
......@@ -12,6 +12,7 @@
#include "RTC/RtpPacket.hpp"
#include "RTC/RtpStreamRecv.hpp"
#include "RTC/Transport.hpp"
#include "handles/Timer.hpp"
#include <json/json.h>
#include <map>
#include <string>
......@@ -19,7 +20,7 @@
namespace RTC
{
class Producer : public RtpStreamRecv::Listener
class Producer : public RtpStreamRecv::Listener, public Timer::Listener
{
public:
struct RtpMapping
......@@ -62,7 +63,7 @@ namespace RTC
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now);
void ReceiveRtcpFeedback(RTC::RTCP::FeedbackPsPacket* packet) const;
void ReceiveRtcpFeedback(RTC::RTCP::FeedbackRtpPacket* packet) const;
void RequestFullFrame() const;
void RequestFullFrame(bool force = false);
private:
void FillKnownHeaderExtensions();
......@@ -74,6 +75,10 @@ namespace RTC
void OnNackRequired(RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) override;
void OnPliRequired(RTC::RtpStreamRecv* rtpStream) override;
/* Pure virtual methods inherited from Timer::Listener. */
public:
void OnTimer(Timer* timer) override;
public:
// Passed by argument.
uint32_t producerId{ 0 };
......@@ -89,11 +94,13 @@ namespace RTC
// Allocated by this.
std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams;
std::map<uint32_t, RTC::RtpStreamRecv*> mapRtxStreams;
Timer* fullFrameRequestBlockTimer{ nullptr };
// Others.
struct KnownHeaderExtensions knownHeaderExtensions;
bool paused{ false };
bool rtpRawEventEnabled{ false };
bool rtpObjectEventEnabled{ false };
bool isFullFrameRequested{ false };
// Timestamp when last RTCP was sent.
uint64_t lastRtcpSentTime{ 0 };
uint16_t maxRtcpInterval{ 0 };
......
......@@ -94,7 +94,7 @@ namespace RTC
std::unordered_map<uint32_t, RTC::Producer*> producers;
std::unordered_map<uint32_t, RTC::Consumer*> consumers;
std::unordered_map<const RTC::Producer*, std::unordered_set<RTC::Consumer*>> mapProducerConsumers;
std::unordered_map<const RTC::Consumer*, const RTC::Producer*> mapConsumerProducer;
std::unordered_map<const RTC::Consumer*, RTC::Producer*> mapConsumerProducer;
std::unordered_map<RTC::Producer*, struct AudioLevelContainer> mapProducerAudioLevelContainer;
bool audioLevelsEventEnabled{ false };
};
......
......@@ -76,15 +76,6 @@ namespace RTC
{
return this->hasRtx;
}
inline void RtpStreamSend::Reset()
{
this->receivedBytes = 0;
this->lastPacketTimeMs = 0;
this->lastPacketRtpTimestamp = 0;
InitSeq(0);
}
} // namespace RTC
#endif
......@@ -291,6 +291,9 @@ namespace RTC
{
MS_TRACE();
if (this->kind == RTC::Media::Kind::AUDIO)
return;
for (auto& listener : this->listeners)
{
listener->OnConsumerFullFrameRequired(this);
......
......@@ -10,6 +10,11 @@
namespace RTC
{
/* Static. */
// TODO: Set a proper value.
static constexpr uint64_t FullFrameRequestBlockTimeout{ 1000 }; // In ms.
/* Instance methods. */
Producer::Producer(
......@@ -41,6 +46,9 @@ namespace RTC
this->maxRtcpInterval = RTC::RTCP::MaxAudioIntervalMs;
else
this->maxRtcpInterval = RTC::RTCP::MaxAudioIntervalMs;
// Set the RTP fullframe request block timer.
this->fullFrameRequestBlockTimer = new Timer(this);
}
Producer::~Producer()
......@@ -66,6 +74,9 @@ namespace RTC
listener->OnProducerClosed(this);
}
// Close the RTP fullframe request block timer.
this->fullFrameRequestBlockTimer->Destroy();
delete this;
}
......@@ -159,12 +170,12 @@ namespace RTC
if (wasPaused)
{
RequestFullFrame(true);
for (auto& listener : this->listeners)
{
listener->OnProducerResumed(this);
}
RequestFullFrame();
}
break;
......@@ -187,7 +198,7 @@ namespace RTC
// If set, require a full frame.
if (this->rtpRawEventEnabled)
RequestFullFrame();
RequestFullFrame(true);
break;
}
......@@ -209,7 +220,7 @@ namespace RTC
// If set, require a full frame.
if (this->rtpObjectEventEnabled)
RequestFullFrame();
RequestFullFrame(true);
break;
}
......@@ -348,16 +359,42 @@ namespace RTC
this->transport->SendRtcpPacket(packet);
}
void Producer::RequestFullFrame() const
void Producer::RequestFullFrame(bool force)
{
MS_TRACE();
if (this->kind == RTC::Media::Kind::AUDIO)
return;
if (force)
{
// Stop the timer.
this->fullFrameRequestBlockTimer->Stop();
}
else if (this->fullFrameRequestBlockTimer->IsActive())
{
MS_DEBUG_TAG(rtx, "blocking fullframe request until timer expires");
// Set flag.
this->isFullFrameRequested = true;
return;
}
else
{
// Run the timer.
this->fullFrameRequestBlockTimer->Start(FullFrameRequestBlockTimeout);
}
for (auto& kv : this->rtpStreams)
{
auto rtpStream = kv.second;
rtpStream->RequestFullFrame();
}
// Reset flag.
this->isFullFrameRequested = false;
}
void Producer::FillKnownHeaderExtensions()
......@@ -562,4 +599,20 @@ namespace RTC
this->transport->SendRtcpPacket(&packet);
this->transport->SendRtcpPacket(&packet);
}
inline void Producer::OnTimer(Timer* timer)
{
MS_TRACE();
if (timer == this->fullFrameRequestBlockTimer)
{
// Nobody asked for a fullframe since the timer was started.
if (!this->isFullFrameRequested)
return;
MS_DEBUG_TAG(rtx, "requesting fullframe after timer expires");
RequestFullFrame();
}
}
} // namespace RTC
......@@ -120,6 +120,7 @@ namespace RTC
return false;
}
if (udelta < MaxDropout)
{
// In order, with permissible gap.
......
......@@ -312,6 +312,20 @@ 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 = 0;
// Also reset RtpStreamSend own members.
this->receivedBytes = 0;
this->lastPacketTimeMs = 0;
this->lastPacketRtpTimestamp = 0;
}
void RtpStreamSend::ClearBuffer()
{
MS_TRACE();
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论