Fix: make VFP test runner propagate the right exceptions
PiperOrigin-RevId: 608337651
This commit is contained in:
parent
d097fe11d0
commit
e6facd6a7e
@ -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<Bitmap, TimestampIterator>... frames) {
|
||||
public void queueInputBitmaps(int width, int height, Pair<Bitmap, TimestampIterator>... frames)
|
||||
throws VideoFrameProcessingException {
|
||||
queueInputBitmaps(width, height, ColorInfo.SRGB_BT709_FULL, frames);
|
||||
}
|
||||
|
||||
public void queueInputBitmaps(
|
||||
int width, int height, ColorInfo colorInfo, Pair<Bitmap, TimestampIterator>... frames) {
|
||||
int width, int height, ColorInfo colorInfo, Pair<Bitmap, TimestampIterator>... 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.
|
||||
*
|
||||
* <p>Waits for frame processing to end, for {@code videoFrameProcessingWaitTimeMs}.
|
||||
* <p>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);
|
||||
|
@ -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<Long> 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();
|
||||
}
|
||||
|
@ -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<Long> timestamps)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException, VideoFrameProcessingException {
|
||||
Bitmap bitmap = readBitmap(bitmapAssetPath);
|
||||
videoFrameProcessorTestRunner.queueInputBitmaps(
|
||||
bitmap.getWidth(),
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user