diff --git a/libraries/test_utils/src/main/java/androidx/media3/test/utils/VideoFrameProcessorTestRunner.java b/libraries/test_utils/src/main/java/androidx/media3/test/utils/VideoFrameProcessorTestRunner.java index 5481badb4b..c71a8e1477 100644 --- a/libraries/test_utils/src/main/java/androidx/media3/test/utils/VideoFrameProcessorTestRunner.java +++ b/libraries/test_utils/src/main/java/androidx/media3/test/utils/VideoFrameProcessorTestRunner.java @@ -338,7 +338,11 @@ public final class VideoFrameProcessorTestRunner { mediaFormat.getInteger(MediaFormat.KEY_HEIGHT)) .setPixelWidthHeightRatio(pixelWidthHeightRatio) .build()); - awaitVideoFrameProcessorReady(); + try { + awaitVideoFrameProcessorReady(); + } catch (VideoFrameProcessingException e) { + throw new IllegalStateException(e); + } checkState(videoFrameProcessor.registerInputFrame()); } @@ -353,16 +357,13 @@ public final class VideoFrameProcessorTestRunner { public void queueInputBitmap( Bitmap inputBitmap, long durationUs, long offsetToAddUs, float frameRate) - throws InterruptedException { + throws VideoFrameProcessingException { queueInputBitmap(inputBitmap, durationUs, offsetToAddUs, frameRate, ColorInfo.SRGB_BT709_FULL); } public void queueInputBitmap( - Bitmap inputBitmap, - long durationUs, - long offsetToAddUs, - float frameRate, - ColorInfo colorInfo) { + Bitmap inputBitmap, long durationUs, long offsetToAddUs, float frameRate, ColorInfo colorInfo) + throws VideoFrameProcessingException { videoFrameProcessorReadyCondition.close(); videoFrameProcessor.registerInputStream( INPUT_TYPE_BITMAP, @@ -377,12 +378,14 @@ public final class VideoFrameProcessorTestRunner { inputBitmap, new ConstantRateTimestampIterator(durationUs, frameRate))); } - public void queueInputBitmaps(int width, int height, Pair... frames) { + public void queueInputBitmaps(int width, int height, Pair... frames) + throws VideoFrameProcessingException { queueInputBitmaps(width, height, ColorInfo.SRGB_BT709_FULL, frames); } public void queueInputBitmaps( - int width, int height, ColorInfo colorInfo, Pair... frames) { + int width, int height, ColorInfo colorInfo, Pair... frames) + throws VideoFrameProcessingException { videoFrameProcessorReadyCondition.close(); videoFrameProcessor.registerInputStream( INPUT_TYPE_BITMAP, @@ -397,7 +400,7 @@ public final class VideoFrameProcessorTestRunner { } public void queueInputTexture(GlTextureInfo inputTexture, long pts, ColorInfo colorInfo) - throws InterruptedException { + throws VideoFrameProcessingException { videoFrameProcessor.registerInputStream( INPUT_TYPE_TEXTURE_ID, effects, @@ -418,18 +421,18 @@ public final class VideoFrameProcessorTestRunner { } /** {@link #endFrameProcessing(long)} with {@link #VIDEO_FRAME_PROCESSING_WAIT_MS} applied. */ - public void endFrameProcessing() { + public void endFrameProcessing() throws Exception { endFrameProcessing(VIDEO_FRAME_PROCESSING_WAIT_MS); } /** * Ends {@link VideoFrameProcessor} frame processing. * - *

Waits for frame processing to end, for {@code videoFrameProcessingWaitTimeMs}. + *

Waits for frame processing to end, for {@code videoFrameProcessingWaitMs}. */ - public void endFrameProcessing(long videoFrameProcessingWaitTimeMs) { + public void endFrameProcessing(long videoFrameProcessingWaitMs) throws Exception { signalEndOfInput(); - awaitFrameProcessingEnd(videoFrameProcessingWaitTimeMs); + awaitFrameProcessingEnd(videoFrameProcessingWaitMs); } /** @@ -448,11 +451,11 @@ public final class VideoFrameProcessorTestRunner { } /** After {@link #signalEndOfInput}, is called, wait for this instance to end. */ - public void awaitFrameProcessingEnd(long videoFrameProcessingWaitTimeMs) { + public void awaitFrameProcessingEnd(long videoFrameProcessingWaitMs) throws Exception { @Nullable Exception endFrameProcessingException = null; try { if (!checkNotNull(videoFrameProcessingEndedLatch) - .await(videoFrameProcessingWaitTimeMs, MILLISECONDS)) { + .await(videoFrameProcessingWaitMs, MILLISECONDS)) { endFrameProcessingException = new IllegalStateException("Video frame processing timed out."); } @@ -460,8 +463,12 @@ public final class VideoFrameProcessorTestRunner { Thread.currentThread().interrupt(); endFrameProcessingException = e; } - checkState(videoFrameProcessingException.get() == null); - checkState(endFrameProcessingException == null); + if (videoFrameProcessingException.get() != null) { + throw videoFrameProcessingException.get(); + } + if (endFrameProcessingException != null) { + throw endFrameProcessingException; + } } /** @@ -552,10 +559,12 @@ public final class VideoFrameProcessorTestRunner { }; } - private void awaitVideoFrameProcessorReady() { + private void awaitVideoFrameProcessorReady() throws VideoFrameProcessingException { try { videoFrameProcessorReadyCondition.block(); - checkState(videoFrameProcessingException.get() == null); + if (videoFrameProcessingException.get() != null) { + throw videoFrameProcessingException.get(); + } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException(e); diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/DefaultVideoCompositorPixelTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/DefaultVideoCompositorPixelTest.java index 6d3c8e2815..66d343a37f 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/DefaultVideoCompositorPixelTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/DefaultVideoCompositorPixelTest.java @@ -777,7 +777,8 @@ public final class DefaultVideoCompositorPixelTest { * Queues {@code durationSec} bitmaps, with one bitmap per second, starting from and including * {@code 0} seconds. Sources have a {@code frameRate} of {@code 1}. */ - public void queueBitmapToAllInputs(int durationSec) throws IOException, InterruptedException { + public void queueBitmapToAllInputs(int durationSec) + throws IOException, VideoFrameProcessingException { for (int i = 0; i < inputVideoFrameProcessorTestRunners.size(); i++) { inputVideoFrameProcessorTestRunners .get(i) @@ -790,7 +791,7 @@ public final class DefaultVideoCompositorPixelTest { } public void queueBitmapToInput(int inputId, List timestamps) - throws IOException, InterruptedException { + throws IOException, VideoFrameProcessingException { Bitmap bitmap = readBitmapUnpremultipliedAlpha(ORIGINAL_PNG_ASSET_PATH); inputVideoFrameProcessorTestRunners .get(inputId) @@ -800,7 +801,7 @@ public final class DefaultVideoCompositorPixelTest { Pair.create(bitmap, createTimestampIterator(timestamps))); } - public void endCompositing() { + public void endCompositing() throws Exception { for (int i = 0; i < inputVideoFrameProcessorTestRunners.size(); i++) { inputVideoFrameProcessorTestRunners.get(i).signalEndOfInput(); } diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/DefaultVideoFrameProcessorMultipleTextureOutputPixelTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/DefaultVideoFrameProcessorMultipleTextureOutputPixelTest.java index 587d5a37d1..2922552921 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/DefaultVideoFrameProcessorMultipleTextureOutputPixelTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/DefaultVideoFrameProcessorMultipleTextureOutputPixelTest.java @@ -24,6 +24,7 @@ import static com.google.common.truth.Truth.assertThat; import android.graphics.Bitmap; import android.util.Pair; +import androidx.media3.common.VideoFrameProcessingException; import androidx.media3.common.VideoFrameProcessor; import androidx.media3.effect.DefaultVideoFrameProcessor; import androidx.media3.test.utils.BitmapPixelTestUtil; @@ -148,7 +149,7 @@ public class DefaultVideoFrameProcessorMultipleTextureOutputPixelTest { VideoFrameProcessorTestRunner videoFrameProcessorTestRunner, String bitmapAssetPath, List timestamps) - throws IOException, InterruptedException { + throws IOException, VideoFrameProcessingException { Bitmap bitmap = readBitmap(bitmapAssetPath); videoFrameProcessorTestRunner.queueInputBitmaps( bitmap.getWidth(), diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/DefaultVideoFrameProcessorTextureOutputPixelTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/DefaultVideoFrameProcessorTextureOutputPixelTest.java index ca67775293..eec640ab4d 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/DefaultVideoFrameProcessorTextureOutputPixelTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/DefaultVideoFrameProcessorTextureOutputPixelTest.java @@ -493,7 +493,8 @@ public final class DefaultVideoFrameProcessorTextureOutputPixelTest { DefaultVideoFrameProcessor.Factory defaultVideoFrameProcessorFactory = new DefaultVideoFrameProcessor.Factory.Builder() .setTextureOutput( - (outputTextureProducer, outputTexture, presentationTimeUs, syncObject) -> + (outputTextureProducer, outputTexture, presentationTimeUs, syncObject) -> { + try { inputTextureIntoVideoFrameProcessor( testId, consumersBitmapReader, @@ -502,7 +503,11 @@ public final class DefaultVideoFrameProcessorTextureOutputPixelTest { outputTexture, outputTextureProducer, presentationTimeUs, - syncObject), + syncObject); + } catch (Exception e) { + throw VideoFrameProcessingException.from(e, presentationTimeUs); + } + }, /* textureOutputCapacity= */ 1) .build(); return new VideoFrameProcessorTestRunner.Builder() @@ -523,7 +528,7 @@ public final class DefaultVideoFrameProcessorTextureOutputPixelTest { GlTextureProducer textureProducer, long presentationTimeUs, long syncObject) - throws VideoFrameProcessingException, GlUtil.GlException { + throws Exception { GlObjectsProvider contextSharingGlObjectsProvider = new DefaultGlObjectsProvider(GlUtil.getCurrentContext()); DefaultVideoFrameProcessor.Factory defaultVideoFrameProcessorFactory = @@ -545,12 +550,7 @@ public final class DefaultVideoFrameProcessorTextureOutputPixelTest { .setEffects(effects) .build(); GlUtil.awaitSyncObject(syncObject); - try { - videoFrameProcessorTestRunner.queueInputTexture(texture, presentationTimeUs, colorInfo); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw VideoFrameProcessingException.from(e); - } + videoFrameProcessorTestRunner.queueInputTexture(texture, presentationTimeUs, colorInfo); videoFrameProcessorTestRunner.endFrameProcessing(VIDEO_FRAME_PROCESSING_WAIT_MS / 2); textureProducer.releaseOutputTexture(presentationTimeUs); }