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

Improve paused Consumer.

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