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