Chromium Code Reviews| Index: webrtc/video/vie_encoder.cc |
| diff --git a/webrtc/video/vie_encoder.cc b/webrtc/video/vie_encoder.cc |
| index 3a848f852f846e9d6276bd008e39dfcf69e956ac..5612dd1e20e4ed58aab7b975269f95763876c40f 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) { |
| + int cpu_scale_counter = GetScaleCounters()[reason]; |
|
kthelgason
2017/04/19 08:23:04
this can be const right?
åsapersson
2017/04/20 13:44:47
Done.
|
| + 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,24 +916,8 @@ 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. |
| + // degradation preference mode. If it is 1, 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); |
| @@ -933,7 +925,7 @@ void ViEEncoder::AdaptUp(AdaptReason reason) { |
| case VideoSendStream::DegradationPreference::kBalanced: |
| FALLTHROUGH(); |
| case VideoSendStream::DegradationPreference::kMaintainFramerate: |
| - if (scale_sum == 0) { |
| + if (scale_sum == 1) { |
| LOG(LS_INFO) << "Removing resolution down-scaling setting."; |
| source_proxy_->RequestHigherResolutionThan( |
| std::numeric_limits<int>::max()); |
| @@ -944,7 +936,7 @@ void ViEEncoder::AdaptUp(AdaptReason reason) { |
| } |
| break; |
| case VideoSendStream::DegradationPreference::kMaintainResolution: |
| - if (scale_sum == 0) { |
| + if (scale_sum == 1) { |
| LOG(LS_INFO) << "Removing framerate down-scaling setting."; |
| source_proxy_->RequestHigherFramerateThan( |
| std::numeric_limits<int>::max()); |
| @@ -958,8 +950,27 @@ void ViEEncoder::AdaptUp(AdaptReason reason) { |
| RTC_NOTREACHED(); |
| } |
| + last_adaptation_request_.emplace(adaptation_request); |
| + |
| + // Decrease counter of how many times we have scaled down, for this |
| + // degradation preference mode and reason. |
| + IncrementScaleCounter(reason, -1); |
|
kthelgason
2017/04/19 08:23:04
Why move this below the switch-case? IMO it's less
åsapersson
2017/04/20 13:44:47
Moved this up.
|
| + |
| + // 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(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"); |
| } |
| } |