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

Consumer: make use of RTC::RtpMonitor

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