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

Consumer: make use of RTC::RtpMonitor

上级 30f9b95c
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "RTC/RTCP/Sdes.hpp" #include "RTC/RTCP/Sdes.hpp"
#include "RTC/RtpDataCounter.hpp" #include "RTC/RtpDataCounter.hpp"
#include "RTC/RtpDictionaries.hpp" #include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpMonitor.hpp"
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include "RTC/RtpStreamSend.hpp" #include "RTC/RtpStreamSend.hpp"
#include "RTC/SeqManager.hpp" #include "RTC/SeqManager.hpp"
...@@ -21,7 +22,7 @@ ...@@ -21,7 +22,7 @@
namespace RTC namespace RTC
{ {
class Consumer : public RTC::RtpStreamSend::Listener class Consumer : public RTC::RtpMonitor::Listener
{ {
public: public:
Consumer( Consumer(
...@@ -72,10 +73,10 @@ namespace RTC ...@@ -72,10 +73,10 @@ namespace RTC
void SetEffectiveProfile(RTC::RtpEncodingParameters::Profile profile); void SetEffectiveProfile(RTC::RtpEncodingParameters::Profile profile);
void MayRunProbation(); void MayRunProbation();
/* Pure virtual methods inherited from RTC::RtpStreamSend::Listener. */ /* Pure virtual methods inherited from RTC::RtpMonitor::Listener. */
public: public:
void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) override; void OnRtpMonitorHealthy() override;
void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) override; void OnRtpMonitorUnhealthy() override;
public: public:
// Passed by argument. // Passed by argument.
...@@ -91,6 +92,7 @@ namespace RTC ...@@ -91,6 +92,7 @@ namespace RTC
std::unordered_set<RTC::ConsumerListener*> listeners; std::unordered_set<RTC::ConsumerListener*> listeners;
// Allocated by this. // Allocated by this.
RTC::RtpStreamSend* rtpStream{ nullptr }; RTC::RtpStreamSend* rtpStream{ nullptr };
RtpMonitor* rtpMonitor{ nullptr };
// Others. // Others.
std::unordered_set<uint8_t> supportedCodecPayloadTypes; std::unordered_set<uint8_t> supportedCodecPayloadTypes;
bool paused{ false }; bool paused{ false };
......
...@@ -11,14 +11,6 @@ namespace RTC ...@@ -11,14 +11,6 @@ namespace RTC
{ {
class RtpStreamSend : public RtpStream class RtpStreamSend : public RtpStream
{ {
public:
class Listener
{
public:
virtual void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) = 0;
virtual void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) = 0;
};
private: private:
struct StorageItem struct StorageItem
{ {
...@@ -34,7 +26,7 @@ namespace RTC ...@@ -34,7 +26,7 @@ namespace RTC
}; };
public: public:
RtpStreamSend(Listener* listener, RTC::RtpStream::Params& params, size_t bufferSize); RtpStreamSend(RTC::RtpStream::Params& params, size_t bufferSize);
~RtpStreamSend() override; ~RtpStreamSend() override;
Json::Value GetStats() override; Json::Value GetStats() override;
...@@ -58,14 +50,11 @@ namespace RTC ...@@ -58,14 +50,11 @@ namespace RTC
private: private:
// Passed by argument. // Passed by argument.
Listener* listener{ nullptr };
std::vector<StorageItem> storage; std::vector<StorageItem> storage;
using Buffer = std::list<BufferItem>; using Buffer = std::list<BufferItem>;
Buffer buffer; Buffer buffer;
// Stats. // Stats.
float rtt{ 0 }; float rtt{ 0 };
// Others.
bool healthy{ true };
private: private:
// Retransmittion related. // Retransmittion related.
...@@ -80,9 +69,9 @@ namespace RTC ...@@ -80,9 +69,9 @@ namespace RTC
return this->hasRtx; return this->hasRtx;
} }
inline bool RtpStreamSend::IsHealthy() const inline void RtpStreamSend::CheckStatus()
{ {
return this->healthy; return;
} }
} // namespace RTC } // namespace RTC
......
...@@ -32,6 +32,8 @@ namespace RTC ...@@ -32,6 +32,8 @@ namespace RTC
this->maxRtcpInterval = RTC::RTCP::MaxAudioIntervalMs; this->maxRtcpInterval = RTC::RTCP::MaxAudioIntervalMs;
else else
this->maxRtcpInterval = RTC::RTCP::MaxVideoIntervalMs; this->maxRtcpInterval = RTC::RTCP::MaxVideoIntervalMs;
this->rtpMonitor = new RTC::RtpMonitor(this);
} }
Consumer::~Consumer() Consumer::~Consumer()
...@@ -39,6 +41,7 @@ namespace RTC ...@@ -39,6 +41,7 @@ namespace RTC
MS_TRACE(); MS_TRACE();
delete this->rtpStream; delete this->rtpStream;
delete this->rtpMonitor;
} }
void Consumer::Destroy() void Consumer::Destroy()
...@@ -186,7 +189,7 @@ namespace RTC ...@@ -186,7 +189,7 @@ namespace RTC
if (IsEnabled() && !this->sourcePaused) if (IsEnabled() && !this->sourcePaused)
{ {
this->rtpStream->StopStatusCheckTimer(); this->rtpMonitor->Reset();
this->rtpStream->ClearRetransmissionBuffer(); this->rtpStream->ClearRetransmissionBuffer();
this->rtpPacketsBeforeProbation = RtpPacketsBeforeProbation; this->rtpPacketsBeforeProbation = RtpPacketsBeforeProbation;
...@@ -211,8 +214,6 @@ namespace RTC ...@@ -211,8 +214,6 @@ namespace RTC
if (IsEnabled() && !this->sourcePaused) if (IsEnabled() && !this->sourcePaused)
{ {
this->rtpStream->RestartStatusCheckTimer();
// We need to sync and wait for a key frame. Otherwise the receiver will // We need to sync and wait for a key frame. Otherwise the receiver will
// request lot of NACKs due to unknown RTP packets. // request lot of NACKs due to unknown RTP packets.
this->syncRequired = true; this->syncRequired = true;
...@@ -236,7 +237,7 @@ namespace RTC ...@@ -236,7 +237,7 @@ namespace RTC
if (IsEnabled() && !this->paused) if (IsEnabled() && !this->paused)
{ {
this->rtpStream->StopStatusCheckTimer(); this->rtpMonitor->Reset();
this->rtpStream->ClearRetransmissionBuffer(); this->rtpStream->ClearRetransmissionBuffer();
this->rtpPacketsBeforeProbation = RtpPacketsBeforeProbation; this->rtpPacketsBeforeProbation = RtpPacketsBeforeProbation;
...@@ -263,8 +264,6 @@ namespace RTC ...@@ -263,8 +264,6 @@ namespace RTC
if (IsEnabled() && !this->paused) if (IsEnabled() && !this->paused)
{ {
this->rtpStream->RestartStatusCheckTimer();
// We need to sync. However we don't need to request a key frame since the source // We need to sync. However we don't need to request a key frame since the source
// (Producer) already requested it. // (Producer) already requested it.
this->syncRequired = true; this->syncRequired = true;
...@@ -331,9 +330,8 @@ namespace RTC ...@@ -331,9 +330,8 @@ namespace RTC
this->isProbing = false; this->isProbing = false;
this->probingProfile = RtpEncodingParameters::Profile::NONE; this->probingProfile = RtpEncodingParameters::Profile::NONE;
// Restart the health check timer so this probation doesn't affect the effective // Reset the RTP monitor so this probation doesn't affect the current profile.
// profile. this->rtpMonitor->Reset();
this->rtpStream->RestartStatusCheckTimer();
return; return;
} }
...@@ -703,6 +701,7 @@ namespace RTC ...@@ -703,6 +701,7 @@ namespace RTC
return; return;
this->rtpStream->ReceiveRtcpReceiverReport(report); this->rtpStream->ReceiveRtcpReceiverReport(report);
this->rtpMonitor->ReceiveRtcpReceiverReport(report);
} }
float Consumer::GetLossPercentage() const float Consumer::GetLossPercentage() const
...@@ -743,7 +742,7 @@ namespace RTC ...@@ -743,7 +742,7 @@ namespace RTC
} }
} }
void Consumer::OnRtpStreamHealthy(RtpStream* rtpStream) void Consumer::OnRtpMonitorHealthy()
{ {
MS_TRACE(); MS_TRACE();
...@@ -773,7 +772,7 @@ namespace RTC ...@@ -773,7 +772,7 @@ namespace RTC
RTC::RtpEncodingParameters::profile2String[this->targetProfile].c_str()); RTC::RtpEncodingParameters::profile2String[this->targetProfile].c_str());
} }
void Consumer::OnRtpStreamUnhealthy(RtpStream* rtpStream) void Consumer::OnRtpMonitorUnhealthy()
{ {
MS_TRACE(); MS_TRACE();
...@@ -815,8 +814,8 @@ namespace RTC ...@@ -815,8 +814,8 @@ namespace RTC
if (IsEnabled() && !IsPaused()) if (IsEnabled() && !IsPaused())
RequestKeyFrame(); RequestKeyFrame();
// We want to be notified about this new profile's health. // Reset the RTP monitor to have clear data about the new profile.
this->rtpStream->RestartStatusCheckTimer(); this->rtpMonitor->Reset();
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtp, rtp,
...@@ -840,7 +839,7 @@ namespace RTC ...@@ -840,7 +839,7 @@ namespace RTC
return; return;
// Current health status is not good. // Current health status is not good.
if (!this->rtpStream->IsHealthy()) if (!this->rtpMonitor->IsHealthy())
return; return;
RecalculateTargetProfile(); RecalculateTargetProfile();
...@@ -894,9 +893,9 @@ namespace RTC ...@@ -894,9 +893,9 @@ namespace RTC
// Create a RtpStreamSend for sending a single media stream. // Create a RtpStreamSend for sending a single media stream.
if (useNack) if (useNack)
this->rtpStream = new RTC::RtpStreamSend(this, params, 1500); this->rtpStream = new RTC::RtpStreamSend(params, 1500);
else else
this->rtpStream = new RTC::RtpStreamSend(this, params, 0); this->rtpStream = new RTC::RtpStreamSend(params, 0);
if (encoding.hasRtx && encoding.rtx.ssrc != 0u) if (encoding.hasRtx && encoding.rtx.ssrc != 0u)
{ {
...@@ -1027,7 +1026,6 @@ namespace RTC ...@@ -1027,7 +1026,6 @@ namespace RTC
{ {
this->isProbing = true; this->isProbing = true;
this->probingProfile = newTargetProfile; this->probingProfile = newTargetProfile;
this->rtpStream->RestartStatusCheckTimer();
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtp, rtp,
......
...@@ -14,18 +14,13 @@ namespace RTC ...@@ -14,18 +14,13 @@ namespace RTC
// Don't retransmit packets older than this (ms). // Don't retransmit packets older than this (ms).
static constexpr uint32_t MaxRetransmissionDelay{ 2000 }; static constexpr uint32_t MaxRetransmissionDelay{ 2000 };
static constexpr uint32_t DefaultRtt{ 100 }; static constexpr uint32_t DefaultRtt{ 100 };
static constexpr uint8_t MaxHealthLossPercentage{ 20 };
static constexpr uint16_t StatusCheckPeriod{ 1000 };
/* Instance methods. */ /* Instance methods. */
RtpStreamSend::RtpStreamSend(Listener* listener, RTC::RtpStream::Params& params, size_t bufferSize) RtpStreamSend::RtpStreamSend(RTC::RtpStream::Params& params, size_t bufferSize)
: RtpStream::RtpStream(params), listener(listener), storage(bufferSize) : RtpStream::RtpStream(params), storage(bufferSize)
{ {
MS_TRACE(); MS_TRACE();
// Run the timer.
this->statusCheckTimer->Start(StatusCheckPeriod, StatusCheckPeriod);
} }
RtpStreamSend::~RtpStreamSend() RtpStreamSend::~RtpStreamSend()
...@@ -399,32 +394,6 @@ namespace RTC ...@@ -399,32 +394,6 @@ namespace RTC
(*newBufferIt).packet = packet->Clone(store); (*newBufferIt).packet = packet->Clone(store);
} }
void RtpStreamSend::CheckStatus()
{
MS_TRACE();
auto lossPercentage = GetLossPercentage();
if (lossPercentage >= MaxHealthLossPercentage)
{
if (this->notifyStatus || this->healthy)
{
MS_DEBUG_TAG(
rtp, "rtp stream packet loss [ssrc:%" PRIu32 ", %.2f%%]", GetSsrc(), lossPercentage);
this->healthy = false;
this->listener->OnRtpStreamUnhealthy(this);
}
}
else if (this->notifyStatus || !this->healthy)
{
this->healthy = true;
this->listener->OnRtpStreamHealthy(this);
}
this->notifyStatus = false;
}
void RtpStreamSend::SetRtx(uint8_t payloadType, uint32_t ssrc) void RtpStreamSend::SetRtx(uint8_t payloadType, uint32_t ssrc)
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -11,14 +11,14 @@ SCENARIO("RTP Monitor", "[rtp][monitor]") ...@@ -11,14 +11,14 @@ SCENARIO("RTP Monitor", "[rtp][monitor]")
class TestRtpMonitorListener : public RtpMonitor::Listener class TestRtpMonitorListener : public RtpMonitor::Listener
{ {
public: public:
virtual void OnHealthy(RTC::RtpMonitor* /*rtpMonitor*/) override virtual void OnRtpMonitorHealthy() override
{ {
INFO("OnHealthy"); INFO("OnHealthy");
this->healthyTriggered = true; this->healthyTriggered = true;
} }
virtual void OnUnhealthy(RTC::RtpMonitor* /*rtpMonitor*/) override virtual void OnRtpMonitorUnhealthy() override
{ {
INFO("OnUnhealthy"); INFO("OnUnhealthy");
......
...@@ -11,13 +11,6 @@ using namespace RTC; ...@@ -11,13 +11,6 @@ using namespace RTC;
// Can retransmit up to 17 RTP packets. // Can retransmit up to 17 RTP packets.
static std::vector<RtpPacket*> rtpRetransmissionContainer(18); static std::vector<RtpPacket*> rtpRetransmissionContainer(18);
class RtpStreamSendListener : public RtpStreamSend::Listener
{
public:
void OnRtpStreamHealthy(RTC::RtpStream* /*rtpStream*/){};
void OnRtpStreamUnhealthy(RTC::RtpStream* /*rtpStream*/){};
} rtpStreamSendListener;
SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp]") SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp]")
{ {
SECTION("receive NACK and get retransmitted packets") SECTION("receive NACK and get retransmitted packets")
...@@ -86,7 +79,7 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp]") ...@@ -86,7 +79,7 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp]")
params.useNack = true; params.useNack = true;
// Create a RtpStreamSend. // Create a RtpStreamSend.
RtpStreamSend* stream = new RtpStreamSend(&rtpStreamSendListener, params, 200); RtpStreamSend* stream = new RtpStreamSend(params, 200);
// Receive all the packets in order into the stream. // Receive all the packets in order into the stream.
stream->ReceivePacket(packet1); stream->ReceivePacket(packet1);
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论