提交 b9532fcf authored 作者: José Luis Millán's avatar José Luis Millán

Producer: Do not destroy the stream upon RTP inactivity

上级 37450db9
...@@ -73,7 +73,7 @@ namespace RTC ...@@ -73,7 +73,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::RtpStream::Listener. */ /* Pure virtual methods inherited from RTC::RtpStream::Listener. */
public: public:
void OnRtpStreamDied(RTC::RtpStream* rtpStream) override; void OnRtpStreamInactivity(RTC::RtpStream* rtpStream) override;
void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) override; void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) override;
void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) override; void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) override;
......
...@@ -90,7 +90,7 @@ namespace RTC ...@@ -90,7 +90,7 @@ namespace RTC
void OnRtpStreamRecvNackRequired( void OnRtpStreamRecvNackRequired(
RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) override; RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) override;
void OnRtpStreamRecvPliRequired(RTC::RtpStreamRecv* rtpStream) override; void OnRtpStreamRecvPliRequired(RTC::RtpStreamRecv* rtpStream) override;
void OnRtpStreamDied(RTC::RtpStream* rtpStream) override; void OnRtpStreamInactivity(RTC::RtpStream* rtpStream) override;
void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) override; void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) override;
void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) override; void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) override;
......
...@@ -16,7 +16,7 @@ namespace RTC ...@@ -16,7 +16,7 @@ namespace RTC
class Listener class Listener
{ {
public: public:
virtual void OnRtpStreamDied(RTC::RtpStream* rtpStream) = 0; virtual void OnRtpStreamInactivity(RTC::RtpStream* rtpStream) = 0;
virtual void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) = 0; virtual void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) = 0;
virtual void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) = 0; virtual void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) = 0;
}; };
...@@ -50,6 +50,7 @@ namespace RTC ...@@ -50,6 +50,7 @@ namespace RTC
const RTC::RtpCodecMimeType& GetMimeType() const; const RTC::RtpCodecMimeType& GetMimeType() const;
float GetLossPercentage() const; float GetLossPercentage() const;
bool IsHealthy() const; bool IsHealthy() const;
void SetUnhealthy();
void ResetHealthCheckTimer(uint16_t timeout = HealthCheckPeriod); void ResetHealthCheckTimer(uint16_t timeout = HealthCheckPeriod);
protected: protected:
...@@ -128,6 +129,11 @@ namespace RTC ...@@ -128,6 +129,11 @@ namespace RTC
{ {
return this->healthy; return this->healthy;
} }
inline void RtpStream::SetUnhealthy()
{
this->healthy = false;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -699,7 +699,7 @@ namespace RTC ...@@ -699,7 +699,7 @@ namespace RTC
} }
} }
void Consumer::OnRtpStreamDied(RtpStream* rtpStream) void Consumer::OnRtpStreamInactivity(RtpStream* rtpStream)
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -772,7 +772,7 @@ namespace RTC ...@@ -772,7 +772,7 @@ namespace RTC
rtpStream->pliCount++; rtpStream->pliCount++;
} }
void Producer::OnRtpStreamDied(RTC::RtpStream* rtpStream) void Producer::OnRtpStreamInactivity(RTC::RtpStream* rtpStream)
{ {
MS_TRACE(); MS_TRACE();
...@@ -782,10 +782,42 @@ namespace RTC ...@@ -782,10 +782,42 @@ namespace RTC
this->mapRtpStreamProfiles.find(rtpStreamRecv) != this->mapRtpStreamProfiles.end(), this->mapRtpStreamProfiles.find(rtpStreamRecv) != this->mapRtpStreamProfiles.end(),
"stream not present in mapRtpStreamProfiles"); "stream not present in mapRtpStreamProfiles");
MS_DEBUG_TAG(rtp, "stream is dead [ssrc:%" PRIu32 "]", rtpStream->GetSsrc()); // Single healthy profile present. Ignore.
if (this->healthyProfiles.size() == 1)
return;
// Simulcast. Check whether any RTP is being received at all.
uint32_t totalBitrate = 0;
uint64_t now = DepLibUV::GetTime();
for (auto it : this->healthyProfiles)
{
auto healthyRtpStream = it.second;
auto ssrc = healthyRtpStream->GetSsrc();
totalBitrate += this->rtpStreams[ssrc]->GetRate(now);
}
// No RTP is being received at all. Ignore.
if (totalBitrate == 0)
return;
// Simulcast. Remove the stream from healthy profiles.
MS_DEBUG_TAG(rtp,
"rtp inactivity detected [ssrc:%" PRIu32,
rtpStream->GetSsrc());
rtpStream->SetUnhealthy();
RemoveHealthyProfiles(rtpStreamRecv);
// Completely destroy the stream. // Reset health check timer on every healthy stream.
ClearRtpStream(rtpStreamRecv); for (auto it : this->healthyProfiles)
{
auto healthyRtpStream = it.second;
auto ssrc = healthyRtpStream->GetSsrc();
this->rtpStreams[ssrc]->ResetHealthCheckTimer(RTC::RtpStream::HealthCheckPeriod * 2);
}
} }
void Producer::OnRtpStreamHealthy(RTC::RtpStream* rtpStream) void Producer::OnRtpStreamHealthy(RTC::RtpStream* rtpStream)
......
...@@ -232,7 +232,7 @@ namespace RTC ...@@ -232,7 +232,7 @@ namespace RTC
auto now = DepLibUV::GetTime(); auto now = DepLibUV::GetTime();
if (this->transmissionCounter.GetRate(now) == 0) if (this->transmissionCounter.GetRate(now) == 0)
this->listener->OnRtpStreamDied(this); this->listener->OnRtpStreamInactivity(this);
} }
void RtpStreamRecv::OnNackGeneratorNackRequired(const std::vector<uint16_t>& seqNumbers) void RtpStreamRecv::OnNackGeneratorNackRequired(const std::vector<uint16_t>& seqNumbers)
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论