提交 97c7f8b7 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

worker: refactor stream status check timers

上级 21ceb014
...@@ -25,9 +25,6 @@ namespace RTC ...@@ -25,9 +25,6 @@ namespace RTC
bool usePli{ false }; bool usePli{ false };
}; };
public:
static constexpr uint16_t StatusCheckPeriod{ 1000 };
public: public:
explicit RtpStream(RTC::RtpStream::Params& params); explicit RtpStream(RTC::RtpStream::Params& params);
virtual ~RtpStream(); virtual ~RtpStream();
...@@ -40,7 +37,7 @@ namespace RTC ...@@ -40,7 +37,7 @@ namespace RTC
uint8_t GetPayloadType() const; uint8_t GetPayloadType() const;
const RTC::RtpCodecMimeType& GetMimeType() const; const RTC::RtpCodecMimeType& GetMimeType() const;
float GetLossPercentage() const; float GetLossPercentage() const;
void ResetStatusCheckTimer(uint16_t timeout = StatusCheckPeriod); void ResetStatusCheckTimer();
protected: protected:
bool UpdateSeq(RTC::RtpPacket* packet); bool UpdateSeq(RTC::RtpPacket* packet);
......
...@@ -28,6 +28,7 @@ public: ...@@ -28,6 +28,7 @@ public:
void Destroy(); void Destroy();
void Start(uint64_t timeout, uint64_t repeat = 0); void Start(uint64_t timeout, uint64_t repeat = 0);
void Stop(); void Stop();
void Reset();
bool IsActive() const; bool IsActive() const;
/* Callbacks fired by UV events. */ /* Callbacks fired by UV events. */
......
...@@ -821,15 +821,6 @@ namespace RTC ...@@ -821,15 +821,6 @@ namespace RTC
// Deactivate stream profiles if active. // Deactivate stream profiles if active.
if (IsStreamActive(rtpStream)) if (IsStreamActive(rtpStream))
DeactivateStreamProfiles(rtpStreamRecv); DeactivateStreamProfiles(rtpStreamRecv);
// Reset stream check timer on every stream whose profiles are active.
for (auto it : this->mapActiveProfiles)
{
auto activeRtpStream = it.second;
auto ssrc = activeRtpStream->GetSsrc();
this->rtpStreams[ssrc]->ResetStatusCheckTimer(RTC::RtpStream::StatusCheckPeriod * 2);
}
} }
void Producer::OnRtpStreamActive(RTC::RtpStream* rtpStream) void Producer::OnRtpStreamActive(RTC::RtpStream* rtpStream)
......
...@@ -27,9 +27,6 @@ namespace RTC ...@@ -27,9 +27,6 @@ namespace RTC
// Set the status check timer. // Set the status check timer.
this->statusCheckTimer = new Timer(this); this->statusCheckTimer = new Timer(this);
// Run the timer.
this->statusCheckTimer->Start(StatusCheckPeriod, StatusCheckPeriod);
} }
RtpStream::~RtpStream() RtpStream::~RtpStream()
...@@ -149,11 +146,11 @@ namespace RTC ...@@ -149,11 +146,11 @@ namespace RTC
return this->transmissionCounter.GetRate(now); return this->transmissionCounter.GetRate(now);
} }
void RtpStream::ResetStatusCheckTimer(uint16_t timeout) void RtpStream::ResetStatusCheckTimer()
{ {
// Notify about status on next check. // Notify about status on next check.
this->notifyStatus = true; this->notifyStatus = true;
this->statusCheckTimer->Start(timeout, StatusCheckPeriod); this->statusCheckTimer->Reset();
} }
void RtpStream::InitSeq(uint16_t seq) void RtpStream::InitSeq(uint16_t seq)
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
namespace RTC namespace RTC
{ {
/* Static. */
static constexpr uint16_t StatusCheckPeriod{ 250 };
/* Instance methods. */ /* Instance methods. */
RtpStreamRecv::RtpStreamRecv(Listener* listener, RTC::RtpStream::Params& params) RtpStreamRecv::RtpStreamRecv(Listener* listener, RTC::RtpStream::Params& params)
...@@ -17,6 +21,9 @@ namespace RTC ...@@ -17,6 +21,9 @@ namespace RTC
if (this->params.useNack) if (this->params.useNack)
this->nackGenerator.reset(new RTC::NackGenerator(this)); this->nackGenerator.reset(new RTC::NackGenerator(this));
// Run the timer.
this->statusCheckTimer->Start(StatusCheckPeriod, StatusCheckPeriod);
} }
RtpStreamRecv::~RtpStreamRecv() RtpStreamRecv::~RtpStreamRecv()
......
...@@ -12,10 +12,10 @@ namespace RTC ...@@ -12,10 +12,10 @@ namespace RTC
/* Static. */ /* Static. */
// Don't retransmit packets older than this (ms). // Don't retransmit packets older than this (ms).
// TODO: This must be tunned. static constexpr uint32_t MaxRetransmissionDelay{ 2000 };
static constexpr uint32_t MaxRetransmissionDelay{ 1000 };
static constexpr uint32_t DefaultRtt{ 100 }; static constexpr uint32_t DefaultRtt{ 100 };
static constexpr uint8_t MaxHealthLossPercentage{ 20 }; static constexpr uint8_t MaxHealthLossPercentage{ 20 };
static constexpr uint16_t StatusCheckPeriod{ 1000 };
/* Instance methods. */ /* Instance methods. */
...@@ -23,6 +23,9 @@ namespace RTC ...@@ -23,6 +23,9 @@ namespace RTC
: RtpStream::RtpStream(params), listener(listener), storage(bufferSize) : RtpStream::RtpStream(params), listener(listener), storage(bufferSize)
{ {
MS_TRACE(); MS_TRACE();
// Run the timer.
this->statusCheckTimer->Start(StatusCheckPeriod, StatusCheckPeriod);
} }
RtpStreamSend::~RtpStreamSend() RtpStreamSend::~RtpStreamSend()
......
...@@ -74,6 +74,25 @@ void Timer::Stop() ...@@ -74,6 +74,25 @@ void Timer::Stop()
MS_THROW_ERROR("uv_timer_stop() failed: %s", uv_strerror(err)); MS_THROW_ERROR("uv_timer_stop() failed: %s", uv_strerror(err));
} }
void Timer::Reset()
{
MS_TRACE();
int err;
if (uv_is_active(reinterpret_cast<uv_handle_t*>(this->uvHandle)) == 0)
return;
auto repeat = uv_timer_get_repeat(this->uvHandle);
if (repeat == 0u)
return;
err = uv_timer_start(this->uvHandle, static_cast<uv_timer_cb>(onTimer), repeat, repeat);
if (err != 0)
MS_THROW_ERROR("uv_timer_start() failed: %s", uv_strerror(err));
}
inline void Timer::OnUvTimer() inline void Timer::OnUvTimer()
{ {
MS_TRACE(); MS_TRACE();
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论