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

RtpStream: periodic health checks

上级 500d9987
......@@ -19,7 +19,7 @@
namespace RTC
{
class Consumer
class Consumer: public RtpStream::Listener
{
public:
Consumer(
......@@ -60,6 +60,10 @@ namespace RTC
void CreateRtpStream(RTC::RtpEncodingParameters& encoding);
void RetransmitRtpPacket(RTC::RtpPacket* packet);
/* Pure virtual methods inherited from RTC::RtpStream::Listener. */
public:
void OnRtpStreamHealthReport(RTC::RtpStream* rtpStream, bool healthy) override;
public:
// Passed by argument.
uint32_t consumerId{ 0 };
......
......@@ -96,6 +96,7 @@ namespace RTC
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;
/* Pure virtual methods inherited from Timer::Listener. */
public:
......
......@@ -4,12 +4,20 @@
#include "common.hpp"
#include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp"
#include "handles/Timer.hpp"
#include <json/json.h>
namespace RTC
{
class RtpStream
class RtpStream: public Timer::Listener
{
public:
class Listener
{
public:
virtual void OnRtpStreamHealthReport(RTC::RtpStream* rtpStream, bool healthy) = 0;
};
public:
struct Params
{
......@@ -40,6 +48,11 @@ namespace RTC
/* Pure virtual methods that must be implemented by the subclass. */
protected:
virtual void OnInitSeq() = 0;
virtual void CheckHealth() = 0;
/* Pure virtual methods inherited from Timer::Listener. */
public:
void OnTimer(Timer* timer) override;
protected:
// Given as argument.
......@@ -58,6 +71,7 @@ namespace RTC
uint32_t receivedPrior{ 0 }; // Packet received at last interval.
// Others.
uint32_t maxTimestamp{ 0 }; // Highest timestamp seen.
Timer* healthCheckTimer{ nullptr };
};
/* Inline instance methods. */
......
......@@ -12,7 +12,7 @@ namespace RTC
class RtpStreamRecv : public RtpStream, public RTC::NackGenerator::Listener
{
public:
class Listener
class Listener : public RtpStream::Listener
{
public:
virtual void OnRtpStreamRecvNackRequired(
......@@ -39,6 +39,7 @@ namespace RTC
/* Pure virtual methods inherited from RtpStream. */
protected:
void OnInitSeq() override;
virtual void CheckHealth() override;
/* Pure virtual methods inherited from RTC::NackGenerator. */
protected:
......
......@@ -47,6 +47,7 @@ namespace RTC
/* Pure virtual methods inherited from RtpStream. */
protected:
void OnInitSeq() override;
void CheckHealth() override;
private:
std::vector<StorageItem> storage;
......
......@@ -457,6 +457,14 @@ namespace RTC
}
}
void Consumer::OnRtpStreamHealthReport(RtpStream* stream, bool healthy)
{
MS_TRACE();
if (!IsEnabled())
return;
}
void Consumer::FillSupportedCodecPayloadTypes()
{
MS_TRACE();
......
......@@ -700,6 +700,14 @@ namespace RTC
this->transport->SendRtcpPacket(&packet);
}
void Producer::OnRtpStreamHealthReport(RTC::RtpStream* rtpStream, bool healthy)
{
MS_TRACE();
if (!healthy)
MS_DEBUG_TAG(rtp, "stream is not healthy [ssrc:%" PRIu32 "]", rtpStream->GetSsrc());
}
inline void Producer::OnTimer(Timer* timer)
{
MS_TRACE();
......
......@@ -14,17 +14,27 @@ namespace RTC
static constexpr uint16_t MaxDropout{ 3000 };
static constexpr uint16_t MaxMisorder{ 100 };
static constexpr uint32_t RtpSeqMod{ 1 << 16 };
static constexpr uint16_t HealthCheckPeriod { 1000 };
/* Instance methods. */
RtpStream::RtpStream(RTC::RtpStream::Params& params) : params(params)
{
MS_TRACE();
// Set the health check timer.
this->healthCheckTimer = new Timer(this);
// Run the timer.
this->healthCheckTimer->Start(HealthCheckPeriod, HealthCheckPeriod);
}
RtpStream::~RtpStream()
{
MS_TRACE();
// Close the health check timer.
this->healthCheckTimer->Destroy();
}
bool RtpStream::ReceivePacket(RTC::RtpPacket* packet)
......@@ -192,4 +202,14 @@ namespace RTC
return json;
}
void RtpStream::OnTimer(Timer* timer)
{
MS_TRACE();
if (timer == this->healthCheckTimer)
{
this->CheckHealth();
}
}
} // namespace RTC
......@@ -247,6 +247,17 @@ namespace RTC
// Do nothing.
}
void RtpStreamRecv::CheckHealth()
{
auto now = DepLibUV::GetTime();
bool healthy = true;
if (this->receivedCounter.GetRate(now) == 0)
healthy = false;
this->listener->OnRtpStreamHealthReport(this, healthy);
}
void RtpStreamRecv::OnNackGeneratorNackRequired(const std::vector<uint16_t>& seqNumbers)
{
MS_TRACE();
......
......@@ -443,6 +443,11 @@ namespace RTC
ClearRetransmissionBuffer();
}
void RtpStreamSend::CheckHealth()
{
MS_TRACE();
}
void RtpStreamSend::SetRtx(uint8_t payloadType, uint32_t ssrc)
{
MS_TRACE();
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论