Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ public static String getMediaMimeType(@Nullable String codec) {
} else if (codec.startsWith("dvav")
|| codec.startsWith("dva1")
|| codec.startsWith("dvhe")
|| codec.startsWith("dvh1")) {
|| codec.startsWith("dvh1")
|| codec.startsWith("dav1")) {
return MimeTypes.VIDEO_DOLBY_VISION;
} else if (codec.startsWith("av01")) {
return MimeTypes.VIDEO_AV1;
Expand Down Expand Up @@ -599,8 +600,8 @@ public static boolean isDolbyVisionCodec(
if (codecs == null) {
return false;
}
if (codecs.startsWith("dvhe") || codecs.startsWith("dvh1")) {
// profile 5
if (codecs.startsWith("dvhe") || codecs.startsWith("dvh1") || codecs.startsWith("dav1")) {
// profiles 5, 10.0 and 20.0
return true;
}
if (supplementalCodecs == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ public abstract class Mp4Box {
@SuppressWarnings("ConstantCaseForConstants")
public static final int TYPE_dvvC = 0x64767643;

@SuppressWarnings("ConstantCaseForConstants")
public static final int TYPE_dav1 = 0x64617631;

@SuppressWarnings("ConstantCaseForConstants")
public static final int TYPE_dvwC = 0x64767743;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,10 @@ protected DecoderReuseEvaluation onInputFormatChanged(FormatHolder formatHolder)
// * b/229399008#comment9
// * https://github.com/androidx/media/issues/2408
if ((Objects.equals(newFormat.sampleMimeType, MimeTypes.VIDEO_AV1)
|| Objects.equals(newFormat.sampleMimeType, MimeTypes.VIDEO_VP9))
|| Objects.equals(newFormat.sampleMimeType, MimeTypes.VIDEO_VP9)
|| (Objects.equals(newFormat.sampleMimeType, MimeTypes.VIDEO_DOLBY_VISION)
&& Objects.equals(MediaCodecUtil.getDolbyVisionBlMimeType(newFormat),
MimeTypes.VIDEO_AV1)))
&& !newFormat.initializationData.isEmpty()) {
newFormat = newFormat.buildUpon().setInitializationData(null).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.VisibleForTesting;
import androidx.media3.common.C;
import androidx.media3.common.Format;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.util.CodecSpecificDataUtil;
Expand Down Expand Up @@ -365,6 +366,33 @@ public static Pair<Integer, Integer> getHevcBaseLayerCodecProfileAndLevel(Format
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<Integer, Integer> codecProfileAndLevel = getCodecProfileAndLevel(format);
if (codecProfileAndLevel != null) {
int profile = codecProfileAndLevel.first;
if (profile == CodecProfileLevel.DolbyVisionProfileDvheDtr
|| profile == CodecProfileLevel.DolbyVisionProfileDvheSt) {
return MimeTypes.VIDEO_H265;
} else if (profile == CodecProfileLevel.DolbyVisionProfileDvavSe) {
return MimeTypes.VIDEO_H264;
} else if (profile == CodecProfileLevel.DolbyVisionProfileDvav110) {
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}.
Expand Down Expand Up @@ -394,6 +422,11 @@ public static String getAlternativeCodecMimeType(Format format) {
} else if (profile == CodecProfileLevel.DolbyVisionProfileDvavSe) {
return MimeTypes.VIDEO_H264;
} else if (profile == CodecProfileLevel.DolbyVisionProfileDvav110) {
if (format.colorInfo != null
&& format.colorInfo.colorTransfer == C.COLOR_TRANSFER_ST2084
&& format.colorInfo.colorRange == C.COLOR_RANGE_FULL) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, it means this is a DV profile 10.0 content, which is not backward compatible to AV1 so that it cannot be played as AV1 content on non-Dolby licensed device.
Instead, DV profile 10.1 and 10.4 can be played as AV1 content on non-Dolby licensed device.
See more details on https://professionalsupport.dolby.com/s/article/What-is-Dolby-Vision-Profile?language=en_US, table 2.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ybai001
Do DV profiles 10.1 and 10.4 not have these color space values? Or your solution is to only set these values for 10.0 and using that fact to make sure its not backwards compatible?

If other DV profiles have these color space values then its not a robust solution. What if in the future that information is generally parsed for all DolbyVision streams for some other purpose? Is there any other way to know the cross-compatibility id?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@microkatz, we actually set these values for other profiles here.

Let me provide more info about this code change.

Dolby Vision profile 10 includes profile 10.0, 10.1 and 10.4 currently. P10.0 is not backward-compatible with AV1 and cannot be played on non-Dolby licensed device while P10.1 and P10.4 can. The purpose of this piece of code is to return null for P10.0 and to return MimeTypes.VIDEO_AV1 for P10.1 and 10.4.

This method (getAlternativeCodecMimeType()) is called in both track selection and codec selection phase.

During track selection phase, the input is manifest file. CCID is not explicitly indicated in manifest file. The only method is to calculate it based on supplementalCodecs and supplementalProfiles (Since neither supplementalCodecs nor supplementalProfiles is the member of Format structure, we set ColorInfo at first then conclude the CCID based on it).

During codec selection phase, the input includes MPEG4 box info. CCID can be get directly by parsing Format::initializationData.

As a common method in both track selection and codec selection phase, we adopted the ColorInfo method in this PR.

I agree it is not a perfect solution. In future, maybe we need to update getColorInfoForFormat() method to adapt new Dolby Vision profile definitions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ybai001

CCID is not explicitly indicated in manifest file. The only method is to calculate it based on supplementalCodecs and supplementalProfiles (Since neither supplementalCodecs nor supplementalProfiles is the member of Format structure, we set ColorInfo at first then conclude the CCID based on it).

Just to clarify, you said that "CCID is not explicitly indicated in the manifest file" but you can interpret it through the supplementalCodecs and supplementalProfiles data? Or more specifically if the codecs string starts with dav1 then it is 10.0 and not 10.1/10.4?

I don't think only setting the ColorInfo for these specific cases is a robust solution. It may be in the future that we need to set this data for the other profiles as well.

Is there any other difference between 10.0, 10.1 & 10.4 that we can use? If we are able to identify the profile characteristic from the manfiest and there is not another value in Format that we can set, then we might need to add a value to Format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@microkatz

Just to clarify, you said that "CCID is not explicitly indicated in the manifest file" but you can interpret it through the supplementalCodecs and supplementalProfiles data? Or more specifically if the codecs string starts with dav1 then it is 10.0 and not 10.1/10.4?

Right.

Is there any other difference between 10.0, 10.1 & 10.4 that we can use? If we are able to identify the profile characteristic from the manfiest and there is not another value in Format that we can set, then we might need to add a value to Format.

Based on the current "format" structure, this is no other reliable parameter we can use. This is has been reviewed by our Dolby Vision architecture team. ColorInfo is a reliable method since its difference has been declared in Dolby Vision specification document. I actually discussed with Dolby Vision architecture team about adding supplementalCodecs and supplementalProfiles into "format" structure but they didn't suggest me to do it in that way. There is an internal discussion about whether adding a new field in manifest to indicate CCID directly but there is no timeline when decision is done. Since DV profile 10 content creation tool/code has already been delivered to customs, we have to make AndroidX Media support this profile now. The method in this PR is a solution after Dolby internal discusssion.

return null;
}
return MimeTypes.VIDEO_AV1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.util.Xml;
import androidx.annotation.Nullable;
import androidx.media3.common.C;
import androidx.media3.common.ColorInfo;
import androidx.media3.common.DrmInitData;
import androidx.media3.common.DrmInitData.SchemeData;
import androidx.media3.common.Format;
Expand Down Expand Up @@ -848,6 +849,9 @@ protected Format buildFormat(
codecs = MimeTypes.CODEC_E_AC3_JOC;
}
}

ColorInfo colorInfo = getColorInfoForFormat(codecs, supplementalCodecs, supplementalProfiles);

if (MimeTypes.isDolbyVisionCodec(codecs, supplementalCodecs)) {
sampleMimeType = MimeTypes.VIDEO_DOLBY_VISION;
codecs = supplementalCodecs != null ? supplementalCodecs : codecs;
Expand All @@ -868,6 +872,7 @@ protected Format buildFormat(
.setPeakBitrate(bitrate)
.setSelectionFlags(selectionFlags)
.setRoleFlags(roleFlags)
.setColorInfo(colorInfo)
.setLanguage(language)
.setTileCountHorizontal(tileCounts != null ? tileCounts.first : Format.NO_VALUE)
.setTileCountVertical(tileCounts != null ? tileCounts.second : Format.NO_VALUE);
Expand Down Expand Up @@ -2174,6 +2179,47 @@ private boolean isDvbProfileDeclared(String[] profiles) {
return false;
}

private static ColorInfo getColorInfoForFormat(
@Nullable String codecs,
@Nullable String supplementalCodecs,
@Nullable String supplementalProfiles) {

@C.ColorSpace int colorSpace = Format.NO_VALUE;
@C.ColorRange int colorRange = Format.NO_VALUE;
@C.ColorTransfer int colorTransfer = Format.NO_VALUE;

if (MimeTypes.isDolbyVisionCodec(codecs, supplementalCodecs)) {
if (codecs.startsWith("dvhe") || codecs.startsWith("dvh1") || codecs.startsWith("dav1")) {
// profiles 5, 10.0 and 20.0
colorSpace = C.COLOR_SPACE_BT2020;
colorTransfer = C.COLOR_TRANSFER_ST2084;
colorRange = C.COLOR_RANGE_FULL;
} else if (supplementalProfiles != null) {
if (supplementalProfiles.equals("db1p")) {
//BL signal cross-compatibility ID = 1 (e.g profile 8.1)
colorSpace = C.COLOR_SPACE_BT2020;
colorTransfer = C.COLOR_TRANSFER_ST2084;
colorRange = C.COLOR_RANGE_LIMITED;
} else if (supplementalProfiles.startsWith("db4")) { // db4g or db4h
//BL signal cross-compatibility ID = 4 (e.g profile 8.4)
colorSpace = C.COLOR_SPACE_BT2020;
colorTransfer = C.COLOR_TRANSFER_HLG;
colorRange = C.COLOR_RANGE_LIMITED;
}
}
}

if (colorSpace == Format.NO_VALUE) {
return null;
}

return new ColorInfo.Builder()
.setColorSpace(colorSpace)
.setColorRange(colorRange)
.setColorTransfer(colorTransfer)
.build();
}

/** A parsed Representation element. */
protected static final class RepresentationInfo {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,7 @@ private static Format deriveVideoFormat(Format variantFormat) {
.setFrameRate(variantFormat.frameRate)
.setSelectionFlags(variantFormat.selectionFlags)
.setRoleFlags(variantFormat.roleFlags)
.setColorInfo(variantFormat.colorInfo)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.util.Base64;
import androidx.annotation.Nullable;
import androidx.media3.common.C;
import androidx.media3.common.ColorInfo;
import androidx.media3.common.DrmInitData;
import androidx.media3.common.DrmInitData.SchemeData;
import androidx.media3.common.Format;
Expand Down Expand Up @@ -394,6 +395,47 @@ private static int skipIgnorableWhitespace(BufferedReader reader, boolean skipLi
return c;
}

private static ColorInfo getColorInfoForFormat(
@Nullable String codecs,
@Nullable String supplementalCodecs,
@Nullable String supplementalProfiles) {

@C.ColorSpace int colorSpace = Format.NO_VALUE;
@C.ColorRange int colorRange = Format.NO_VALUE;
@C.ColorTransfer int colorTransfer = Format.NO_VALUE;

if (MimeTypes.isDolbyVisionCodec(codecs, supplementalCodecs)) {
if (codecs.startsWith("dvhe") || codecs.startsWith("dvh1") || codecs.startsWith("dav1")) {
// profiles 5, 10.0 and 20.0
colorSpace = C.COLOR_SPACE_BT2020;
colorTransfer = C.COLOR_TRANSFER_ST2084;
colorRange = C.COLOR_RANGE_FULL;
} else if (supplementalProfiles != null) {
if (supplementalProfiles.equals("db1p")) {
//BL signal cross-compatibility ID = 1 (e.g profile 8.1)
colorSpace = C.COLOR_SPACE_BT2020;
colorTransfer = C.COLOR_TRANSFER_ST2084;
colorRange = C.COLOR_RANGE_LIMITED;
} else if (supplementalProfiles.startsWith("db4")) { // db4g or db4h
//BL signal cross-compatibility ID = 4 (e.g profile 8.4)
colorSpace = C.COLOR_SPACE_BT2020;
colorTransfer = C.COLOR_TRANSFER_HLG;
colorRange = C.COLOR_RANGE_LIMITED;
}
}
}

if (colorSpace == Format.NO_VALUE) {
return null;
}

return new ColorInfo.Builder()
.setColorSpace(colorSpace)
.setColorRange(colorRange)
.setColorTransfer(colorTransfer)
.build();
}

private static boolean isDolbyVisionFormat(
@Nullable String videoRange,
@Nullable String codecs,
Expand Down Expand Up @@ -484,6 +526,10 @@ private static HlsMultivariantPlaylist parseMultivariantPlaylist(
supplementalProfiles = codecsAndProfiles[1];
}
}

ColorInfo colorInfo =
getColorInfoForFormat(codecs, supplementalCodecs, supplementalProfiles);

String videoCodecs = Util.getCodecsOfType(codecs, C.TRACK_TYPE_VIDEO);
if (isDolbyVisionFormat(
videoRange, videoCodecs, supplementalCodecs, supplementalProfiles)) {
Expand Down Expand Up @@ -545,6 +591,7 @@ private static HlsMultivariantPlaylist parseMultivariantPlaylist(
.setHeight(height)
.setFrameRate(frameRate)
.setRoleFlags(roleFlags)
.setColorInfo(colorInfo)
.build();
Variant variant =
new Variant(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,8 @@ private static StsdData parseStsd(
|| childAtomType == Mp4Box.TYPE_dva1
|| childAtomType == Mp4Box.TYPE_dvhe
|| childAtomType == Mp4Box.TYPE_dvh1
|| childAtomType == Mp4Box.TYPE_apv1) {
|| childAtomType == Mp4Box.TYPE_apv1
|| childAtomType == Mp4Box.TYPE_dav1) {
parseVideoSampleEntry(
stsd,
childAtomType,
Expand Down