From 8a3efab14112fcbd7f981e6a079650900e1e0229 Mon Sep 17 00:00:00 2001 From: xiaomings Date: Mon, 24 Jun 2024 14:34:07 -0700 Subject: [PATCH] [android] Refine MediaCodec error message (#3638) The exception information is now included as part of the error message, which is forwarded to DOM and can be accessed via `HTMLMediaElement.error.message`. b/348438829 --- .../java/dev/cobalt/media/MediaCodecBridge.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridge.java b/starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridge.java index 6fa4e720b759..cbf1cbf068f7 100644 --- a/starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridge.java +++ b/starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridge.java @@ -752,10 +752,10 @@ public static void createVideoMediaCodecBridge( // outCreateMediaCodecBridgeResult.mErrorMessage is set inside configureVideo() on error. return; } - if (!bridge.start()) { + if (!bridge.start(outCreateMediaCodecBridgeResult)) { Log.e(TAG, "Failed to start video codec."); bridge.release(); - outCreateMediaCodecBridgeResult.mErrorMessage = "Failed to start video codec"; + // outCreateMediaCodecBridgeResult.mErrorMessage is set inside start() on error. return; } @@ -777,13 +777,21 @@ public void release() { mMediaCodec.set(null); } + public boolean start() { + return start(null); + } + @SuppressWarnings("unused") @UsedByNative - public boolean start() { + public boolean start(CreateMediaCodecBridgeResult outCreateMediaCodecBridgeResult) { try { mMediaCodec.get().start(); } catch (IllegalStateException | IllegalArgumentException e) { - Log.e(TAG, "Cannot start the media codec", e); + Log.e(TAG, "Failed to start the media codec", e); + if (outCreateMediaCodecBridgeResult != null) { + outCreateMediaCodecBridgeResult.mErrorMessage = + "Failed to start media codec " + e.toString(); + } return false; } return true;