Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: webrtc/media/base/videoadapter.cc

Issue 1695263002: Move direct use of VideoCapturer::VideoAdapter to VideoSinkWants. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: switched to int. Found bug in adapter... Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/media/base/videoadapter.cc
diff --git a/webrtc/media/base/videoadapter.cc b/webrtc/media/base/videoadapter.cc
index 9228e6d84cf75846ce3dc72c96cb96c0c0c58ace..3a086eb91d89b1bf397fc5e2c09e7d82581c5968 100644
--- a/webrtc/media/base/videoadapter.cc
+++ b/webrtc/media/base/videoadapter.cc
@@ -21,17 +21,6 @@
namespace cricket {
-// TODO(fbarchard): Make downgrades settable
-static const int kMaxCpuDowngrades = 2; // Downgrade at most 2 times for CPU.
-// The number of cpu samples to require before adapting. This value depends on
-// the cpu monitor sampling frequency being 2000ms.
-static const int kCpuLoadMinSamples = 3;
-// The amount of weight to give to each new cpu load sample. The lower the
-// value, the slower we'll adapt to changing cpu conditions.
-static const float kCpuLoadWeightCoefficient = 0.4f;
-// The seed value for the cpu load moving average.
-static const float kCpuLoadInitialAverage = 0.5f;
-
// Desktop needs 1/8 scale for HD (1280 x 720) to QQVGA (160 x 90)
static const float kScaleFactors[] = {
1.f / 1.f, // Full size.
@@ -198,12 +187,6 @@ void CoordinatedVideoAdapter::SetInputFormat(const VideoFormat& format) {
}
}
-void CoordinatedVideoAdapter::set_cpu_smoothing(bool enable) {
- LOG(LS_INFO) << "CPU smoothing is now "
- << (enable ? "enabled" : "disabled");
- cpu_smoothing_ = enable;
-}
-
void VideoAdapter::SetOutputFormat(const VideoFormat& format) {
rtc::CritScope cs(&critical_section_);
int64_t old_output_interval = output_format_.interval;
@@ -346,18 +329,11 @@ CoordinatedVideoAdapter::CoordinatedVideoAdapter()
gd_adaptation_(true),
view_adaptation_(true),
view_switch_(false),
- cpu_downgrade_count_(0),
- cpu_load_min_samples_(kCpuLoadMinSamples),
- cpu_load_num_samples_(0),
- high_system_threshold_(kHighSystemCpuThreshold),
- low_system_threshold_(kLowSystemCpuThreshold),
- process_threshold_(kProcessCpuThreshold),
view_desired_num_pixels_(INT_MAX),
view_desired_interval_(0),
encoder_desired_num_pixels_(INT_MAX),
cpu_desired_num_pixels_(INT_MAX),
- adapt_reason_(ADAPTREASON_NONE),
- system_load_average_(kCpuLoadInitialAverage) {
+ adapt_reason_(ADAPTREASON_NONE) {
}
// Helper function to UPGRADE or DOWNGRADE a number of pixels
@@ -379,21 +355,6 @@ void CoordinatedVideoAdapter::StepPixelCount(
return;
}
-// Find the adaptation request of the cpu based on the load. Return UPGRADE if
-// the load is low, DOWNGRADE if the load is high, and KEEP otherwise.
-CoordinatedVideoAdapter::AdaptRequest CoordinatedVideoAdapter::FindCpuRequest(
- int current_cpus, int max_cpus,
- float process_load, float system_load) {
- // Downgrade if system is high and plugin is at least more than midrange.
- if (system_load >= high_system_threshold_ * max_cpus &&
- process_load >= process_threshold_ * current_cpus) {
- return CoordinatedVideoAdapter::DOWNGRADE;
- // Upgrade if system is low.
- } else if (system_load < low_system_threshold_ * max_cpus) {
- return CoordinatedVideoAdapter::UPGRADE;
- }
- return CoordinatedVideoAdapter::KEEP;
-}
// A remote view request for a new resolution.
void CoordinatedVideoAdapter::OnOutputFormatRequest(const VideoFormat& format) {
@@ -416,48 +377,6 @@ void CoordinatedVideoAdapter::OnOutputFormatRequest(const VideoFormat& format) {
<< " To: " << new_width << "x" << new_height;
}
-void CoordinatedVideoAdapter::set_cpu_load_min_samples(
- int cpu_load_min_samples) {
- if (cpu_load_min_samples_ != cpu_load_min_samples) {
- LOG(LS_INFO) << "VAdapt Change Cpu Adapt Min Samples from: "
- << cpu_load_min_samples_ << " to "
- << cpu_load_min_samples;
- cpu_load_min_samples_ = cpu_load_min_samples;
- }
-}
-
-void CoordinatedVideoAdapter::set_high_system_threshold(
- float high_system_threshold) {
- ASSERT(high_system_threshold <= 1.0f);
- ASSERT(high_system_threshold >= 0.0f);
- if (high_system_threshold_ != high_system_threshold) {
- LOG(LS_INFO) << "VAdapt Change High System Threshold from: "
- << high_system_threshold_ << " to " << high_system_threshold;
- high_system_threshold_ = high_system_threshold;
- }
-}
-
-void CoordinatedVideoAdapter::set_low_system_threshold(
- float low_system_threshold) {
- ASSERT(low_system_threshold <= 1.0f);
- ASSERT(low_system_threshold >= 0.0f);
- if (low_system_threshold_ != low_system_threshold) {
- LOG(LS_INFO) << "VAdapt Change Low System Threshold from: "
- << low_system_threshold_ << " to " << low_system_threshold;
- low_system_threshold_ = low_system_threshold;
- }
-}
-
-void CoordinatedVideoAdapter::set_process_threshold(float process_threshold) {
- ASSERT(process_threshold <= 1.0f);
- ASSERT(process_threshold >= 0.0f);
- if (process_threshold_ != process_threshold) {
- LOG(LS_INFO) << "VAdapt Change High Process Threshold from: "
- << process_threshold_ << " to " << process_threshold;
- process_threshold_ = process_threshold;
- }
-}
-
// A Bandwidth GD request for new resolution
void CoordinatedVideoAdapter::OnEncoderResolutionRequest(
int width, int height, AdaptRequest request) {
@@ -495,90 +414,27 @@ void CoordinatedVideoAdapter::OnEncoderResolutionRequest(
<< " To: " << new_width << "x" << new_height;
}
-// A Bandwidth GD request for new resolution
-void CoordinatedVideoAdapter::OnCpuResolutionRequest(AdaptRequest request) {
+void CoordinatedVideoAdapter::OnLimitResolution(int max_number_of_pixels) {
rtc::CritScope cs(&request_critical_section_);
if (!cpu_adaptation_) {
return;
}
- // Update how many times we have downgraded due to the cpu load.
- switch (request) {
- case DOWNGRADE:
- // Ignore downgrades if we have downgraded the maximum times.
- if (cpu_downgrade_count_ < kMaxCpuDowngrades) {
- ++cpu_downgrade_count_;
- } else {
- LOG(LS_VERBOSE) << "VAdapt CPU load high but do not downgrade "
- "because maximum downgrades reached";
- SignalCpuAdaptationUnable();
- }
- break;
- case UPGRADE:
- if (cpu_downgrade_count_ > 0) {
- bool is_min = IsMinimumFormat(cpu_desired_num_pixels_);
- if (is_min) {
- --cpu_downgrade_count_;
- } else {
- LOG(LS_VERBOSE) << "VAdapt CPU load low but do not upgrade "
- "because cpu is not limiting resolution";
- }
- } else {
- LOG(LS_VERBOSE) << "VAdapt CPU load low but do not upgrade "
- "because minimum downgrades reached";
- }
- break;
- case KEEP:
- default:
- break;
- }
- if (KEEP != request) {
- // TODO(fbarchard): compute stepping up/down from OutputNumPixels but
- // clamp to inputpixels / 4 (2 steps)
- cpu_desired_num_pixels_ = cpu_downgrade_count_ == 0 ? INT_MAX :
- static_cast<int>(input_format().width * input_format().height >>
- cpu_downgrade_count_);
+
+ const VideoFormat& input = input_format();
+ if (input.IsSize0x0()) {
+ // TODO NOW.... Make sure AdaptToMinimumFormat can be called before first frame....
+ return;
}
+ cpu_desired_num_pixels_ =
+ std::min(input.width * input.height, max_number_of_pixels);
+
int new_width, new_height;
bool changed = AdaptToMinimumFormat(&new_width, &new_height);
- LOG(LS_INFO) << "VAdapt CPU Request: "
- << (DOWNGRADE == request ? "down" :
- (UPGRADE == request ? "up" : "keep"))
- << " Steps: " << cpu_downgrade_count_
+ LOG(LS_INFO) << "VAdapt OnLimitResolution: "
<< " Changed: " << (changed ? "true" : "false")
<< " To: " << new_width << "x" << new_height;
}
-// A CPU request for new resolution
-// TODO(fbarchard): Move outside adapter.
-void CoordinatedVideoAdapter::OnCpuLoadUpdated(
- int current_cpus, int max_cpus, float process_load, float system_load) {
- rtc::CritScope cs(&request_critical_section_);
- if (!cpu_adaptation_) {
- return;
- }
- // Update the moving average of system load. Even if we aren't smoothing,
- // we'll still calculate this information, in case smoothing is later enabled.
- system_load_average_ = kCpuLoadWeightCoefficient * system_load +
- (1.0f - kCpuLoadWeightCoefficient) * system_load_average_;
- ++cpu_load_num_samples_;
- if (cpu_smoothing_) {
- system_load = system_load_average_;
- }
- AdaptRequest request = FindCpuRequest(current_cpus, max_cpus,
- process_load, system_load);
- // Make sure we're not adapting too quickly.
- if (request != KEEP) {
- if (cpu_load_num_samples_ < cpu_load_min_samples_) {
- LOG(LS_VERBOSE) << "VAdapt CPU load high/low but do not adapt until "
- << (cpu_load_min_samples_ - cpu_load_num_samples_)
- << " more samples";
- request = KEEP;
- }
- }
-
- OnCpuResolutionRequest(request);
-}
-
// Called by cpu adapter on up requests.
bool CoordinatedVideoAdapter::IsMinimumFormat(int pixels) {
// Find closest scale factor that matches input resolution to min_num_pixels
@@ -689,13 +545,6 @@ bool CoordinatedVideoAdapter::AdaptToMinimumFormat(int* new_width,
<< " Changed: " << (changed ? "true" : "false")
<< " Reason: " << kReasons[adapt_reason_];
- if (changed) {
- // When any adaptation occurs, historic CPU load levels are no longer
- // accurate. Clear out our state so we can re-learn at the new normal.
- cpu_load_num_samples_ = 0;
- system_load_average_ = kCpuLoadInitialAverage;
- }
-
return changed;
}

Powered by Google App Engine
This is Rietveld 408576698