From a5524c09c50007a44f5cf1c13ab142708d9ecf2d Mon Sep 17 00:00:00 2001 From: ybai001 Date: Tue, 2 Apr 2024 12:59:06 +0800 Subject: [PATCH 01/10] Add Dolby Vision Transcoding and Editing Support --- .../transformer/DefaultDecoderFactory.java | 3 + .../media3/transformer/EncoderUtil.java | 7 +++ .../media3/transformer/FrameworkMuxer.java | 63 +++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultDecoderFactory.java b/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultDecoderFactory.java index 180664bb2fe..7b8671e33d8 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultDecoderFactory.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultDecoderFactory.java @@ -135,6 +135,9 @@ public DefaultCodec createForVideoDecoding( if (SDK_INT >= 31 && requestSdrToneMapping) { mediaFormat.setInteger( MediaFormat.KEY_COLOR_TRANSFER_REQUEST, MediaFormat.COLOR_TRANSFER_SDR_VIDEO); + } else if (SDK_INT >= 31 && MimeTypes.VIDEO_DOLBY_VISION.equals(format.sampleMimeType)) { + mediaFormat.setInteger( + MediaFormat.KEY_COLOR_TRANSFER_REQUEST, MediaFormat.COLOR_TRANSFER_HLG); } @Nullable diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/EncoderUtil.java b/libraries/transformer/src/main/java/androidx/media3/transformer/EncoderUtil.java index d3071a63db9..108afe6dd75 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/EncoderUtil.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/EncoderUtil.java @@ -150,6 +150,13 @@ public static ImmutableList getCodecProfilesForHdrFormat( return ImmutableList.of(MediaCodecInfo.CodecProfileLevel.AV1ProfileMain10HDR10); } break; + case MimeTypes.VIDEO_DOLBY_VISION: + if (colorTransfer == C.COLOR_TRANSFER_HLG) { + return ImmutableList.of( + MediaCodecInfo.CodecProfileLevel.DolbyVisionProfileDvheSt); + } + // CodecProfileLevel does not support PQ for Dolby Vision. + break; default: break; } diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java index c63d8148f6a..b309fe2448d 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java @@ -22,9 +22,12 @@ import android.annotation.SuppressLint; import android.media.MediaCodec; +import android.media.MediaCodecInfo; import android.media.MediaFormat; import android.media.MediaMuxer; +import android.os.Build; import android.util.SparseLongArray; +import androidx.annotation.RequiresApi; import androidx.media3.common.C; import androidx.media3.common.Format; import androidx.media3.common.Metadata; @@ -108,6 +111,11 @@ public int addTrack(Format format) throws MuxerException { if (isVideo) { mediaFormat = MediaFormat.createVideoFormat(sampleMimeType, format.width, format.height); MediaFormatUtil.maybeSetColorInfo(mediaFormat, format.colorInfo); + if (sampleMimeType.equals(MimeTypes.VIDEO_DOLBY_VISION) && + android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) { + mediaFormat.setInteger(MediaFormat.KEY_PROFILE, getDvProfile(format)); + mediaFormat.setInteger(MediaFormat.KEY_LEVEL, getDvLevel(format)); + } try { mediaMuxer.setOrientationHint(format.rotationDegrees); } catch (RuntimeException e) { @@ -276,9 +284,64 @@ private static ImmutableList getSupportedVideoSampleMimeTypes() { if (SDK_INT >= 24) { supportedMimeTypes.add(MimeTypes.VIDEO_H265); } + if (SDK_INT >= 33) { + supportedMimeTypes.add(MimeTypes.VIDEO_DOLBY_VISION); + } if (SDK_INT >= 34) { supportedMimeTypes.add(MimeTypes.VIDEO_AV1); } return supportedMimeTypes.build(); } + + // Get Dolby Vision profile + // Refer to https://professionalsupport.dolby.com/s/article/What-is-Dolby-Vision-Profile + @RequiresApi(api = Build.VERSION_CODES.TIRAMISU) + private static int getDvProfile(Format format) { + // Currently, only profile 8 is supported for encoding + // TODO: set profile ID based on format. + return MediaCodecInfo.CodecProfileLevel.DolbyVisionProfileDvheSt; + } + + // Get Dolby Vision level + // Refer to https://professionalsupport.dolby.com/s/article/What-is-Dolby-Vision-Profile + @RequiresApi(api = Build.VERSION_CODES.TIRAMISU) + private static int getDvLevel(Format format) { + int level = -1; + int maxWidthHeight = Math.max(format.width, format.height); + float pps = format.width * format.height * format.frameRate; + + if (maxWidthHeight <= 1280) { + if (pps <= 22118400) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelHd24; // Level 01 + } else if (pps <= 27648000) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelHd30; // Level 02 + } + } else if (maxWidthHeight <= 1920 && pps <= 49766400) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelFhd24; // Level 03 + } else if (maxWidthHeight <= 2560 && pps <= 62208000) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelFhd30; // Level 04 + } else if (maxWidthHeight <= 3840) { + if (pps <= 124416000) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelFhd60; // Level 05 + } else if (pps <= 199065600) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelUhd24; // Level 06 + } else if (pps <= 248832000) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelUhd30; // Level 07 + } else if (pps <= 398131200) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelUhd48; // Level 08 + } else if (pps <= 497664000) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelUhd60; // Level 09 + } else if (pps <= 995328000) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelUhd120; // Level 10 + } + } else if (maxWidthHeight <= 7680) { + if (pps <= 995328000) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevel8k30; // Level 11 + } else if (pps <= 1990656000) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevel8k60; // Level 12 + } + } + + return level; + } } From 6acfa0cc68d4a722fdc160b4ddcefc39e94cdb9a Mon Sep 17 00:00:00 2001 From: ybai001 Date: Tue, 2 Apr 2024 12:59:06 +0800 Subject: [PATCH 02/10] Add Dolby Vision Transcoding and Editing Support --- .../transformer/DefaultDecoderFactory.java | 4 ++ .../media3/transformer/EncoderUtil.java | 7 +++ .../media3/transformer/FrameworkMuxer.java | 63 +++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultDecoderFactory.java b/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultDecoderFactory.java index 180664bb2fe..9d5b19deac8 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultDecoderFactory.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultDecoderFactory.java @@ -42,6 +42,7 @@ import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * Default implementation of {@link Codec.DecoderFactory} that uses {@link MediaCodec} for decoding. @@ -135,6 +136,9 @@ public DefaultCodec createForVideoDecoding( if (SDK_INT >= 31 && requestSdrToneMapping) { mediaFormat.setInteger( MediaFormat.KEY_COLOR_TRANSFER_REQUEST, MediaFormat.COLOR_TRANSFER_SDR_VIDEO); + } else if (SDK_INT >= 31 && Objects.equals(format.sampleMimeType, MimeTypes.VIDEO_DOLBY_VISION)) { + mediaFormat.setInteger( + MediaFormat.KEY_COLOR_TRANSFER_REQUEST, MediaFormat.COLOR_TRANSFER_HLG); } @Nullable diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/EncoderUtil.java b/libraries/transformer/src/main/java/androidx/media3/transformer/EncoderUtil.java index d3071a63db9..108afe6dd75 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/EncoderUtil.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/EncoderUtil.java @@ -150,6 +150,13 @@ public static ImmutableList getCodecProfilesForHdrFormat( return ImmutableList.of(MediaCodecInfo.CodecProfileLevel.AV1ProfileMain10HDR10); } break; + case MimeTypes.VIDEO_DOLBY_VISION: + if (colorTransfer == C.COLOR_TRANSFER_HLG) { + return ImmutableList.of( + MediaCodecInfo.CodecProfileLevel.DolbyVisionProfileDvheSt); + } + // CodecProfileLevel does not support PQ for Dolby Vision. + break; default: break; } diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java index c63d8148f6a..b309fe2448d 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java @@ -22,9 +22,12 @@ import android.annotation.SuppressLint; import android.media.MediaCodec; +import android.media.MediaCodecInfo; import android.media.MediaFormat; import android.media.MediaMuxer; +import android.os.Build; import android.util.SparseLongArray; +import androidx.annotation.RequiresApi; import androidx.media3.common.C; import androidx.media3.common.Format; import androidx.media3.common.Metadata; @@ -108,6 +111,11 @@ public int addTrack(Format format) throws MuxerException { if (isVideo) { mediaFormat = MediaFormat.createVideoFormat(sampleMimeType, format.width, format.height); MediaFormatUtil.maybeSetColorInfo(mediaFormat, format.colorInfo); + if (sampleMimeType.equals(MimeTypes.VIDEO_DOLBY_VISION) && + android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) { + mediaFormat.setInteger(MediaFormat.KEY_PROFILE, getDvProfile(format)); + mediaFormat.setInteger(MediaFormat.KEY_LEVEL, getDvLevel(format)); + } try { mediaMuxer.setOrientationHint(format.rotationDegrees); } catch (RuntimeException e) { @@ -276,9 +284,64 @@ private static ImmutableList getSupportedVideoSampleMimeTypes() { if (SDK_INT >= 24) { supportedMimeTypes.add(MimeTypes.VIDEO_H265); } + if (SDK_INT >= 33) { + supportedMimeTypes.add(MimeTypes.VIDEO_DOLBY_VISION); + } if (SDK_INT >= 34) { supportedMimeTypes.add(MimeTypes.VIDEO_AV1); } return supportedMimeTypes.build(); } + + // Get Dolby Vision profile + // Refer to https://professionalsupport.dolby.com/s/article/What-is-Dolby-Vision-Profile + @RequiresApi(api = Build.VERSION_CODES.TIRAMISU) + private static int getDvProfile(Format format) { + // Currently, only profile 8 is supported for encoding + // TODO: set profile ID based on format. + return MediaCodecInfo.CodecProfileLevel.DolbyVisionProfileDvheSt; + } + + // Get Dolby Vision level + // Refer to https://professionalsupport.dolby.com/s/article/What-is-Dolby-Vision-Profile + @RequiresApi(api = Build.VERSION_CODES.TIRAMISU) + private static int getDvLevel(Format format) { + int level = -1; + int maxWidthHeight = Math.max(format.width, format.height); + float pps = format.width * format.height * format.frameRate; + + if (maxWidthHeight <= 1280) { + if (pps <= 22118400) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelHd24; // Level 01 + } else if (pps <= 27648000) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelHd30; // Level 02 + } + } else if (maxWidthHeight <= 1920 && pps <= 49766400) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelFhd24; // Level 03 + } else if (maxWidthHeight <= 2560 && pps <= 62208000) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelFhd30; // Level 04 + } else if (maxWidthHeight <= 3840) { + if (pps <= 124416000) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelFhd60; // Level 05 + } else if (pps <= 199065600) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelUhd24; // Level 06 + } else if (pps <= 248832000) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelUhd30; // Level 07 + } else if (pps <= 398131200) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelUhd48; // Level 08 + } else if (pps <= 497664000) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelUhd60; // Level 09 + } else if (pps <= 995328000) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelUhd120; // Level 10 + } + } else if (maxWidthHeight <= 7680) { + if (pps <= 995328000) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevel8k30; // Level 11 + } else if (pps <= 1990656000) { + level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevel8k60; // Level 12 + } + } + + return level; + } } From 5eb064d2d11a7de0db842f7aaaa1fe98ca32be01 Mon Sep 17 00:00:00 2001 From: ybai001 Date: Wed, 3 Jul 2024 16:22:43 +0800 Subject: [PATCH 03/10] Add test cases for Dolby Vision transformer support --- .../transformer/TransformerEndToEndTest.java | 33 ++++++ .../media3/transformer/mh/HdrEditingTest.java | 109 +++++++++++++++++- .../media3/transformer/FrameworkMuxer.java | 6 +- 3 files changed, 143 insertions(+), 5 deletions(-) diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java index f9b2f8e03e1..541437dbf0a 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java @@ -1280,6 +1280,39 @@ public void transcode_withOutputVideoMimeTypeAv1_completesSuccessfully() throws assertThat(exportResult.videoMimeType).isEqualTo(MimeTypes.VIDEO_AV1); } + @Test + public void transcode_withOutputVideoMimeTypeDolbyVision_completesSuccessfully() throws Exception { + if (AndroidTestUtil.skipAndLogIfFormatsUnsupported( + context, + testId, + /* inputFormat= */ MP4_ASSET_FORMAT, + /* outputFormat= */ MP4_ASSET_FORMAT + .buildUpon() + .setSampleMimeType(MimeTypes.VIDEO_DOLBY_VISION) + .setCodecs(null) + .build())) { + return; + } + MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_URI_STRING)); + EditedMediaItem editedMediaItem = new EditedMediaItem.Builder(mediaItem).build(); + Transformer transformer = + new Transformer.Builder(context).setVideoMimeType(MimeTypes.VIDEO_DOLBY_VISION).build(); + + ExportTestResult exportTestResult = + new TransformerAndroidTestRunner.Builder(context, transformer) + .build() + .run(testId, editedMediaItem); + ExportResult exportResult = exportTestResult.exportResult; + + assert exportTestResult.filePath != null; + String actualMimeType = + retrieveTrackFormat(context, exportTestResult.filePath, C.TRACK_TYPE_VIDEO).sampleMimeType; + assertThat(actualMimeType).isEqualTo(MimeTypes.VIDEO_DOLBY_VISION); + assertThat(exportResult.exportException).isNull(); + assertThat(exportResult.durationMs).isGreaterThan(0); + assertThat(exportResult.videoMimeType).isEqualTo(MimeTypes.VIDEO_DOLBY_VISION); + } + @Test public void transcode_withOutputAudioMimeTypeAac_completesSuccessfully() throws Exception { MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP3_ASSET_URI_STRING)); diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java index 908cf0ec7e0..0b896da096c 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java @@ -139,6 +139,41 @@ public void export_transmuxHlg10File() throws Exception { assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_HLG); } + @Test + public void export_transmuxDolbyVisionFile() throws Exception { + Context context = ApplicationProvider.getApplicationContext(); + + if (Util.SDK_INT < 24) { + // TODO: b/285543404 - Remove suppression once we can transmux H.265/HEVC before API 24. + recordTestSkipped(context, testId, /* reason= */ "Can't transmux H.265/HEVC before API 24"); + return; + } + + if (AndroidTestUtil.skipAndLogIfFormatsUnsupported( + context, + testId, + /* inputFormat= */ MP4_ASSET_DOLBY_VISION_HDR_FORMAT, + /* outputFormat= */ null)) { + return; + } + + Transformer transformer = new Transformer.Builder(context).build(); + MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_DOLBY_VISION_HDR)); + + ExportTestResult exportTestResult = + new TransformerAndroidTestRunner.Builder(context, transformer) + .build() + .run(testId, mediaItem); + assert exportTestResult.filePath != null; + @C.ColorTransfer + int actualColorTransfer = + Objects.requireNonNull( + retrieveTrackFormat(context, exportTestResult.filePath, C.TRACK_TYPE_VIDEO) + .colorInfo) + .colorTransfer; + assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_HLG); + } + @Test public void exportAndTranscode_hdr10File_whenHdrEditingIsSupported() throws Exception { Context context = ApplicationProvider.getApplicationContext(); @@ -224,10 +259,12 @@ public void exportAndTranscode_dolbyVisionFile_whenHdrEditingIsSupported() throw new TransformerAndroidTestRunner.Builder(context, transformer) .build() .run(testId, editedMediaItem); + assert exportTestResult.filePath != null; @C.ColorTransfer int actualColorTransfer = - retrieveTrackFormat(context, exportTestResult.filePath, C.TRACK_TYPE_VIDEO) - .colorInfo + Objects.requireNonNull( + retrieveTrackFormat(context, exportTestResult.filePath, C.TRACK_TYPE_VIDEO) + .colorInfo) .colorTransfer; assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_HLG); } @@ -360,6 +397,74 @@ public void onFallbackApplied( } } + @Test + public void exportAndTranscode_dolbyVisionFile_whenHdrEditingUnsupported_toneMapsOrThrows() + throws Exception { + Context context = ApplicationProvider.getApplicationContext(); + Format format = MP4_ASSET_DOLBY_VISION_HDR_FORMAT; + assert format.colorInfo != null; + if (deviceSupportsHdrEditing(VIDEO_H265, format.colorInfo)) { + recordTestSkipped(context, testId, /* reason= */ "Device supports Dolby Vision editing."); + return; + } + + if (AndroidTestUtil.skipAndLogIfFormatsUnsupported( + context, testId, /* inputFormat= */ format, /* outputFormat= */ null)) { + return; + } + + AtomicBoolean isFallbackListenerInvoked = new AtomicBoolean(); + AtomicBoolean isToneMappingFallbackApplied = new AtomicBoolean(); + Transformer transformer = + new Transformer.Builder(context) + .addListener( + new Transformer.Listener() { + @Override + public void onFallbackApplied( + MediaItem inputMediaItem, + TransformationRequest originalTransformationRequest, + TransformationRequest fallbackTransformationRequest) { + isFallbackListenerInvoked.set(true); + assertThat(originalTransformationRequest.hdrMode).isEqualTo(HDR_MODE_KEEP_HDR); + isToneMappingFallbackApplied.set( + fallbackTransformationRequest.hdrMode + == HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL); + } + }) + .build(); + MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_DOLBY_VISION_HDR)); + EditedMediaItem editedMediaItem = + new EditedMediaItem.Builder(mediaItem).setEffects(FORCE_TRANSCODE_VIDEO_EFFECTS).build(); + + try { + ExportTestResult exportTestResult = + new TransformerAndroidTestRunner.Builder(context, transformer) + .build() + .run(testId, editedMediaItem); + assertThat(isToneMappingFallbackApplied.get()).isTrue(); + assert exportTestResult.filePath != null; + @C.ColorTransfer + int actualColorTransfer = + Objects.requireNonNull( + retrieveTrackFormat(context, exportTestResult.filePath, C.TRACK_TYPE_VIDEO) + .colorInfo) + .colorTransfer; + assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_SDR); + } catch (ExportException exception) { + if (exception.getCause() != null) { + @Nullable String message = exception.getCause().getMessage(); + if (message != null + && (Objects.equals(message, "Decoding HDR is not supported on this device.") + || message.contains( + "OpenGL ES 3.0 context support is required for HDR input or output.") + || Objects.equals(message, "Device lacks YUV extension support."))) { + return; + } + } + throw exception; + } + } + private static boolean deviceSupportsHdrEditing(String mimeType, ColorInfo colorInfo) { checkState(ColorInfo.isTransferHdr(colorInfo)); return !EncoderUtil.getSupportedEncodersForHdrEditing(mimeType, colorInfo).isEmpty(); diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java index b309fe2448d..d54d7f7b454 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java @@ -313,7 +313,7 @@ private static int getDvLevel(Format format) { if (maxWidthHeight <= 1280) { if (pps <= 22118400) { level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelHd24; // Level 01 - } else if (pps <= 27648000) { + } else { // pps <= 27648000 level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelHd30; // Level 02 } } else if (maxWidthHeight <= 1920 && pps <= 49766400) { @@ -331,13 +331,13 @@ private static int getDvLevel(Format format) { level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelUhd48; // Level 08 } else if (pps <= 497664000) { level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelUhd60; // Level 09 - } else if (pps <= 995328000) { + } else { // pps <= 995328000 level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevelUhd120; // Level 10 } } else if (maxWidthHeight <= 7680) { if (pps <= 995328000) { level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevel8k30; // Level 11 - } else if (pps <= 1990656000) { + } else { // pps <= 1990656000 level = MediaCodecInfo.CodecProfileLevel.DolbyVisionLevel8k60; // Level 12 } } From 6b6d66c7ce7e153c3d795f3a6287effe0a925a70 Mon Sep 17 00:00:00 2001 From: ybai001 Date: Mon, 29 Jul 2024 16:12:29 +0800 Subject: [PATCH 04/10] Update code based on Google comments --- .../transformer/TransformerEndToEndTest.java | 1 - .../media3/transformer/mh/HdrEditingTest.java | 24 +++++++++---------- .../media3/transformer/FrameworkMuxer.java | 7 +++--- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java index 541437dbf0a..c3d182ff0ea 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java @@ -1304,7 +1304,6 @@ public void transcode_withOutputVideoMimeTypeDolbyVision_completesSuccessfully() .run(testId, editedMediaItem); ExportResult exportResult = exportTestResult.exportResult; - assert exportTestResult.filePath != null; String actualMimeType = retrieveTrackFormat(context, exportTestResult.filePath, C.TRACK_TYPE_VIDEO).sampleMimeType; assertThat(actualMimeType).isEqualTo(MimeTypes.VIDEO_DOLBY_VISION); diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java index 0b896da096c..34cf1245bd8 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java @@ -15,6 +15,7 @@ */ package androidx.media3.transformer.mh; +import static androidx.media3.common.MimeTypes.VIDEO_DOLBY_VISION; import static androidx.media3.common.MimeTypes.VIDEO_H265; import static androidx.media3.common.util.Assertions.checkState; import static androidx.media3.test.utils.TestUtil.retrieveTrackFormat; @@ -164,14 +165,16 @@ public void export_transmuxDolbyVisionFile() throws Exception { new TransformerAndroidTestRunner.Builder(context, transformer) .build() .run(testId, mediaItem); - assert exportTestResult.filePath != null; @C.ColorTransfer int actualColorTransfer = - Objects.requireNonNull( - retrieveTrackFormat(context, exportTestResult.filePath, C.TRACK_TYPE_VIDEO) - .colorInfo) + retrieveTrackFormat(context, exportTestResult.filePath, C.TRACK_TYPE_VIDEO) + .colorInfo .colorTransfer; assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_HLG); + String actualMimeType = + retrieveTrackFormat(context, exportTestResult.filePath, C.TRACK_TYPE_VIDEO) + .sampleMimeType; + assertThat(actualMimeType).isEqualTo(VIDEO_DOLBY_VISION); } @Test @@ -259,12 +262,10 @@ public void exportAndTranscode_dolbyVisionFile_whenHdrEditingIsSupported() throw new TransformerAndroidTestRunner.Builder(context, transformer) .build() .run(testId, editedMediaItem); - assert exportTestResult.filePath != null; @C.ColorTransfer int actualColorTransfer = - Objects.requireNonNull( - retrieveTrackFormat(context, exportTestResult.filePath, C.TRACK_TYPE_VIDEO) - .colorInfo) + retrieveTrackFormat(context, exportTestResult.filePath, C.TRACK_TYPE_VIDEO) + .colorInfo .colorTransfer; assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_HLG); } @@ -402,7 +403,6 @@ public void exportAndTranscode_dolbyVisionFile_whenHdrEditingUnsupported_toneMap throws Exception { Context context = ApplicationProvider.getApplicationContext(); Format format = MP4_ASSET_DOLBY_VISION_HDR_FORMAT; - assert format.colorInfo != null; if (deviceSupportsHdrEditing(VIDEO_H265, format.colorInfo)) { recordTestSkipped(context, testId, /* reason= */ "Device supports Dolby Vision editing."); return; @@ -442,12 +442,10 @@ public void onFallbackApplied( .build() .run(testId, editedMediaItem); assertThat(isToneMappingFallbackApplied.get()).isTrue(); - assert exportTestResult.filePath != null; @C.ColorTransfer int actualColorTransfer = - Objects.requireNonNull( - retrieveTrackFormat(context, exportTestResult.filePath, C.TRACK_TYPE_VIDEO) - .colorInfo) + retrieveTrackFormat(context, exportTestResult.filePath, C.TRACK_TYPE_VIDEO) + .colorInfo .colorTransfer; assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_SDR); } catch (ExportException exception) { diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java index d54d7f7b454..41d68a3fc3c 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java @@ -111,8 +111,7 @@ public int addTrack(Format format) throws MuxerException { if (isVideo) { mediaFormat = MediaFormat.createVideoFormat(sampleMimeType, format.width, format.height); MediaFormatUtil.maybeSetColorInfo(mediaFormat, format.colorInfo); - if (sampleMimeType.equals(MimeTypes.VIDEO_DOLBY_VISION) && - android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) { + if (sampleMimeType.equals(MimeTypes.VIDEO_DOLBY_VISION) && SDK_INT >= 33) { mediaFormat.setInteger(MediaFormat.KEY_PROFILE, getDvProfile(format)); mediaFormat.setInteger(MediaFormat.KEY_LEVEL, getDvLevel(format)); } @@ -295,7 +294,7 @@ private static ImmutableList getSupportedVideoSampleMimeTypes() { // Get Dolby Vision profile // Refer to https://professionalsupport.dolby.com/s/article/What-is-Dolby-Vision-Profile - @RequiresApi(api = Build.VERSION_CODES.TIRAMISU) + @RequiresApi(33) private static int getDvProfile(Format format) { // Currently, only profile 8 is supported for encoding // TODO: set profile ID based on format. @@ -304,7 +303,7 @@ private static int getDvProfile(Format format) { // Get Dolby Vision level // Refer to https://professionalsupport.dolby.com/s/article/What-is-Dolby-Vision-Profile - @RequiresApi(api = Build.VERSION_CODES.TIRAMISU) + @RequiresApi(33) private static int getDvLevel(Format format) { int level = -1; int maxWidthHeight = Math.max(format.width, format.height); From 2822919df66df251948364e949df0186ce8d79ce Mon Sep 17 00:00:00 2001 From: ybai001 Date: Mon, 5 Aug 2024 16:20:03 +0800 Subject: [PATCH 05/10] Update test code based on Google comments --- .../media3/transformer/mh/HdrEditingTest.java | 18 ++++++------------ .../media3/transformer/FrameworkMuxer.java | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java index 34cf1245bd8..2396de0e1c6 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java @@ -30,6 +30,7 @@ import static androidx.media3.transformer.Composition.HDR_MODE_KEEP_HDR; import static androidx.media3.transformer.Composition.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assume.assumeTrue; import android.content.Context; import android.net.Uri; @@ -144,11 +145,7 @@ public void export_transmuxHlg10File() throws Exception { public void export_transmuxDolbyVisionFile() throws Exception { Context context = ApplicationProvider.getApplicationContext(); - if (Util.SDK_INT < 24) { - // TODO: b/285543404 - Remove suppression once we can transmux H.265/HEVC before API 24. - recordTestSkipped(context, testId, /* reason= */ "Can't transmux H.265/HEVC before API 24"); - return; - } + assumeTrue(Util.SDK_INT >= 24); if (AndroidTestUtil.skipAndLogIfFormatsUnsupported( context, @@ -165,15 +162,12 @@ public void export_transmuxDolbyVisionFile() throws Exception { new TransformerAndroidTestRunner.Builder(context, transformer) .build() .run(testId, mediaItem); + Format trackFormat = + retrieveTrackFormat(context, exportTestResult.filePath, C.TRACK_TYPE_VIDEO); @C.ColorTransfer - int actualColorTransfer = - retrieveTrackFormat(context, exportTestResult.filePath, C.TRACK_TYPE_VIDEO) - .colorInfo - .colorTransfer; + int actualColorTransfer = trackFormat.colorInfo.colorTransfer; assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_HLG); - String actualMimeType = - retrieveTrackFormat(context, exportTestResult.filePath, C.TRACK_TYPE_VIDEO) - .sampleMimeType; + String actualMimeType = trackFormat.sampleMimeType; assertThat(actualMimeType).isEqualTo(VIDEO_DOLBY_VISION); } diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java index 41d68a3fc3c..147964a6e60 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java @@ -292,8 +292,13 @@ private static ImmutableList getSupportedVideoSampleMimeTypes() { return supportedMimeTypes.build(); } - // Get Dolby Vision profile - // Refer to https://professionalsupport.dolby.com/s/article/What-is-Dolby-Vision-Profile + /** + * Get Dolby Vision profile + * + *

Refer to What + * are Dolby Vision profiles and levels. + */ @RequiresApi(33) private static int getDvProfile(Format format) { // Currently, only profile 8 is supported for encoding @@ -301,8 +306,13 @@ private static int getDvProfile(Format format) { return MediaCodecInfo.CodecProfileLevel.DolbyVisionProfileDvheSt; } - // Get Dolby Vision level - // Refer to https://professionalsupport.dolby.com/s/article/What-is-Dolby-Vision-Profile + /** + * Get Dolby Vision level + * + *

Refer to What + * are Dolby Vision profiles and levels. + */ @RequiresApi(33) private static int getDvLevel(Format format) { int level = -1; From d8321cd0fdcd97b35e3237e0acdb51e651cf2877 Mon Sep 17 00:00:00 2001 From: ybai001 Date: Tue, 6 Aug 2024 11:09:15 +0800 Subject: [PATCH 06/10] Replace assumeTrue() with @SdkSupress() --- .../java/androidx/media3/transformer/mh/HdrEditingTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java index 2396de0e1c6..235334b523b 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java @@ -50,6 +50,7 @@ import androidx.media3.transformer.TransformerAndroidTestRunner; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.SdkSuppress; import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; import org.checkerframework.checker.nullness.qual.Nullable; @@ -142,11 +143,10 @@ public void export_transmuxHlg10File() throws Exception { } @Test + @SdkSuppress(minSdkVersion = 24) public void export_transmuxDolbyVisionFile() throws Exception { Context context = ApplicationProvider.getApplicationContext(); - assumeTrue(Util.SDK_INT >= 24); - if (AndroidTestUtil.skipAndLogIfFormatsUnsupported( context, testId, From fd133459f84480c274ea1ead35b347cbee44cb6c Mon Sep 17 00:00:00 2001 From: ybai001 Date: Tue, 6 Aug 2024 11:19:42 +0800 Subject: [PATCH 07/10] Remove unused imported class --- .../java/androidx/media3/transformer/mh/HdrEditingTest.java | 1 - .../main/java/androidx/media3/transformer/FrameworkMuxer.java | 1 - 2 files changed, 2 deletions(-) diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java index 235334b523b..750ec58862a 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java @@ -30,7 +30,6 @@ import static androidx.media3.transformer.Composition.HDR_MODE_KEEP_HDR; import static androidx.media3.transformer.Composition.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assume.assumeTrue; import android.content.Context; import android.net.Uri; diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java index 147964a6e60..b559205e75e 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java @@ -25,7 +25,6 @@ import android.media.MediaCodecInfo; import android.media.MediaFormat; import android.media.MediaMuxer; -import android.os.Build; import android.util.SparseLongArray; import androidx.annotation.RequiresApi; import androidx.media3.common.C; From b8d02d9a435452b3934652b3d6926e6faa17c34a Mon Sep 17 00:00:00 2001 From: ybai001 Date: Thu, 8 Aug 2024 11:13:12 +0800 Subject: [PATCH 08/10] Update code again based on latest comments --- .../media3/transformer/TransformerEndToEndTest.java | 1 - .../androidx/media3/transformer/mh/HdrEditingTest.java | 10 +--------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java index c3d182ff0ea..0c42c91b185 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java @@ -1307,7 +1307,6 @@ public void transcode_withOutputVideoMimeTypeDolbyVision_completesSuccessfully() String actualMimeType = retrieveTrackFormat(context, exportTestResult.filePath, C.TRACK_TYPE_VIDEO).sampleMimeType; assertThat(actualMimeType).isEqualTo(MimeTypes.VIDEO_DOLBY_VISION); - assertThat(exportResult.exportException).isNull(); assertThat(exportResult.durationMs).isGreaterThan(0); assertThat(exportResult.videoMimeType).isEqualTo(MimeTypes.VIDEO_DOLBY_VISION); } diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java index 750ec58862a..d9996cd52e9 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java @@ -146,14 +146,6 @@ public void export_transmuxHlg10File() throws Exception { public void export_transmuxDolbyVisionFile() throws Exception { Context context = ApplicationProvider.getApplicationContext(); - if (AndroidTestUtil.skipAndLogIfFormatsUnsupported( - context, - testId, - /* inputFormat= */ MP4_ASSET_DOLBY_VISION_HDR_FORMAT, - /* outputFormat= */ null)) { - return; - } - Transformer transformer = new Transformer.Builder(context).build(); MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_DOLBY_VISION_HDR)); @@ -350,7 +342,7 @@ public void exportAndTranscode_hlg10File_whenHdrEditingUnsupported_toneMapsOrThr new Transformer.Listener() { @Override public void onFallbackApplied( - MediaItem inputMediaItem, + Composition composition, TransformationRequest originalTransformationRequest, TransformationRequest fallbackTransformationRequest) { assertThat(originalTransformationRequest.hdrMode).isEqualTo(HDR_MODE_KEEP_HDR); From ffecefbec232d20645b577d568acb5a62220a0b2 Mon Sep 17 00:00:00 2001 From: ybai001 Date: Thu, 8 Aug 2024 13:33:08 +0800 Subject: [PATCH 09/10] Fix a bug in HdrEditingTest.java --- .../androidx/media3/transformer/mh/HdrEditingTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java index d9996cd52e9..521f532d5e3 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java @@ -15,7 +15,6 @@ */ package androidx.media3.transformer.mh; -import static androidx.media3.common.MimeTypes.VIDEO_DOLBY_VISION; import static androidx.media3.common.MimeTypes.VIDEO_H265; import static androidx.media3.common.util.Assertions.checkState; import static androidx.media3.test.utils.TestUtil.retrieveTrackFormat; @@ -37,6 +36,7 @@ import androidx.media3.common.ColorInfo; import androidx.media3.common.Format; import androidx.media3.common.MediaItem; +import androidx.media3.common.MimeTypes; import androidx.media3.common.util.Util; import androidx.media3.transformer.AndroidTestUtil; import androidx.media3.transformer.Composition; @@ -159,7 +159,7 @@ public void export_transmuxDolbyVisionFile() throws Exception { int actualColorTransfer = trackFormat.colorInfo.colorTransfer; assertThat(actualColorTransfer).isEqualTo(C.COLOR_TRANSFER_HLG); String actualMimeType = trackFormat.sampleMimeType; - assertThat(actualMimeType).isEqualTo(VIDEO_DOLBY_VISION); + assertThat(actualMimeType).isEqualTo(MimeTypes.VIDEO_DOLBY_VISION); } @Test @@ -342,7 +342,7 @@ public void exportAndTranscode_hlg10File_whenHdrEditingUnsupported_toneMapsOrThr new Transformer.Listener() { @Override public void onFallbackApplied( - Composition composition, + MediaItem inputMediaItem, TransformationRequest originalTransformationRequest, TransformationRequest fallbackTransformationRequest) { assertThat(originalTransformationRequest.hdrMode).isEqualTo(HDR_MODE_KEEP_HDR); @@ -406,7 +406,7 @@ public void exportAndTranscode_dolbyVisionFile_whenHdrEditingUnsupported_toneMap new Transformer.Listener() { @Override public void onFallbackApplied( - MediaItem inputMediaItem, + Composition composition, TransformationRequest originalTransformationRequest, TransformationRequest fallbackTransformationRequest) { isFallbackListenerInvoked.set(true); @@ -452,4 +452,4 @@ private static boolean deviceSupportsHdrEditing(String mimeType, ColorInfo color checkState(ColorInfo.isTransferHdr(colorInfo)); return !EncoderUtil.getSupportedEncodersForHdrEditing(mimeType, colorInfo).isEmpty(); } -} +} \ No newline at end of file From 62e1383a5b7a2883e8d9a0039c2777a16141cef2 Mon Sep 17 00:00:00 2001 From: ybai001 Date: Thu, 8 Aug 2024 17:25:06 +0800 Subject: [PATCH 10/10] Refine code to match the latest branch --- .../transformer/TransformerEndToEndTest.java | 14 +++++++------- .../media3/transformer/mh/HdrEditingTest.java | 18 ++++++------------ .../media3/transformer/FrameworkMuxer.java | 2 +- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java index d6a17366234..0da31757425 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerEndToEndTest.java @@ -1635,18 +1635,18 @@ public void transcode_withOutputVideoMimeTypeAv1_completesSuccessfully() throws @Test public void transcode_withOutputVideoMimeTypeDolbyVision_completesSuccessfully() throws Exception { - if (AndroidTestUtil.skipAndLogIfFormatsUnsupported( + assumeFormatsSupported( context, testId, - /* inputFormat= */ MP4_ASSET_FORMAT, - /* outputFormat= */ MP4_ASSET_FORMAT + /* inputFormat= */ MP4_ASSET.videoFormat, + /* outputFormat= */ MP4_ASSET + .videoFormat .buildUpon() .setSampleMimeType(MimeTypes.VIDEO_DOLBY_VISION) .setCodecs(null) - .build())) { - return; - } - MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_URI_STRING)); + .build()); + + MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET.uri)); EditedMediaItem editedMediaItem = new EditedMediaItem.Builder(mediaItem).build(); Transformer transformer = new Transformer.Builder(context).setVideoMimeType(MimeTypes.VIDEO_DOLBY_VISION).build(); diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java index 32f4a054546..e67af36ab55 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/HdrEditingTest.java @@ -144,7 +144,7 @@ public void export_transmuxDolbyVisionFile() throws Exception { Context context = ApplicationProvider.getApplicationContext(); Transformer transformer = new Transformer.Builder(context).build(); - MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_DOLBY_VISION_HDR)); + MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_DOLBY_VISION_HDR.uri)); ExportTestResult exportTestResult = new TransformerAndroidTestRunner.Builder(context, transformer) @@ -428,16 +428,10 @@ public void onFallbackApplied( public void exportAndTranscode_dolbyVisionFile_whenHdrEditingUnsupported_toneMapsOrThrows() throws Exception { Context context = ApplicationProvider.getApplicationContext(); - Format format = MP4_ASSET_DOLBY_VISION_HDR_FORMAT; - if (deviceSupportsHdrEditing(VIDEO_H265, format.colorInfo)) { - recordTestSkipped(context, testId, /* reason= */ "Device supports Dolby Vision editing."); - return; - } + Format format = MP4_ASSET_DOLBY_VISION_HDR.videoFormat; + assumeDeviceDoesNotSupportHdrEditing(testId, format); - if (AndroidTestUtil.skipAndLogIfFormatsUnsupported( - context, testId, /* inputFormat= */ format, /* outputFormat= */ null)) { - return; - } + assumeFormatsSupported(context, testId, /* inputFormat= */ format, /* outputFormat= */ null); AtomicBoolean isFallbackListenerInvoked = new AtomicBoolean(); AtomicBoolean isToneMappingFallbackApplied = new AtomicBoolean(); @@ -458,7 +452,7 @@ public void onFallbackApplied( } }) .build(); - MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_DOLBY_VISION_HDR)); + MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_DOLBY_VISION_HDR.uri)); EditedMediaItem editedMediaItem = new EditedMediaItem.Builder(mediaItem).setEffects(FORCE_TRANSCODE_VIDEO_EFFECTS).build(); @@ -488,4 +482,4 @@ public void onFallbackApplied( throw exception; } } -} \ No newline at end of file +} diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java index e77d9e497ec..2185e93c06d 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java @@ -376,4 +376,4 @@ public TrackTokenImpl(int trackIndex) { this.trackIndex = trackIndex; } } -} \ No newline at end of file +}