Move luma and chroma bitdepths to ColorInfo class

This commit is contained in:
Daniele Sparano 2023-07-27 14:51:47 +01:00 committed by microkatz
parent 59ff0dbb85
commit f8d98861ea
9 changed files with 144 additions and 116 deletions

View file

@ -43,12 +43,16 @@ public final class ColorInfo implements Bundleable {
private @C.ColorRange int colorRange; private @C.ColorRange int colorRange;
private @C.ColorTransfer int colorTransfer; private @C.ColorTransfer int colorTransfer;
@Nullable private byte[] hdrStaticInfo; @Nullable private byte[] hdrStaticInfo;
private int lumaBitdepth;
private int chromaBitdepth;
/** Creates a new instance with default values. */ /** Creates a new instance with default values. */
public Builder() { public Builder() {
colorSpace = Format.NO_VALUE; colorSpace = Format.NO_VALUE;
colorRange = Format.NO_VALUE; colorRange = Format.NO_VALUE;
colorTransfer = Format.NO_VALUE; colorTransfer = Format.NO_VALUE;
lumaBitdepth = Format.NO_VALUE;
chromaBitdepth = Format.NO_VALUE;
} }
/** Creates a new instance to build upon the provided {@link ColorInfo}. */ /** Creates a new instance to build upon the provided {@link ColorInfo}. */
@ -57,6 +61,8 @@ public final class ColorInfo implements Bundleable {
this.colorRange = colorInfo.colorRange; this.colorRange = colorInfo.colorRange;
this.colorTransfer = colorInfo.colorTransfer; this.colorTransfer = colorInfo.colorTransfer;
this.hdrStaticInfo = colorInfo.hdrStaticInfo; this.hdrStaticInfo = colorInfo.hdrStaticInfo;
this.lumaBitdepth = colorInfo.lumaBitdepth;
this.chromaBitdepth = colorInfo.chromaBitdepth;
} }
/** /**
@ -116,19 +122,43 @@ public final class ColorInfo implements Bundleable {
return this; return this;
} }
/**
* Sets the luma bit depth.
*
* @param lumaBitdepth The lumaBitdepth. The default value is {@link Format#NO_VALUE}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setLumaBitdepth(int lumaBitdepth) {
this.lumaBitdepth = lumaBitdepth;
return this;
}
/**
* Sets chroma bit depth.
*
* @param chromaBitdepth The chromaBitdepth. The default value is {@link Format#NO_VALUE}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setChromaBitdepth(int chromaBitdepth) {
this.chromaBitdepth = chromaBitdepth;
return this;
}
/** Builds a new {@link ColorInfo} instance. */ /** Builds a new {@link ColorInfo} instance. */
public ColorInfo build() { public ColorInfo build() {
return new ColorInfo(colorSpace, colorRange, colorTransfer, hdrStaticInfo); return new ColorInfo(colorSpace, colorRange, colorTransfer, hdrStaticInfo, lumaBitdepth, chromaBitdepth);
} }
} }
/** Color info representing SDR BT.709 limited range, which is a common SDR video color format. */ /** Color info representing SDR BT.709 limited range, which is a common SDR video color format. */
public static final ColorInfo SDR_BT709_LIMITED = public static final ColorInfo SDR_BT709_LIMITED =
new ColorInfo( new ColorInfo.Builder()
C.COLOR_SPACE_BT709, .setColorSpace(C.COLOR_SPACE_BT709)
C.COLOR_RANGE_LIMITED, .setColorRange(C.COLOR_RANGE_LIMITED)
C.COLOR_TRANSFER_SDR, .setColorTransfer(C.COLOR_TRANSFER_SDR)
/* hdrStaticInfo= */ null); .build();
/** /**
* Color info representing SDR sRGB in accordance with {@link * Color info representing SDR sRGB in accordance with {@link
@ -213,6 +243,11 @@ public final class ColorInfo implements Bundleable {
/** HdrStaticInfo as defined in CTA-861.3, or null if none specified. */ /** HdrStaticInfo as defined in CTA-861.3, or null if none specified. */
@Nullable public final byte[] hdrStaticInfo; @Nullable public final byte[] hdrStaticInfo;
/** The bit depth of the luma samples of the video. */
public final int lumaBitdepth;
/** The bit depth of the chroma samples of the video. It may differ from the luma bit depth. */
public final int chromaBitdepth;
// Lazily initialized hashcode. // Lazily initialized hashcode.
private int hashCode; private int hashCode;
@ -223,6 +258,8 @@ public final class ColorInfo implements Bundleable {
* @param colorRange The color range of the video. * @param colorRange The color range of the video.
* @param colorTransfer The color transfer characteristics of the video. * @param colorTransfer The color transfer characteristics of the video.
* @param hdrStaticInfo HdrStaticInfo as defined in CTA-861.3, or null if none specified. * @param hdrStaticInfo HdrStaticInfo as defined in CTA-861.3, or null if none specified.
* @param lumaBitdepth The bit depth of the luma samples of the video.
* @param chromaBitdepth The bit depth of the chroma samples of the video.
* @deprecated Use {@link Builder}. * @deprecated Use {@link Builder}.
*/ */
@Deprecated @Deprecated
@ -230,11 +267,15 @@ public final class ColorInfo implements Bundleable {
@C.ColorSpace int colorSpace, @C.ColorSpace int colorSpace,
@C.ColorRange int colorRange, @C.ColorRange int colorRange,
@C.ColorTransfer int colorTransfer, @C.ColorTransfer int colorTransfer,
@Nullable byte[] hdrStaticInfo) { @Nullable byte[] hdrStaticInfo,
int lumaBitdepth,
int chromaBitdepth) {
this.colorSpace = colorSpace; this.colorSpace = colorSpace;
this.colorRange = colorRange; this.colorRange = colorRange;
this.colorTransfer = colorTransfer; this.colorTransfer = colorTransfer;
this.hdrStaticInfo = hdrStaticInfo; this.hdrStaticInfo = hdrStaticInfo;
this.lumaBitdepth = lumaBitdepth;
this.chromaBitdepth = chromaBitdepth;
} }
/** Returns a {@link Builder} initialized with the values of this instance. */ /** Returns a {@link Builder} initialized with the values of this instance. */
@ -245,7 +286,8 @@ public final class ColorInfo implements Bundleable {
/** /**
* Returns whether this instance is valid. * Returns whether this instance is valid.
* *
* <p>This instance is valid if no members are {@link Format#NO_VALUE}. * <p>This instance is valid if no color members are {@link Format#NO_VALUE},
* while bit depths may be unset.
*/ */
public boolean isValid() { public boolean isValid() {
return colorSpace != Format.NO_VALUE return colorSpace != Format.NO_VALUE
@ -258,7 +300,7 @@ public final class ColorInfo implements Bundleable {
* *
* @see Format#toLogString(Format) * @see Format#toLogString(Format)
*/ */
public String toLogString() { public String toColorString() {
if (!isValid()) { if (!isValid()) {
return "NA"; return "NA";
} }
@ -270,6 +312,20 @@ public final class ColorInfo implements Bundleable {
colorTransferToString(colorTransfer)); colorTransferToString(colorTransfer));
} }
/**
* Returns whether this instance has valid bitdepths.
*
* <p>This instance has valid bitdepths if none of them is {@link Format#NO_VALUE}.
*/
public boolean isBppValid() {
return lumaBitdepth != Format.NO_VALUE
&& chromaBitdepth != Format.NO_VALUE;
}
public String toBppString() {
return isBppValid() ? lumaBitdepth + "," + chromaBitdepth : "NA";
}
@Override @Override
public boolean equals(@Nullable Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
@ -282,12 +338,18 @@ public final class ColorInfo implements Bundleable {
return colorSpace == other.colorSpace return colorSpace == other.colorSpace
&& colorRange == other.colorRange && colorRange == other.colorRange
&& colorTransfer == other.colorTransfer && colorTransfer == other.colorTransfer
&& Arrays.equals(hdrStaticInfo, other.hdrStaticInfo); && Arrays.equals(hdrStaticInfo, other.hdrStaticInfo)
&& lumaBitdepth == other.lumaBitdepth
&& chromaBitdepth == other.chromaBitdepth;
} }
@Override @Override
public String toString() { public String toString() {
return "ColorInfo(" return "ColorInfo("
+ lumaBitdepth
+ ", "
+ chromaBitdepth
+ ", "
+ colorSpaceToString(colorSpace) + colorSpaceToString(colorSpace)
+ ", " + ", "
+ colorRangeToString(colorRange) + colorRangeToString(colorRange)
@ -358,6 +420,8 @@ public final class ColorInfo implements Bundleable {
result = 31 * result + colorRange; result = 31 * result + colorRange;
result = 31 * result + colorTransfer; result = 31 * result + colorTransfer;
result = 31 * result + Arrays.hashCode(hdrStaticInfo); result = 31 * result + Arrays.hashCode(hdrStaticInfo);
result = 31 * result + lumaBitdepth;
result = 31 * result + chromaBitdepth;
hashCode = result; hashCode = result;
} }
return hashCode; return hashCode;
@ -369,6 +433,8 @@ public final class ColorInfo implements Bundleable {
private static final String FIELD_COLOR_RANGE = Util.intToStringMaxRadix(1); private static final String FIELD_COLOR_RANGE = Util.intToStringMaxRadix(1);
private static final String FIELD_COLOR_TRANSFER = Util.intToStringMaxRadix(2); private static final String FIELD_COLOR_TRANSFER = Util.intToStringMaxRadix(2);
private static final String FIELD_HDR_STATIC_INFO = Util.intToStringMaxRadix(3); private static final String FIELD_HDR_STATIC_INFO = Util.intToStringMaxRadix(3);
private static final String FIELD_LUMA_BITDEPTH = Util.intToStringMaxRadix(4);
private static final String FIELD_CHROMA_BITDEPTH = Util.intToStringMaxRadix(5);
@Override @Override
public Bundle toBundle() { public Bundle toBundle() {
@ -377,6 +443,8 @@ public final class ColorInfo implements Bundleable {
bundle.putInt(FIELD_COLOR_RANGE, colorRange); bundle.putInt(FIELD_COLOR_RANGE, colorRange);
bundle.putInt(FIELD_COLOR_TRANSFER, colorTransfer); bundle.putInt(FIELD_COLOR_TRANSFER, colorTransfer);
bundle.putByteArray(FIELD_HDR_STATIC_INFO, hdrStaticInfo); bundle.putByteArray(FIELD_HDR_STATIC_INFO, hdrStaticInfo);
bundle.putInt(FIELD_LUMA_BITDEPTH, lumaBitdepth);
bundle.putInt(FIELD_CHROMA_BITDEPTH, chromaBitdepth);
return bundle; return bundle;
} }
@ -386,5 +454,7 @@ public final class ColorInfo implements Bundleable {
bundle.getInt(FIELD_COLOR_SPACE, Format.NO_VALUE), bundle.getInt(FIELD_COLOR_SPACE, Format.NO_VALUE),
bundle.getInt(FIELD_COLOR_RANGE, Format.NO_VALUE), bundle.getInt(FIELD_COLOR_RANGE, Format.NO_VALUE),
bundle.getInt(FIELD_COLOR_TRANSFER, Format.NO_VALUE), bundle.getInt(FIELD_COLOR_TRANSFER, Format.NO_VALUE),
bundle.getByteArray(FIELD_HDR_STATIC_INFO)); bundle.getByteArray(FIELD_HDR_STATIC_INFO),
bundle.getInt(FIELD_LUMA_BITDEPTH, Format.NO_VALUE),
bundle.getInt(FIELD_CHROMA_BITDEPTH, Format.NO_VALUE));
} }

View file

@ -96,8 +96,6 @@ import java.util.UUID;
* <li>{@link #projectionData} * <li>{@link #projectionData}
* <li>{@link #stereoMode} * <li>{@link #stereoMode}
* <li>{@link #colorInfo} * <li>{@link #colorInfo}
* <li>{@link #lumaBitdepth}
* <li>{@link #chromaBitdepth}
* </ul> * </ul>
* *
* <h2 id="audio-formats">Fields relevant to audio formats</h2> * <h2 id="audio-formats">Fields relevant to audio formats</h2>
@ -169,8 +167,6 @@ public final class Format implements Bundleable {
@Nullable private byte[] projectionData; @Nullable private byte[] projectionData;
private @C.StereoMode int stereoMode; private @C.StereoMode int stereoMode;
@Nullable private ColorInfo colorInfo; @Nullable private ColorInfo colorInfo;
private int lumaBitdepth;
private int chromaBitdepth;
// Audio specific. // Audio specific.
@ -207,8 +203,6 @@ public final class Format implements Bundleable {
frameRate = NO_VALUE; frameRate = NO_VALUE;
pixelWidthHeightRatio = 1.0f; pixelWidthHeightRatio = 1.0f;
stereoMode = NO_VALUE; stereoMode = NO_VALUE;
lumaBitdepth = 8;
chromaBitdepth = 8;
// Audio specific. // Audio specific.
channelCount = NO_VALUE; channelCount = NO_VALUE;
sampleRate = NO_VALUE; sampleRate = NO_VALUE;
@ -255,8 +249,6 @@ public final class Format implements Bundleable {
this.projectionData = format.projectionData; this.projectionData = format.projectionData;
this.stereoMode = format.stereoMode; this.stereoMode = format.stereoMode;
this.colorInfo = format.colorInfo; this.colorInfo = format.colorInfo;
this.lumaBitdepth = format.lumaBitdepth;
this.chromaBitdepth = format.chromaBitdepth;
// Audio specific. // Audio specific.
this.channelCount = format.channelCount; this.channelCount = format.channelCount;
this.sampleRate = format.sampleRate; this.sampleRate = format.sampleRate;
@ -568,30 +560,6 @@ public final class Format implements Bundleable {
return this; return this;
} }
/**
* Sets {@link Format#lumaBitdepth}. The default value is 8.
*
* @param lumaBitdepth The {@link Format#lumaBitdepth}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setLumaBitdepth(int lumaBitdepth) {
this.lumaBitdepth = lumaBitdepth;
return this;
}
/**
* Sets {@link Format#chromaBitdepth}. The default value is 8.
*
* @param chromaBitdepth The {@link Format#chromaBitdepth}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setChromaBitdepth(int chromaBitdepth) {
this.chromaBitdepth = chromaBitdepth;
return this;
}
// Audio specific. // Audio specific.
/** /**
@ -904,10 +872,6 @@ public final class Format implements Bundleable {
/** The color metadata associated with the video, or null if not applicable. */ /** The color metadata associated with the video, or null if not applicable. */
@UnstableApi @Nullable public final ColorInfo colorInfo; @UnstableApi @Nullable public final ColorInfo colorInfo;
/** The bit depth of the luma samples of the video. */
public final int lumaBitdepth;
/** The bit depth of the chroma samples of the video. It might differ from the luma bit depth. */
public final int chromaBitdepth;
// Audio specific. // Audio specific.
@ -995,8 +959,6 @@ public final class Format implements Bundleable {
projectionData = builder.projectionData; projectionData = builder.projectionData;
stereoMode = builder.stereoMode; stereoMode = builder.stereoMode;
colorInfo = builder.colorInfo; colorInfo = builder.colorInfo;
lumaBitdepth = builder.lumaBitdepth;
chromaBitdepth = builder.chromaBitdepth;
// Audio specific. // Audio specific.
channelCount = builder.channelCount; channelCount = builder.channelCount;
sampleRate = builder.sampleRate; sampleRate = builder.sampleRate;
@ -1130,10 +1092,6 @@ public final class Format implements Bundleable {
+ ", " + ", "
+ frameRate + frameRate
+ ", " + ", "
+ lumaBitdepth
+ ", "
+ chromaBitdepth
+ ", "
+ colorInfo + colorInfo
+ "]" + "]"
+ ", [" + ", ["
@ -1174,8 +1132,6 @@ public final class Format implements Bundleable {
// [Omitted] projectionData. // [Omitted] projectionData.
result = 31 * result + stereoMode; result = 31 * result + stereoMode;
// [Omitted] colorInfo. // [Omitted] colorInfo.
result = 31 * result + lumaBitdepth;
result = 31 * result + chromaBitdepth;
// Audio specific. // Audio specific.
result = 31 * result + channelCount; result = 31 * result + channelCount;
result = 31 * result + sampleRate; result = 31 * result + sampleRate;
@ -1217,8 +1173,6 @@ public final class Format implements Bundleable {
&& height == other.height && height == other.height
&& rotationDegrees == other.rotationDegrees && rotationDegrees == other.rotationDegrees
&& stereoMode == other.stereoMode && stereoMode == other.stereoMode
&& lumaBitdepth == other.lumaBitdepth
&& chromaBitdepth == other.chromaBitdepth
&& channelCount == other.channelCount && channelCount == other.channelCount
&& sampleRate == other.sampleRate && sampleRate == other.sampleRate
&& pcmEncoding == other.pcmEncoding && pcmEncoding == other.pcmEncoding
@ -1305,11 +1259,8 @@ public final class Format implements Bundleable {
if (format.width != NO_VALUE && format.height != NO_VALUE) { if (format.width != NO_VALUE && format.height != NO_VALUE) {
builder.append(", res=").append(format.width).append("x").append(format.height); builder.append(", res=").append(format.width).append("x").append(format.height);
} }
if (format.lumaBitdepth != NO_VALUE && format.chromaBitdepth != NO_VALUE) {
builder.append(", bitdepth=[").append(format.lumaBitdepth).append(",").append(format.chromaBitdepth).append(']');
}
if (format.colorInfo != null && format.colorInfo.isValid()) { if (format.colorInfo != null && format.colorInfo.isValid()) {
builder.append(", color=").append(format.colorInfo.toLogString()); builder.append(", color=").append(format.colorInfo.toColorString());
} }
if (format.frameRate != NO_VALUE) { if (format.frameRate != NO_VALUE) {
builder.append(", fps=").append(format.frameRate); builder.append(", fps=").append(format.frameRate);
@ -1422,17 +1373,15 @@ public final class Format implements Bundleable {
private static final String FIELD_PROJECTION_DATA = Util.intToStringMaxRadix(20); private static final String FIELD_PROJECTION_DATA = Util.intToStringMaxRadix(20);
private static final String FIELD_STEREO_MODE = Util.intToStringMaxRadix(21); private static final String FIELD_STEREO_MODE = Util.intToStringMaxRadix(21);
private static final String FIELD_COLOR_INFO = Util.intToStringMaxRadix(22); private static final String FIELD_COLOR_INFO = Util.intToStringMaxRadix(22);
private static final String FIELD_LUMA_BITDEPTH = Util.intToStringMaxRadix(23); private static final String FIELD_CHANNEL_COUNT = Util.intToStringMaxRadix(23);
private static final String FIELD_CHROMA_BITDEPTH = Util.intToStringMaxRadix(24); private static final String FIELD_SAMPLE_RATE = Util.intToStringMaxRadix(24);
private static final String FIELD_CHANNEL_COUNT = Util.intToStringMaxRadix(25); private static final String FIELD_PCM_ENCODING = Util.intToStringMaxRadix(25);
private static final String FIELD_SAMPLE_RATE = Util.intToStringMaxRadix(26); private static final String FIELD_ENCODER_DELAY = Util.intToStringMaxRadix(26);
private static final String FIELD_PCM_ENCODING = Util.intToStringMaxRadix(27); private static final String FIELD_ENCODER_PADDING = Util.intToStringMaxRadix(27);
private static final String FIELD_ENCODER_DELAY = Util.intToStringMaxRadix(28); private static final String FIELD_ACCESSIBILITY_CHANNEL = Util.intToStringMaxRadix(28);
private static final String FIELD_ENCODER_PADDING = Util.intToStringMaxRadix(29); private static final String FIELD_CRYPTO_TYPE = Util.intToStringMaxRadix(29);
private static final String FIELD_ACCESSIBILITY_CHANNEL = Util.intToStringMaxRadix(30); private static final String FIELD_TILE_COUNT_HORIZONTAL = Util.intToStringMaxRadix(30);
private static final String FIELD_CRYPTO_TYPE = Util.intToStringMaxRadix(31); private static final String FIELD_TILE_COUNT_VERTICAL = Util.intToStringMaxRadix(31);
private static final String FIELD_TILE_COUNT_HORIZONTAL = Util.intToStringMaxRadix(32);
private static final String FIELD_TILE_COUNT_VERTICAL = Util.intToStringMaxRadix(33);
@UnstableApi @UnstableApi
@Override @Override
@ -1482,8 +1431,6 @@ public final class Format implements Bundleable {
if (colorInfo != null) { if (colorInfo != null) {
bundle.putBundle(FIELD_COLOR_INFO, colorInfo.toBundle()); bundle.putBundle(FIELD_COLOR_INFO, colorInfo.toBundle());
} }
bundle.putInt(FIELD_LUMA_BITDEPTH, lumaBitdepth);
bundle.putInt(FIELD_CHROMA_BITDEPTH, chromaBitdepth);
// Audio specific. // Audio specific.
bundle.putInt(FIELD_CHANNEL_COUNT, channelCount); bundle.putInt(FIELD_CHANNEL_COUNT, channelCount);
bundle.putInt(FIELD_SAMPLE_RATE, sampleRate); bundle.putInt(FIELD_SAMPLE_RATE, sampleRate);
@ -1549,8 +1496,6 @@ public final class Format implements Bundleable {
if (colorInfoBundle != null) { if (colorInfoBundle != null) {
builder.setColorInfo(ColorInfo.CREATOR.fromBundle(colorInfoBundle)); builder.setColorInfo(ColorInfo.CREATOR.fromBundle(colorInfoBundle));
} }
builder.setLumaBitdepth(bundle.getInt(FIELD_LUMA_BITDEPTH, DEFAULT.lumaBitdepth));
builder.setChromaBitdepth(bundle.getInt(FIELD_CHROMA_BITDEPTH, DEFAULT.chromaBitdepth));
// Audio specific. // Audio specific.
builder builder
.setChannelCount(bundle.getInt(FIELD_CHANNEL_COUNT, DEFAULT.channelCount)) .setChannelCount(bundle.getInt(FIELD_CHANNEL_COUNT, DEFAULT.channelCount))

View file

@ -78,7 +78,9 @@ public final class FormatTest {
C.COLOR_SPACE_BT709, C.COLOR_SPACE_BT709,
C.COLOR_RANGE_LIMITED, C.COLOR_RANGE_LIMITED,
C.COLOR_TRANSFER_SDR, C.COLOR_TRANSFER_SDR,
new byte[] {1, 2, 3, 4, 5, 6, 7}); new byte[] {1, 2, 3, 4, 5, 6, 7},
/* lumaBitdepth */ 9,
/* chromaBitdepth */ 11);
return new Format.Builder() return new Format.Builder()
.setId("id") .setId("id")
@ -104,8 +106,6 @@ public final class FormatTest {
.setProjectionData(projectionData) .setProjectionData(projectionData)
.setStereoMode(C.STEREO_MODE_TOP_BOTTOM) .setStereoMode(C.STEREO_MODE_TOP_BOTTOM)
.setColorInfo(colorInfo) .setColorInfo(colorInfo)
.setLumaBitdepth(9)
.setChromaBitdepth(11)
.setChannelCount(6) .setChannelCount(6)
.setSampleRate(44100) .setSampleRate(44100)
.setPcmEncoding(C.ENCODING_PCM_24BIT) .setPcmEncoding(C.ENCODING_PCM_24BIT)

View file

@ -139,7 +139,6 @@ public class DebugTextViewHelper {
+ format.width + format.width
+ "x" + "x"
+ format.height + format.height
+ getBitdepthInfoString(format.lumaBitdepth)
+ getColorInfoString(format.colorInfo) + getColorInfoString(format.colorInfo)
+ getPixelAspectRatioString(format.pixelWidthHeightRatio) + getPixelAspectRatioString(format.pixelWidthHeightRatio)
+ getDecoderCountersBufferCountString(decoderCounters) + getDecoderCountersBufferCountString(decoderCounters)
@ -189,12 +188,9 @@ public class DebugTextViewHelper {
+ counters.droppedToKeyframeCount; + counters.droppedToKeyframeCount;
} }
private static String getBitdepthInfoString(int lumaBitdepth) {
return lumaBitdepth != Format.NO_VALUE ? " b:" + lumaBitdepth : "";
}
private static String getColorInfoString(@Nullable ColorInfo colorInfo) { private static String getColorInfoString(@Nullable ColorInfo colorInfo) {
return colorInfo != null && colorInfo.isValid() ? " colr:" + colorInfo.toLogString() : ""; return colorInfo != null ? (colorInfo.isBppValid() ? " b:" + colorInfo.toBppString() : "")
+ (colorInfo.isValid() ? " colr:" + colorInfo.toColorString() : "") : "";
} }
private static String getPixelAspectRatioString(float pixelAspectRatio) { private static String getPixelAspectRatioString(float pixelAspectRatio) {

View file

@ -32,6 +32,7 @@ import android.util.Pair;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.media3.common.C; import androidx.media3.common.C;
import androidx.media3.common.ColorInfo;
import androidx.media3.common.Format; import androidx.media3.common.Format;
import androidx.media3.common.MimeTypes; import androidx.media3.common.MimeTypes;
import androidx.media3.common.ParserException; import androidx.media3.common.ParserException;
@ -421,10 +422,14 @@ import com.google.common.collect.ImmutableMap;
formatBuilder.setPixelWidthHeightRatio(spsData.pixelWidthHeightRatio); formatBuilder.setPixelWidthHeightRatio(spsData.pixelWidthHeightRatio);
formatBuilder.setHeight(spsData.height); formatBuilder.setHeight(spsData.height);
formatBuilder.setWidth(spsData.width); formatBuilder.setWidth(spsData.width);
int bitdepthLuma = spsData.bitDepthLumaMinus8 + 8; formatBuilder.setColorInfo(
formatBuilder.setLumaBitdepth(bitdepthLuma); new ColorInfo(
int bitdepthChroma = spsData.bitDepthChromaMinus8 + 8; spsData.colorSpace,
formatBuilder.setChromaBitdepth(bitdepthChroma); spsData.colorRange,
spsData.colorTransfer,
null,
spsData.bitDepthLumaMinus8 + 8,
spsData.bitDepthChromaMinus8 + 8));
@Nullable String profileLevel = fmtpAttributes.get(PARAMETER_PROFILE_LEVEL_ID); @Nullable String profileLevel = fmtpAttributes.get(PARAMETER_PROFILE_LEVEL_ID);
if (profileLevel != null) { if (profileLevel != null) {
@ -468,10 +473,14 @@ import com.google.common.collect.ImmutableMap;
spsNalDataWithStartCode, NAL_START_CODE.length, spsNalDataWithStartCode.length); spsNalDataWithStartCode, NAL_START_CODE.length, spsNalDataWithStartCode.length);
formatBuilder.setPixelWidthHeightRatio(spsData.pixelWidthHeightRatio); formatBuilder.setPixelWidthHeightRatio(spsData.pixelWidthHeightRatio);
formatBuilder.setHeight(spsData.height).setWidth(spsData.width); formatBuilder.setHeight(spsData.height).setWidth(spsData.width);
int bitdepthLuma = spsData.bitDepthLumaMinus8 + 8; formatBuilder.setColorInfo(
formatBuilder.setLumaBitdepth(bitdepthLuma); new ColorInfo(
int bitdepthChroma = spsData.bitDepthChromaMinus8 + 8; spsData.colorSpace,
formatBuilder.setChromaBitdepth(bitdepthChroma); spsData.colorRange,
spsData.colorTransfer,
null,
spsData.bitDepthLumaMinus8 + 8,
spsData.bitDepthChromaMinus8 + 8));
formatBuilder.setCodecs( formatBuilder.setCodecs(
CodecSpecificDataUtil.buildHevcCodecString( CodecSpecificDataUtil.buildHevcCodecString(

View file

@ -1021,6 +1021,7 @@ public class MatroskaExtractor implements Extractor {
break; break;
case ID_COLOUR_BITS_PER_CHANNEL: case ID_COLOUR_BITS_PER_CHANNEL:
assertInTrackEntry(id); assertInTrackEntry(id);
currentTrack.hasColorInfo = true;
currentTrack.bitsPerChannel = (int)value; currentTrack.bitsPerChannel = (int)value;
break; break;
case ID_COLOUR_RANGE: case ID_COLOUR_RANGE:
@ -2307,7 +2308,7 @@ public class MatroskaExtractor implements Extractor {
@Nullable ColorInfo colorInfo = null; @Nullable ColorInfo colorInfo = null;
if (hasColorInfo) { if (hasColorInfo) {
@Nullable byte[] hdrStaticInfo = getHdrStaticInfo(); @Nullable byte[] hdrStaticInfo = getHdrStaticInfo();
colorInfo = new ColorInfo(colorSpace, colorRange, colorTransfer, hdrStaticInfo); colorInfo = new ColorInfo(colorSpace, colorRange, colorTransfer, hdrStaticInfo, bitsPerChannel, bitsPerChannel);
} }
int rotationDegrees = Format.NO_VALUE; int rotationDegrees = Format.NO_VALUE;
@ -2332,8 +2333,6 @@ public class MatroskaExtractor implements Extractor {
formatBuilder formatBuilder
.setWidth(width) .setWidth(width)
.setHeight(height) .setHeight(height)
.setLumaBitdepth(bitsPerChannel)
.setChromaBitdepth(bitsPerChannel)
.setPixelWidthHeightRatio(pixelWidthHeightRatio) .setPixelWidthHeightRatio(pixelWidthHeightRatio)
.setRotationDegrees(rotationDegrees) .setRotationDegrees(rotationDegrees)
.setProjectionData(projectionData) .setProjectionData(projectionData)

View file

@ -1358,27 +1358,22 @@ import java.util.List;
.setCodecs(codecs) .setCodecs(codecs)
.setWidth(width) .setWidth(width)
.setHeight(height) .setHeight(height)
.setLumaBitdepth(bitdepthLuma)
.setChromaBitdepth(bitdepthChroma)
.setPixelWidthHeightRatio(pixelWidthHeightRatio) .setPixelWidthHeightRatio(pixelWidthHeightRatio)
.setRotationDegrees(rotationDegrees) .setRotationDegrees(rotationDegrees)
.setProjectionData(projectionData) .setProjectionData(projectionData)
.setStereoMode(stereoMode) .setStereoMode(stereoMode)
.setInitializationData(initializationData) .setInitializationData(initializationData)
.setDrmInitData(drmInitData); .setDrmInitData(drmInitData)
if (colorSpace != Format.NO_VALUE // Note that if either mdcv or clli are missing, we leave the corresponding HDR static
|| colorRange != Format.NO_VALUE // metadata bytes with value zero. See [Internal ref: b/194535665].
|| colorTransfer != Format.NO_VALUE .setColorInfo(
|| hdrStaticInfo != null) { new ColorInfo(
// Note that if either mdcv or clli are missing, we leave the corresponding HDR static colorSpace,
// metadata bytes with value zero. See [Internal ref: b/194535665]. colorRange,
formatBuilder.setColorInfo( colorTransfer,
new ColorInfo( hdrStaticInfo != null ? hdrStaticInfo.array() : null,
colorSpace, bitdepthLuma,
colorRange, bitdepthChroma));
colorTransfer,
hdrStaticInfo != null ? hdrStaticInfo.array() : null));
}
if (esdsData != null) { if (esdsData != null) {
formatBuilder formatBuilder

View file

@ -20,6 +20,7 @@ import static androidx.media3.extractor.ts.TsPayloadReader.FLAG_RANDOM_ACCESS_IN
import android.util.SparseArray; import android.util.SparseArray;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.media3.common.C; import androidx.media3.common.C;
import androidx.media3.common.ColorInfo;
import androidx.media3.common.Format; import androidx.media3.common.Format;
import androidx.media3.common.MimeTypes; import androidx.media3.common.MimeTypes;
import androidx.media3.common.util.Assertions; import androidx.media3.common.util.Assertions;
@ -219,8 +220,14 @@ public final class H264Reader implements ElementaryStreamReader {
.setCodecs(codecs) .setCodecs(codecs)
.setWidth(spsData.width) .setWidth(spsData.width)
.setHeight(spsData.height) .setHeight(spsData.height)
.setLumaBitdepth(spsData.bitDepthLumaMinus8 + 8) .setColorInfo(
.setChromaBitdepth(spsData.bitDepthChromaMinus8 + 8) new ColorInfo(
spsData.colorSpace,
spsData.colorRange,
spsData.colorTransfer,
null,
spsData.bitDepthLumaMinus8 + 8,
spsData.bitDepthChromaMinus8 + 8))
.setPixelWidthHeightRatio(spsData.pixelWidthHeightRatio) .setPixelWidthHeightRatio(spsData.pixelWidthHeightRatio)
.setInitializationData(initializationData) .setInitializationData(initializationData)
.build()); .build());

View file

@ -17,6 +17,7 @@ package androidx.media3.extractor.ts;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.media3.common.C; import androidx.media3.common.C;
import androidx.media3.common.ColorInfo;
import androidx.media3.common.Format; import androidx.media3.common.Format;
import androidx.media3.common.MimeTypes; import androidx.media3.common.MimeTypes;
import androidx.media3.common.util.Assertions; import androidx.media3.common.util.Assertions;
@ -264,8 +265,14 @@ public final class H265Reader implements ElementaryStreamReader {
.setCodecs(codecs) .setCodecs(codecs)
.setWidth(spsData.width) .setWidth(spsData.width)
.setHeight(spsData.height) .setHeight(spsData.height)
.setLumaBitdepth(spsData.bitDepthLumaMinus8 + 8) .setColorInfo(
.setChromaBitdepth(spsData.bitDepthChromaMinus8 + 8) new ColorInfo(
spsData.colorSpace,
spsData.colorRange,
spsData.colorTransfer,
null,
spsData.bitDepthLumaMinus8 + 8,
spsData.bitDepthChromaMinus8 + 8))
.setPixelWidthHeightRatio(spsData.pixelWidthHeightRatio) .setPixelWidthHeightRatio(spsData.pixelWidthHeightRatio)
.setInitializationData(Collections.singletonList(csdData)) .setInitializationData(Collections.singletonList(csdData))
.build(); .build();