Refactor assertFileHasColorTransfer method

PiperOrigin-RevId: 603662313
This commit is contained in:
sheenachhabra 2024-02-02 05:39:07 -08:00 committed by Copybara-Service
parent ae85ba9ee9
commit 30b60f6c60
5 changed files with 55 additions and 32 deletions

View File

@ -17,7 +17,6 @@
package androidx.media3.test.utils;
import static androidx.media3.common.util.Assertions.checkState;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import androidx.annotation.Nullable;
@ -36,22 +35,16 @@ import java.util.concurrent.ExecutionException;
public final class FileUtil {
/**
* Asserts that the file has a certain color transfer.
*
* @param context The current context.
* @param filePath The path of the input file.
* @param expectedColorTransfer The expected {@link C.ColorTransfer} for the input file.
* Returns {@link C.ColorTransfer} information from the media file, or {@link
* C#COLOR_TRANSFER_SDR} if the information can not be found.
*/
public static void assertFileHasColorTransfer(
Context context, @Nullable String filePath, @C.ColorTransfer int expectedColorTransfer) {
public static @C.ColorTransfer int retrieveColorTransfer(
Context context, @Nullable String filePath) {
Format videoTrackFormat = retrieveTrackFormat(context, filePath, C.TRACK_TYPE_VIDEO);
@Nullable ColorInfo colorInfo = videoTrackFormat.colorInfo;
@C.ColorTransfer
int actualColorTransfer =
colorInfo == null || colorInfo.colorTransfer == Format.NO_VALUE
? C.COLOR_TRANSFER_SDR
: colorInfo.colorTransfer;
assertThat(actualColorTransfer).isEqualTo(expectedColorTransfer);
return colorInfo == null || colorInfo.colorTransfer == Format.NO_VALUE
? C.COLOR_TRANSFER_SDR
: colorInfo.colorTransfer;
}
/** Returns {@linkplain Format track format} from the media file. */

View File

@ -16,13 +16,14 @@
package androidx.media3.transformer.mh;
import static androidx.media3.common.util.Util.SDK_INT;
import static androidx.media3.test.utils.FileUtil.assertFileHasColorTransfer;
import static androidx.media3.test.utils.FileUtil.retrieveColorTransfer;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_720P_4_SECOND_HDR10;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_720P_4_SECOND_HDR10_FORMAT;
import static androidx.media3.transformer.AndroidTestUtil.recordTestSkipped;
import static androidx.media3.transformer.AndroidTestUtil.skipAndLogIfFormatsUnsupported;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.net.Uri;
@ -85,7 +86,9 @@ public class ForceInterpretHdrVideoAsSdrTest {
.build()
.run(testId, composition);
assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
@C.ColorTransfer
int actualColorTransfer = retrieveColorTransfer(context, exportTestResult.filePath);
assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_SDR);
}
@Test
@ -124,6 +127,8 @@ public class ForceInterpretHdrVideoAsSdrTest {
.build()
.run(testId, composition);
assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
@C.ColorTransfer
int actualColorTransfer = retrieveColorTransfer(context, exportTestResult.filePath);
assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_SDR);
}
}

View File

