From 070e8217ac7afe39f5c09dc474e586bd2d3e2814 Mon Sep 17 00:00:00 2001 From: kimvde Date: Wed, 28 Aug 2024 09:12:08 -0700 Subject: [PATCH] Report swallowed exceptions in ExternalTextureManager The error was swallowed if ExternalTextureManager.removeAllSurfaceTextureFrames was throwing. PiperOrigin-RevId: 668480565 --- .../media3/effect/ExternalTextureManager.java | 12 +++++++++++- .../effect/VideoFrameProcessingTaskExecutor.java | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libraries/effect/src/main/java/androidx/media3/effect/ExternalTextureManager.java b/libraries/effect/src/main/java/androidx/media3/effect/ExternalTextureManager.java index 05f8e57d90..3564a117e8 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/ExternalTextureManager.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/ExternalTextureManager.java @@ -110,6 +110,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; // a frame to arrive on the SurfaceTexture. private long firstTryToRemoveAllFramesTimeMs; + @Nullable private volatile RuntimeException releaseAllFramesException; + /** * Creates a new instance. The caller's thread must have a current GL context. * @@ -185,6 +187,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; Thread.currentThread().interrupt(); Log.w(TAG, "Interrupted when waiting for MediaCodec frames to arrive."); } + if (releaseAllFramesException != null) { + throw releaseAllFramesException; + } } /** @@ -350,7 +355,12 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; } private void releaseAllFramesFromMediaCodec(CountDownLatch latch) { - removeAllSurfaceTextureFrames(); + try { + removeAllSurfaceTextureFrames(); + } catch (RuntimeException e) { + releaseAllFramesException = e; + latch.countDown(); + } if (pendingFrames.isEmpty() // Assumes a frame that is registered would not take longer than SURFACE_TEXTURE_TIMEOUT_MS diff --git a/libraries/effect/src/main/java/androidx/media3/effect/VideoFrameProcessingTaskExecutor.java b/libraries/effect/src/main/java/androidx/media3/effect/VideoFrameProcessingTaskExecutor.java index b9e1ed2fd9..e5498cc85e 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/VideoFrameProcessingTaskExecutor.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/VideoFrameProcessingTaskExecutor.java @@ -284,8 +284,8 @@ import java.util.concurrent.TimeoutException; private void handleException(Exception exception) { synchronized (lock) { if (shouldCancelTasks) { - // Ignore exception after cancelation as it can be caused by a previously reported exception - // that is the reason for the cancelation. + // Ignore exception after cancellation as it can be caused by a previously reported + // exception that is the reason for the cancellation. return; } shouldCancelTasks = true;