diff --git a/video/adaptation/overuse_frame_detector.cc b/video/adaptation/overuse_frame_detector.cc index 9836a466b5..e5c2c7d379 100644 --- a/video/adaptation/overuse_frame_detector.cc +++ b/video/adaptation/overuse_frame_detector.cc @@ -429,62 +429,6 @@ class OverdoseInjector : public OveruseFrameDetector::ProcessingUsage { } // namespace -CpuOveruseOptions::CpuOveruseOptions(const FieldTrialsView& field_trials) - : high_encode_usage_threshold_percent(85), - frame_timeout_interval_ms(1500), - min_frame_samples(120), - min_process_count(3), - high_threshold_consecutive_count(2), - // Disabled by default. - filter_time_ms(0) { -#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) - // Kill switch for re-enabling special adaptation rules for macOS. - // TODO(bugs.webrtc.org/14138): Remove once removal is deemed safe. - if (field_trials.IsEnabled( - "WebRTC-MacSpecialOveruseRulesRemovalKillSwitch")) { - // This is proof-of-concept code for letting the physical core count affect - // the interval into which we attempt to scale. For now, the code is Mac OS - // specific, since that's the platform were we saw most problems. - // TODO(torbjorng): Enhance SystemInfo to return this metric. - - mach_port_t mach_host = mach_host_self(); - host_basic_info hbi = {}; - mach_msg_type_number_t info_count = HOST_BASIC_INFO_COUNT; - kern_return_t kr = - host_info(mach_host, HOST_BASIC_INFO, - reinterpret_cast(&hbi), &info_count); - mach_port_deallocate(mach_task_self(), mach_host); - - int n_physical_cores; - if (kr != KERN_SUCCESS) { - // If we couldn't get # of physical CPUs, don't panic. Assume we have 1. - n_physical_cores = 1; - RTC_LOG(LS_ERROR) - << "Failed to determine number of physical cores, assuming 1"; - } else { - n_physical_cores = hbi.physical_cpu; - RTC_LOG(LS_INFO) << "Number of physical cores:" << n_physical_cores; - } - - // Change init list default for few core systems. The assumption here is - // that encoding, which we measure here, takes about 1/4 of the processing - // of a two-way call. This is roughly true for x86 using both vp8 and vp9 - // without hardware encoding. Since we don't affect the incoming stream - // here, we only control about 1/2 of the total processing needs, but this - // is not taken into account. - if (n_physical_cores == 1) - high_encode_usage_threshold_percent = 20; // Roughly 1/4 of 100%. - else if (n_physical_cores == 2) - high_encode_usage_threshold_percent = 40; // Roughly 1/4 of 200%. - } -#endif // defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) - // Note that we make the interval 2x+epsilon wide, since libyuv scaling steps - // are close to that (when squared). This wide interval makes sure that - // scaling up or down does not jump all the way across the interval. - low_encode_usage_threshold_percent = - (high_encode_usage_threshold_percent - 1) / 2; -} - std::unique_ptr OveruseFrameDetector::CreateProcessingUsage(const CpuOveruseOptions& options) { std::unique_ptr instance; @@ -521,10 +465,8 @@ OveruseFrameDetector::CreateProcessingUsage(const CpuOveruseOptions& options) { } OveruseFrameDetector::OveruseFrameDetector( - CpuOveruseMetricsObserver* metrics_observer, - const FieldTrialsView& field_trials) - : options_(field_trials), - metrics_observer_(metrics_observer), + CpuOveruseMetricsObserver* metrics_observer) + : metrics_observer_(metrics_observer), num_process_times_(0), // TODO(bugs.webrtc.org/9078): Use absl::optional last_capture_time_us_(-1), diff --git a/video/adaptation/overuse_frame_detector.h b/video/adaptation/overuse_frame_detector.h index 4e1f6a83a4..f39cee043e 100644 --- a/video/adaptation/overuse_frame_detector.h +++ b/video/adaptation/overuse_frame_detector.h @@ -30,21 +30,29 @@ namespace webrtc { class VideoFrame; struct CpuOveruseOptions { - explicit CpuOveruseOptions(const FieldTrialsView& field_trials); - - int low_encode_usage_threshold_percent; // Threshold for triggering underuse. - int high_encode_usage_threshold_percent; // Threshold for triggering overuse. + // Threshold for triggering overuse. + int high_encode_usage_threshold_percent = 85; + // Threshold for triggering underuse. + // Note that we make the interval 2x+epsilon wide, since libyuv scaling steps + // are close to that (when squared). This wide interval makes sure that + // scaling up or down does not jump all the way across the interval. + int low_encode_usage_threshold_percent = + (high_encode_usage_threshold_percent - 1) / 2; // General settings. - int frame_timeout_interval_ms; // The maximum allowed interval between two - // frames before resetting estimations. - int min_frame_samples; // The minimum number of frames required. - int min_process_count; // The number of initial process times required before - // triggering an overuse/underuse. - int high_threshold_consecutive_count; // The number of consecutive checks - // above the high threshold before - // triggering an overuse. + // The maximum allowed interval between two frames before resetting + // estimations. + int frame_timeout_interval_ms = 1500; + // The minimum number of frames required. + int min_frame_samples = 120; + + // The number of initial process times required before + // triggering an overuse/underuse. + int min_process_count = 3; + // The number of consecutive checks above the high threshold before triggering + // an overuse. + int high_threshold_consecutive_count = 2; // New estimator enabled if this is set non-zero. - int filter_time_ms; // Time constant for averaging + int filter_time_ms = 0; // Time constant for averaging }; class OveruseFrameDetectorObserverInterface { @@ -65,8 +73,7 @@ class OveruseFrameDetectorObserverInterface { // check for overuse. class OveruseFrameDetector { public: - explicit OveruseFrameDetector(CpuOveruseMetricsObserver* metrics_observer, - const FieldTrialsView& field_trials); + explicit OveruseFrameDetector(CpuOveruseMetricsObserver* metrics_observer); virtual ~OveruseFrameDetector(); OveruseFrameDetector(const OveruseFrameDetector&) = delete; diff --git a/video/adaptation/overuse_frame_detector_unittest.cc b/video/adaptation/overuse_frame_detector_unittest.cc index 5098c9c2ec..85a84fe23a 100644 --- a/video/adaptation/overuse_frame_detector_unittest.cc +++ b/video/adaptation/overuse_frame_detector_unittest.cc @@ -12,7 +12,6 @@ #include -#include "api/field_trials_view.h" #include "api/video/encoded_image.h" #include "api/video/i420_buffer.h" #include "api/video/video_adaptation_reason.h" @@ -36,7 +35,6 @@ const int kHeight = 480; // Corresponds to load of 15% const int kFrameIntervalUs = 33 * rtc::kNumMicrosecsPerMillisec; const int kProcessTimeUs = 5 * rtc::kNumMicrosecsPerMillisec; -const test::ScopedKeyValueConfig kFieldTrials; } // namespace class MockCpuOveruseObserver : public OveruseFrameDetectorObserverInterface { @@ -64,7 +62,7 @@ class OveruseFrameDetectorUnderTest : public OveruseFrameDetector { public: explicit OveruseFrameDetectorUnderTest( CpuOveruseMetricsObserver* metrics_observer) - : OveruseFrameDetector(metrics_observer, kFieldTrials) {} + : OveruseFrameDetector(metrics_observer) {} ~OveruseFrameDetectorUnderTest() {} using OveruseFrameDetector::CheckForOveruse; @@ -74,8 +72,6 @@ class OveruseFrameDetectorUnderTest : public OveruseFrameDetector { class OveruseFrameDetectorTest : public ::testing::Test, public CpuOveruseMetricsObserver { protected: - OveruseFrameDetectorTest() : options_(kFieldTrials) {} - void SetUp() override { observer_ = &mock_observer_; options_.min_process_count = 0; diff --git a/video/adaptation/video_stream_encoder_resource_manager.cc b/video/adaptation/video_stream_encoder_resource_manager.cc index 2470bc8893..0dcbc01ab6 100644 --- a/video/adaptation/video_stream_encoder_resource_manager.cc +++ b/video/adaptation/video_stream_encoder_resource_manager.cc @@ -672,7 +672,7 @@ CpuOveruseOptions VideoStreamEncoderResourceManager::GetCpuOveruseOptions() // This is already ensured by the only caller of this method: // StartResourceAdaptation(). RTC_DCHECK(encoder_settings_.has_value()); - CpuOveruseOptions options(field_trials_); + CpuOveruseOptions options; // Hardware accelerated encoders are assumed to be pipelined; give them // additional overuse time. if (encoder_settings_->encoder_info().is_hardware_accelerated) { diff --git a/video/video_send_stream.cc b/video/video_send_stream.cc index e95ca260a4..9111c3e6ed 100644 --- a/video/video_send_stream.cc +++ b/video/video_send_stream.cc @@ -122,7 +122,7 @@ std::unique_ptr CreateVideoStreamEncoder( TaskQueueBase* encoder_queue_ptr = encoder_queue.get(); return std::make_unique( clock, num_cpu_cores, stats_proxy, encoder_settings, - std::make_unique(stats_proxy, field_trials), + std::make_unique(stats_proxy), FrameCadenceAdapterInterface::Create(clock, encoder_queue_ptr, field_trials), std::move(encoder_queue), bitrate_allocation_callback_type, field_trials, diff --git a/video/video_stream_encoder_unittest.cc b/video/video_stream_encoder_unittest.cc index 2b7399de12..2800f2b049 100644 --- a/video/video_stream_encoder_unittest.cc +++ b/video/video_stream_encoder_unittest.cc @@ -222,9 +222,8 @@ class FakeNV12NativeBuffer : public webrtc::VideoFrameBuffer { class CpuOveruseDetectorProxy : public OveruseFrameDetector { public: - CpuOveruseDetectorProxy(CpuOveruseMetricsObserver* metrics_observer, - const FieldTrialsView& field_trials) - : OveruseFrameDetector(metrics_observer, field_trials), + explicit CpuOveruseDetectorProxy(CpuOveruseMetricsObserver* metrics_observer) + : OveruseFrameDetector(metrics_observer), last_target_framerate_fps_(-1), framerate_updated_event_(true /* manual_reset */, false /* initially_signaled */) {} @@ -383,18 +382,17 @@ class VideoStreamEncoderUnderTest : public VideoStreamEncoder { allocation_callback_type, const FieldTrialsView& field_trials, int num_cores) - : VideoStreamEncoder( - time_controller->GetClock(), - num_cores, - stats_proxy, - settings, - std::unique_ptr( - overuse_detector_proxy_ = - new CpuOveruseDetectorProxy(stats_proxy, field_trials)), - std::move(cadence_adapter), - std::move(encoder_queue), - allocation_callback_type, - field_trials), + : VideoStreamEncoder(time_controller->GetClock(), + num_cores, + stats_proxy, + settings, + std::unique_ptr( + overuse_detector_proxy_ = + new CpuOveruseDetectorProxy(stats_proxy)), + std::move(cadence_adapter), + std::move(encoder_queue), + allocation_callback_type, + field_trials), time_controller_(time_controller), fake_cpu_resource_(FakeResource::Create("FakeResource[CPU]")), fake_quality_resource_(FakeResource::Create("FakeResource[QP]")), @@ -700,8 +698,7 @@ class SimpleVideoStreamEncoderFactory { /*number_of_cores=*/1, /*stats_proxy=*/stats_proxy_.get(), encoder_settings_, std::make_unique( - /*stats_proxy=*/nullptr, - field_trials ? *field_trials : field_trials_), + /*stats_proxy=*/nullptr), std::move(zero_hertz_adapter), std::move(encoder_queue), VideoStreamEncoder::BitrateAllocationCallbackType:: kVideoBitrateAllocation, @@ -7060,8 +7057,7 @@ TEST_F(VideoStreamEncoderTest, DefaultCpuAdaptationThresholdsForSoftwareEncoder) { const int kFrameWidth = 1280; const int kFrameHeight = 720; - const test::ScopedKeyValueConfig kFieldTrials; - const CpuOveruseOptions default_options(kFieldTrials); + const CpuOveruseOptions default_options; video_stream_encoder_->OnBitrateUpdatedAndWaitForManagedResources( kTargetBitrate, kTargetBitrate, kTargetBitrate, 0, 0, 0); video_source_.IncomingCapturedFrame( @@ -7080,8 +7076,7 @@ TEST_F(VideoStreamEncoderTest, HigherCpuAdaptationThresholdsForHardwareEncoder) { const int kFrameWidth = 1280; const int kFrameHeight = 720; - const test::ScopedKeyValueConfig kFieldTrials; - CpuOveruseOptions hardware_options(kFieldTrials); + CpuOveruseOptions hardware_options; hardware_options.low_encode_usage_threshold_percent = 150; hardware_options.high_encode_usage_threshold_percent = 200; fake_encoder_.SetIsHardwareAccelerated(true); @@ -7105,8 +7100,7 @@ TEST_F(VideoStreamEncoderTest, const int kFrameWidth = 1280; const int kFrameHeight = 720; - const test::ScopedKeyValueConfig kFieldTrials; - const CpuOveruseOptions default_options(kFieldTrials); + const CpuOveruseOptions default_options; video_stream_encoder_->OnBitrateUpdatedAndWaitForManagedResources( kTargetBitrate, kTargetBitrate, kTargetBitrate, 0, 0, 0); video_source_.IncomingCapturedFrame( @@ -7119,7 +7113,7 @@ TEST_F(VideoStreamEncoderTest, .high_encode_usage_threshold_percent, default_options.high_encode_usage_threshold_percent); - CpuOveruseOptions hardware_options(kFieldTrials); + CpuOveruseOptions hardware_options; hardware_options.low_encode_usage_threshold_percent = 150; hardware_options.high_encode_usage_threshold_percent = 200; fake_encoder_.SetIsHardwareAccelerated(true); @@ -9237,8 +9231,7 @@ TEST(VideoStreamEncoderSimpleTest, CreateDestroy) { // the posted init task will simply be deleted. auto encoder = std::make_unique( time_controller.GetClock(), 1, stats_proxy.get(), encoder_settings, - std::make_unique(stats_proxy.get(), - field_trials), + std::make_unique(stats_proxy.get()), std::move(adapter), std::move(encoder_queue), VideoStreamEncoder::BitrateAllocationCallbackType:: kVideoBitrateAllocation,