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))
|
mediaFormat.getInteger(MediaFormat.KEY_HEIGHT))
|
||||||
.setPixelWidthHeightRatio(pixelWidthHeightRatio)
|
.setPixelWidthHeightRatio(pixelWidthHeightRatio)
|
||||||
.build());
|
.build());
|
||||||
awaitVideoFrameProcessorReady();
|
try {
|
||||||
|
awaitVideoFrameProcessorReady();
|
||||||
|
} catch (VideoFrameProcessingException e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
checkState(videoFrameProcessor.registerInputFrame());
|
checkState(videoFrameProcessor.registerInputFrame());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,16 +357,13 @@ public final class VideoFrameProcessorTestRunner {
|
|||||||
|
|
||||||
public void queueInputBitmap(
|
public void queueInputBitmap(
|
||||||
Bitmap inputBitmap, long durationUs, long offsetToAddUs, float frameRate)
|
Bitmap inputBitmap, long durationUs, long offsetToAddUs, float frameRate)
|
||||||
throws InterruptedException {
|
throws VideoFrameProcessingException {
|
||||||
queueInputBitmap(inputBitmap, durationUs, offsetToAddUs, frameRate, ColorInfo.SRGB_BT709_FULL);
|
queueInputBitmap(inputBitmap, durationUs, offsetToAddUs, frameRate, ColorInfo.SRGB_BT709_FULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void queueInputBitmap(
|
public void queueInputBitmap(
|
||||||
Bitmap inputBitmap,
|
Bitmap inputBitmap, long durationUs, long offsetToAddUs, float frameRate, ColorInfo colorInfo)
|
||||||
long durationUs,
|
throws VideoFrameProcessingException {
|
||||||
long offsetToAddUs,
|
|
||||||
float frameRate,
|
|
||||||
ColorInfo colorInfo) {
|
|
||||||
videoFrameProcessorReadyCondition.close();
|
videoFrameProcessorReadyCondition.close();
|
||||||
videoFrameProcessor.registerInputStream(
|
videoFrameProcessor.registerInputStream(
|
||||||
INPUT_TYPE_BITMAP,
|
INPUT_TYPE_BITMAP,
|
||||||
@ -377,12 +378,14 @@ public final class VideoFrameProcessorTestRunner {
|
|||||||
inputBitmap, new ConstantRateTimestampIterator(durationUs, frameRate)));
|
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);
|
queueInputBitmaps(width, height, ColorInfo.SRGB_BT709_FULL, frames);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void queueInputBitmaps(
|
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();
|
videoFrameProcessorReadyCondition.close();
|
||||||
videoFrameProcessor.registerInputStream(
|
videoFrameProcessor.registerInputStream(
|
||||||
INPUT_TYPE_BITMAP,
|
INPUT_TYPE_BITMAP,
|
||||||
@ -397,7 +400,7 @@ public final class VideoFrameProcessorTestRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void queueInputTexture(GlTextureInfo inputTexture, long pts, ColorInfo colorInfo)
|
public void queueInputTexture(GlTextureInfo inputTexture, long pts, ColorInfo colorInfo)
|
||||||
throws InterruptedException {
|
throws VideoFrameProcessingException {
|
||||||
videoFrameProcessor.registerInputStream(
|
videoFrameProcessor.registerInputStream(
|
||||||
INPUT_TYPE_TEXTURE_ID,
|
INPUT_TYPE_TEXTURE_ID,
|
||||||
effects,
|
effects,
|
||||||
@ -418,18 +421,18 @@ public final class VideoFrameProcessorTestRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** {@link #endFrameProcessing(long)} with {@link #VIDEO_FRAME_PROCESSING_WAIT_MS} applied. */
|
/** {@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);
|
endFrameProcessing(VIDEO_FRAME_PROCESSING_WAIT_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ends {@link VideoFrameProcessor} frame processing.
|
* 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();
|
signalEndOfInput();
|
||||||
awaitFrameProcessingEnd(videoFrameProcessingWaitTimeMs);
|
awaitFrameProcessingEnd(videoFrameProcessingWaitMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -448,11 +451,11 @@ public final class VideoFrameProcessorTestRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** After {@link #signalEndOfInput}, is called, wait for this instance to end. */
|
/** 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;
|
@Nullable Exception endFrameProcessingException = null;
|
||||||
try {
|
try {
|
||||||
if (!checkNotNull(videoFrameProcessingEndedLatch)
|
if (!checkNotNull(videoFrameProcessingEndedLatch)
|
||||||
.await(videoFrameProcessingWaitTimeMs, MILLISECONDS)) {
|
.await(videoFrameProcessingWaitMs, MILLISECONDS)) {
|
||||||
endFrameProcessingException =
|
endFrameProcessingException =
|
||||||
new IllegalStateException("Video frame processing timed out.");
|
new IllegalStateException("Video frame processing timed out.");
|
||||||
}
|
}
|
||||||
@ -460,8 +463,12 @@ public final class VideoFrameProcessorTestRunner {
|
|||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
endFrameProcessingException = e;
|
endFrameProcessingException = e;
|
||||||
}
|
}
|
||||||
checkState(videoFrameProcessingException.get() == null);
|
if (videoFrameProcessingException.get() != null) {
|
||||||
checkState(endFrameProcessingException == 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 {
|
try {
|
||||||
videoFrameProcessorReadyCondition.block();
|
videoFrameProcessorReadyCondition.block();
|
||||||
checkState(videoFrameProcessingException.get() == null);
|
if (videoFrameProcessingException.get() != null) {
|
||||||
|
throw videoFrameProcessingException.get();
|
||||||
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
throw new IllegalStateException(e);
|
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
|
* Queues {@code durationSec} bitmaps, with one bitmap per second, starting from and including
|
||||||
* {@code 0} seconds. Sources have a {@code frameRate} of {@code 1}.
|
* {@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++) {
|
for (int i = 0; i < inputVideoFrameProcessorTestRunners.size(); i++) {
|
||||||
inputVideoFrameProcessorTestRunners
|
inputVideoFrameProcessorTestRunners
|
||||||
.get(i)
|
.get(i)
|
||||||
@ -790,7 +791,7 @@ public final class DefaultVideoCompositorPixelTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void queueBitmapToInput(int inputId, List<Long> timestamps)
|
public void queueBitmapToInput(int inputId, List<Long> timestamps)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, VideoFrameProcessingException {
|
||||||
Bitmap bitmap = readBitmapUnpremultipliedAlpha(ORIGINAL_PNG_ASSET_PATH);
|
Bitmap bitmap = readBitmapUnpremultipliedAlpha(ORIGINAL_PNG_ASSET_PATH);
|
||||||
inputVideoFrameProcessorTestRunners
|
inputVideoFrameProcessorTestRunners
|
||||||
.get(inputId)
|
.get(inputId)
|
||||||
@ -800,7 +801,7 @@ public final class DefaultVideoCompositorPixelTest {
|
|||||||
Pair.create(bitmap, createTimestampIterator(timestamps)));
|
Pair.create(bitmap, createTimestampIterator(timestamps)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endCompositing() {
|
public void endCompositing() throws Exception {
|
||||||
for (int i = 0; i < inputVideoFrameProcessorTestRunners.size(); i++) {
|
for (int i = 0; i < inputVideoFrameProcessorTestRunners.size(); i++) {
|
||||||
inputVideoFrameProcessorTestRunners.get(i).signalEndOfInput();
|
inputVideoFrameProcessorTestRunners.get(i).signalEndOfInput();
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
import androidx.media3.common.VideoFrameProcessingException;
|
||||||
import androidx.media3.common.VideoFrameProcessor;
|
import androidx.media3.common.VideoFrameProcessor;
|
||||||
import androidx.media3.effect.DefaultVideoFrameProcessor;
|
import androidx.media3.effect.DefaultVideoFrameProcessor;
|
||||||
import androidx.media3.test.utils.BitmapPixelTestUtil;
|
import androidx.media3.test.utils.BitmapPixelTestUtil;
|
||||||
@ -148,7 +149,7 @@ public class DefaultVideoFrameProcessorMultipleTextureOutputPixelTest {
|
|||||||
VideoFrameProcessorTestRunner videoFrameProcessorTestRunner,
|
VideoFrameProcessorTestRunner videoFrameProcessorTestRunner,
|
||||||
String bitmapAssetPath,
|
String bitmapAssetPath,
|
||||||
List<Long> timestamps)
|
List<Long> timestamps)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, VideoFrameProcessingException {
|
||||||
Bitmap bitmap = readBitmap(bitmapAssetPath);
|
Bitmap bitmap = readBitmap(bitmapAssetPath);
|
||||||
videoFrameProcessorTestRunner.queueInputBitmaps(
|
videoFrameProcessorTestRunner.queueInputBitmaps(
|
||||||
bitmap.getWidth(),
|
bitmap.getWidth(),
|
||||||
|
@ -493,7 +493,8 @@ public final class DefaultVideoFrameProcessorTextureOutputPixelTest {
|
|||||||
DefaultVideoFrameProcessor.Factory defaultVideoFrameProcessorFactory =
|
DefaultVideoFrameProcessor.Factory defaultVideoFrameProcessorFactory =
|
||||||
new DefaultVideoFrameProcessor.Factory.Builder()
|
new DefaultVideoFrameProcessor.Factory.Builder()
|
||||||
.setTextureOutput(
|
.setTextureOutput(
|
||||||
(outputTextureProducer, outputTexture, presentationTimeUs, syncObject) ->
|
(outputTextureProducer, outputTexture, presentationTimeUs, syncObject) -> {
|
||||||
|
try {
|
||||||
inputTextureIntoVideoFrameProcessor(
|
inputTextureIntoVideoFrameProcessor(
|
||||||
testId,
|
testId,
|
||||||
consumersBitmapReader,
|
consumersBitmapReader,
|
||||||
@ -502,7 +503,11 @@ public final class DefaultVideoFrameProcessorTextureOutputPixelTest {
|
|||||||
outputTexture,
|
outputTexture,
|
||||||
outputTextureProducer,
|
outputTextureProducer,
|
||||||
presentationTimeUs,
|
presentationTimeUs,
|
||||||
syncObject),
|
syncObject);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw VideoFrameProcessingException.from(e, presentationTimeUs);
|
||||||
|
}
|
||||||
|
},
|
||||||
/* textureOutputCapacity= */ 1)
|
/* textureOutputCapacity= */ 1)
|
||||||
.build();
|
.build();
|
||||||
return new VideoFrameProcessorTestRunner.Builder()
|
return new VideoFrameProcessorTestRunner.Builder()
|
||||||
@ -523,7 +528,7 @@ public final class DefaultVideoFrameProcessorTextureOutputPixelTest {
|
|||||||
GlTextureProducer textureProducer,
|
GlTextureProducer textureProducer,
|
||||||
long presentationTimeUs,
|
long presentationTimeUs,
|
||||||
long syncObject)
|
long syncObject)
|
||||||
throws VideoFrameProcessingException, GlUtil.GlException {
|
throws Exception {
|
||||||
GlObjectsProvider contextSharingGlObjectsProvider =
|
GlObjectsProvider contextSharingGlObjectsProvider =
|
||||||
new DefaultGlObjectsProvider(GlUtil.getCurrentContext());
|
new DefaultGlObjectsProvider(GlUtil.getCurrentContext());
|
||||||
DefaultVideoFrameProcessor.Factory defaultVideoFrameProcessorFactory =
|
DefaultVideoFrameProcessor.Factory defaultVideoFrameProcessorFactory =
|
||||||
@ -545,12 +550,7 @@ public final class DefaultVideoFrameProcessorTextureOutputPixelTest {
|
|||||||
.setEffects(effects)
|
.setEffects(effects)
|
||||||
.build();
|
.build();
|
||||||
GlUtil.awaitSyncObject(syncObject);
|
GlUtil.awaitSyncObject(syncObject);
|
||||||
try {
|
videoFrameProcessorTestRunner.queueInputTexture(texture, presentationTimeUs, colorInfo);
|
||||||
videoFrameProcessorTestRunner.queueInputTexture(texture, presentationTimeUs, colorInfo);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
throw VideoFrameProcessingException.from(e);
|
|
||||||
}
|
|
||||||
videoFrameProcessorTestRunner.endFrameProcessing(VIDEO_FRAME_PROCESSING_WAIT_MS / 2);
|
videoFrameProcessorTestRunner.endFrameProcessing(VIDEO_FRAME_PROCESSING_WAIT_MS / 2);
|
||||||
textureProducer.releaseOutputTexture(presentationTimeUs);
|
textureProducer.releaseOutputTexture(presentationTimeUs);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user