MediaCodecVideoEncoder: Add QP stats to Encoded callback for VP9 and turn on quality scaling.
Add default QP scaling thresholds for VP9.
BUG=webrtc:7662
Review-Url: https://codereview.webrtc.org/2914363002
Cr-Original-Commit-Position: refs/heads/master@{#18469}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: 1e15a994ac668d37d8b2d7bbcf4864635e3fb3f3
diff --git a/media/engine/webrtcvideoengine2.cc b/media/engine/webrtcvideoengine2.cc
index 4f3c283..f9fccf1 100644
--- a/media/engine/webrtcvideoengine2.cc
+++ b/media/engine/webrtcvideoengine2.cc
@@ -421,6 +421,7 @@
// VP9 denoising is disabled by default.
vp9_settings.denoisingOn = codec_default_denoising ? true : denoising;
vp9_settings.frameDroppingOn = frame_dropping;
+ vp9_settings.automaticResizeOn = automatic_resize;
return new rtc::RefCountedObject<
webrtc::VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings);
}
diff --git a/modules/video_coding/utility/quality_scaler.cc b/modules/video_coding/utility/quality_scaler.cc
index f1623cb..3709ee3 100644
--- a/modules/video_coding/utility/quality_scaler.cc
+++ b/modules/video_coding/utility/quality_scaler.cc
@@ -39,6 +39,11 @@
// bitstream range of [0, 127] and not the user-level range of [0,63].
static const int kLowVp8QpThreshold = 29;
static const int kHighVp8QpThreshold = 95;
+// QP is obtained from VP9-bitstream for HW, so the QP corresponds to the
+// bitstream range of [0, 255] and not the user-level range of [0,63].
+// Current VP9 settings are mapped from VP8 thresholds above.
+static const int kLowVp9QpThreshold = 96;
+static const int kHighVp9QpThreshold = 208;
static const int kMinFramesNeededToScale = 2 * 30;
static VideoEncoder::QpThresholds CodecTypeToDefaultThresholds(
@@ -54,6 +59,10 @@
low = kLowVp8QpThreshold;
high = kHighVp8QpThreshold;
break;
+ case kVideoCodecVP9:
+ low = kLowVp9QpThreshold;
+ high = kHighVp9QpThreshold;
+ break;
default:
RTC_NOTREACHED() << "Invalid codec type for QualityScaler.";
}
diff --git a/sdk/android/src/jni/DEPS b/sdk/android/src/jni/DEPS
index 629ad00..0052c97 100644
--- a/sdk/android/src/jni/DEPS
+++ b/sdk/android/src/jni/DEPS
@@ -4,6 +4,7 @@
"+webrtc/common_video/libyuv/include/webrtc_libyuv.h",
"+webrtc/modules/utility/include/jvm_android.h",
"+webrtc/modules/video_coding/utility/vp8_header_parser.h",
+ "+webrtc/modules/video_coding/utility/vp9_uncompressed_header_parser.h",
"+webrtc/pc",
"+webrtc/system_wrappers/include/field_trial_default.h",
]
diff --git a/sdk/android/src/jni/androidmediaencoder_jni.cc b/sdk/android/src/jni/androidmediaencoder_jni.cc
index 1c86f08..40d21d2 100644
--- a/sdk/android/src/jni/androidmediaencoder_jni.cc
+++ b/sdk/android/src/jni/androidmediaencoder_jni.cc
@@ -39,6 +39,7 @@
#include "webrtc/modules/video_coding/include/video_codec_interface.h"
#include "webrtc/modules/video_coding/utility/quality_scaler.h"
#include "webrtc/modules/video_coding/utility/vp8_header_parser.h"
+#include "webrtc/modules/video_coding/utility/vp9_uncompressed_header_parser.h"
#include "webrtc/sdk/android/src/jni/androidmediacodeccommon.h"
#include "webrtc/sdk/android/src/jni/classreferenceholder.h"
#include "webrtc/sdk/android/src/jni/native_handle_impl.h"
@@ -404,12 +405,14 @@
codec_mode_ = codec_settings->mode;
int init_width = codec_settings->width;
int init_height = codec_settings->height;
- // Scaling is disabled for VP9, but optionally enabled for VP8.
+ // Scaling is optionally enabled for VP8 and VP9.
// TODO(pbos): Extract automaticResizeOn out of VP8 settings.
scale_ = false;
if (codec_type == kVideoCodecVP8) {
scale_ = codec_settings->VP8().automaticResizeOn;
- } else if (codec_type != kVideoCodecVP9) {
+ } else if (codec_type == kVideoCodecVP9) {
+ scale_ = codec_settings->VP9().automaticResizeOn;
+ } else {
scale_ = true;
}
@@ -1104,6 +1107,12 @@
current_acc_qp_ += qp;
image->qp_ = qp;
}
+ } else if (codec_type == kVideoCodecVP9) {
+ int qp;
+ if (webrtc::vp9::GetQp(payload, payload_size, &qp)) {
+ current_acc_qp_ += qp;
+ image->qp_ = qp;
+ }
}
} else if (codec_type == kVideoCodecH264) {
h264_bitstream_parser_.ParseBitstream(payload, payload_size);