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

RtpStream: multiple health status callbacks: 'died', 'healthy', 'unhealthy'

上级 4584fad8
...@@ -66,7 +66,9 @@ namespace RTC ...@@ -66,7 +66,9 @@ namespace RTC
/* Pure virtual methods inherited from RTC::RtpStream::Listener. */ /* Pure virtual methods inherited from RTC::RtpStream::Listener. */
public: public:
void OnRtpStreamHealthReport(RTC::RtpStream* rtpStream, bool healthy) override; void OnRtpStreamDied(RTC::RtpStream* rtpStream) override;
void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) override;
void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) override;
public: public:
// Passed by argument. // Passed by argument.
......
...@@ -70,7 +70,7 @@ namespace RTC ...@@ -70,7 +70,7 @@ namespace RTC
void ReceiveRtcpFeedback(RTC::RTCP::FeedbackPsPacket* packet) const; void ReceiveRtcpFeedback(RTC::RTCP::FeedbackPsPacket* packet) const;
void ReceiveRtcpFeedback(RTC::RTCP::FeedbackRtpPacket* packet) const; void ReceiveRtcpFeedback(RTC::RTCP::FeedbackRtpPacket* packet) const;
void RequestKeyFrame(bool force = false); void RequestKeyFrame(bool force = false);
const std::set<RTC::RtpEncodingParameters::Profile> GetProfiles() const; const std::set<RTC::RtpEncodingParameters::Profile>& GetHealthyProfiles() const;
private: private:
void FillHeaderExtensionIds(); void FillHeaderExtensionIds();
...@@ -80,13 +80,17 @@ namespace RTC ...@@ -80,13 +80,17 @@ namespace RTC
void ClearRtpStreams(); void ClearRtpStreams();
void ApplyRtpMapping(RTC::RtpPacket* packet) const; void ApplyRtpMapping(RTC::RtpPacket* packet) const;
RTC::RtpEncodingParameters::Profile GetProfile(RTC::RtpStreamRecv* rtpStream, RTC::RtpPacket* packet); RTC::RtpEncodingParameters::Profile GetProfile(RTC::RtpStreamRecv* rtpStream, RTC::RtpPacket* packet);
void AddHealthyProfiles(RTC::RtpStreamRecv* rtpStream);
void RemoveHealthyProfiles(RTC::RtpStreamRecv* rtpStream);
/* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */ /* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */
public: public:
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 OnRtpStreamHealthReport(RTC::RtpStream* rtpStream, bool healthy) override; void OnRtpStreamDied(RTC::RtpStream* rtpStream) override;
void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) override;
void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) override;
/* Pure virtual methods inherited from Timer::Listener. */ /* Pure virtual methods inherited from Timer::Listener. */
public: public:
...@@ -107,7 +111,8 @@ namespace RTC ...@@ -107,7 +111,8 @@ namespace RTC
// Allocated by this. // Allocated by this.
std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams; std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams;
std::map<uint32_t, RTC::RtpStreamRecv*> mapRtxStreams; std::map<uint32_t, RTC::RtpStreamRecv*> mapRtxStreams;
std::map<RTC::RtpStreamRecv*, std::set<RTC::RtpEncodingParameters::Profile>> profiles; std::map<RTC::RtpStreamRecv*, std::set<RTC::RtpEncodingParameters::Profile>> mapRtpStreamProfiles;
std::set<RTC::RtpEncodingParameters::Profile> healthyProfiles;
Timer* keyFrameRequestBlockTimer{ nullptr }; Timer* keyFrameRequestBlockTimer{ nullptr };
// Others. // Others.
std::vector<RtpEncodingParameters> outputEncodings; std::vector<RtpEncodingParameters> outputEncodings;
...@@ -159,24 +164,9 @@ namespace RTC ...@@ -159,24 +164,9 @@ namespace RTC
} }
} }
inline const std::set<RTC::RtpEncodingParameters::Profile> Producer::GetProfiles() const inline const std::set<RTC::RtpEncodingParameters::Profile>& Producer::GetHealthyProfiles() const
{ {
std::set<RTC::RtpEncodingParameters::Profile> profiles; return this->healthyProfiles;
for (const auto& it : this->profiles)
{
for (const auto& it2 : it.second)
{
auto profile = it2;
if (profile == RTC::RtpEncodingParameters::Profile::DEFAULT)
break;
profiles.insert(profile);
}
}
return profiles;
} }
} // namespace RTC } // namespace RTC
......
...@@ -16,7 +16,9 @@ namespace RTC ...@@ -16,7 +16,9 @@ namespace RTC
class Listener class Listener
{ {
public: public:
virtual void OnRtpStreamHealthReport(RTC::RtpStream* rtpStream, bool healthy) = 0; virtual void OnRtpStreamDied(RTC::RtpStream* rtpStream) = 0;
virtual void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) = 0;
virtual void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) = 0;
}; };
public: public:
......
...@@ -544,12 +544,19 @@ namespace RTC ...@@ -544,12 +544,19 @@ namespace RTC
} }
} }
void Consumer::OnRtpStreamHealthReport(RtpStream* stream, bool healthy) void Consumer::OnRtpStreamDied(RtpStream* /*stream*/)
{ {
MS_TRACE(); MS_TRACE();
}
if (!IsEnabled()) void Consumer::OnRtpStreamHealthy(RtpStream* /*stream*/)
return; {
MS_TRACE();
}
void Consumer::OnRtpStreamUnhealthy(RtpStream* /*stream*/)
{
MS_TRACE();
} }
void Consumer::FillSupportedCodecPayloadTypes() void Consumer::FillSupportedCodecPayloadTypes()
......
...@@ -50,7 +50,7 @@ namespace RTC ...@@ -50,7 +50,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
this->profiles.clear(); this->mapRtpStreamProfiles.clear();
ClearRtpStreams(); ClearRtpStreams();
} }
...@@ -507,20 +507,14 @@ namespace RTC ...@@ -507,20 +507,14 @@ namespace RTC
this->mapRtxStreams[encoding.rtx.ssrc] = rtpStream; this->mapRtxStreams[encoding.rtx.ssrc] = rtpStream;
} }
// Enter the stream into the profiles map. // TODO: For SVC, the dependencyEncodingIds must be checked and their respective profiles must be also added into mapRtpStreamProfiles.
// NOTE: This is specific to simulcast with no temporal layers.
auto profile = encoding.profile; auto profile = encoding.profile;
this->profiles[rtpStream].insert(profile); // Add the stream to the profiles map.
this->mapRtpStreamProfiles[rtpStream].insert(profile);
// Don't announce default profile, but just those for simulcast/SVC. // Add new profile/s into healthyProfiles and notify the listener.
if (profile != RTC::RtpEncodingParameters::Profile::DEFAULT) AddHealthyProfiles(rtpStream);
{
for (auto& listener : this->listeners)
{
listener->OnProducerProfileEnabled(this, profile);
}
}
// Request a key frame since we may have lost the first packets of this stream. // Request a key frame since we may have lost the first packets of this stream.
RequestKeyFrame(true); RequestKeyFrame(true);
...@@ -530,20 +524,8 @@ namespace RTC ...@@ -530,20 +524,8 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
auto& profiles = this->profiles[rtpStream]; // Remove the profiles related to this stream from healthyProfiles and notify the listener.
RemoveHealthyProfiles(rtpStream);
// Notify about the profiles being disabled.
for (auto& profile : profiles)
{
// Don't announce default profile, but just those for simulcast/SVC.
if (profile == RTC::RtpEncodingParameters::Profile::DEFAULT)
break;
for (auto& listener : this->listeners)
{
listener->OnProducerProfileDisabled(this, profile);
}
}
this->rtpStreams.erase(rtpStream->GetSsrc()); this->rtpStreams.erase(rtpStream->GetSsrc());
...@@ -560,7 +542,7 @@ namespace RTC ...@@ -560,7 +542,7 @@ namespace RTC
} }
} }
this->profiles.erase(rtpStream); this->mapRtpStreamProfiles.erase(rtpStream);
delete rtpStream; delete rtpStream;
} }
...@@ -577,7 +559,7 @@ namespace RTC ...@@ -577,7 +559,7 @@ namespace RTC
} }
// Notify about all profiles being disabled. // Notify about all profiles being disabled.
for (auto& kv : this->profiles) for (auto& kv : this->mapRtpStreamProfiles)
{ {
auto& profiles = kv.second; auto& profiles = kv.second;
...@@ -596,7 +578,8 @@ namespace RTC ...@@ -596,7 +578,8 @@ namespace RTC
this->rtpStreams.clear(); this->rtpStreams.clear();
this->mapRtxStreams.clear(); this->mapRtxStreams.clear();
this->profiles.clear(); this->mapRtpStreamProfiles.clear();
this->healthyProfiles.clear();
} }
void Producer::ApplyRtpMapping(RTC::RtpPacket* packet) const void Producer::ApplyRtpMapping(RTC::RtpPacket* packet) const
...@@ -638,9 +621,9 @@ namespace RTC ...@@ -638,9 +621,9 @@ namespace RTC
RTC::RtpStreamRecv* rtpStream, RTC::RtpPacket* packet) RTC::RtpStreamRecv* rtpStream, RTC::RtpPacket* packet)
{ {
// The stream is already mapped to a profile. // The stream is already mapped to a profile.
if (this->profiles.find(rtpStream) != this->profiles.end()) if (this->mapRtpStreamProfiles.find(rtpStream) != this->mapRtpStreamProfiles.end())
{ {
auto it = this->profiles[rtpStream].begin(); auto it = this->mapRtpStreamProfiles[rtpStream].begin();
auto profile = *it; auto profile = *it;
return profile; return profile;
...@@ -649,6 +632,52 @@ namespace RTC ...@@ -649,6 +632,52 @@ namespace RTC
MS_THROW_ERROR("unknown RTP packet received [ssrc:%" PRIu32 "]", packet->GetSsrc()); MS_THROW_ERROR("unknown RTP packet received [ssrc:%" PRIu32 "]", packet->GetSsrc());
} }
void Producer::AddHealthyProfiles(RTC::RtpStreamRecv* rtpStream)
{
auto& profiles = this->mapRtpStreamProfiles[rtpStream];
// Notify about the profiles being enabled.
for (auto& profile : profiles)
{
// Don't announce default profile, but just those for simulcast/SVC.
if (profile == RTC::RtpEncodingParameters::Profile::DEFAULT)
break;
// Add the profile to the healthy profiles set.
const auto& result = this->healthyProfiles.insert(profile);
bool profileExisted = !result.second;
MS_ASSERT(!profileExisted, "profile already in headltyProfiles set");
for (auto& listener : this->listeners)
{
listener->OnProducerProfileEnabled(this, profile);
}
}
}
void Producer::RemoveHealthyProfiles(RTC::RtpStreamRecv* rtpStream)
{
auto& profiles = this->mapRtpStreamProfiles[rtpStream];
// Notify about the profiles being disabled.
for (auto& profile : profiles)
{
// Don't announce default profile, but just those for simulcast/SVC.
if (profile == RTC::RtpEncodingParameters::Profile::DEFAULT)
break;
// Remove the profile from the healthy profiles set.
auto result = this->healthyProfiles.erase(profile);
bool profileExisted = (result == 1);
MS_ASSERT(profileExisted, "profile not present in headltyProfiles set");
for (auto& listener : this->listeners)
{
listener->OnProducerProfileDisabled(this, profile);
}
}
}
void Producer::OnRtpStreamRecvNackRequired( void Producer::OnRtpStreamRecvNackRequired(
RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers)
{ {
...@@ -713,45 +742,52 @@ namespace RTC ...@@ -713,45 +742,52 @@ namespace RTC
this->transport->SendRtcpPacket(&packet); this->transport->SendRtcpPacket(&packet);
} }
void Producer::OnRtpStreamHealthReport(RTC::RtpStream* rtpStream, bool healthy) void Producer::OnRtpStreamDied(RTC::RtpStream* rtpStream)
{ {
MS_TRACE(); MS_TRACE();
auto rtpStreamRecv = static_cast<RtpStreamRecv*>(rtpStream); auto rtpStreamRecv = static_cast<RtpStreamRecv*>(rtpStream);
MS_ASSERT( MS_ASSERT(
this->profiles.find(rtpStreamRecv) != this->profiles.end(), this->mapRtpStreamProfiles.find(rtpStreamRecv) != this->mapRtpStreamProfiles.end(),
"stream not present in profiles map"); "stream not present in mapRtpStreamProfiles");
auto& profiles = this->profiles[rtpStreamRecv]; MS_DEBUG_TAG(rtp, "stream is dead [ssrc:%" PRIu32 "]", rtpStream->GetSsrc());
// The stream has transitioned to non healthy.
if (rtpStream->IsHealthy() && !healthy)
{
MS_DEBUG_TAG(rtp, "stream is now unhealthy [ssrc:%" PRIu32 "]", rtpStream->GetSsrc());
// Completely destroy the stream. // Completely destroy the stream.
ClearRtpStream(rtpStreamRecv); ClearRtpStream(rtpStreamRecv);
} }
// The stream has transitioned to healthy. void Producer::OnRtpStreamHealthy(RTC::RtpStream* rtpStream)
if (!rtpStream->IsHealthy() && healthy)
{ {
MS_TRACE();
auto rtpStreamRecv = static_cast<RtpStreamRecv*>(rtpStream);
MS_ASSERT(
this->mapRtpStreamProfiles.find(rtpStreamRecv) != this->mapRtpStreamProfiles.end(),
"stream not present in mapRtpStreamProfiles");
MS_DEBUG_TAG(rtp, "stream is now healthy [ssrc:%" PRIu32 "]", rtpStream->GetSsrc()); MS_DEBUG_TAG(rtp, "stream is now healthy [ssrc:%" PRIu32 "]", rtpStream->GetSsrc());
// Notify about the profiles being disabled. // Add the profiles related to this stream into healthyProfiles and notify the listener.
for (auto& profile : profiles) AddHealthyProfiles(rtpStreamRecv);
{ }
// Don't announce default profile, but just those for simulcast/SVC.
if (profile == RTC::RtpEncodingParameters::Profile::DEFAULT)
break;
for (auto& listener : this->listeners) void Producer::OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream)
{ {
listener->OnProducerProfileEnabled(this, profile); MS_TRACE();
}
} auto rtpStreamRecv = static_cast<RtpStreamRecv*>(rtpStream);
}
MS_ASSERT(
this->mapRtpStreamProfiles.find(rtpStreamRecv) != this->mapRtpStreamProfiles.end(),
"stream not present in mapRtpStreamProfiles");
MS_DEBUG_TAG(rtp, "stream is now unhealthy [ssrc:%" PRIu32 "]", rtpStream->GetSsrc());
// Remove the profiles related to this stream from healthyProfiles and notify the listener.
RemoveHealthyProfiles(rtpStreamRecv);
} }
inline void Producer::OnTimer(Timer* timer) inline void Producer::OnTimer(Timer* timer)
......
...@@ -454,7 +454,7 @@ namespace RTC ...@@ -454,7 +454,7 @@ namespace RTC
// Add us as listener. // Add us as listener.
consumer->AddListener(this); consumer->AddListener(this);
auto profiles = producer->GetProfiles(); auto profiles = producer->GetHealthyProfiles();
std::set<RtpEncodingParameters::Profile>::reverse_iterator it; std::set<RtpEncodingParameters::Profile>::reverse_iterator it;
for (it = profiles.rbegin(); it != profiles.rend(); ++it) for (it = profiles.rbegin(); it != profiles.rend(); ++it)
......
...@@ -211,14 +211,9 @@ namespace RTC ...@@ -211,14 +211,9 @@ namespace RTC
void RtpStreamRecv::CheckHealth() void RtpStreamRecv::CheckHealth()
{ {
auto now = DepLibUV::GetTime(); auto now = DepLibUV::GetTime();
bool healthy = true;
if (this->counter.GetRate(now) == 0) if (this->counter.GetRate(now) == 0)
healthy = false; this->listener->OnRtpStreamDied(this);
// NOTE: Update the 'healthy' value after notification.
this->listener->OnRtpStreamHealthReport(this, healthy);
this->healthy = healthy;
} }
void RtpStreamRecv::OnNackGeneratorNackRequired(const std::vector<uint16_t>& seqNumbers) void RtpStreamRecv::OnNackGeneratorNackRequired(const std::vector<uint16_t>& seqNumbers)
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论