Commit 0cb5c588 by huangdarwin Committed by christosts

HDR: Catch test util decoder support error.

Otherwise, a lack of HDR decoding support will result in the tests checking output files for HDR output, like HdrEditingTest.transform_noRequestedTranscode_hdr10File_transformsOrThrows, failing.

PiperOrigin-RevId: 510213020
parent 9ca1122b
......@@ -26,18 +26,29 @@ import com.google.android.exoplayer2.testutil.DecodeOneFrameUtil;
import com.google.android.exoplayer2.util.MediaFormatUtil;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.ColorInfo;
import java.io.IOException;
/** Utilities for reading color info from a file. */
public class FileUtil {
public static void assertFileHasColorTransfer(
@Nullable String filePath, @C.ColorTransfer int expectedColorTransfer) throws Exception {
/** Utilities for accessing details of media files. */
/* package */ class FileUtil {
/**
* Assert that the file has a certain color transfer, if supported on this device.
*
* <p>This will silently pass if under API 29, or if decoding this file is not supported on this
* device.
*
* @param filePath The path of the input file.
* @param expectedColorTransfer The expected {@link C.ColorTransfer} for the input file.
* @throws IOException If extractor or codec creation fails.
*/
public static void maybeAssertFileHasColorTransfer(
@Nullable String filePath, @C.ColorTransfer int expectedColorTransfer) throws IOException {
if (Util.SDK_INT < 29) {
// Skipping on this API version due to lack of support for MediaFormat#getInteger, which is
// required for MediaFormatUtil#getColorInfo.
return;
}
DecodeOneFrameUtil.decodeOneCacheFileFrame(
checkNotNull(filePath),
DecodeOneFrameUtil.Listener listener =
new DecodeOneFrameUtil.Listener() {
@Override
public void onContainerExtracted(MediaFormat mediaFormat) {
......@@ -50,8 +61,19 @@ public class FileUtil {
@Nullable ColorInfo decodedColorInfo = MediaFormatUtil.getColorInfo(mediaFormat);
assertColorInfoHasTransfer(decodedColorInfo, expectedColorTransfer);
}
},
/* surface= */ null);
};
try {
DecodeOneFrameUtil.decodeOneCacheFileFrame(
checkNotNull(filePath), listener, /* surface= */ null);
} catch (UnsupportedOperationException e) {
if (e.getMessage() != null
&& e.getMessage().equals(DecodeOneFrameUtil.NO_DECODER_SUPPORT_ERROR_STRING)) {
return;
} else {
throw e;
}
}
}
private static void assertColorInfoHasTransfer(
......
......@@ -19,7 +19,7 @@ import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSE
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_1080P_4_SECOND_HDR10_FORMAT;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT;
import static com.google.android.exoplayer2.transformer.mh.FileUtil.assertFileHasColorTransfer;
import static com.google.android.exoplayer2.transformer.mh.FileUtil.maybeAssertFileHasColorTransfer;
import android.content.Context;
import android.net.Uri;
......@@ -73,7 +73,7 @@ public class ForceInterpretHdrVideoAsSdrTest {
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, mediaItem);
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
Log.i(TAG, "Transformed.");
} catch (ExportException exception) {
if (exception.errorCode != ExportException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED) {
......@@ -109,7 +109,7 @@ public class ForceInterpretHdrVideoAsSdrTest {
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, mediaItem);
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
Log.i(TAG, "Transformed.");
} catch (ExportException exception) {
if (exception.errorCode != ExportException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED) {
......
......@@ -19,7 +19,7 @@ import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSE
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_1080P_4_SECOND_HDR10;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.recordTestSkipped;
import static com.google.android.exoplayer2.transformer.mh.FileUtil.assertFileHasColorTransfer;
import static com.google.android.exoplayer2.transformer.mh.FileUtil.maybeAssertFileHasColorTransfer;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.android.exoplayer2.util.MimeTypes.VIDEO_H265;
import static com.google.common.truth.Truth.assertThat;
......@@ -82,7 +82,7 @@ public class HdrEditingTest {
.build()
.run(testId, mediaItem);
Log.i(TAG, "Exported.");
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_ST2084);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_ST2084);
} catch (ExportException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString());
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
......@@ -107,7 +107,7 @@ public class HdrEditingTest {
.build()
.run(testId, mediaItem);
Log.i(TAG, "Exported.");
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_HLG);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_HLG);
} catch (ExportException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString());
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
......@@ -139,7 +139,7 @@ public class HdrEditingTest {
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, editedMediaItem);
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_ST2084);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_ST2084);
}
@Test
......@@ -163,7 +163,7 @@ public class HdrEditingTest {
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, editedMediaItem);
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_HLG);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_HLG);
}
@Test
......@@ -210,7 +210,7 @@ public class HdrEditingTest {
.run(testId, editedMediaItem);
Log.i(TAG, "Tone mapped.");
assertThat(isToneMappingFallbackApplied.get()).isTrue();
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString());
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
......@@ -264,7 +264,7 @@ public class HdrEditingTest {
.run(testId, editedMediaItem);
Log.i(TAG, "Tone mapped.");
assertThat(isToneMappingFallbackApplied.get()).isTrue();
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString());
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
......
......@@ -17,7 +17,7 @@ package com.google.android.exoplayer2.transformer.mh;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_1080P_4_SECOND_HDR10;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10;
import static com.google.android.exoplayer2.transformer.mh.FileUtil.assertFileHasColorTransfer;
import static com.google.android.exoplayer2.transformer.mh.FileUtil.maybeAssertFileHasColorTransfer;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.common.truth.Truth.assertThat;
......@@ -83,7 +83,7 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
.build()
.run(testId, mediaItem);
Log.i(TAG, "Tone mapped.");
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString());
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
......@@ -125,7 +125,7 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
.build()
.run(testId, mediaItem);
Log.i(TAG, "Tone mapped.");
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString());
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
......@@ -172,7 +172,7 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
.build()
.run(testId, editedMediaItem);
Log.i(TAG, "Tone mapped.");
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString());
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
......@@ -219,7 +219,7 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
.build()
.run(testId, editedMediaItem);
Log.i(TAG, "Tone mapped.");
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString());
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
......
......@@ -21,7 +21,7 @@ import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSE
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.recordTestSkipped;
import static com.google.android.exoplayer2.transformer.mh.FileUtil.assertFileHasColorTransfer;
import static com.google.android.exoplayer2.transformer.mh.FileUtil.maybeAssertFileHasColorTransfer;
import android.content.Context;
import android.net.Uri;
......@@ -90,7 +90,8 @@ public class ToneMapHdrToSdrUsingOpenGlTest {
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, mediaItem);
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
Log.i(TAG, "Tone mapped.");
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) {
Log.e(TAG, "Error during export.", exception);
if (exception.errorCode != ExportException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED) {
......@@ -140,7 +141,8 @@ public class ToneMapHdrToSdrUsingOpenGlTest {
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, mediaItem);
assertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
Log.i(TAG, "Tone mapped.");
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) {
Log.e(TAG, "Error during export.", exception);
if (exception.errorCode != ExportException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED) {
......
......@@ -34,6 +34,7 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.MediaFormatUtil;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.checkerframework.checker.nullness.qual.Nullable;
......@@ -65,9 +66,10 @@ public final class DecodeOneFrameUtil {
* @param listener A {@link Listener} implementation.
* @param surface The {@link Surface} to render the decoded frame to, {@code null} if the decoded
* frame is not needed.
* @throws IOException If extractor or codec creation fails.
*/
public static void decodeOneCacheFileFrame(
String cacheFilePath, Listener listener, @Nullable Surface surface) throws Exception {
String cacheFilePath, Listener listener, @Nullable Surface surface) throws IOException {
MediaExtractor mediaExtractor = new MediaExtractor();
try {
mediaExtractor.setDataSource(cacheFilePath);
......@@ -107,10 +109,12 @@ public final class DecodeOneFrameUtil {
* @param listener A {@link Listener} implementation.
* @param surface The {@link Surface} to render the decoded frame to, {@code null} if the decoded
* frame is not needed.
* @throws IOException If codec creation fails.
* @throws UnsupportedOperationException If no decoder supports this file's MediaFormat.
*/
private static void decodeOneFrame(
MediaExtractor mediaExtractor, Listener listener, @Nullable Surface surface)
throws Exception {
throws IOException {
// Set up the extractor to read the first video frame and get its format.
if (surface == null) {
// Creates a placeholder surface.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment