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

Unified Diff: webrtc/video/vie_encoder.cc

Issue 2800403002: Scale counter and resolution downgrade stats may be incorrect. (Closed)
Patch Set: address comments Created 3 years, 8 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
« no previous file with comments | « no previous file | webrtc/video/vie_encoder_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/video/vie_encoder.cc
diff --git a/webrtc/video/vie_encoder.cc b/webrtc/video/vie_encoder.cc
index 3a848f852f846e9d6276bd008e39dfcf69e956ac..2287a7e3bb911b74d1889a3113b5c193a03d79b7 100644
--- a/webrtc/video/vie_encoder.cc
+++ b/webrtc/video/vie_encoder.cc
@@ -210,24 +210,26 @@ class ViEEncoder::VideoSourceProxy {
return wants;
}
- void RequestResolutionLowerThan(int pixel_count) {
+ bool RequestResolutionLowerThan(int pixel_count) {
// Called on the encoder task queue.
rtc::CritScope lock(&crit_);
if (!IsResolutionScalingEnabledLocked()) {
// This can happen since |degradation_preference_| is set on libjingle's
// worker thread but the adaptation is done on the encoder task queue.
- return;
+ return false;
}
// The input video frame size will have a resolution with less than or
// equal to |max_pixel_count| depending on how the source can scale the
// input frame size.
const int pixels_wanted = (pixel_count * 3) / 5;
if (pixels_wanted < kMinPixelsPerFrame)
- return;
+ return false;
+
sink_wants_.max_pixel_count = pixels_wanted;
sink_wants_.target_pixel_count = rtc::Optional<int>();
if (source_)
source_->AddOrUpdateSink(vie_encoder_, GetActiveSinkWants());
+ return true;
}
void RequestFramerateLowerThan(int framerate_fps) {
@@ -833,30 +835,20 @@ void ViEEncoder::AdaptDown(AdaptReason reason) {
return;
}
- last_adaptation_request_.emplace(adaptation_request);
- const std::vector<int>& scale_counter = GetScaleCounters();
-
- switch (reason) {
- case kQuality:
- stats_proxy_->OnQualityRestrictedResolutionChanged(scale_counter[reason] +
- 1);
- break;
- case kCpu:
- if (scale_counter[reason] >= max_downgrades)
- return;
- // Update stats accordingly.
- stats_proxy_->OnCpuRestrictedResolutionChanged(true);
- break;
+ if (reason == kCpu) {
+ const int cpu_scale_counter = GetScaleCounters()[reason];
+ if (cpu_scale_counter >= max_downgrades)
+ return;
}
- IncrementScaleCounter(reason, 1);
-
switch (degradation_preference_) {
case VideoSendStream::DegradationPreference::kBalanced:
FALLTHROUGH();
case VideoSendStream::DegradationPreference::kMaintainFramerate:
- source_proxy_->RequestResolutionLowerThan(
- adaptation_request.input_pixel_count_);
+ if (!source_proxy_->RequestResolutionLowerThan(
+ adaptation_request.input_pixel_count_)) {
+ return;
+ }
LOG(LS_INFO) << "Scaling down resolution.";
break;
case VideoSendStream::DegradationPreference::kMaintainResolution:
@@ -868,8 +860,24 @@ void ViEEncoder::AdaptDown(AdaptReason reason) {
RTC_NOTREACHED();
}
+ last_adaptation_request_.emplace(adaptation_request);
+
+ IncrementScaleCounter(reason, 1);
+
+ // Update stats.
+ const std::vector<int>& scale_counters = GetScaleCounters();
+ switch (reason) {
+ case kQuality:
+ stats_proxy_->OnQualityRestrictedResolutionChanged(
+ scale_counters[reason]);
+ break;
+ case kCpu:
+ stats_proxy_->OnCpuRestrictedResolutionChanged(true);
+ break;
+ }
+
for (size_t i = 0; i < kScaleReasonSize; ++i) {
- LOG(LS_INFO) << "Scaled " << GetScaleCounters()[i]
+ LOG(LS_INFO) << "Scaled " << scale_counters[i]
<< " times for reason: " << (i ? "cpu" : "quality");
}
}
@@ -908,27 +916,15 @@ void ViEEncoder::AdaptUp(AdaptReason reason) {
return;
}
- last_adaptation_request_.emplace(adaptation_request);
-
- switch (reason) {
- case kQuality:
- stats_proxy_->OnQualityRestrictedResolutionChanged(scale_counter - 1);
- break;
- case kCpu:
- // Update stats accordingly.
- stats_proxy_->OnCpuRestrictedResolutionChanged(scale_counter > 1);
- break;
- }
-
// Decrease counter of how many times we have scaled down, for this
// degradation preference mode and reason.
IncrementScaleCounter(reason, -1);
// Get a sum of how many times have scaled down, in total, for this
// degradation preference mode. If it is 0, remove any restraints.
- const std::vector<int>& current_scale_counters = GetScaleCounters();
- const int scale_sum = std::accumulate(current_scale_counters.begin(),
- current_scale_counters.end(), 0);
+ const std::vector<int>& scale_counters = GetScaleCounters();
+ const int scale_sum =
+ std::accumulate(scale_counters.begin(), scale_counters.end(), 0);
switch (degradation_preference_) {
case VideoSendStream::DegradationPreference::kBalanced:
FALLTHROUGH();
@@ -958,8 +954,22 @@ void ViEEncoder::AdaptUp(AdaptReason reason) {
RTC_NOTREACHED();
}
+ last_adaptation_request_.emplace(adaptation_request);
+
+ // Update stats.
+ switch (reason) {
+ case kQuality:
+ stats_proxy_->OnQualityRestrictedResolutionChanged(
+ scale_counters[reason]);
+ break;
+ case kCpu:
+ stats_proxy_->OnCpuRestrictedResolutionChanged(scale_counters[reason] >
+ 0);
+ break;
+ }
+
for (size_t i = 0; i < kScaleReasonSize; ++i) {
- LOG(LS_INFO) << "Scaled " << current_scale_counters[i]
+ LOG(LS_INFO) << "Scaled " << scale_counters[i]
<< " times for reason: " << (i ? "cpu" : "quality");
}
}
« no previous file with comments | « no previous file | webrtc/video/vie_encoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698