Skip to content

Commit

Permalink
[android] Fix incorrect JNI call on MediaCodecBridge
Browse files Browse the repository at this point in the history
Fix incorrect JNI call on MediaCodecBridge start(). A new argument added in [PR 3672](#3672). However, the corresponding JNI call didn't change, which could cause native crash by player_worker.

b/366746149
b/320568573
b/364415911
  • Loading branch information
borongc committed Sep 14, 2024
1 parent 727a2b7 commit 38b4dd9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions starboard/android/shared/media_codec_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,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() {
Expand Down
2 changes: 1 addition & 1 deletion starboard/android/shared/media_codec_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions starboard/android/shared/media_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 38b4dd9

Please sign in to comment.