diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/mediacodec/MediaCodecRenderer.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/mediacodec/MediaCodecRenderer.java index 1f1a9d443c7..04bb83ac0e3 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/mediacodec/MediaCodecRenderer.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/mediacodec/MediaCodecRenderer.java @@ -1813,7 +1813,7 @@ protected DecoderReuseEvaluation onInputFormatChanged(FormatHolder formatHolder) || Objects.equals(newFormat.sampleMimeType, MimeTypes.VIDEO_VP9) || (Objects.equals(newFormat.sampleMimeType, MimeTypes.VIDEO_DOLBY_VISION) && Objects.equals( - MediaCodecUtil.getAlternativeCodecMimeType(newFormat), MimeTypes.VIDEO_AV1))) + MediaCodecUtil.getDolbyVisionBlMimeType(newFormat), MimeTypes.VIDEO_AV1))) && !newFormat.initializationData.isEmpty()) { newFormat = newFormat.buildUpon().setInitializationData(null).build(); } diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/mediacodec/MediaCodecUtil.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/mediacodec/MediaCodecUtil.java index c04c497b0b3..a75509a5483 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/mediacodec/MediaCodecUtil.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/mediacodec/MediaCodecUtil.java @@ -365,6 +365,34 @@ public static MediaCodecProfileAndLevel getHevcBaseLayerCodecProfileAndLevel(For return getHevcProfileAndLevel(codecs, parts, format.colorInfo); } + /** + * Returns a Dolby Vision base layer codec MIME type of the provided {@link Format}. + * + * @param format The media format. + * @return A Dolby Vision base layer MIME type, or null if a Dolby Vision profile is not + * identified. + */ + @Nullable + public static String getDolbyVisionBlMimeType(Format format) { + + if (MimeTypes.VIDEO_DOLBY_VISION.equals(format.sampleMimeType)) { + @Nullable Pair codecProfileAndLevel = getCodecProfileAndLevel(format); + if (codecProfileAndLevel != null) { + int profile = codecProfileAndLevel.first; + if (profile == CodecProfileLevel.DolbyVisionProfileDvheDtr // profile 4 + || profile == CodecProfileLevel.DolbyVisionProfileDvheStn // profile 5 + || profile == CodecProfileLevel.DolbyVisionProfileDvheSt) { // profile 8 + return MimeTypes.VIDEO_H265; + } else if (profile == CodecProfileLevel.DolbyVisionProfileDvavSe) { // profile 9 + return MimeTypes.VIDEO_H264; + } else if (profile == CodecProfileLevel.DolbyVisionProfileDvav110) { // profile 10 + return MimeTypes.VIDEO_AV1; + } + } + } + return null; + } + /** * Returns an alternative codec MIME type (besides the default {@link Format#sampleMimeType}) that * can be used to decode samples of the provided {@link Format}.