@@ -1208,15 +1208,9 @@ private static void parseVideoSampleEntry(
12081208 pixelWidthHeightRatio = hevcConfig .pixelWidthHeightRatio ;
12091209 }
12101210 codecs = hevcConfig .codecs ;
1211- // Modify these values only if they have not already been set. If 'Atom.TYPE_colr' atom is
1212- // present, these values may be overridden.
1213- if (colorSpace == Format .NO_VALUE
1214- && colorRange == Format .NO_VALUE
1215- && colorTransfer == Format .NO_VALUE ) {
1216- colorSpace = hevcConfig .colorSpace ;
1217- colorRange = hevcConfig .colorRange ;
1218- colorTransfer = hevcConfig .colorTransfer ;
1219- }
1211+ colorSpace = hevcConfig .colorSpace ;
1212+ colorRange = hevcConfig .colorRange ;
1213+ colorTransfer = hevcConfig .colorTransfer ;
12201214 } else if (childAtomType == Atom .TYPE_dvcC || childAtomType == Atom .TYPE_dvvC ) {
12211215 @ Nullable DolbyVisionConfig dolbyVisionConfig = DolbyVisionConfig .parse (parent );
12221216 if (dolbyVisionConfig != null ) {
@@ -1232,16 +1226,10 @@ private static void parseVideoSampleEntry(
12321226 boolean fullRangeFlag = (parent .readUnsignedByte () & 1 ) != 0 ;
12331227 int colorPrimaries = parent .readUnsignedByte ();
12341228 int transferCharacteristics = parent .readUnsignedByte ();
1235- // Modify these values only if they have not already been set. If 'Atom.TYPE_colr' atom is
1236- // present, these values may be overridden.
1237- if (colorSpace == Format .NO_VALUE
1238- && colorRange == Format .NO_VALUE
1239- && colorTransfer == Format .NO_VALUE ) {
1240- colorSpace = ColorInfo .isoColorPrimariesToColorSpace (colorPrimaries );
1241- colorRange = fullRangeFlag ? C .COLOR_RANGE_FULL : C .COLOR_RANGE_LIMITED ;
1242- colorTransfer =
1243- ColorInfo .isoTransferCharacteristicsToColorTransfer (transferCharacteristics );
1244- }
1229+ colorSpace = ColorInfo .isoColorPrimariesToColorSpace (colorPrimaries );
1230+ colorRange = fullRangeFlag ? C .COLOR_RANGE_FULL : C .COLOR_RANGE_LIMITED ;
1231+ colorTransfer =
1232+ ColorInfo .isoTransferCharacteristicsToColorTransfer (transferCharacteristics );
12451233 } else if (childAtomType == Atom .TYPE_av1C ) {
12461234 ExtractorUtil .checkContainerInput (mimeType == null , /* message= */ null );
12471235 mimeType = MimeTypes .VIDEO_AV1 ;
@@ -1321,26 +1309,33 @@ private static void parseVideoSampleEntry(
13211309 }
13221310 }
13231311 } else if (childAtomType == Atom .TYPE_colr ) {
1324- int colorType = parent .readInt ();
1325- if (colorType == TYPE_nclx || colorType == TYPE_nclc ) {
1326- // For more info on syntax, see Section 8.5.2.2 in ISO/IEC 14496-12:2012(E) and
1327- // https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html.
1328- int colorPrimaries = parent .readUnsignedShort ();
1329- int transferCharacteristics = parent .readUnsignedShort ();
1330- parent .skipBytes (2 ); // matrix_coefficients.
1331-
1332- // Only try and read full_range_flag if the box is long enough. It should be present in
1333- // all colr boxes with type=nclx (Section 8.5.2.2 in ISO/IEC 14496-12:2012(E)) but some
1334- // device cameras record videos with type=nclx without this final flag (and therefore
1335- // size=18): https://github.com/google/ExoPlayer/issues/9332
1336- boolean fullRangeFlag =
1337- childAtomSize == 19 && (parent .readUnsignedByte () & 0b10000000) != 0 ;
1338- colorSpace = ColorInfo .isoColorPrimariesToColorSpace (colorPrimaries );
1339- colorRange = fullRangeFlag ? C .COLOR_RANGE_FULL : C .COLOR_RANGE_LIMITED ;
1340- colorTransfer =
1341- ColorInfo .isoTransferCharacteristicsToColorTransfer (transferCharacteristics );
1342- } else {
1343- Log .w (TAG , "Unsupported color type: " + Atom .getAtomTypeString (colorType ));
1312+ // Only modify these values if they have not been previously established by the bitstream.
1313+ // If 'Atom.TYPE_hvcC' atom or 'Atom.TYPE_vpcC' is available, they will take precedence and
1314+ // overwrite any existing values.
1315+ if (colorSpace == Format .NO_VALUE
1316+ && colorRange == Format .NO_VALUE
1317+ && colorTransfer == Format .NO_VALUE ) {
1318+ int colorType = parent .readInt ();
1319+ if (colorType == TYPE_nclx || colorType == TYPE_nclc ) {
1320+ // For more info on syntax, see Section 8.5.2.2 in ISO/IEC 14496-12:2012(E) and
1321+ // https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html.
1322+ int colorPrimaries = parent .readUnsignedShort ();
1323+ int transferCharacteristics = parent .readUnsignedShort ();
1324+ parent .skipBytes (2 ); // matrix_coefficients.
1325+
1326+ // Only try and read full_range_flag if the box is long enough. It should be present in
1327+ // all colr boxes with type=nclx (Section 8.5.2.2 in ISO/IEC 14496-12:2012(E)) but some
1328+ // device cameras record videos with type=nclx without this final flag (and therefore
1329+ // size=18): https://github.com/google/ExoPlayer/issues/9332
1330+ boolean fullRangeFlag =
1331+ childAtomSize == 19 && (parent .readUnsignedByte () & 0b10000000) != 0 ;
1332+ colorSpace = ColorInfo .isoColorPrimariesToColorSpace (colorPrimaries );
1333+ colorRange = fullRangeFlag ? C .COLOR_RANGE_FULL : C .COLOR_RANGE_LIMITED ;
1334+ colorTransfer =
1335+ ColorInfo .isoTransferCharacteristicsToColorTransfer (transferCharacteristics );
1336+ } else {
1337+ Log .w (TAG , "Unsupported color type: " + Atom .getAtomTypeString (colorType ));
1338+ }
13441339 }
13451340 }
13461341 childPosition += childAtomSize ;
0 commit comments