diff --git a/webrtc/api/java/jni/androidmediaencoder_jni.cc b/webrtc/api/java/jni/androidmediaencoder_jni.cc index 937aef8349..b46d82ecd7 100644 --- a/webrtc/api/java/jni/androidmediaencoder_jni.cc +++ b/webrtc/api/java/jni/androidmediaencoder_jni.cc @@ -354,8 +354,7 @@ int32_t MediaCodecVideoEncoder::InitEncode( const webrtc::VideoCodec* codec_settings, int32_t /* number_of_cores */, size_t /* max_payload_size */) { - const int kMinWidth = 320; - const int kMinHeight = 180; + const int kMinDimension = 180; if (codec_settings == NULL) { ALOGE << "NULL VideoCodec instance"; return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; @@ -398,11 +397,11 @@ int32_t MediaCodecVideoEncoder::InitEncode( RTC_NOTREACHED() << "Unsupported codec without configured QP thresholds."; scale_ = false; } - quality_scaler_.SetMinResolution(kMinWidth, kMinHeight); + quality_scaler_.SetMinResolution(kMinDimension, kMinDimension); quality_scaler_.ReportFramerate(codec_settings->maxFramerate); QualityScaler::Resolution res = quality_scaler_.GetScaledResolution(); - init_width = std::max(res.width, kMinWidth); - init_height = std::max(res.height, kMinHeight); + init_width = std::max(res.width, kMinDimension); + init_height = std::max(res.height, kMinDimension); ALOGD << "Scaled resolution: " << init_width << " x " << init_height; } diff --git a/webrtc/modules/video_coding/utility/quality_scaler.cc b/webrtc/modules/video_coding/utility/quality_scaler.cc index a46e8502cb..68ae9218ea 100644 --- a/webrtc/modules/video_coding/utility/quality_scaler.cc +++ b/webrtc/modules/video_coding/utility/quality_scaler.cc @@ -40,6 +40,9 @@ void QualityScaler::Init(int low_qp_threshold, low_qp_threshold_ = low_qp_threshold; high_qp_threshold_ = high_qp_threshold; use_framerate_reduction_ = use_framerate_reduction; + downscale_shift_ = 0; + const int init_width = width; + const int init_height = height; // TODO(glaznev): Investigate using thresholds for other resolutions // or threshold tables. if (initial_bitrate_kbps > 0 && @@ -51,8 +54,7 @@ void QualityScaler::Init(int low_qp_threshold, height /= 2; } } - res_.width = width; - res_.height = height; + UpdateTargetResolution(init_width, init_height); target_framerate_ = -1; } @@ -81,8 +83,6 @@ void QualityScaler::OnEncodeFrame(const VideoFrame& frame) { // Should be set through InitEncode -> Should be set by now. assert(low_qp_threshold_ >= 0); assert(num_samples_ > 0); - res_.width = frame.width(); - res_.height = frame.height(); // Update scale factor. int avg_drop = 0; @@ -117,15 +117,7 @@ void QualityScaler::OnEncodeFrame(const VideoFrame& frame) { AdjustScale(true); } } - - assert(downscale_shift_ >= 0); - for (int shift = downscale_shift_; - shift > 0 && (res_.width / 2 >= min_width_) && - (res_.height / 2 >= min_height_); - --shift) { - res_.width /= 2; - res_.height /= 2; - } + UpdateTargetResolution(frame.width(), frame.height()); } QualityScaler::Resolution QualityScaler::GetScaledResolution() const { @@ -153,6 +145,19 @@ const VideoFrame& QualityScaler::GetScaledFrame(const VideoFrame& frame) { return scaled_frame_; } +void QualityScaler::UpdateTargetResolution(int frame_width, int frame_height) { + assert(downscale_shift_ >= 0); + res_.width = frame_width; + res_.height = frame_height; + for (int shift = downscale_shift_; + shift > 0 && (res_.width / 2 >= min_width_) && + (res_.height / 2 >= min_height_); + --shift) { + res_.width /= 2; + res_.height /= 2; + } +} + void QualityScaler::ClearSamples() { framedrop_percent_.Reset(); average_qp_.Reset(); diff --git a/webrtc/modules/video_coding/utility/quality_scaler.h b/webrtc/modules/video_coding/utility/quality_scaler.h index 4a2c207af6..ebceb06893 100644 --- a/webrtc/modules/video_coding/utility/quality_scaler.h +++ b/webrtc/modules/video_coding/utility/quality_scaler.h @@ -44,6 +44,7 @@ class QualityScaler { private: void AdjustScale(bool up); + void UpdateTargetResolution(int frame_width, int frame_height); void ClearSamples(); Scaler scaler_;