Move default thresholds from QualityScaler to encoders.

Overriding implementations of VideoEncoder::GetScalingSettings that
want to enable quality scaling must now provide the thresholds.

Bug: webrtc:8830
Change-Id: I75c47cb56ac1b9cf77401684980b3167e485f51c
Reviewed-on: https://webrtc-review.googlesource.com/46622
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22172}
This commit is contained in:
Niels Möller
2018-02-22 15:03:53 +01:00
committed by Commit Bot
parent 12fb17035c
commit 225c787c6e
16 changed files with 140 additions and 102 deletions

View File

@ -1205,8 +1205,11 @@ void MediaCodecVideoEncoder::LogStatistics(bool force_log) {
VideoEncoder::ScalingSettings MediaCodecVideoEncoder::GetScalingSettings()
const {
if (!scale_)
return VideoEncoder::ScalingSettings::kOff;
const VideoCodecType codec_type = GetCodecType();
if (field_trial::IsEnabled(kCustomQPThresholdsFieldTrial)) {
const VideoCodecType codec_type = GetCodecType();
std::string experiment_string =
field_trial::FindFullName(kCustomQPThresholdsFieldTrial);
ALOGD << "QP custom thresholds: " << experiment_string << " for codec "
@ -1224,15 +1227,38 @@ VideoEncoder::ScalingSettings MediaCodecVideoEncoder::GetScalingSettings()
RTC_CHECK_GT(high_h264_qp_threshold, low_h264_qp_threshold);
RTC_CHECK_GT(low_h264_qp_threshold, 0);
if (codec_type == kVideoCodecVP8) {
return VideoEncoder::ScalingSettings(scale_, low_vp8_qp_threshold,
return VideoEncoder::ScalingSettings(low_vp8_qp_threshold,
high_vp8_qp_threshold);
} else if (codec_type == kVideoCodecH264) {
return VideoEncoder::ScalingSettings(scale_, low_h264_qp_threshold,
return VideoEncoder::ScalingSettings(low_h264_qp_threshold,
high_h264_qp_threshold);
}
}
}
return VideoEncoder::ScalingSettings(scale_);
if (codec_type == kVideoCodecVP8) {
// Same as in vp8_impl.cc.
static const int kLowVp8QpThreshold = 29;
static const int kHighVp8QpThreshold = 95;
return VideoEncoder::ScalingSettings(kLowVp8QpThreshold,
kHighVp8QpThreshold);
} else if (codec_type == kVideoCodecVP9) {
// QP is obtained from VP9-bitstream, so the QP corresponds to the bitstream
// range of [0, 255] and not the user-level range of [0,63].
static const int kLowVp9QpThreshold = 96;
static const int kHighVp9QpThreshold = 185;
return VideoEncoder::ScalingSettings(kLowVp9QpThreshold,
kHighVp9QpThreshold);
} else if (codec_type == kVideoCodecH264) {
// Same as in h264_encoder_impl.cc.
static const int kLowH264QpThreshold = 24;
static const int kHighH264QpThreshold = 37;
return VideoEncoder::ScalingSettings(kLowH264QpThreshold,
kHighH264QpThreshold);
}
return VideoEncoder::ScalingSettings::kOff;
}
const char* MediaCodecVideoEncoder::ImplementationName() const {

View File

@ -165,6 +165,9 @@ VideoEncoderWrapper::ScalingSettings VideoEncoderWrapper::GetScalingSettings()
bool isOn =
Java_VideoEncoderWrapper_getScalingSettingsOn(jni, j_scaling_settings);
if (!isOn)
return ScalingSettings::kOff;
rtc::Optional<int> low = JavaToNativeOptionalInt(
jni,
Java_VideoEncoderWrapper_getScalingSettingsLow(jni, j_scaling_settings));
@ -172,8 +175,36 @@ VideoEncoderWrapper::ScalingSettings VideoEncoderWrapper::GetScalingSettings()
jni,
Java_VideoEncoderWrapper_getScalingSettingsHigh(jni, j_scaling_settings));
return (low && high) ? ScalingSettings(isOn, *low, *high)
: ScalingSettings(isOn);
if (low && high)
return ScalingSettings(*low, *high);
switch (codec_settings_.codecType) {
case kVideoCodecVP8: {
// Same as in vp8_impl.cc.
static const int kLowVp8QpThreshold = 29;
static const int kHighVp8QpThreshold = 95;
return ScalingSettings(low.value_or(kLowVp8QpThreshold),
high.value_or(kHighVp8QpThreshold));
}
case kVideoCodecVP9: {
// QP is obtained from VP9-bitstream, so the QP corresponds to the
// bitstream range of [0, 255] and not the user-level range of [0,63].
static const int kLowVp9QpThreshold = 96;
static const int kHighVp9QpThreshold = 185;
return VideoEncoder::ScalingSettings(kLowVp9QpThreshold,
kHighVp9QpThreshold);
}
case kVideoCodecH264: {
// Same as in h264_encoder_impl.cc.
static const int kLowH264QpThreshold = 24;
static const int kHighH264QpThreshold = 37;
return ScalingSettings(low.value_or(kLowH264QpThreshold),
high.value_or(kHighH264QpThreshold));
}
default:
return ScalingSettings::kOff;
}
}
const char* VideoEncoderWrapper::ImplementationName() const {