From 197deab14510917bfef902d7d5673f3074cc28d5 Mon Sep 17 00:00:00 2001 From: Bo-Rong Chen Date: Mon, 7 Oct 2024 11:22:56 -0700 Subject: [PATCH] [android] Fix incorrect JNI call on MediaCodecBridge This is the same PR as https://github.com/youtube/cobalt/pull/4112. Original commit message: Fix incorrect JNI call on MediaCodecBridge start(). A new argument CreateMediaCodecBridgeResult was added in [PR 3672](https://github.com/youtube/cobalt/pull/3672). However, the corresponding JNI call didn't change, which could cause native crash by player_worker. b/366746149 b/320568573 b/364415911 --- .../src/main/java/dev/cobalt/media/MediaCodecBridge.java | 6 ++++++ starboard/android/shared/media_codec_bridge.cc | 6 +++--- starboard/android/shared/media_codec_bridge.h | 2 +- starboard/android/shared/media_decoder.cc | 6 +++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cobalt/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridge.java b/cobalt/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridge.java index e36f1f90c239..21bea46a6c65 100644 --- a/cobalt/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridge.java +++ b/cobalt/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridge.java @@ -769,6 +769,12 @@ public boolean start() { @SuppressWarnings("unused") @UsedByNative + private boolean restart() { + // Restart MediaCodec after flush(). + return start(null); + } + + @SuppressWarnings("unused") public boolean start(CreateMediaCodecBridgeResult outCreateMediaCodecBridgeResult) { try { mMediaCodec.get().start(); diff --git a/starboard/android/shared/media_codec_bridge.cc b/starboard/android/shared/media_codec_bridge.cc index 483d824f800d..04cc1be84782 100644 --- a/starboard/android/shared/media_codec_bridge.cc +++ b/starboard/android/shared/media_codec_bridge.cc @@ -495,9 +495,9 @@ void MediaCodecBridge::SetPlaybackRate(double playback_rate) { j_media_codec_bridge_, "setPlaybackRate", "(D)V", playback_rate); } -bool MediaCodecBridge::Start() { - return JniEnvExt::Get()->CallBooleanMethodOrAbort(j_media_codec_bridge_, - "start", "()Z") == JNI_TRUE; +bool MediaCodecBridge::Restart() { + return JniEnvExt::Get()->CallBooleanMethodOrAbort( + j_media_codec_bridge_, "restart", "()Z") == JNI_TRUE; } jint MediaCodecBridge::Flush() { diff --git a/starboard/android/shared/media_codec_bridge.h b/starboard/android/shared/media_codec_bridge.h index 3c41af888a8a..888d2c7ccebd 100644 --- a/starboard/android/shared/media_codec_bridge.h +++ b/starboard/android/shared/media_codec_bridge.h @@ -200,7 +200,7 @@ class MediaCodecBridge { void ReleaseOutputBufferAtTimestamp(jint index, jlong render_timestamp_ns); void SetPlaybackRate(double playback_rate); - bool Start(); + bool Restart(); jint Flush(); FrameSize GetOutputSize(); AudioOutputFormatResult GetAudioOutputFormat(); diff --git a/starboard/android/shared/media_decoder.cc b/starboard/android/shared/media_decoder.cc index e1ea3dc1bd87..65345ec4f489 100644 --- a/starboard/android/shared/media_decoder.cc +++ b/starboard/android/shared/media_decoder.cc @@ -702,11 +702,11 @@ bool MediaDecoder::Flush() { dequeue_output_result.index = -1; dequeue_output_results_.push_back(dequeue_output_result); - // 2.4. Start() |media_codec_bridge_|. As the codec is configured in + // 2.4. Restart() |media_codec_bridge_|. As the codec is configured in // asynchronous mode, call Start() after Flush() has returned to - // resume codec operations. After Start(), input_buffer_index should + // resume codec operations. After Restart(), input_buffer_index should // start with 0. - if (!media_codec_bridge_->Start()) { + if (!media_codec_bridge_->Restart()) { SB_LOG(ERROR) << "Failed to start media codec."; return false; }