Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Unified Diff: webrtc/api/java/jni/androidmediadecoder_jni.cc

Issue 1732533002: Add an option to soft reset HW decoder. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Address comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/api/java/jni/androidmediadecoder_jni.cc
diff --git a/webrtc/api/java/jni/androidmediadecoder_jni.cc b/webrtc/api/java/jni/androidmediadecoder_jni.cc
index 7c303e8fc311eeefb0a8bb4610047230e74cba42..335e035ac4a6687652ba81e793e1f4edb33ae73c 100644
--- a/webrtc/api/java/jni/androidmediadecoder_jni.cc
+++ b/webrtc/api/java/jni/androidmediadecoder_jni.cc
@@ -99,6 +99,7 @@ class MediaCodecVideoDecoder : public webrtc::VideoDecoder,
void CheckOnCodecThread();
int32_t InitDecodeOnCodecThread();
+ int32_t ResetDecodeOnCodecThread();
int32_t ReleaseOnCodecThread();
int32_t DecodeOnCodecThread(const EncodedImage& inputImage);
// Deliver any outputs pending in the MediaCodec to our |callback_| and return
@@ -106,6 +107,7 @@ class MediaCodecVideoDecoder : public webrtc::VideoDecoder,
bool DeliverPendingOutputs(JNIEnv* jni, int dequeue_timeout_us);
int32_t ProcessHWErrorOnCodecThread();
void EnableFrameLogOnWarning();
+ void ResetVariables();
// Type of video codec.
VideoCodecType codecType_;
@@ -139,6 +141,7 @@ class MediaCodecVideoDecoder : public webrtc::VideoDecoder,
ScopedGlobalRef<jclass> j_media_codec_video_decoder_class_;
ScopedGlobalRef<jobject> j_media_codec_video_decoder_;
jmethodID j_init_decode_method_;
+ jmethodID j_reset_method_;
jmethodID j_release_method_;
jmethodID j_dequeue_input_buffer_method_;
jmethodID j_queue_input_buffer_method_;
@@ -200,6 +203,8 @@ MediaCodecVideoDecoder::MediaCodecVideoDecoder(
jni, *j_media_codec_video_decoder_class_, "initDecode",
"(Lorg/webrtc/MediaCodecVideoDecoder$VideoCodecType;"
"IILorg/webrtc/SurfaceTextureHelper;)Z");
+ j_reset_method_ =
+ GetMethodID(jni, *j_media_codec_video_decoder_class_, "reset", "(II)V");
j_release_method_ =
GetMethodID(jni, *j_media_codec_video_decoder_class_, "release", "()V");
j_dequeue_input_buffer_method_ = GetMethodID(
@@ -306,6 +311,18 @@ int32_t MediaCodecVideoDecoder::InitDecode(const VideoCodec* inst,
Bind(&MediaCodecVideoDecoder::InitDecodeOnCodecThread, this));
}
+void MediaCodecVideoDecoder::ResetVariables() {
+ key_frame_required_ = true;
pbos-webrtc 2016/03/04 10:23:13 CheckOnCodecThread?
AlexG 2016/03/04 18:44:12 Done.
+ frames_received_ = 0;
+ frames_decoded_ = 0;
+ frames_decoded_logged_ = kMaxDecodedLogFrames;
+ start_time_ms_ = GetCurrentTimeMs();
+ current_frames_ = 0;
+ current_bytes_ = 0;
+ current_decoding_time_ms_ = 0;
+ current_delay_time_ms_ = 0;
+}
+
int32_t MediaCodecVideoDecoder::InitDecodeOnCodecThread() {
CheckOnCodecThread();
JNIEnv* jni = AttachCurrentThreadIfNeeded();
@@ -322,11 +339,7 @@ int32_t MediaCodecVideoDecoder::InitDecodeOnCodecThread() {
return WEBRTC_VIDEO_CODEC_ERROR;
}
- // Always start with a complete key frame.
- key_frame_required_ = true;
- frames_received_ = 0;
- frames_decoded_ = 0;
- frames_decoded_logged_ = kMaxDecodedLogFrames;
+ ResetVariables();
jobject java_surface_texture_helper_ = nullptr;
if (use_surface_) {
@@ -352,6 +365,7 @@ int32_t MediaCodecVideoDecoder::InitDecodeOnCodecThread() {
codec_.width,
codec_.height,
java_surface_texture_helper_);
+
if (CheckException(jni) || !success) {
ALOGE << "Codec initialization error - fallback to SW codec.";
sw_fallback_required_ = true;
@@ -372,16 +386,11 @@ int32_t MediaCodecVideoDecoder::InitDecodeOnCodecThread() {
default:
max_pending_frames_ = 0;
}
- start_time_ms_ = GetCurrentTimeMs();
- current_frames_ = 0;
- current_bytes_ = 0;
- current_decoding_time_ms_ = 0;
- current_delay_time_ms_ = 0;
+ ALOGD << "Maximum amount of pending frames: " << max_pending_frames_;
jobjectArray input_buffers = (jobjectArray)GetObjectField(
jni, *j_media_codec_video_decoder_, j_input_buffers_field_);
size_t num_input_buffers = jni->GetArrayLength(input_buffers);
- ALOGD << "Maximum amount of pending frames: " << max_pending_frames_;
input_buffers_.resize(num_input_buffers);
for (size_t i = 0; i < num_input_buffers; ++i) {
input_buffers_[i] =
@@ -398,6 +407,37 @@ int32_t MediaCodecVideoDecoder::InitDecodeOnCodecThread() {
return WEBRTC_VIDEO_CODEC_OK;
}
+int32_t MediaCodecVideoDecoder::ResetDecodeOnCodecThread() {
+ CheckOnCodecThread();
+ JNIEnv* jni = AttachCurrentThreadIfNeeded();
+ ScopedLocalRefFrame local_ref_frame(jni);
+ ALOGD << "ResetDecodeOnCodecThread Type: " << (int)codecType_ << ". "
+ << codec_.width << " x " << codec_.height;
+ ALOGD << " Frames received: " << frames_received_ <<
+ ". Frames decoded: " << frames_decoded_;
+
+ inited_ = false;
+ rtc::MessageQueueManager::Clear(this);
+ ResetVariables();
+
+ jni->CallVoidMethod(
+ *j_media_codec_video_decoder_,
+ j_reset_method_,
+ codec_.width,
+ codec_.height);
+
+ if (CheckException(jni)) {
+ ALOGE << "Soft reset error - fallback to SW codec.";
+ sw_fallback_required_ = true;
+ return WEBRTC_VIDEO_CODEC_ERROR;
+ }
+ inited_ = true;
+
+ codec_thread_->PostDelayed(kMediaCodecPollMs, this);
+
+ return WEBRTC_VIDEO_CODEC_OK;
+}
+
int32_t MediaCodecVideoDecoder::Release() {
ALOGD << "DecoderRelease request";
return codec_thread_->Invoke<int32_t>(
@@ -493,9 +533,21 @@ int32_t MediaCodecVideoDecoder::Decode(
if ((inputImage._encodedWidth * inputImage._encodedHeight > 0) &&
(inputImage._encodedWidth != codec_.width ||
inputImage._encodedHeight != codec_.height)) {
+ ALOGW << "Input resolution changed from " <<
+ codec_.width << " x " << codec_.height << " to " <<
+ inputImage._encodedWidth << " x " << inputImage._encodedHeight;
codec_.width = inputImage._encodedWidth;
codec_.height = inputImage._encodedHeight;
- int32_t ret = InitDecode(&codec_, 1);
+ int32_t ret;
+ if (use_surface_ && codecType_ == kVideoCodecVP8) {
+ // Soft codec reset - only for VP8 and surface decoding.
+ // TODO(glaznev): try to use similar approach for H.264.
pbos-webrtc 2016/03/04 10:23:13 (and buffer decoding?)
AlexG 2016/03/04 18:44:12 Done.
+ ret = codec_thread_->Invoke<int32_t>(Bind(
+ &MediaCodecVideoDecoder::ResetDecodeOnCodecThread, this));
+ } else {
+ // Hard codec reset.
+ ret = InitDecode(&codec_, 1);
+ }
if (ret < 0) {
ALOGE << "InitDecode failure: " << ret << " - fallback to SW codec";
sw_fallback_required_ = true;

Powered by Google App Engine
This is Rietveld 408576698