diff --git a/worker/deps/libwebrtc/libwebrtc/call/rtp_transport_controller_send.cc b/worker/deps/libwebrtc/libwebrtc/call/rtp_transport_controller_send.cc index f99aaa2846..e2889c5b17 100644 --- a/worker/deps/libwebrtc/libwebrtc/call/rtp_transport_controller_send.cc +++ b/worker/deps/libwebrtc/libwebrtc/call/rtp_transport_controller_send.cc @@ -19,7 +19,7 @@ #include "system_wrappers/source/field_trial.h" #include "modules/congestion_controller/goog_cc/goog_cc_network_control.h" -#include "DepLibUV.hpp" +#include "handles/Timer.hpp" #include "Logger.hpp" #include "RTC/RTCP/FeedbackRtpTransport.hpp" @@ -36,7 +36,7 @@ TargetRateConstraints ConvertConstraints(int min_bitrate_bps, int max_bitrate_bps, int start_bitrate_bps) { TargetRateConstraints msg; - msg.at_time = Timestamp::ms(DepLibUV::GetTimeMsInt64()); + msg.at_time = Timestamp::ms(GetTimeMsInt64()); msg.min_data_rate = min_bitrate_bps >= 0 ? DataRate::bps(min_bitrate_bps) : DataRate::Zero(); msg.max_data_rate = max_bitrate_bps > 0 ? DataRate::bps(max_bitrate_bps) @@ -63,7 +63,7 @@ RtpTransportControllerSend::RtpTransportControllerSend( observer_(nullptr), controller_factory_override_(controller_factory), process_interval_(controller_factory_override_->GetProcessInterval()), - last_report_block_time_(Timestamp::ms(DepLibUV::GetTimeMsInt64())), + last_report_block_time_(Timestamp::ms(GetTimeMsInt64())), send_side_bwe_with_overhead_( webrtc::field_trial::IsEnabled("WebRTC-SendSideBwe-WithOverhead")), transport_overhead_bytes_per_packet_(0), @@ -147,7 +147,7 @@ void RtpTransportControllerSend::OnNetworkAvailability(bool network_available) { MS_DEBUG_DEV("<<<<< network_available:%s", network_available ? "true" : "false"); NetworkAvailability msg; - msg.at_time = Timestamp::ms(DepLibUV::GetTimeMsInt64()); + msg.at_time = Timestamp::ms(GetTimeMsInt64()); msg.network_available = network_available; if (network_available_ == msg.network_available) @@ -200,7 +200,7 @@ void RtpTransportControllerSend::OnReceivedEstimatedBitrate(uint32_t bitrate) { MS_DEBUG_DEV("<<<<< bitrate:%zu", bitrate); RemoteBitrateReport msg; - msg.receive_time = Timestamp::ms(DepLibUV::GetTimeMsInt64()); + msg.receive_time = Timestamp::ms(GetTimeMsInt64()); msg.bandwidth = DataRate::bps(bitrate); PostUpdates(controller_->OnRemoteBitrateReport(msg)); @@ -228,7 +228,7 @@ void RtpTransportControllerSend::OnAddPacket( packet_info, send_side_bwe_with_overhead_ ? transport_overhead_bytes_per_packet_.load() : 0, - Timestamp::ms(DepLibUV::GetTimeMsInt64())); + Timestamp::ms(GetTimeMsInt64())); } void RtpTransportControllerSend::OnTransportFeedback( @@ -237,7 +237,7 @@ void RtpTransportControllerSend::OnTransportFeedback( absl::optional feedback_msg = transport_feedback_adapter_.ProcessTransportFeedback( - feedback, Timestamp::ms(DepLibUV::GetTimeMsInt64())); + feedback, Timestamp::ms(GetTimeMsInt64())); if (feedback_msg) PostUpdates(controller_->OnTransportPacketsFeedback(*feedback_msg)); pacer_.UpdateOutstandingData( @@ -246,7 +246,7 @@ void RtpTransportControllerSend::OnTransportFeedback( void RtpTransportControllerSend::OnRemoteNetworkEstimate( NetworkStateEstimate estimate) { - estimate.update_time = Timestamp::ms(DepLibUV::GetTimeMsInt64()); + estimate.update_time = Timestamp::ms(GetTimeMsInt64()); controller_->OnNetworkStateEstimate(estimate); } @@ -268,7 +268,7 @@ void RtpTransportControllerSend::MaybeCreateControllers() { control_handler_ = absl::make_unique(); initial_config_.constraints.at_time = - Timestamp::ms(DepLibUV::GetTimeMsInt64()); + Timestamp::ms(GetTimeMsInt64()); controller_ = controller_factory_override_->Create(initial_config_); process_interval_ = controller_factory_override_->GetProcessInterval(); @@ -283,7 +283,7 @@ void RtpTransportControllerSend::UpdateControllerWithTimeInterval() { MS_ASSERT(controller_, "controller not set"); ProcessInterval msg; - msg.at_time = Timestamp::ms(DepLibUV::GetTimeMsInt64()); + msg.at_time = Timestamp::ms(GetTimeMsInt64()); PostUpdates(controller_->OnProcessInterval(msg)); } @@ -291,7 +291,7 @@ void RtpTransportControllerSend::UpdateControllerWithTimeInterval() { void RtpTransportControllerSend::UpdateStreamsConfig() { MS_DEBUG_DEV("<<<<<"); - streams_config_.at_time = Timestamp::ms(DepLibUV::GetTimeMsInt64()); + streams_config_.at_time = Timestamp::ms(GetTimeMsInt64()); if (controller_) PostUpdates(controller_->OnStreamsConfig(streams_config_)); } diff --git a/worker/deps/libwebrtc/libwebrtc/modules/congestion_controller/goog_cc/alr_detector.cc b/worker/deps/libwebrtc/libwebrtc/modules/congestion_controller/goog_cc/alr_detector.cc index 95a000d346..219225286d 100644 --- a/worker/deps/libwebrtc/libwebrtc/modules/congestion_controller/goog_cc/alr_detector.cc +++ b/worker/deps/libwebrtc/libwebrtc/modules/congestion_controller/goog_cc/alr_detector.cc @@ -14,7 +14,7 @@ #include "modules/congestion_controller/goog_cc/alr_detector.h" #include "rtc_base/numerics/safe_conversions.h" -#include "DepLibUV.hpp" +#include "handles/Timer.hpp" #include "Logger.hpp" #include @@ -85,7 +85,7 @@ void AlrDetector::OnBytesSent(size_t bytes_sent, int64_t send_time_ms) { bool state_changed = false; if (alr_budget_.budget_ratio() > start_budget_level_ratio_ && !alr_started_time_ms_) { - alr_started_time_ms_.emplace(DepLibUV::GetTimeMsInt64()); + alr_started_time_ms_.emplace(GetTimeMsInt64()); state_changed = true; } else if (alr_budget_.budget_ratio() < stop_budget_level_ratio_ && alr_started_time_ms_) { diff --git a/worker/deps/libwebrtc/libwebrtc/modules/pacing/paced_sender.cc b/worker/deps/libwebrtc/libwebrtc/modules/pacing/paced_sender.cc index 9c69384b19..73fd0cfe26 100644 --- a/worker/deps/libwebrtc/libwebrtc/modules/pacing/paced_sender.cc +++ b/worker/deps/libwebrtc/libwebrtc/modules/pacing/paced_sender.cc @@ -17,7 +17,7 @@ #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "system_wrappers/source/field_trial.h" // webrtc::field_trial. -#include "DepLibUV.hpp" +#include "handles/Timer.hpp" #include "Logger.hpp" #include "RTC/RtpPacket.hpp" @@ -53,7 +53,7 @@ PacedSender::PacedSender(PacketRouter* packet_router, prober_(*field_trials_), probing_send_failure_(false), pacing_bitrate_kbps_(0), - time_last_process_us_(DepLibUV::GetTimeUsInt64()), + time_last_process_us_(GetTimeUsInt64()), first_sent_packet_ms_(-1), packet_counter_(0), account_for_audio_(false) { @@ -66,7 +66,7 @@ void PacedSender::CreateProbeCluster(int bitrate_bps, int cluster_id) { // TODO: REMOVE // MS_DEBUG_DEV("---- bitrate_bps:%d, cluster_id:%d", bitrate_bps, cluster_id); - prober_.CreateProbeCluster(bitrate_bps, DepLibUV::GetTimeMsInt64(), cluster_id); + prober_.CreateProbeCluster(bitrate_bps, GetTimeMsInt64(), cluster_id); } void PacedSender::Pause() { @@ -147,7 +147,7 @@ void PacedSender::SetAccountForAudioPackets(bool account_for_audio) { int64_t PacedSender::TimeUntilNextProcess() { int64_t elapsed_time_us = - DepLibUV::GetTimeUsInt64() - time_last_process_us_; + GetTimeUsInt64() - time_last_process_us_; int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; // When paused we wake up every 500 ms to send a padding packet to ensure // we won't get stuck in the paused state due to no feedback being received. @@ -155,7 +155,7 @@ int64_t PacedSender::TimeUntilNextProcess() { return std::max(kPausedProcessIntervalMs - elapsed_time_ms, 0); if (prober_.IsProbing()) { - int64_t ret = prober_.TimeUntilNextProbe(DepLibUV::GetTimeMsInt64()); + int64_t ret = prober_.TimeUntilNextProbe(GetTimeMsInt64()); if (ret > 0 || (ret == 0 && !probing_send_failure_)) return ret; } @@ -176,7 +176,7 @@ int64_t PacedSender::UpdateTimeAndGetElapsedMs(int64_t now_us) { } void PacedSender::Process() { - int64_t now_us = DepLibUV::GetTimeUsInt64(); + int64_t now_us = GetTimeUsInt64(); int64_t elapsed_time_ms = UpdateTimeAndGetElapsedMs(now_us); if (paused_) @@ -230,10 +230,8 @@ void PacedSender::Process() { if (bytes_sent != 0) { - auto now = DepLibUV::GetTimeUsInt64(); - - OnPaddingSent(now, bytes_sent); - prober_.ProbeSent((now + 500) / 1000, bytes_sent); + OnPaddingSent(now_us, bytes_sent); + prober_.ProbeSent((now_us + 500) / 1000, bytes_sent); } } @@ -265,7 +263,7 @@ size_t PacedSender::PaddingBytesToAdd( void PacedSender::OnPacketSent(size_t size) { if (first_sent_packet_ms_ == -1) - first_sent_packet_ms_ = DepLibUV::GetTimeMsInt64(); + first_sent_packet_ms_ = GetTimeMsInt64(); // Update media bytes sent. UpdateBudgetWithBytesSent(size); diff --git a/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.cc b/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.cc index 30da04df75..4a04aeb200 100644 --- a/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.cc +++ b/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.cc @@ -17,7 +17,7 @@ #include "rtc_base/constructor_magic.h" #include "Logger.hpp" -#include "DepLibUV.hpp" +#include "handles/Timer.hpp" #include #include @@ -251,7 +251,7 @@ void RemoteBitrateEstimatorAbsSendTime::IncomingPacketInfo( uint32_t timestamp = send_time_24bits << kAbsSendTimeInterArrivalUpshift; int64_t send_time_ms = static_cast(timestamp) * kTimestampToMs; - int64_t now_ms = DepLibUV::GetTimeMsInt64(); + int64_t now_ms = GetTimeMsInt64(); // TODO(holmer): SSRCs are only needed for REMB, should be broken out from // here. diff --git a/worker/include/RTC/RateCalculator.hpp b/worker/include/RTC/RateCalculator.hpp index d4e974e740..1de0cb424c 100644 --- a/worker/include/RTC/RateCalculator.hpp +++ b/worker/include/RTC/RateCalculator.hpp @@ -2,7 +2,6 @@ #define MS_RTC_RATE_CALCULATOR_HPP #include "common.hpp" -#include "DepLibUV.hpp" #include "RTC/RtpPacket.hpp" namespace RTC diff --git a/worker/include/handles/Timer.hpp b/worker/include/handles/Timer.hpp index dfb9c47ee7..d659f03bf6 100644 --- a/worker/include/handles/Timer.hpp +++ b/worker/include/handles/Timer.hpp @@ -4,6 +4,40 @@ #include "common.hpp" #include +#ifdef FAKE_TIMERS + +#include + +class FakeTimerManager +{ +public: + static uint16_t GetNexTimerId(); + static void StartTimer(uint16_t timerId, uint64_t timeout, uint64_t repeat, std::function cb); + static void StopTimer(uint16_t timerId); + static bool IsActive(uint16_t timerId); + + static int64_t GetTimeMs() + { + return now; + } + static int64_t NextTimerTime(); + static void RunPending(int64_t now); + static void RunLoop(int64_t maxTime = -1); + +private: + struct Timer + { + uint64_t nextTime; + uint64_t repeat; + std::function cb; + }; + + static int64_t now; + static uint16_t nextTimerId; + static std::map timers; +}; +#endif + class Timer { public: @@ -36,10 +70,7 @@ class Timer { return this->repeat; } - bool IsActive() const - { - return uv_is_active(reinterpret_cast(this->uvHandle)) != 0; - } + bool IsActive() const; /* Callbacks fired by UV events. */ public: @@ -48,12 +79,21 @@ class Timer private: // Passed by argument. Listener* listener{ nullptr }; +#ifdef FAKE_TIMERS + uint64_t timerId; +#else // Allocated by this. uv_timer_t* uvHandle{ nullptr }; +#endif // Others. bool closed{ false }; uint64_t timeout{ 0u }; uint64_t repeat{ 0u }; }; +uint64_t GetTimeMs(); +int64_t GetTimeMsInt64(); +uint64_t GetTimeUs(); +int64_t GetTimeUsInt64(); + #endif diff --git a/worker/meson.build b/worker/meson.build index 9f2bba2a91..1482942104 100644 --- a/worker/meson.build +++ b/worker/meson.build @@ -334,6 +334,7 @@ mediasoup_worker_test = executable( cpp_args: cpp_args + [ '-DMS_LOG_STD', '-DMS_TEST', + '-DFAKE_TIMERS', ], ) diff --git a/worker/src/RTC/RateCalculator.cpp b/worker/src/RTC/RateCalculator.cpp index b449eb7d06..2a4e899eff 100644 --- a/worker/src/RTC/RateCalculator.cpp +++ b/worker/src/RTC/RateCalculator.cpp @@ -3,6 +3,7 @@ #include "RTC/RateCalculator.hpp" #include "Logger.hpp" +#include "handles/Timer.hpp" #include // std::trunc() namespace RTC @@ -116,7 +117,7 @@ namespace RTC void RtpDataCounter::Update(RTC::RtpPacket* packet) { - const uint64_t nowMs = DepLibUV::GetTimeMs(); + const uint64_t nowMs = GetTimeMs(); this->packets++; this->rate.Update(packet->GetSize(), nowMs); diff --git a/worker/src/RTC/TransportCongestionControlClient.cpp b/worker/src/RTC/TransportCongestionControlClient.cpp index 2a0d35badd..f6d40f0383 100644 --- a/worker/src/RTC/TransportCongestionControlClient.cpp +++ b/worker/src/RTC/TransportCongestionControlClient.cpp @@ -3,7 +3,6 @@ #define USE_TREND_CALCULATOR #include "RTC/TransportCongestionControlClient.hpp" -#include "DepLibUV.hpp" #include "Logger.hpp" #include "MediaSoupErrors.hpp" #include // webrtc::TargetRateConstraints @@ -114,7 +113,7 @@ namespace RTC MS_TRACE(); #ifdef USE_TREND_CALCULATOR - auto nowMs = DepLibUV::GetTimeMsInt64(); + auto nowMs = GetTimeMsInt64(); #endif this->bitrates.desiredBitrate = 0u; @@ -306,7 +305,7 @@ namespace RTC MS_TRACE(); #ifdef USE_TREND_CALCULATOR - auto nowMs = DepLibUV::GetTimeMsInt64(); + auto nowMs = GetTimeMsInt64(); #endif // Manage it via trending and increase it a bit to avoid immediate oscillations. @@ -408,7 +407,7 @@ namespace RTC webrtc::TargetRateConstraints constraints; - constraints.at_time = webrtc::Timestamp::ms(DepLibUV::GetTimeMs()); + constraints.at_time = webrtc::Timestamp::ms(GetTimeMs()); constraints.min_data_rate = webrtc::DataRate::bps(this->bitrates.minBitrate); constraints.max_data_rate = webrtc::DataRate::bps(this->bitrates.maxBitrate); constraints.starting_rate = webrtc::DataRate::bps(this->bitrates.startBitrate); @@ -434,14 +433,14 @@ namespace RTC { MS_TRACE(); - this->lastAvailableBitrateEventAtMs = DepLibUV::GetTimeMs(); + this->lastAvailableBitrateEventAtMs = GetTimeMs(); } void TransportCongestionControlClient::MayEmitAvailableBitrateEvent(uint32_t previousAvailableBitrate) { MS_TRACE(); - const uint64_t nowMs = DepLibUV::GetTimeMsInt64(); + const uint64_t nowMs = GetTimeMsInt64(); bool notify{ false }; // Ignore if first event. diff --git a/worker/src/RTC/TransportCongestionControlServer.cpp b/worker/src/RTC/TransportCongestionControlServer.cpp index 8c7a016949..904d81d900 100644 --- a/worker/src/RTC/TransportCongestionControlServer.cpp +++ b/worker/src/RTC/TransportCongestionControlServer.cpp @@ -2,7 +2,6 @@ // #define MS_LOG_DEV_LEVEL 3 #include "RTC/TransportCongestionControlServer.hpp" -#include "DepLibUV.hpp" #include "Logger.hpp" #include "RTC/RTCP/FeedbackPsRemb.hpp" #include // std::ostream_iterator @@ -275,7 +274,7 @@ namespace RTC { MS_TRACE(); - auto nowMs = DepLibUV::GetTimeMs(); + auto nowMs = GetTimeMs(); // May fix unlimitedRembCounter. if (this->unlimitedRembCounter > 0u && this->maxIncomingBitrate != 0u) diff --git a/worker/src/handles/Timer.cpp b/worker/src/handles/Timer.cpp index ce6bad6264..2c5f012bf1 100644 --- a/worker/src/handles/Timer.cpp +++ b/worker/src/handles/Timer.cpp @@ -6,6 +6,181 @@ #include "Logger.hpp" #include "MediaSoupErrors.hpp" +#ifdef FAKE_TIMERS + +#include + +int64_t FakeTimerManager::now = + 1; // Don't start in 0 to avoid problems with timers that are set to run in 0. +uint16_t FakeTimerManager::nextTimerId = 0; +std::map FakeTimerManager::timers; + +uint16_t FakeTimerManager::GetNexTimerId() +{ + return FakeTimerManager::nextTimerId++; +} + +void FakeTimerManager::StartTimer( + uint16_t timerId, uint64_t timeout, uint64_t repeat, std::function cb) +{ + FakeTimerManager::timers[timerId] = { FakeTimerManager::now + timeout, repeat, cb }; +} + +void FakeTimerManager::StopTimer(uint16_t timerId) +{ + FakeTimerManager::timers.erase(timerId); +} + +bool FakeTimerManager::IsActive(uint16_t timerId) +{ + return FakeTimerManager::timers.find(timerId) != FakeTimerManager::timers.end(); +} + +int64_t FakeTimerManager::NextTimerTime() +{ + int64_t nextTime = -1; + + for (auto& kv : FakeTimerManager::timers) + { + if (nextTime == -1 || kv.second.nextTime < nextTime) + { + nextTime = kv.second.nextTime; + } + } + + return nextTime; +} + +void FakeTimerManager::RunPending(int64_t now) +{ + FakeTimerManager::now = now; + + auto copy = FakeTimerManager::timers; + for (auto& kv : copy) + { + if (kv.second.nextTime <= now) + { + auto it = FakeTimerManager::timers.find(kv.first); + it->second.nextTime = kv.second.repeat != 0u ? now + kv.second.repeat : -1; + kv.second.cb(); + } + } +} + +void FakeTimerManager::RunLoop(int64_t maxTime) +{ + while (true) + { + uint64_t nextTime = FakeTimerManager::NextTimerTime(); + + if (nextTime == -1 || (maxTime != -1 && nextTime > maxTime)) + { + break; + } + + FakeTimerManager::RunPending(nextTime); + } +} + +Timer::Timer(Listener* listener) : listener(listener) +{ + this->timerId = FakeTimerManager::GetNexTimerId(); +} + +Timer::~Timer() +{ + MS_TRACE(); + + if (!this->closed) + { + Close(); + } +} + +void Timer::Close() +{ + MS_TRACE(); + + if (this->closed) + { + return; + } + + Stop(); + + this->closed = true; +} + +void Timer::Start(uint64_t timeout, uint64_t repeat) +{ + MS_TRACE(); + + if (this->closed) + { + MS_THROW_ERROR("closed"); + } + + this->timeout = timeout; + this->repeat = repeat; + + FakeTimerManager::StartTimer( + this->timerId, timeout, repeat, [this]() { this->listener->OnTimer(this); }); +} + +void Timer::Stop() +{ + MS_TRACE(); + + if (this->closed) + { + MS_THROW_ERROR("closed"); + } + + FakeTimerManager::StopTimer(this->timerId); +} + +bool Timer::IsActive() const +{ + return FakeTimerManager::IsActive(this->timerId); +} + +void Timer::Reset() +{ + MS_TRACE(); + + if (this->closed) + { + MS_THROW_ERROR("closed"); + } + + if (!this->IsActive()) + { + return; + } + + if (this->repeat == 0u) + { + return; + } + + this->Start(this->repeat, this->repeat); +} + +void Timer::Restart() +{ + MS_TRACE(); + + if (this->closed) + { + MS_THROW_ERROR("closed"); + } + + this->Stop(); + this->Start(this->timeout, this->repeat); +} + +#else // FAKE_TIMERS + /* Static methods for UV callbacks. */ inline static void onTimer(uv_timer_t* handle) @@ -104,6 +279,11 @@ void Timer::Stop() } } +bool Timer::IsActive() const +{ + return uv_is_active(reinterpret_cast(this->uvHandle)) != 0; +} + void Timer::Reset() { MS_TRACE(); @@ -162,3 +342,33 @@ inline void Timer::OnUvTimer() // Notify the listener. this->listener->OnTimer(this); } + +#endif // FAKE_TIMERS + +uint64_t GetTimeMs() +{ +#if FAKE_TIMERS + return static_cast(FakeTimerManager::GetTimeMs()); +#else + return uv_hrtime() / 1000000u; +#endif +} + +int64_t GetTimeMsInt64() +{ + return static_cast(GetTimeMs()); +} + +uint64_t GetTimeUs() +{ +#if FAKE_TIMERS + return FakeTimerManager::GetTimeMs() * 1000; +#else + return uv_hrtime() / 1000u; +#endif +} + +int64_t GetTimeUsInt64() +{ + return static_cast(GetTimeUs()); +} diff --git a/worker/test/src/RTC/TestKeyFrameRequestManager.cpp b/worker/test/src/RTC/TestKeyFrameRequestManager.cpp index 0fdc8449a3..ff6f9c91d2 100644 --- a/worker/test/src/RTC/TestKeyFrameRequestManager.cpp +++ b/worker/test/src/RTC/TestKeyFrameRequestManager.cpp @@ -1,6 +1,7 @@ #include "common.hpp" #include "DepLibUV.hpp" #include "RTC/KeyFrameRequestManager.hpp" +#include "handles/Timer.hpp" #include using namespace RTC; @@ -34,7 +35,7 @@ SCENARIO("KeyFrameRequestManager", "[rtp][keyframe]") keyFrameRequestManager.KeyFrameNeeded(1111); // Must run the loop here to consume the timer before doing the check. - DepLibUV::RunLoop(); + FakeTimerManager::RunLoop(); REQUIRE(listener.onKeyFrameNeededTimesCalled == 2); } @@ -50,7 +51,7 @@ SCENARIO("KeyFrameRequestManager", "[rtp][keyframe]") keyFrameRequestManager.KeyFrameNeeded(1111); // Must run the loop here to consume the timer before doing the check. - DepLibUV::RunLoop(); + FakeTimerManager::RunLoop(); REQUIRE(listener.onKeyFrameNeededTimesCalled == 2); } @@ -64,7 +65,7 @@ SCENARIO("KeyFrameRequestManager", "[rtp][keyframe]") keyFrameRequestManager.KeyFrameReceived(1111); // Must run the loop here to consume the timer before doing the check. - DepLibUV::RunLoop(); + FakeTimerManager::RunLoop(); REQUIRE(listener.onKeyFrameNeededTimesCalled == 1); } @@ -78,7 +79,7 @@ SCENARIO("KeyFrameRequestManager", "[rtp][keyframe]") keyFrameRequestManager.ForceKeyFrameNeeded(1111); // Must run the loop here to consume the timer before doing the check. - DepLibUV::RunLoop(); + FakeTimerManager::RunLoop(); REQUIRE(listener.onKeyFrameNeededTimesCalled == 3); } @@ -93,13 +94,8 @@ SCENARIO("KeyFrameRequestManager", "[rtp][keyframe]") keyFrameRequestManager.KeyFrameReceived(1111); // Must run the loop here to consume the timer before doing the check. - DepLibUV::RunLoop(); + FakeTimerManager::RunLoop(); REQUIRE(listener.onKeyFrameNeededTimesCalled == 2); } - - // Must run the loop to wait for UV timers and close them. - // NOTE: Not really needed in this file since we run it in each SECTION in - // purpose. - DepLibUV::RunLoop(); } diff --git a/worker/test/src/RTC/TestRateCalculator.cpp b/worker/test/src/RTC/TestRateCalculator.cpp index ae566fe53e..101c11dea0 100644 --- a/worker/test/src/RTC/TestRateCalculator.cpp +++ b/worker/test/src/RTC/TestRateCalculator.cpp @@ -1,6 +1,6 @@ #include "common.hpp" -#include "DepLibUV.hpp" #include "RTC/RateCalculator.hpp" +#include "handles/Timer.hpp" #include #include @@ -25,7 +25,7 @@ void validate(RateCalculator& rate, uint64_t timeBase, std::vector& input) SCENARIO("Bitrate calculator", "[rtp][bitrate]") { - uint64_t nowMs = DepLibUV::GetTimeMs(); + uint64_t nowMs = GetTimeMs(); SECTION("receive single item per 1000 ms") {