Skip to content

Commit 009d48a

Browse files
Merge pull request androidx#491 from v-novaltd:dsparano-exo128
PiperOrigin-RevId: 574129451
2 parents dc0bee9 + 7162407 commit 009d48a

File tree

143 files changed

+642
-71
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+642
-71
lines changed

RELEASENOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
* Common Library:
66
* ExoPlayer:
7+
* Add luma and chroma bitdepth to `ColorInfo`
8+
[#491](https://github.com/androidx/media/pull/491).
79
* Transformer:
810
* Track Selection:
911
* Add `DefaultTrackSelector.Parameters.allowAudioNonSeamlessAdaptiveness`

libraries/common/src/main/java/androidx/media3/common/ColorInfo.java

Lines changed: 133 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ public static final class Builder {
4343
private @C.ColorRange int colorRange;
4444
private @C.ColorTransfer int colorTransfer;
4545
@Nullable private byte[] hdrStaticInfo;
46+
private int lumaBitdepth;
47+
private int chromaBitdepth;
4648

4749
/** Creates a new instance with default values. */
4850
public Builder() {
4951
colorSpace = Format.NO_VALUE;
5052
colorRange = Format.NO_VALUE;
5153
colorTransfer = Format.NO_VALUE;
54+
lumaBitdepth = Format.NO_VALUE;
55+
chromaBitdepth = Format.NO_VALUE;
5256
}
5357

5458
/** Creates a new instance to build upon the provided {@link ColorInfo}. */
@@ -57,6 +61,8 @@ private Builder(ColorInfo colorInfo) {
5761
this.colorRange = colorInfo.colorRange;
5862
this.colorTransfer = colorInfo.colorTransfer;
5963
this.hdrStaticInfo = colorInfo.hdrStaticInfo;
64+
this.lumaBitdepth = colorInfo.lumaBitdepth;
65+
this.chromaBitdepth = colorInfo.chromaBitdepth;
6066
}
6167

6268
/**
@@ -116,19 +122,44 @@ public Builder setHdrStaticInfo(@Nullable byte[] hdrStaticInfo) {
116122
return this;
117123
}
118124

125+
/**
126+
* Sets the luma bit depth.
127+
*
128+
* @param lumaBitdepth The lumaBitdepth. The default value is {@link Format#NO_VALUE}.
129+
* @return The builder.
130+
*/
131+
@CanIgnoreReturnValue
132+
public Builder setLumaBitdepth(int lumaBitdepth) {
133+
this.lumaBitdepth = lumaBitdepth;
134+
return this;
135+
}
136+
137+
/**
138+
* Sets chroma bit depth.
139+
*
140+
* @param chromaBitdepth The chromaBitdepth. The default value is {@link Format#NO_VALUE}.
141+
* @return The builder.
142+
*/
143+
@CanIgnoreReturnValue
144+
public Builder setChromaBitdepth(int chromaBitdepth) {
145+
this.chromaBitdepth = chromaBitdepth;
146+
return this;
147+
}
148+
119149
/** Builds a new {@link ColorInfo} instance. */
120150
public ColorInfo build() {
121-
return new ColorInfo(colorSpace, colorRange, colorTransfer, hdrStaticInfo);
151+
return new ColorInfo(
152+
colorSpace, colorRange, colorTransfer, hdrStaticInfo, lumaBitdepth, chromaBitdepth);
122153
}
123154
}
124155

125156
/** Color info representing SDR BT.709 limited range, which is a common SDR video color format. */
126157
public static final ColorInfo SDR_BT709_LIMITED =
127-
new ColorInfo(
128-
C.COLOR_SPACE_BT709,
129-
C.COLOR_RANGE_LIMITED,
130-
C.COLOR_TRANSFER_SDR,
131-
/* hdrStaticInfo= */ null);
158+
new ColorInfo.Builder()
159+
.setColorSpace(C.COLOR_SPACE_BT709)
160+
.setColorRange(C.COLOR_RANGE_LIMITED)
161+
.setColorTransfer(C.COLOR_TRANSFER_SDR)
162+
.build();
132163

133164
/**
134165
* Color info representing SDR sRGB in accordance with {@link
@@ -213,6 +244,12 @@ public static boolean isTransferHdr(@Nullable ColorInfo colorInfo) {
213244
/** HdrStaticInfo as defined in CTA-861.3, or null if none specified. */
214245
@Nullable public final byte[] hdrStaticInfo;
215246

247+
/** The bit depth of the luma samples of the video. */
248+
public final int lumaBitdepth;
249+
250+
/** The bit depth of the chroma samples of the video. It may differ from the luma bit depth. */
251+
public final int chromaBitdepth;
252+
216253
// Lazily initialized hashcode.
217254
private int hashCode;
218255

@@ -231,10 +268,34 @@ public ColorInfo(
231268
@C.ColorRange int colorRange,
232269
@C.ColorTransfer int colorTransfer,
233270
@Nullable byte[] hdrStaticInfo) {
271+
this(colorSpace, colorRange, colorTransfer, hdrStaticInfo, Format.NO_VALUE, Format.NO_VALUE);
272+
}
273+
274+
/**
275+
* Constructs the ColorInfo.
276+
*
277+
* @param colorSpace The color space of the video.
278+
* @param colorRange The color range of the video.
279+
* @param colorTransfer The color transfer characteristics of the video.
280+
* @param hdrStaticInfo HdrStaticInfo as defined in CTA-861.3, or null if none specified.
281+
* @param lumaBitdepth The bit depth of the luma samples of the video.
282+
* @param chromaBitdepth The bit depth of the chroma samples of the video.
283+
* @deprecated Use {@link Builder}.
284+
*/
285+
@Deprecated
286+
public ColorInfo(
287+
@C.ColorSpace int colorSpace,
288+
@C.ColorRange int colorRange,
289+
@C.ColorTransfer int colorTransfer,
290+
@Nullable byte[] hdrStaticInfo,
291+
int lumaBitdepth,
292+
int chromaBitdepth) {
234293
this.colorSpace = colorSpace;
235294
this.colorRange = colorRange;
236295
this.colorTransfer = colorTransfer;
237296
this.hdrStaticInfo = hdrStaticInfo;
297+
this.lumaBitdepth = lumaBitdepth;
298+
this.chromaBitdepth = chromaBitdepth;
238299
}
239300

240301
/** Returns a {@link Builder} initialized with the values of this instance. */
@@ -245,9 +306,27 @@ public Builder buildUpon() {
245306
/**
246307
* Returns whether this instance is valid.
247308
*
248-
* <p>This instance is valid if no members are {@link Format#NO_VALUE}.
309+
* <p>This instance is valid if at least one between bitdepths and DataSpace info are valid.
249310
*/
250311
public boolean isValid() {
312+
return isBitdepthValid() || isDataSpaceValid();
313+
}
314+
315+
/**
316+
* Returns whether this instance has valid bitdepths.
317+
*
318+
* <p>This instance has valid bitdepths if none of them is {@link Format#NO_VALUE}.
319+
*/
320+
public boolean isBitdepthValid() {
321+
return lumaBitdepth != Format.NO_VALUE && chromaBitdepth != Format.NO_VALUE;
322+
}
323+
324+
/**
325+
* Returns whether this instance has valid DataSpace members.
326+
*
327+
* <p>This instance is valid if no DataSpace members are {@link Format#NO_VALUE}.
328+
*/
329+
public boolean isDataSpaceValid() {
251330
return colorSpace != Format.NO_VALUE
252331
&& colorRange != Format.NO_VALUE
253332
&& colorTransfer != Format.NO_VALUE;
@@ -259,15 +338,16 @@ public boolean isValid() {
259338
* @see Format#toLogString(Format)
260339
*/
261340
public String toLogString() {
262-
if (!isValid()) {
263-
return "NA";
264-
}
265-
266-
return Util.formatInvariant(
267-
"%s/%s/%s",
268-
colorSpaceToString(colorSpace),
269-
colorRangeToString(colorRange),
270-
colorTransferToString(colorTransfer));
341+
String dataspaceString =
342+
isDataSpaceValid()
343+
? Util.formatInvariant(
344+
"%s/%s/%s",
345+
colorSpaceToString(colorSpace),
346+
colorRangeToString(colorRange),
347+
colorTransferToString(colorTransfer))
348+
: "NA/NA/NA";
349+
String bitdepthsString = isBitdepthValid() ? lumaBitdepth + "/" + chromaBitdepth : "NA/NA";
350+
return dataspaceString + "/" + bitdepthsString;
271351
}
272352

273353
@Override
@@ -282,7 +362,24 @@ public boolean equals(@Nullable Object obj) {
282362
return colorSpace == other.colorSpace
283363
&& colorRange == other.colorRange
284364
&& colorTransfer == other.colorTransfer
285-
&& Arrays.equals(hdrStaticInfo, other.hdrStaticInfo);
365+
&& Arrays.equals(hdrStaticInfo, other.hdrStaticInfo)
366+
&& lumaBitdepth == other.lumaBitdepth
367+
&& chromaBitdepth == other.chromaBitdepth;
368+
}
369+
370+
@Override
371+
public int hashCode() {
372+
if (hashCode == 0) {
373+
int result = 17;
374+
result = 31 * result + colorSpace;
375+
result = 31 * result + colorRange;
376+
result = 31 * result + colorTransfer;
377+
result = 31 * result + Arrays.hashCode(hdrStaticInfo);
378+
result = 31 * result + lumaBitdepth;
379+
result = 31 * result + chromaBitdepth;
380+
hashCode = result;
381+
}
382+
return hashCode;
286383
}
287384

288385
@Override
@@ -295,9 +392,21 @@ public String toString() {
295392
+ colorTransferToString(colorTransfer)
296393
+ ", "
297394
+ (hdrStaticInfo != null)
395+
+ ", "
396+
+ lumaBitdepthToString(lumaBitdepth)
397+
+ ", "
398+
+ chromaBitdepthToString(chromaBitdepth)
298399
+ ")";
299400
}
300401

402+
private static String lumaBitdepthToString(int val) {
403+
return val != Format.NO_VALUE ? val + "bit Luma" : "NA";
404+
}
405+
406+
private static String chromaBitdepthToString(int val) {
407+
return val != Format.NO_VALUE ? val + "bit Chroma" : "NA";
408+
}
409+
301410
private static String colorSpaceToString(@C.ColorSpace int colorSpace) {
302411
// LINT.IfChange(color_space)
303412
switch (colorSpace) {
@@ -350,25 +459,14 @@ private static String colorRangeToString(@C.ColorRange int colorRange) {
350459
}
351460
}
352461

353-
@Override
354-
public int hashCode() {
355-
if (hashCode == 0) {
356-
int result = 17;
357-
result = 31 * result + colorSpace;
358-
result = 31 * result + colorRange;
359-
result = 31 * result + colorTransfer;
360-
result = 31 * result + Arrays.hashCode(hdrStaticInfo);
361-
hashCode = result;
362-
}
363-
return hashCode;
364-
}
365-
366462
// Bundleable implementation
367463

368464
private static final String FIELD_COLOR_SPACE = Util.intToStringMaxRadix(0);
369465
private static final String FIELD_COLOR_RANGE = Util.intToStringMaxRadix(1);
370466
private static final String FIELD_COLOR_TRANSFER = Util.intToStringMaxRadix(2);
371467
private static final String FIELD_HDR_STATIC_INFO = Util.intToStringMaxRadix(3);
468+
private static final String FIELD_LUMA_BITDEPTH = Util.intToStringMaxRadix(4);
469+
private static final String FIELD_CHROMA_BITDEPTH = Util.intToStringMaxRadix(5);
372470

373471
@Override
374472
public Bundle toBundle() {
@@ -377,6 +475,8 @@ public Bundle toBundle() {
377475
bundle.putInt(FIELD_COLOR_RANGE, colorRange);
378476
bundle.putInt(FIELD_COLOR_TRANSFER, colorTransfer);
379477
bundle.putByteArray(FIELD_HDR_STATIC_INFO, hdrStaticInfo);
478+
bundle.putInt(FIELD_LUMA_BITDEPTH, lumaBitdepth);
479+
bundle.putInt(FIELD_CHROMA_BITDEPTH, chromaBitdepth);
380480
return bundle;
381481
}
382482

@@ -386,5 +486,7 @@ public Bundle toBundle() {
386486
bundle.getInt(FIELD_COLOR_SPACE, Format.NO_VALUE),
387487
bundle.getInt(FIELD_COLOR_RANGE, Format.NO_VALUE),
388488
bundle.getInt(FIELD_COLOR_TRANSFER, Format.NO_VALUE),
389-
bundle.getByteArray(FIELD_HDR_STATIC_INFO));
489+
bundle.getByteArray(FIELD_HDR_STATIC_INFO),
490+
bundle.getInt(FIELD_LUMA_BITDEPTH, Format.NO_VALUE),
491+
bundle.getInt(FIELD_CHROMA_BITDEPTH, Format.NO_VALUE));
390492
}

libraries/common/src/test/java/androidx/media3/common/FormatTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ private static Format createTestFormat() {
7878
C.COLOR_SPACE_BT709,
7979
C.COLOR_RANGE_LIMITED,
8080
C.COLOR_TRANSFER_SDR,
81-
new byte[] {1, 2, 3, 4, 5, 6, 7});
81+
new byte[] {1, 2, 3, 4, 5, 6, 7},
82+
/* lumaBitdepth */ 9,
83+
/* chromaBitdepth */ 11);
8284

8385
return new Format.Builder()
8486
.setId("id")

libraries/common/src/test/java/androidx/media3/common/util/MediaFormatUtilTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,12 @@ public void createMediaFormatFromFormat_withPopulatedFormat_generatesExpectedEnt
150150
.setAverageBitrate(1)
151151
.setChannelCount(2)
152152
.setColorInfo(
153-
new ColorInfo(
154-
/* colorSpace= */ C.COLOR_SPACE_BT601,
155-
/* colorRange= */ C.COLOR_RANGE_FULL,
156-
/* colorTransfer= */ C.COLOR_TRANSFER_HLG,
157-
new byte[] {3}))
153+
new ColorInfo.Builder()
154+
.setColorSpace(C.COLOR_SPACE_BT601)
155+
.setColorRange(C.COLOR_RANGE_FULL)
156+
.setColorTransfer(C.COLOR_TRANSFER_HLG)
157+
.setHdrStaticInfo(new byte[] {3})
158+
.build())
158159
.setSampleMimeType(MimeTypes.VIDEO_H264)
159160
.setCodecs("avc.123")
160161
.setFrameRate(4)

libraries/container/src/main/java/androidx/media3/container/NalUnitUtil.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public static final class SpsData {
6666
public final int width;
6767
public final int height;
6868
public final float pixelWidthHeightRatio;
69+
public final int bitDepthLumaMinus8;
70+
public final int bitDepthChromaMinus8;
6971
public final boolean separateColorPlaneFlag;
7072
public final boolean frameMbsOnlyFlag;
7173
public final int frameNumLength;
@@ -85,6 +87,8 @@ public SpsData(
8587
int width,
8688
int height,
8789
float pixelWidthHeightRatio,
90+
int bitDepthLumaMinus8,
91+
int bitDepthChromaMinus8,
8892
boolean separateColorPlaneFlag,
8993
boolean frameMbsOnlyFlag,
9094
int frameNumLength,
@@ -102,6 +106,8 @@ public SpsData(
102106
this.width = width;
103107
this.height = height;
104108
this.pixelWidthHeightRatio = pixelWidthHeightRatio;
109+
this.bitDepthLumaMinus8 = bitDepthLumaMinus8;
110+
this.bitDepthChromaMinus8 = bitDepthChromaMinus8;
105111
this.separateColorPlaneFlag = separateColorPlaneFlag;
106112
this.frameMbsOnlyFlag = frameMbsOnlyFlag;
107113
this.frameNumLength = frameNumLength;
@@ -382,6 +388,8 @@ public static SpsData parseSpsNalUnitPayload(byte[] nalData, int nalOffset, int
382388

383389
int chromaFormatIdc = 1; // Default is 4:2:0
384390
boolean separateColorPlaneFlag = false;
391+
int bitDepthLumaMinus8 = 0;
392+
int bitDepthChromaMinus8 = 0;
385393
if (profileIdc == 100
386394
|| profileIdc == 110
387395
|| profileIdc == 122
@@ -396,8 +404,8 @@ public static SpsData parseSpsNalUnitPayload(byte[] nalData, int nalOffset, int
396404
if (chromaFormatIdc == 3) {
397405
separateColorPlaneFlag = data.readBit();
398406
}
399-
data.readUnsignedExpGolombCodedInt(); // bit_depth_luma_minus8
400-
data.readUnsignedExpGolombCodedInt(); // bit_depth_chroma_minus8
407+
bitDepthLumaMinus8 = data.readUnsignedExpGolombCodedInt();
408+
bitDepthChromaMinus8 = data.readUnsignedExpGolombCodedInt();
401409
data.skipBit(); // qpprime_y_zero_transform_bypass_flag
402410
boolean seqScalingMatrixPresentFlag = data.readBit();
403411
if (seqScalingMatrixPresentFlag) {
@@ -511,6 +519,8 @@ public static SpsData parseSpsNalUnitPayload(byte[] nalData, int nalOffset, int
511519
frameWidth,
512520
frameHeight,
513521
pixelWidthHeightRatio,
522+
bitDepthLumaMinus8,
523+
bitDepthChromaMinus8,
514524
separateColorPlaneFlag,
515525
frameMbsOnlyFlag,
516526
frameNumLength,

libraries/effect/src/main/java/androidx/media3/effect/DefaultVideoFrameProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ public DefaultVideoFrameProcessor create(
253253
throws VideoFrameProcessingException {
254254
// TODO(b/261188041) Add tests to verify the Listener is invoked on the given Executor.
255255

256-
checkArgument(inputColorInfo.isValid());
256+
checkArgument(inputColorInfo.isDataSpaceValid());
257257
checkArgument(inputColorInfo.colorTransfer != C.COLOR_TRANSFER_LINEAR);
258-
checkArgument(outputColorInfo.isValid());
258+
checkArgument(outputColorInfo.isDataSpaceValid());
259259
checkArgument(outputColorInfo.colorTransfer != C.COLOR_TRANSFER_LINEAR);
260260
if (ColorInfo.isTransferHdr(inputColorInfo) || ColorInfo.isTransferHdr(outputColorInfo)) {
261261
checkArgument(enableColorTransfers);

libraries/exoplayer/src/test/java/androidx/media3/exoplayer/mediacodec/MediaCodecInfoTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,10 @@ private static MediaCodecInfo buildAacCodecInfo() {
430430
}
431431

432432
private static ColorInfo buildColorInfo(@C.ColorSpace int colorSpace) {
433-
return new ColorInfo(
434-
colorSpace, C.COLOR_RANGE_FULL, C.COLOR_TRANSFER_HLG, /* hdrStaticInfo= */ null);
433+
return new ColorInfo.Builder()
434+
.setColorSpace(colorSpace)
435+
.setColorRange(C.COLOR_RANGE_FULL)
436+
.setColorTransfer(C.COLOR_TRANSFER_HLG)
437+
.build();
435438
}
436439
}

0 commit comments

Comments
 (0)