Skip to content

Commit

Permalink
Tests: Move codec configure() out of VideoDecodingWrapper constructor.
Browse files Browse the repository at this point in the history
This allows us to release both codecs used in SSIM when one fails to
configure() or start().

Tested and confirmed that on Samsung Galaxy Z Flip 4, running all
TransformationTest.java tests, tests after transform8k24() fails to start the
2nd codec:
* Before this CL, all fail.
* After this CL, all pass.

PiperOrigin-RevId: 490461560
  • Loading branch information
dway123 authored and icbaker committed Nov 24, 2022
1 parent 03f0b53 commit 0a176d1
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ private static final class VideoDecodingWrapper implements Closeable {
private static final String ASSET_FILE_SCHEME = "asset:///";
private static final int MAX_IMAGES_ALLOWED = 1;

private final MediaFormat mediaFormat;
private final MediaCodec mediaCodec;
private final MediaExtractor mediaExtractor;
private final MediaCodec.BufferInfo bufferInfo;
Expand All @@ -178,6 +179,7 @@ private static final class VideoDecodingWrapper implements Closeable {
private boolean hasReadEndOfInputStream;
private boolean queuedEndOfStreamToDecoder;
private boolean dequeuedAllDecodedFrames;
private boolean isCodecStarted;
private int dequeuedFramesCount;

/**
Expand Down Expand Up @@ -230,10 +232,8 @@ public VideoDecodingWrapper(Context context, String filePath, int comparisonInte

String sampleMimeType = checkNotNull(mediaFormat.getString(MediaFormat.KEY_MIME));
mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, MEDIA_CODEC_COLOR_SPACE);
this.mediaFormat = mediaFormat;
mediaCodec = MediaCodec.createDecoderByType(sampleMimeType);
mediaCodec.configure(
mediaFormat, imageReader.getSurface(), /* crypto= */ null, /* flags= */ 0);
mediaCodec.start();
}

/**
Expand All @@ -243,6 +243,12 @@ public VideoDecodingWrapper(Context context, String filePath, int comparisonInte
*/
@Nullable
public Image runUntilComparisonFrameOrEnded() throws InterruptedException {
if (!isCodecStarted) {
mediaCodec.configure(
mediaFormat, imageReader.getSurface(), /* crypto= */ null, /* flags= */ 0);
mediaCodec.start();
isCodecStarted = true;
}
while (!hasEnded() && !isCurrentFrameComparisonFrame) {
while (dequeueOneFrameFromDecoder()) {}
while (queueOneFrameToDecoder()) {}
Expand Down

0 comments on commit 0a176d1

Please sign in to comment.