@ -16,7 +16,7 @@
package androidx.media3.transformer.mh;
import static androidx.media3.common.MimeTypes.VIDEO_H265;
import static androidx.media3.test.utils.FileUtil.assertFileHasColorTransfer;
import static androidx.media3.test.utils.FileUtil.retrieveColorTransfer;
import static androidx.media3.transformer.AndroidTestUtil.FORCE_TRANSCODE_VIDEO_EFFECTS;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT;
@ -97,7 +97,9 @@ public final class HdrEditingTest {
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, mediaItem);
assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_ST2084);
@C.ColorTransfer
int actualColorTransfer = retrieveColorTransfer(context, exportTestResult.filePath);
assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_ST2084);
}
@Test
@ -126,7 +128,9 @@ public final class HdrEditingTest {
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, mediaItem);
assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_HLG);
@C.ColorTransfer
int actualColorTransfer = retrieveColorTransfer(context, exportTestResult.filePath);
assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_HLG);
}
@Test
@ -155,7 +159,9 @@ public final class HdrEditingTest {
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, editedMediaItem);
assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_ST2084);
@C.ColorTransfer
int actualColorTransfer = retrieveColorTransfer(context, exportTestResult.filePath);
assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_ST2084);
}
@Test
@ -184,7 +190,9 @@ public final class HdrEditingTest {
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, editedMediaItem);
assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_HLG);
@C.ColorTransfer
int actualColorTransfer = retrieveColorTransfer(context, exportTestResult.filePath);
assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_HLG);
}
@Test
@ -214,7 +222,9 @@ public final class HdrEditingTest {
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, editedMediaItem);
assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_HLG);
@C.ColorTransfer
int actualColorTransfer = retrieveColorTransfer(context, exportTestResult.filePath);
assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_HLG);
}
@Test
@ -264,7 +274,9 @@ public final class HdrEditingTest {
.build()
.run(testId, editedMediaItem);
assertThat(isToneMappingFallbackApplied.get()).isTrue();
assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
@C.ColorTransfer
int actualColorTransfer = retrieveColorTransfer(context, exportTestResult.filePath);
assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) {
if (exception.getCause() != null) {
@Nullable String message = exception.getCause().getMessage();
@ -325,7 +337,9 @@ public final class HdrEditingTest {
.build()
.run(testId, editedMediaItem);
assertThat(isToneMappingFallbackApplied.get()).isTrue();
assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
@C.ColorTransfer
int actualColorTransfer = retrieveColorTransfer(context, exportTestResult.filePath);
assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) {
if (exception.getCause() != null) {
@Nullable String message = exception.getCause().getMessage();

View File

@ -15,7 +15,7 @@
*/
package androidx.media3.transformer.mh;
import static androidx.media3.test.utils.FileUtil.assertFileHasColorTransfer;
import static androidx.media3.test.utils.FileUtil.retrieveColorTransfer;
import static androidx.media3.transformer.AndroidTestUtil.FORCE_TRANSCODE_VIDEO_EFFECTS;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT;
@ -91,7 +91,9 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, composition);
assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
@C.ColorTransfer
int actualColorTransfer = retrieveColorTransfer(context, exportTestResult.filePath);
assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) {
if (exception.getCause() != null
&& (Objects.equals(
@ -149,7 +151,9 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, composition);
assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
@C.ColorTransfer
int actualColorTransfer = retrieveColorTransfer(context, exportTestResult.filePath);
assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) {
if (exception.getCause() != null
&& (Objects.equals(
@ -208,7 +212,9 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, composition);
assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
@C.ColorTransfer
int actualColorTransfer = retrieveColorTransfer(context, exportTestResult.filePath);
assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) {
if (exception.getCause() != null
&& (Objects.equals(
@ -267,7 +273,9 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, composition);
assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
@C.ColorTransfer
int actualColorTransfer = retrieveColorTransfer(context, exportTestResult.filePath);
assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_SDR);
} catch (ExportException exception) {
if (exception.getCause() != null
&& (Objects.equals(

View File

@ -15,7 +15,7 @@
*/
package androidx.media3.transformer.mh;
import static androidx.media3.test.utils.FileUtil.assertFileHasColorTransfer;
import static androidx.media3.test.utils.FileUtil.retrieveColorTransfer;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_720P_4_SECOND_HDR10;
@ -23,6 +23,7 @@ import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_720P_4_SECON
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_DOLBY_VISION_HDR;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_DOLBY_VISION_HDR_FORMAT;
import static androidx.media3.transformer.mh.HdrCapabilitiesUtil.skipAndLogIfOpenGlToneMappingUnsupported;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import androidx.media3.common.C;
@ -92,6 +93,8 @@ public class ToneMapHdrToSdrUsingOpenGlTest {
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, composition);
assertFileHasColorTransfer(context, exportTestResult.filePath, C.COLOR_TRANSFER_SDR);
@C.ColorTransfer
int actualColorTransfer = retrieveColorTransfer(context, exportTestResult.filePath);
assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_SDR);
}
}