diff --git a/modules/video_coding/utility/quality_scaler.cc b/modules/video_coding/utility/quality_scaler.cc index 795f85ea05..4f4bb3b033 100644 --- a/modules/video_coding/utility/quality_scaler.cc +++ b/modules/video_coding/utility/quality_scaler.cc @@ -68,13 +68,14 @@ class QualityScaler::QpSmoother { rtc::ExpFilter smoother_; }; - -QualityScaler::QualityScaler(AdaptationObserverInterface* observer, +QualityScaler::QualityScaler(rtc::TaskQueue* task_queue, + AdaptationObserverInterface* observer, VideoEncoder::QpThresholds thresholds) - : QualityScaler(observer, thresholds, kMeasureMs) {} + : QualityScaler(task_queue, observer, thresholds, kMeasureMs) {} // Protected ctor, should not be called directly. -QualityScaler::QualityScaler(AdaptationObserverInterface* observer, +QualityScaler::QualityScaler(rtc::TaskQueue* task_queue, + AdaptationObserverInterface* observer, VideoEncoder::QpThresholds thresholds, int64_t sampling_period_ms) : observer_(observer), @@ -95,7 +96,7 @@ QualityScaler::QualityScaler(AdaptationObserverInterface* observer, } RTC_DCHECK(observer_ != nullptr); check_qp_task_ = RepeatingTaskHandle::DelayedStart( - TimeDelta::ms(GetSamplingPeriodMs()), [this]() { + task_queue->Get(), TimeDelta::ms(GetSamplingPeriodMs()), [this]() { CheckQp(); return TimeDelta::ms(GetSamplingPeriodMs()); }); diff --git a/modules/video_coding/utility/quality_scaler.h b/modules/video_coding/utility/quality_scaler.h index c2f5b212e8..5e7ee0ded5 100644 --- a/modules/video_coding/utility/quality_scaler.h +++ b/modules/video_coding/utility/quality_scaler.h @@ -19,6 +19,7 @@ #include "rtc_base/experiments/quality_scaling_experiment.h" #include "rtc_base/numerics/moving_average.h" #include "rtc_base/sequenced_task_checker.h" +#include "rtc_base/task_queue.h" #include "rtc_base/task_utils/repeating_task.h" namespace webrtc { @@ -48,7 +49,8 @@ class QualityScaler { // Construct a QualityScaler with given |thresholds| and |observer|. // This starts the quality scaler periodically checking what the average QP // has been recently. - QualityScaler(AdaptationObserverInterface* observer, + QualityScaler(rtc::TaskQueue* task_queue, + AdaptationObserverInterface* observer, VideoEncoder::QpThresholds thresholds); virtual ~QualityScaler(); // Should be called each time a frame is dropped at encoding. @@ -59,7 +61,8 @@ class QualityScaler { // The following members declared protected for testing purposes. protected: - QualityScaler(AdaptationObserverInterface* observer, + QualityScaler(rtc::TaskQueue* task_queue, + AdaptationObserverInterface* observer, VideoEncoder::QpThresholds thresholds, int64_t sampling_period_ms); diff --git a/modules/video_coding/utility/quality_scaler_unittest.cc b/modules/video_coding/utility/quality_scaler_unittest.cc index 342431242e..618439c8a7 100644 --- a/modules/video_coding/utility/quality_scaler_unittest.cc +++ b/modules/video_coding/utility/quality_scaler_unittest.cc @@ -59,9 +59,10 @@ class MockAdaptationObserver : public AdaptationObserverInterface { // Pass a lower sampling period to speed up the tests. class QualityScalerUnderTest : public QualityScaler { public: - explicit QualityScalerUnderTest(AdaptationObserverInterface* observer, + explicit QualityScalerUnderTest(rtc::TaskQueue* task_queue, + AdaptationObserverInterface* observer, VideoEncoder::QpThresholds thresholds) - : QualityScaler(observer, thresholds, 5) {} + : QualityScaler(task_queue, observer, thresholds, 5) {} }; class QualityScalerTest : public ::testing::Test, @@ -81,7 +82,8 @@ class QualityScalerTest : public ::testing::Test, observer_(new MockAdaptationObserver()) { DO_SYNC(q_, { qs_ = std::unique_ptr(new QualityScalerUnderTest( - observer_.get(), VideoEncoder::QpThresholds(kLowQp, kHighQp))); + q_.get(), observer_.get(), + VideoEncoder::QpThresholds(kLowQp, kHighQp))); }); } diff --git a/test/pc/e2e/peer_connection_quality_test.cc b/test/pc/e2e/peer_connection_quality_test.cc index 8ccff69112..3f14746f3b 100644 --- a/test/pc/e2e/peer_connection_quality_test.cc +++ b/test/pc/e2e/peer_connection_quality_test.cc @@ -227,11 +227,12 @@ void PeerConnectionE2EQualityTest::Run( task_queue_.PostTask([&stats_poller, this]() { RTC_DCHECK_RUN_ON(&task_queue_); - stats_polling_task_ = RepeatingTaskHandle::Start([this, &stats_poller]() { - RTC_DCHECK_RUN_ON(&task_queue_); - stats_poller.PollStatsAndNotifyObservers(); - return kStatsUpdateInterval; - }); + stats_polling_task_ = + RepeatingTaskHandle::Start(task_queue_.Get(), [this, &stats_poller]() { + RTC_DCHECK_RUN_ON(&task_queue_); + stats_poller.PollStatsAndNotifyObservers(); + return kStatsUpdateInterval; + }); }); rtc::Event done; diff --git a/video/overuse_frame_detector.cc b/video/overuse_frame_detector.cc index e3e6141e1d..24eed97bcb 100644 --- a/video/overuse_frame_detector.cc +++ b/video/overuse_frame_detector.cc @@ -538,6 +538,7 @@ OveruseFrameDetector::OveruseFrameDetector( OveruseFrameDetector::~OveruseFrameDetector() {} void OveruseFrameDetector::StartCheckForOveruse( + rtc::TaskQueue* task_queue, const CpuOveruseOptions& options, AdaptationObserverInterface* overuse_observer) { RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); @@ -546,7 +547,8 @@ void OveruseFrameDetector::StartCheckForOveruse( SetOptions(options); check_overuse_task_ = RepeatingTaskHandle::DelayedStart( - TimeDelta::ms(kTimeToFirstCheckForOveruseMs), [this, overuse_observer] { + task_queue->Get(), TimeDelta::ms(kTimeToFirstCheckForOveruseMs), + [this, overuse_observer] { CheckForOveruse(overuse_observer); return TimeDelta::ms(kCheckForOveruseIntervalMs); }); diff --git a/video/overuse_frame_detector.h b/video/overuse_frame_detector.h index d4a2c627e4..b63a3aebd3 100644 --- a/video/overuse_frame_detector.h +++ b/video/overuse_frame_detector.h @@ -57,7 +57,8 @@ class OveruseFrameDetector { virtual ~OveruseFrameDetector(); // Start to periodically check for overuse. - void StartCheckForOveruse(const CpuOveruseOptions& options, + void StartCheckForOveruse(rtc::TaskQueue* task_queue, + const CpuOveruseOptions& options, AdaptationObserverInterface* overuse_observer); // StopCheckForOveruse must be called before destruction if diff --git a/video/overuse_frame_detector_unittest.cc b/video/overuse_frame_detector_unittest.cc index 7e160f7551..b356d1d200 100644 --- a/video/overuse_frame_detector_unittest.cc +++ b/video/overuse_frame_detector_unittest.cc @@ -428,8 +428,8 @@ TEST_F(OveruseFrameDetectorTest, RunOnTqNormalUsage) { rtc::TaskQueue queue("OveruseFrameDetectorTestQueue"); rtc::Event event; - queue.PostTask([this, &event] { - overuse_detector_->StartCheckForOveruse(options_, observer_); + queue.PostTask([this, &event, &queue] { + overuse_detector_->StartCheckForOveruse(&queue, options_, observer_); event.Set(); }); event.Wait(rtc::Event::kForever); @@ -908,8 +908,8 @@ TEST_F(OveruseFrameDetectorTest2, RunOnTqNormalUsage) { rtc::TaskQueue queue("OveruseFrameDetectorTestQueue"); rtc::Event event; - queue.PostTask([this, &event] { - overuse_detector_->StartCheckForOveruse(options_, observer_); + queue.PostTask([this, &event, &queue] { + overuse_detector_->StartCheckForOveruse(&queue, options_, observer_); event.Set(); }); event.Wait(rtc::Event::kForever); diff --git a/video/video_send_stream_impl.cc b/video/video_send_stream_impl.cc index b0e1f0d9c5..fc572d61f4 100644 --- a/video/video_send_stream_impl.cc +++ b/video/video_send_stream_impl.cc @@ -390,8 +390,8 @@ void VideoSendStreamImpl::StartupVideoSendStream() { activity_ = false; timed_out_ = false; - check_encoder_activity_task_ = - RepeatingTaskHandle::DelayedStart(kEncoderTimeOut, [this] { + check_encoder_activity_task_ = RepeatingTaskHandle::DelayedStart( + worker_queue_->Get(), kEncoderTimeOut, [this] { RTC_DCHECK_RUN_ON(worker_queue_); if (!activity_) { if (!timed_out_) { diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc index 98ed015916..c1dac5ee44 100644 --- a/video/video_stream_encoder.cc +++ b/video/video_stream_encoder.cc @@ -741,6 +741,7 @@ void VideoStreamEncoder::ReconfigureEncoder() { if (pending_encoder_creation_) { overuse_detector_->StopCheckForOveruse(); overuse_detector_->StartCheckForOveruse( + &encoder_queue_, GetCpuOveruseOptions( settings_, encoder_->GetEncoderInfo().is_hardware_accelerated), this); @@ -829,8 +830,9 @@ void VideoStreamEncoder::ConfigureQualityScaler( // upcast. AdaptationObserverInterface* observer = this; quality_scaler_ = absl::make_unique( - observer, experimental_thresholds ? *experimental_thresholds - : *(scaling_settings.thresholds)); + &encoder_queue_, observer, + experimental_thresholds ? *experimental_thresholds + : *(scaling_settings.thresholds)); has_seen_first_significant_bwe_change_ = false; initial_framedrop_ = 0; }