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 1eed355dcd..d28207d260 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 @@ -312,6 +312,7 @@ public final class VideoFrameProcessorTestRunner { public void onError(VideoFrameProcessingException exception) { videoFrameProcessingException.set(exception); checkNotNull(videoFrameProcessingEndedLatch).countDown(); + videoFrameProcessorReadyCondition.open(); } @Override @@ -340,12 +341,7 @@ public final class VideoFrameProcessorTestRunner { mediaFormat.getInteger(MediaFormat.KEY_HEIGHT)) .setPixelWidthHeightRatio(pixelWidthHeightRatio) .build()); - try { - videoFrameProcessorReadyCondition.block(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new IllegalStateException(e); - } + awaitVideoFrameProcessorReady(); checkState(videoFrameProcessor.registerInputFrame()); } @@ -365,8 +361,11 @@ public final class VideoFrameProcessorTestRunner { } public void queueInputBitmap( - Bitmap inputBitmap, long durationUs, long offsetToAddUs, float frameRate, ColorInfo colorInfo) - throws InterruptedException { + Bitmap inputBitmap, + long durationUs, + long offsetToAddUs, + float frameRate, + ColorInfo colorInfo) { videoFrameProcessorReadyCondition.close(); videoFrameProcessor.registerInputStream( INPUT_TYPE_BITMAP, @@ -375,20 +374,18 @@ public final class VideoFrameProcessorTestRunner { .setPixelWidthHeightRatio(pixelWidthHeightRatio) .setOffsetToAddUs(offsetToAddUs) .build()); - videoFrameProcessorReadyCondition.block(); + awaitVideoFrameProcessorReady(); checkState( videoFrameProcessor.queueInputBitmap( inputBitmap, new ConstantRateTimestampIterator(durationUs, frameRate))); } - public void queueInputBitmaps(int width, int height, Pair... frames) - throws InterruptedException { + public void queueInputBitmaps(int width, int height, Pair... frames) { queueInputBitmaps(width, height, ColorInfo.SRGB_BT709_FULL, frames); } public void queueInputBitmaps( - int width, int height, ColorInfo colorInfo, Pair... frames) - throws InterruptedException { + int width, int height, ColorInfo colorInfo, Pair... frames) { videoFrameProcessorReadyCondition.close(); videoFrameProcessor.registerInputStream( INPUT_TYPE_BITMAP, @@ -396,7 +393,7 @@ public final class VideoFrameProcessorTestRunner { new FrameInfo.Builder(colorInfo, width, height) .setPixelWidthHeightRatio(pixelWidthHeightRatio) .build()); - videoFrameProcessorReadyCondition.block(); + awaitVideoFrameProcessorReady(); for (Pair frame : frames) { videoFrameProcessor.queueInputBitmap(frame.first, frame.second); } @@ -419,7 +416,7 @@ public final class VideoFrameProcessorTestRunner { throw new VideoFrameProcessingException(e); } }); - videoFrameProcessorReadyCondition.block(); + awaitVideoFrameProcessorReady(); checkState(videoFrameProcessor.queueInputTexture(inputTexture.texId, pts)); } @@ -557,4 +554,14 @@ public final class VideoFrameProcessorTestRunner { } }; } + + private void awaitVideoFrameProcessorReady() { + try { + videoFrameProcessorReadyCondition.block(); + assertThat(videoFrameProcessingException.get()).isNull(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new IllegalStateException(e); + } + } }