Commit a9bc111d by andrewlewis Committed by Tofunmi Adigun-Hameed

Tidy color info checking tests

ExoPlayer extractors (backing `MetadataRetriever`) now parse the color format
from the bitstream so using `MetadataRetriever` should be an equivalent but
more lightweight way to verify the color info.

Also remove try/catch blocks in test code calling into these methods, and add
skipping based on decoder capabilities in the cases where it was missing.

PiperOrigin-RevId: 537789483
(cherry picked from commit 88db01116afa54e52f8516533256d447de45e8a4)
parent 2536efcf
...@@ -16,70 +16,57 @@ ...@@ -16,70 +16,57 @@
package com.google.android.exoplayer2.transformer.mh; package com.google.android.exoplayer2.transformer.mh;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import android.media.MediaFormat; import android.content.Context;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.testutil.DecodeOneFrameUtil; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.MediaFormatUtil; import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.MetadataRetriever;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.video.ColorInfo; import com.google.android.exoplayer2.video.ColorInfo;
import java.io.IOException; import java.util.concurrent.ExecutionException;
/** Utilities for accessing details of media files. */ /** Utilities for accessing details of media files. */
/* package */ class FileUtil { /* package */ class FileUtil {
/** /**
* Assert that the file has a certain color transfer, if supported on this device. * Asserts that the file has a certain color transfer.
*
* <p>This will silently pass if under API 24, or if decoding this file is not supported on this
* device.
* *
* @param context The current context.
* @param filePath The path of the input file. * @param filePath The path of the input file.
* @param expectedColorTransfer The expected {@link C.ColorTransfer} for 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( public static void assertFileHasColorTransfer(
@Nullable String filePath, @C.ColorTransfer int expectedColorTransfer) throws IOException { Context context, @Nullable String filePath, @C.ColorTransfer int expectedColorTransfer) {
if (Util.SDK_INT < 24) { TrackGroupArray trackGroupArray;
// MediaFormat#KEY_COLOR_TRANSFER unsupported before API 24. try {
return; trackGroupArray =
MetadataRetriever.retrieveMetadata(context, MediaItem.fromUri("file://" + filePath))
.get();
} catch (ExecutionException | InterruptedException e) {
throw new IllegalStateException(e);
} }
DecodeOneFrameUtil.Listener listener =
new DecodeOneFrameUtil.Listener() {
@Override
public void onContainerExtracted(MediaFormat mediaFormat) {
@Nullable ColorInfo extractedColorInfo = MediaFormatUtil.getColorInfo(mediaFormat);
assertColorInfoHasTransfer(extractedColorInfo, expectedColorTransfer);
}
@Override
public void onFrameDecoded(MediaFormat mediaFormat) {
@Nullable ColorInfo decodedColorInfo = MediaFormatUtil.getColorInfo(mediaFormat);
assertColorInfoHasTransfer(decodedColorInfo, expectedColorTransfer);
}
};
try { int trackGroupCount = trackGroupArray.length;
DecodeOneFrameUtil.decodeOneCacheFileFrame( assertThat(trackGroupCount).isEqualTo(2);
checkNotNull(filePath), listener, /* surface= */ null); for (int i = 0; i < trackGroupCount; i++) {
} catch (UnsupportedOperationException e) { TrackGroup trackGroup = trackGroupArray.get(i);
if (e.getMessage() != null if (trackGroup.type == C.TRACK_TYPE_VIDEO) {
&& e.getMessage().equals(DecodeOneFrameUtil.NO_DECODER_SUPPORT_ERROR_STRING)) { assertThat(trackGroup.length).isEqualTo(1);
@Nullable ColorInfo colorInfo = trackGroup.getFormat(0).colorInfo;
@C.ColorTransfer
int actualColorTransfer =
colorInfo == null || colorInfo.colorTransfer == Format.NO_VALUE
? C.COLOR_TRANSFER_SDR
: colorInfo.colorTransfer;
assertThat(actualColorTransfer).isEqualTo(expectedColorTransfer);
return; return;
} else {
throw e;
} }
} }
} throw new IllegalStateException("Couldn't find video track");
private static void assertColorInfoHasTransfer(
@Nullable ColorInfo colorInfo, @C.ColorTransfer int expectedColorTransfer) {
@C.ColorTransfer
int actualColorTransfer = colorInfo == null ? C.COLOR_TRANSFER_SDR : colorInfo.colorTransfer;
assertThat(actualColorTransfer).isEqualTo(expectedColorTransfer);
} }
private FileUtil() {} private FileUtil() {}
......
...@@ -21,7 +21,7 @@ import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSE ...@@ -21,7 +21,7 @@ import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSE
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_720P_4_SECOND_HDR10_FORMAT; import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_720P_4_SECOND_HDR10_FORMAT;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.recordTestSkipped; import static com.google.android.exoplayer2.transformer.AndroidTestUtil.recordTestSkipped;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.skipAndLogIfFormatsUnsupported; import static com.google.android.exoplayer2.transformer.AndroidTestUtil.skipAndLogIfFormatsUnsupported;
import static com.google.android.exoplayer2.transformer.mh.FileUtil.maybeAssertFileHasColorTransfer; import static com.google.android.exoplayer2.transformer.mh.FileUtil.assertFileHasColorTransfer;
import static com.google.android.exoplayer2.util.Util.SDK_INT; import static com.google.android.exoplayer2.util.Util.SDK_INT;
import android.content.Context; import android.content.Context;
...@@ -46,7 +46,6 @@ import org.junit.runner.RunWith; ...@@ -46,7 +46,6 @@ import org.junit.runner.RunWith;
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class ForceInterpretHdrVideoAsSdrTest { public class ForceInterpretHdrVideoAsSdrTest {
public static final String TAG = "ForceInterpretHdrVideoAsSdrTest";
@Test @Test
public void forceInterpretHdrVideoAsSdrTest_hdr10File_transformsOrThrows() throws Exception { public void forceInterpretHdrVideoAsSdrTest_hdr10File_transformsOrThrows() throws Exception {
...@@ -85,7 +84,7 @@ public class ForceInterpretHdrVideoAsSdrTest { ...@@ -85,7 +84,7 @@ public class ForceInterpretHdrVideoAsSdrTest {
.build() .build()
.run(testId, mediaItem); .run(testId, mediaItem);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR); assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
} }
@Test @Test
...@@ -125,6 +124,6 @@ public class ForceInterpretHdrVideoAsSdrTest { ...@@ -125,6 +124,6 @@ public class ForceInterpretHdrVideoAsSdrTest {
.build() .build()
.run(testId, mediaItem); .run(testId, mediaItem);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR); assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
} }
} }
...@@ -17,9 +17,10 @@ package com.google.android.exoplayer2.transformer.mh; ...@@ -17,9 +17,10 @@ package com.google.android.exoplayer2.transformer.mh;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.FORCE_TRANSCODE_VIDEO_EFFECTS; import static com.google.android.exoplayer2.transformer.AndroidTestUtil.FORCE_TRANSCODE_VIDEO_EFFECTS;
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;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_720P_4_SECOND_HDR10; import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_720P_4_SECOND_HDR10;
import static com.google.android.exoplayer2.transformer.mh.FileUtil.maybeAssertFileHasColorTransfer; import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_720P_4_SECOND_HDR10_FORMAT;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull; import static com.google.android.exoplayer2.transformer.mh.FileUtil.assertFileHasColorTransfer;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import android.content.Context; import android.content.Context;
...@@ -28,13 +29,15 @@ import androidx.test.core.app.ApplicationProvider; ...@@ -28,13 +29,15 @@ import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.transformer.AndroidTestUtil;
import com.google.android.exoplayer2.transformer.EditedMediaItem; import com.google.android.exoplayer2.transformer.EditedMediaItem;
import com.google.android.exoplayer2.transformer.ExportException; import com.google.android.exoplayer2.transformer.ExportException;
import com.google.android.exoplayer2.transformer.ExportTestResult; import com.google.android.exoplayer2.transformer.ExportTestResult;
import com.google.android.exoplayer2.transformer.TransformationRequest; import com.google.android.exoplayer2.transformer.TransformationRequest;
import com.google.android.exoplayer2.transformer.Transformer; import com.google.android.exoplayer2.transformer.Transformer;
import com.google.android.exoplayer2.transformer.TransformerAndroidTestRunner; import com.google.android.exoplayer2.transformer.TransformerAndroidTestRunner;
import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.video.ColorInfo;
import java.util.Objects;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -45,13 +48,23 @@ import org.junit.runner.RunWith; ...@@ -45,13 +48,23 @@ import org.junit.runner.RunWith;
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class ToneMapHdrToSdrUsingMediaCodecTest { public class ToneMapHdrToSdrUsingMediaCodecTest {
public static final String TAG = "ToneMapHdrToSdrUsingMediaCodecTest";
@Test @Test
public void export_toneMapNoRequestedTranscode_hdr10File_toneMapsOrThrows() throws Exception { public void export_toneMapNoRequestedTranscode_hdr10File_toneMapsOrThrows() throws Exception {
String testId = "export_toneMapNoRequestedTranscode_hdr10File_toneMapsOrThrows"; String testId = "export_toneMapNoRequestedTranscode_hdr10File_toneMapsOrThrows";
Context context = ApplicationProvider.getApplicationContext(); Context context = ApplicationProvider.getApplicationContext();
if (AndroidTestUtil.skipAndLogIfFormatsUnsupported(
context,
testId,
/* inputFormat= */ MP4_ASSET_720P_4_SECOND_HDR10_FORMAT,
/* outputFormat= */ MP4_ASSET_720P_4_SECOND_HDR10_FORMAT
.buildUpon()
.setColorInfo(ColorInfo.SDR_BT709_LIMITED)
.build())) {
return;
}
Transformer transformer = Transformer transformer =
new Transformer.Builder(context) new Transformer.Builder(context)
.setTransformationRequest( .setTransformationRequest(
...@@ -79,13 +92,19 @@ public class ToneMapHdrToSdrUsingMediaCodecTest { ...@@ -79,13 +92,19 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.build() .build()
.run(testId, mediaItem); .run(testId, mediaItem);
Log.i(TAG, "Tone mapped."); assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) { } catch (ExportException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString()); if (exception.getCause() != null
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class); && (Objects.equals(
assertThat(exception.errorCode) exception.getCause().getMessage(),
.isEqualTo(ExportException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED); "Tone-mapping HDR is not supported on this device.")
|| Objects.equals(
exception.getCause().getMessage(),
"Tone-mapping requested but not supported by the decoder."))) {
// Expected on devices without a tone-mapping plugin for this codec.
return;
}
throw exception;
} }
} }
...@@ -94,6 +113,17 @@ public class ToneMapHdrToSdrUsingMediaCodecTest { ...@@ -94,6 +113,17 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
String testId = "export_toneMapNoRequestedTranscode_hlg10File_toneMapsOrThrows"; String testId = "export_toneMapNoRequestedTranscode_hlg10File_toneMapsOrThrows";
Context context = ApplicationProvider.getApplicationContext(); Context context = ApplicationProvider.getApplicationContext();
if (AndroidTestUtil.skipAndLogIfFormatsUnsupported(
context,
testId,
/* inputFormat= */ MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT,
/* outputFormat= */ MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT
.buildUpon()
.setColorInfo(ColorInfo.SDR_BT709_LIMITED)
.build())) {
return;
}
Transformer transformer = Transformer transformer =
new Transformer.Builder(context) new Transformer.Builder(context)
.setTransformationRequest( .setTransformationRequest(
...@@ -121,13 +151,19 @@ public class ToneMapHdrToSdrUsingMediaCodecTest { ...@@ -121,13 +151,19 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.build() .build()
.run(testId, mediaItem); .run(testId, mediaItem);
Log.i(TAG, "Tone mapped."); assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) { } catch (ExportException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString()); if (exception.getCause() != null
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class); && (Objects.equals(
assertThat(exception.errorCode) exception.getCause().getMessage(),
.isEqualTo(ExportException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED); "Tone-mapping HDR is not supported on this device.")
|| Objects.equals(
exception.getCause().getMessage(),
"Tone-mapping requested but not supported by the decoder."))) {
// Expected on devices without a tone-mapping plugin for this codec.
return;
}
throw exception;
} }
} }
...@@ -136,6 +172,17 @@ public class ToneMapHdrToSdrUsingMediaCodecTest { ...@@ -136,6 +172,17 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
String testId = "export_toneMapAndTranscode_hdr10File_toneMapsOrThrows"; String testId = "export_toneMapAndTranscode_hdr10File_toneMapsOrThrows";
Context context = ApplicationProvider.getApplicationContext(); Context context = ApplicationProvider.getApplicationContext();
if (AndroidTestUtil.skipAndLogIfFormatsUnsupported(
context,
testId,
/* inputFormat= */ MP4_ASSET_720P_4_SECOND_HDR10_FORMAT,
/* outputFormat= */ MP4_ASSET_720P_4_SECOND_HDR10_FORMAT
.buildUpon()
.setColorInfo(ColorInfo.SDR_BT709_LIMITED)
.build())) {
return;
}
Transformer transformer = Transformer transformer =
new Transformer.Builder(context) new Transformer.Builder(context)
.setTransformationRequest( .setTransformationRequest(
...@@ -165,13 +212,19 @@ public class ToneMapHdrToSdrUsingMediaCodecTest { ...@@ -165,13 +212,19 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.build() .build()
.run(testId, editedMediaItem); .run(testId, editedMediaItem);
Log.i(TAG, "Tone mapped."); assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) { } catch (ExportException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString()); if (exception.getCause() != null
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class); && (Objects.equals(
assertThat(exception.errorCode) exception.getCause().getMessage(),
.isEqualTo(ExportException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED); "Tone-mapping HDR is not supported on this device.")
|| Objects.equals(
exception.getCause().getMessage(),
"Tone-mapping requested but not supported by the decoder."))) {
// Expected on devices without a tone-mapping plugin for this codec.
return;
}
throw exception;
} }
} }
...@@ -180,6 +233,17 @@ public class ToneMapHdrToSdrUsingMediaCodecTest { ...@@ -180,6 +233,17 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
String testId = "export_toneMapAndTranscode_hlg10File_toneMapsOrThrows"; String testId = "export_toneMapAndTranscode_hlg10File_toneMapsOrThrows";
Context context = ApplicationProvider.getApplicationContext(); Context context = ApplicationProvider.getApplicationContext();
if (AndroidTestUtil.skipAndLogIfFormatsUnsupported(
context,
testId,
/* inputFormat= */ MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT,
/* outputFormat= */ MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT
.buildUpon()
.setColorInfo(ColorInfo.SDR_BT709_LIMITED)
.build())) {
return;
}
Transformer transformer = Transformer transformer =
new Transformer.Builder(context) new Transformer.Builder(context)
.setTransformationRequest( .setTransformationRequest(
...@@ -209,13 +273,19 @@ public class ToneMapHdrToSdrUsingMediaCodecTest { ...@@ -209,13 +273,19 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.build() .build()
.run(testId, editedMediaItem); .run(testId, editedMediaItem);
Log.i(TAG, "Tone mapped."); assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
maybeAssertFileHasColorTransfer(exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) { } catch (ExportException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString()); if (exception.getCause() != null
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class); && (Objects.equals(
assertThat(exception.errorCode) exception.getCause().getMessage(),
.isEqualTo(ExportException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED); "Tone-mapping HDR is not supported on this device.")
|| Objects.equals(
exception.getCause().getMessage(),
"Tone-mapping requested but not supported by the decoder."))) {
// Expected on devices without a tone-mapping plugin for this codec.
return;
}
throw exception;
} }
} }
} }
...@@ -23,7 +23,7 @@ import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSE ...@@ -23,7 +23,7 @@ import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSE
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_DOLBY_VISION_HDR; import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_DOLBY_VISION_HDR;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_DOLBY_VISION_HDR_FORMAT; import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_DOLBY_VISION_HDR_FORMAT;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.recordTestSkipped; import static com.google.android.exoplayer2.transformer.AndroidTestUtil.recordTestSkipped;
import static com.google.android.exoplayer2.transformer.mh.FileUtil.maybeAssertFileHasColorTransfer; import static com.google.android.exoplayer2.transformer.mh.FileUtil.assertFileHasColorTransfer;
import android.content.Context; import android.content.Context;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
...@@ -33,14 +33,13 @@ import com.google.android.exoplayer2.Format; ...@@ -33,14 +33,13 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.mediacodec.MediaCodecUtil; import com.google.android.exoplayer2.mediacodec.MediaCodecUtil;
import com.google.android.exoplayer2.transformer.AndroidTestUtil; import com.google.android.exoplayer2.transformer.AndroidTestUtil;
import com.google.android.exoplayer2.transformer.ExportException;
import com.google.android.exoplayer2.transformer.ExportTestResult; import com.google.android.exoplayer2.transformer.ExportTestResult;
import com.google.android.exoplayer2.transformer.TransformationRequest; import com.google.android.exoplayer2.transformer.TransformationRequest;
import com.google.android.exoplayer2.transformer.Transformer; import com.google.android.exoplayer2.transformer.Transformer;
import com.google.android.exoplayer2.transformer.TransformerAndroidTestRunner; import com.google.android.exoplayer2.transformer.TransformerAndroidTestRunner;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.ColorInfo;
import java.io.IOException; import java.io.IOException;
import org.json.JSONException; import org.json.JSONException;
import org.junit.Test; import org.junit.Test;
...@@ -52,13 +51,12 @@ import org.junit.runner.RunWith; ...@@ -52,13 +51,12 @@ import org.junit.runner.RunWith;
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class ToneMapHdrToSdrUsingOpenGlTest { public class ToneMapHdrToSdrUsingOpenGlTest {
public static final String TAG = "ToneMapHdrToSdrUsingOpenGlTest";
private final Context context = ApplicationProvider.getApplicationContext(); private final Context context = ApplicationProvider.getApplicationContext();
@Test @Test
public void export_toneMap_hlg10File_toneMapsOrThrows() throws Exception { public void export_toneMap_hlg10File_toneMaps() throws Exception {
String testId = "export_glToneMap_hlg10File_toneMapsOrThrows"; String testId = "export_glToneMap_hlg10File_toneMaps";
if (!deviceSupportsOpenGlToneMapping( if (!deviceSupportsOpenGlToneMapping(
testId, /* inputFormat= */ MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT)) { testId, /* inputFormat= */ MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT)) {
return; return;
...@@ -68,8 +66,8 @@ public class ToneMapHdrToSdrUsingOpenGlTest { ...@@ -68,8 +66,8 @@ public class ToneMapHdrToSdrUsingOpenGlTest {
} }
@Test @Test
public void export_toneMap_hdr10File_toneMapsOrThrows() throws Exception { public void export_toneMap_hdr10File_toneMaps() throws Exception {
String testId = "export_glToneMap_hdr10File_toneMapsOrThrows"; String testId = "export_glToneMap_hdr10File_toneMaps";
if (!deviceSupportsOpenGlToneMapping( if (!deviceSupportsOpenGlToneMapping(
testId, /* inputFormat= */ MP4_ASSET_720P_4_SECOND_HDR10_FORMAT)) { testId, /* inputFormat= */ MP4_ASSET_720P_4_SECOND_HDR10_FORMAT)) {
return; return;
...@@ -79,8 +77,8 @@ public class ToneMapHdrToSdrUsingOpenGlTest { ...@@ -79,8 +77,8 @@ public class ToneMapHdrToSdrUsingOpenGlTest {
} }
@Test @Test
public void export_toneMap_dolbyVisionFile_toneMapsOrThrows() throws Exception { public void export_toneMap_dolbyVisionFile_toneMaps() throws Exception {
String testId = "export_toneMap_dolbyVisionFile_toneMapsOrThrows"; String testId = "export_toneMap_dolbyVisionFile_toneMaps";
if (!deviceSupportsOpenGlToneMapping( if (!deviceSupportsOpenGlToneMapping(
testId, /* inputFormat= */ MP4_ASSET_DOLBY_VISION_HDR_FORMAT)) { testId, /* inputFormat= */ MP4_ASSET_DOLBY_VISION_HDR_FORMAT)) {
return; return;
...@@ -97,19 +95,11 @@ public class ToneMapHdrToSdrUsingOpenGlTest { ...@@ -97,19 +95,11 @@ public class ToneMapHdrToSdrUsingOpenGlTest {
.setHdrMode(TransformationRequest.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL) .setHdrMode(TransformationRequest.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL)
.build()) .build())
.build(); .build();
try { ExportTestResult exportTestResult =
ExportTestResult exportTestResult = new TransformerAndroidTestRunner.Builder(context, transformer)
new TransformerAndroidTestRunner.Builder(context, transformer) .build()
.build() .run(testId, MediaItem.fromUri(fileUri));
.run(testId, MediaItem.fromUri(fileUri)); assertFileHasColorTransfer(context, 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) {
throw exception;
}
}
} }
private static boolean deviceSupportsOpenGlToneMapping(String testId, Format inputFormat) private static boolean deviceSupportsOpenGlToneMapping(String testId, Format inputFormat)
...@@ -129,6 +119,12 @@ public class ToneMapHdrToSdrUsingOpenGlTest { ...@@ -129,6 +119,12 @@ public class ToneMapHdrToSdrUsingOpenGlTest {
} }
return !AndroidTestUtil.skipAndLogIfFormatsUnsupported( return !AndroidTestUtil.skipAndLogIfFormatsUnsupported(
getApplicationContext(), testId, /* inputFormat= */ inputFormat, /* outputFormat= */ null); getApplicationContext(),
testId,
inputFormat,
/* outputFormat= */ inputFormat
.buildUpon()
.setColorInfo(ColorInfo.SDR_BT709_LIMITED)
.build());
} }
} }
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