From 919288f6ba4ac2112c616c877273e84374904da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Bostr=C3=B6m?= Date: Thu, 12 May 2016 02:17:35 +0200 Subject: [PATCH] Clamp number of downscales in QualityScaler. Fixes bug where QualityScaler would be stuck "way below" QVGA (due to downscale_shift_) even though it would never scale below QVGA. Also fixes issue where samples would be cleared when either staying at max resolution or going below QVGA even though no action happened. BUG= R=glaznev@webrtc.org Review URL: https://codereview.webrtc.org/1971693003 . Cr-Commit-Position: refs/heads/master@{#12691} --- .../video_coding/utility/quality_scaler.cc | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/webrtc/modules/video_coding/utility/quality_scaler.cc b/webrtc/modules/video_coding/utility/quality_scaler.cc index 30a5776b2d..c60b50de63 100644 --- a/webrtc/modules/video_coding/utility/quality_scaler.cc +++ b/webrtc/modules/video_coding/utility/quality_scaler.cc @@ -60,6 +60,10 @@ void QualityScaler::Init(int low_qp_threshold, height /= 2; } } + + // Zero out width/height so they can be checked against inside + // UpdateTargetResolution. + res_.width = res_.height = 0; UpdateTargetResolution(init_width, init_height); ReportFramerate(fps); } @@ -131,15 +135,24 @@ const VideoFrame& QualityScaler::GetScaledFrame(const VideoFrame& frame) { void QualityScaler::UpdateTargetResolution(int frame_width, int frame_height) { assert(downscale_shift_ >= 0); + int shifts_performed = 0; + for (int shift = downscale_shift_; + shift > 0 && (frame_width / 2 >= kMinDownscaleDimension) && + (frame_height / 2 >= kMinDownscaleDimension); + --shift, ++shifts_performed) { + frame_width /= 2; + frame_height /= 2; + } + // Clamp to number of shifts actually performed to not be stuck trying to + // scale way beyond QVGA. + downscale_shift_ = shifts_performed; + if (res_.width == frame_width && res_.height == frame_height) { + // No reset done/needed, using same resolution. + return; + } res_.width = frame_width; res_.height = frame_height; - for (int shift = downscale_shift_; - shift > 0 && (res_.width / 2 >= kMinDownscaleDimension) && - (res_.height / 2 >= kMinDownscaleDimension); - --shift) { - res_.width /= 2; - res_.height /= 2; - } + ClearSamples(); } void QualityScaler::ClearSamples() { @@ -160,11 +173,10 @@ void QualityScaler::AdjustScale(bool up) { if (downscale_shift_ < 0) downscale_shift_ = 0; if (!up) { - // Hit first downscale, start using a slower threshold for going up. + // First downscale hit, start using a slower threshold for going up. measure_seconds_upscale_ = kMeasureSecondsUpscale; UpdateSampleCounts(); } - ClearSamples(); } } // namespace webrtc