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

Improve paused Consumer.

上级 eebb70fd
# TODO in mediasoup v2 (server-side) # TODO in mediasoup v2 (server-side)
* 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": * 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":
``` ```
......
...@@ -55,6 +55,8 @@ namespace RTC ...@@ -55,6 +55,8 @@ namespace RTC
void FillSupportedCodecPayloadTypes(); void FillSupportedCodecPayloadTypes();
void CreateRtpStream(RTC::RtpEncodingParameters& encoding); void CreateRtpStream(RTC::RtpEncodingParameters& encoding);
void RetransmitRtpPacket(RTC::RtpPacket* packet); void RetransmitRtpPacket(RTC::RtpPacket* packet);
void Pause();
void Resume();
public: public:
// Passed by argument. // Passed by argument.
...@@ -114,8 +116,13 @@ namespace RTC ...@@ -114,8 +116,13 @@ namespace RTC
if (this->sourcePaused) if (this->sourcePaused)
return; return;
bool wasPaused = IsPaused();
this->sourcePaused = true; this->sourcePaused = true;
this->notifier->Emit(this->consumerId, "sourcepaused"); this->notifier->Emit(this->consumerId, "sourcepaused");
if (!wasPaused)
Pause();
} }
inline void Consumer::SetSourceResumed() inline void Consumer::SetSourceResumed()
...@@ -123,14 +130,38 @@ namespace RTC ...@@ -123,14 +130,38 @@ namespace RTC
if (!this->sourcePaused) if (!this->sourcePaused)
return; return;
bool wasPaused = IsPaused();
this->sourcePaused = false; this->sourcePaused = false;
this->notifier->Emit(this->consumerId, "sourceresumed"); this->notifier->Emit(this->consumerId, "sourceresumed");
if (wasPaused)
Resume();
} }
inline uint32_t Consumer::GetTransmissionRate(uint64_t now) inline uint32_t Consumer::GetTransmissionRate(uint64_t now)
{ {
return this->transmittedCounter.GetRate(now) + this->retransmittedCounter.GetRate(now); return this->transmittedCounter.GetRate(now) + this->retransmittedCounter.GetRate(now);
} }
inline void Consumer::Pause()
{
if (!IsEnabled())
return;
this->rtpStream->Reset();
}
inline void Consumer::Resume()
{
if (!IsEnabled())
return;
for (auto& listener : this->listeners)
{
listener->OnConsumerFullFrameRequired(this);
}
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -104,7 +104,7 @@ namespace RTC ...@@ -104,7 +104,7 @@ namespace RTC
{ {
rate.Reset(); rate.Reset();
this->packets = 0; this->packets = 0;
this->bytes = 0; this->bytes = 0;
} }
} // namespace RTC } // namespace RTC
......
...@@ -31,8 +31,10 @@ namespace RTC ...@@ -31,8 +31,10 @@ namespace RTC
uint32_t GetSsrc(); uint32_t GetSsrc();
virtual bool ReceivePacket(RTC::RtpPacket* packet); virtual bool ReceivePacket(RTC::RtpPacket* packet);
private: protected:
void InitSeq(uint16_t seq); void InitSeq(uint16_t seq);
private:
bool UpdateSeq(RTC::RtpPacket* packet); bool UpdateSeq(RTC::RtpPacket* packet);
/* Pure virtual methods that must be implemented by the subclass. */ /* Pure virtual methods that must be implemented by the subclass. */
......
...@@ -39,6 +39,7 @@ namespace RTC ...@@ -39,6 +39,7 @@ 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();
private: private:
void ClearBuffer(); void ClearBuffer();
...@@ -75,6 +76,15 @@ namespace RTC ...@@ -75,6 +76,15 @@ namespace RTC
{ {
return this->hasRtx; return this->hasRtx;
} }
inline void RtpStreamSend::Reset()
{
this->receivedBytes = 0;
this->lastPacketTimeMs = 0;
this->lastPacketRtpTimestamp = 0;
InitSeq(0);
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -103,28 +103,34 @@ namespace RTC ...@@ -103,28 +103,34 @@ namespace RTC
case Channel::Request::MethodId::CONSUMER_PAUSE: case Channel::Request::MethodId::CONSUMER_PAUSE:
{ {
if (this->paused)
return;
bool wasPaused = IsPaused();
this->paused = true; this->paused = true;
request->Accept(); request->Accept();
if (!wasPaused)
Pause();
break; break;
} }
case Channel::Request::MethodId::CONSUMER_RESUME: case Channel::Request::MethodId::CONSUMER_RESUME:
{ {
if (!this->paused)
return;
bool wasPaused = IsPaused(); bool wasPaused = IsPaused();
this->paused = false; this->paused = false;
request->Accept(); request->Accept();
if (IsEnabled() && wasPaused && !IsPaused()) if (wasPaused)
{ Resume();
for (auto& listener : this->listeners)
{
listener->OnConsumerFullFrameRequired(this);
}
}
break; break;
} }
......
...@@ -77,11 +77,9 @@ namespace RTC ...@@ -77,11 +77,9 @@ namespace RTC
this->maxSeq = seq; this->maxSeq = seq;
this->badSeq = RtpSeqMod + 1; // So seq == badSeq is false. this->badSeq = RtpSeqMod + 1; // So seq == badSeq is false.
this->cycles = 0; this->cycles = 0;
this->received = 0;
this->receivedPrior = 0; this->receivedPrior = 0;
this->expectedPrior = 0; this->expectedPrior = 0;
// Also reset the highest seen RTP timestamp. this->maxTimestamp = 0; // Also reset the highest seen RTP timestamp.
this->maxTimestamp = 0;
// Call the OnInitSeq method of the child. // Call the OnInitSeq method of the child.
OnInitSeq(); OnInitSeq();
......
...@@ -289,7 +289,7 @@ namespace RTC ...@@ -289,7 +289,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (received == 0u) if (this->received == 0u)
return nullptr; return nullptr;
auto report = new RTC::RTCP::SenderReport(); auto report = new RTC::RTCP::SenderReport();
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论