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

RtpStream: periodic health checks

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