Updated to use ColorInfo.Builder() and formatting issues
This commit is contained in:
parent
bbcf37dc9e
commit
d206be74ef
@ -22,6 +22,9 @@ import androidx.media3.common.util.Util;
|
||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||
import java.util.Arrays;
|
||||
import org.checkerframework.dataflow.qual.Pure;
|
||||
// copybara:exo-only import com.google.android.exoplayer2.Bundleable;
|
||||
// copybara:exo-only import com.google.android.exoplayer2.C;
|
||||
// copybara:exo-only import com.google.android.exoplayer2.Format;
|
||||
|
||||
/**
|
||||
* Stores color info.
|
||||
@ -320,11 +323,6 @@ public final class ColorInfo implements Bundleable {
|
||||
* @see Format#toLogString(Format)
|
||||
*/
|
||||
public String toLogString() {
|
||||
if (!isValid()) {
|
||||
return "NA";
|
||||
}
|
||||
|
||||
String bitdepthsString = isBitdepthValid() ? lumaBitdepth + "/" + chromaBitdepth : "NA";
|
||||
String dataspaceString =
|
||||
isDataSpaceValid()
|
||||
? Util.formatInvariant(
|
||||
@ -332,8 +330,9 @@ public final class ColorInfo implements Bundleable {
|
||||
colorSpaceToString(colorSpace),
|
||||
colorRangeToString(colorRange),
|
||||
colorTransferToString(colorTransfer))
|
||||
: "NA";
|
||||
return bitdepthsString + "/" + dataspaceString;
|
||||
: "NA/NA/NA";
|
||||
String bitdepthsString = isBitdepthValid() ? lumaBitdepth + "/" + chromaBitdepth : "NA/NA";
|
||||
return dataspaceString + "/" + bitdepthsString;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -353,13 +352,24 @@ public final class ColorInfo implements Bundleable {
|
||||
&& chromaBitdepth == other.chromaBitdepth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (hashCode == 0) {
|
||||
int result = 17;
|
||||
result = 31 * result + colorSpace;
|
||||
result = 31 * result + colorRange;
|
||||
result = 31 * result + colorTransfer;
|
||||
result = 31 * result + Arrays.hashCode(hdrStaticInfo);
|
||||
result = 31 * result + lumaBitdepth;
|
||||
result = 31 * result + chromaBitdepth;
|
||||
hashCode = result;
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ColorInfo("
|
||||
+ lumaBitdepthToString(lumaBitdepth)
|
||||
+ ", "
|
||||
+ chromaBitdepthToString(chromaBitdepth)
|
||||
+ ", "
|
||||
+ colorSpaceToString(colorSpace)
|
||||
+ ", "
|
||||
+ colorRangeToString(colorRange)
|
||||
@ -367,6 +377,10 @@ public final class ColorInfo implements Bundleable {
|
||||
+ colorTransferToString(colorTransfer)
|
||||
+ ", "
|
||||
+ (hdrStaticInfo != null)
|
||||
+ ", "
|
||||
+ lumaBitdepthToString(lumaBitdepth)
|
||||
+ ", "
|
||||
+ chromaBitdepthToString(chromaBitdepth)
|
||||
+ ")";
|
||||
}
|
||||
|
||||
@ -392,6 +406,7 @@ public final class ColorInfo implements Bundleable {
|
||||
default:
|
||||
return "Undefined color space";
|
||||
}
|
||||
// LINT.ThenChange(C.java:color_space)
|
||||
}
|
||||
|
||||
private static String colorTransferToString(@C.ColorTransfer int colorTransfer) {
|
||||
@ -414,6 +429,7 @@ public final class ColorInfo implements Bundleable {
|
||||
default:
|
||||
return "Undefined color transfer";
|
||||
}
|
||||
// LINT.ThenChange(C.java:color_transfer)
|
||||
}
|
||||
|
||||
private static String colorRangeToString(@C.ColorRange int colorRange) {
|
||||
@ -428,21 +444,7 @@ public final class ColorInfo implements Bundleable {
|
||||
default:
|
||||
return "Undefined color range";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (hashCode == 0) {
|
||||
int result = 17;
|
||||
result = 31 * result + colorSpace;
|
||||
result = 31 * result + colorRange;
|
||||
result = 31 * result + colorTransfer;
|
||||
result = 31 * result + Arrays.hashCode(hdrStaticInfo);
|
||||
result = 31 * result + lumaBitdepth;
|
||||
result = 31 * result + chromaBitdepth;
|
||||
hashCode = result;
|
||||
}
|
||||
return hashCode;
|
||||
// LINT.ThenChange(C.java:color_range)
|
||||
}
|
||||
|
||||
// Bundleable implementation
|
||||
|
@ -28,6 +28,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
// copybara:exo-only import com.google.android.exoplayer2.drm.DrmInitData;
|
||||
// copybara:exo-only import com.google.android.exoplayer2.util.MimeTypes;
|
||||
// copybara:exo-only import com.google.android.exoplayer2.video.ColorInfo;
|
||||
// copybara:exo-only import com.google.android.exoplayer2.metadata.Metadata;
|
||||
|
||||
/** Unit test for {@link Format}. */
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
|
@ -33,28 +33,21 @@ import java.util.Arrays;
|
||||
public final class NalUnitUtil {
|
||||
|
||||
private static final String TAG = "NalUnitUtil";
|
||||
|
||||
/** Coded slice of a non-IDR picture. */
|
||||
public static final int NAL_UNIT_TYPE_NON_IDR = 1;
|
||||
|
||||
/** Coded slice data partition A. */
|
||||
public static final int NAL_UNIT_TYPE_PARTITION_A = 2;
|
||||
|
||||
/** Coded slice of an IDR picture. */
|
||||
public static final int NAL_UNIT_TYPE_IDR = 5;
|
||||
|
||||
/** Supplemental enhancement information. */
|
||||
public static final int NAL_UNIT_TYPE_SEI = 6;
|
||||
|
||||
/** Sequence parameter set. */
|
||||
public static final int NAL_UNIT_TYPE_SPS = 7;
|
||||
|
||||
/** Picture parameter set. */
|
||||
public static final int NAL_UNIT_TYPE_PPS = 8;
|
||||
|
||||
/** Access unit delimiter. */
|
||||
public static final int NAL_UNIT_TYPE_AUD = 9;
|
||||
|
||||
|
||||
/** Holds data parsed from a H.264 sequence parameter set NAL unit. */
|
||||
public static final class SpsData {
|
||||
|
||||
|
@ -51,7 +51,6 @@ import com.google.common.collect.ImmutableMap;
|
||||
// Format specific parameter names.
|
||||
private static final String PARAMETER_PROFILE_LEVEL_ID = "profile-level-id";
|
||||
private static final String PARAMETER_SPROP_PARAMS = "sprop-parameter-sets";
|
||||
|
||||
private static final String PARAMETER_AMR_OCTET_ALIGN = "octet-align";
|
||||
private static final String PARAMETER_AMR_INTERLEAVING = "interleaving";
|
||||
private static final String PARAMETER_H265_SPROP_SPS = "sprop-sps";
|
||||
@ -60,16 +59,12 @@ import com.google.common.collect.ImmutableMap;
|
||||
private static final String PARAMETER_H265_SPROP_MAX_DON_DIFF = "sprop-max-don-diff";
|
||||
private static final String PARAMETER_MP4A_CONFIG = "config";
|
||||
private static final String PARAMETER_MP4A_C_PRESENT = "cpresent";
|
||||
|
||||
/** Prefix for the RFC6381 codecs string for AAC formats. */
|
||||
private static final String AAC_CODECS_PREFIX = "mp4a.40.";
|
||||
|
||||
/** Prefix for the RFC6381 codecs string for AVC formats. */
|
||||
private static final String H264_CODECS_PREFIX = "avc1.";
|
||||
|
||||
/** Prefix for the RFC6416 codecs string for MPEG4V-ES formats. */
|
||||
private static final String MPEG4_CODECS_PREFIX = "mp4v.";
|
||||
|
||||
private static final String GENERIC_CONTROL_ATTR = "*";
|
||||
|
||||
/**
|
||||
@ -101,7 +96,6 @@ import com.google.common.collect.ImmutableMap;
|
||||
* software VP8 decoder</a>.
|
||||
*/
|
||||
private static final int DEFAULT_VP8_WIDTH = 320;
|
||||
|
||||
/**
|
||||
* Default height for VP8.
|
||||
*
|
||||
@ -125,7 +119,6 @@ import com.google.common.collect.ImmutableMap;
|
||||
* software VP9 decoder</a>.
|
||||
*/
|
||||
private static final int DEFAULT_VP9_WIDTH = 320;
|
||||
|
||||
/**
|
||||
* Default height for VP9.
|
||||
*
|
||||
@ -146,7 +139,6 @@ import com.google.common.collect.ImmutableMap;
|
||||
* >Android's software H263 decoder</a>.
|
||||
*/
|
||||
private static final int DEFAULT_H263_WIDTH = 352;
|
||||
|
||||
/**
|
||||
* Default height for H263.
|
||||
*
|
||||
@ -159,7 +151,6 @@ import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/** The track's associated {@link RtpPayloadFormat}. */
|
||||
public final RtpPayloadFormat payloadFormat;
|
||||
|
||||
/** The track's URI. */
|
||||
public final Uri uri;
|
||||
|
||||
@ -422,14 +413,13 @@ import com.google.common.collect.ImmutableMap;
|
||||
formatBuilder.setPixelWidthHeightRatio(spsData.pixelWidthHeightRatio);
|
||||
formatBuilder.setHeight(spsData.height);
|
||||
formatBuilder.setWidth(spsData.width);
|
||||
formatBuilder.setColorInfo(
|
||||
new ColorInfo(
|
||||
spsData.colorSpace,
|
||||
spsData.colorRange,
|
||||
spsData.colorTransfer,
|
||||
null,
|
||||
spsData.bitDepthLumaMinus8 + 8,
|
||||
spsData.bitDepthChromaMinus8 + 8));
|
||||
formatBuilder.setColorInfo(new ColorInfo.Builder()
|
||||
.setColorSpace(spsData.colorSpace)
|
||||
.setColorRange(spsData.colorRange)
|
||||
.setColorTransfer(spsData.colorTransfer)
|
||||
.setLumaBitdepth(spsData.bitDepthLumaMinus8 + 8)
|
||||
.setChromaBitdepth(spsData.bitDepthChromaMinus8 + 8)
|
||||
.build());
|
||||
|
||||
@Nullable String profileLevel = fmtpAttributes.get(PARAMETER_PROFILE_LEVEL_ID);
|
||||
if (profileLevel != null) {
|
||||
@ -473,14 +463,13 @@ import com.google.common.collect.ImmutableMap;
|
||||
spsNalDataWithStartCode, NAL_START_CODE.length, spsNalDataWithStartCode.length);
|
||||
formatBuilder.setPixelWidthHeightRatio(spsData.pixelWidthHeightRatio);
|
||||
formatBuilder.setHeight(spsData.height).setWidth(spsData.width);
|
||||
formatBuilder.setColorInfo(
|
||||
new ColorInfo(
|
||||
spsData.colorSpace,
|
||||
spsData.colorRange,
|
||||
spsData.colorTransfer,
|
||||
null,
|
||||
spsData.bitDepthLumaMinus8 + 8,
|
||||
spsData.bitDepthChromaMinus8 + 8));
|
||||
formatBuilder.setColorInfo(new ColorInfo.Builder()
|
||||
.setColorSpace(spsData.colorSpace)
|
||||
.setColorRange(spsData.colorRange)
|
||||
.setColorTransfer(spsData.colorTransfer)
|
||||
.setLumaBitdepth(spsData.bitDepthLumaMinus8 + 8)
|
||||
.setChromaBitdepth(spsData.bitDepthChromaMinus8 + 8)
|
||||
.build());
|
||||
|
||||
formatBuilder.setCodecs(
|
||||
CodecSpecificDataUtil.buildHevcCodecString(
|
||||
|
@ -26,6 +26,7 @@ import androidx.media3.container.NalUnitUtil;
|
||||
import androidx.media3.container.NalUnitUtil.SpsData;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
// copybara:exo-only import com.google.android.exoplayer2.util.NalUnitUtil;
|
||||
|
||||
/** AVC configuration data. */
|
||||
@UnstableApi
|
||||
|
@ -25,6 +25,7 @@ import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.container.NalUnitUtil;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
// copybara:exo-only import com.google.android.exoplayer2.util.NalUnitUtil;
|
||||
|
||||
/** HEVC configuration data. */
|
||||
@UnstableApi
|
||||
|
@ -94,7 +94,6 @@ public class MatroskaExtractor implements Extractor {
|
||||
flag = true,
|
||||
value = {FLAG_DISABLE_SEEK_FOR_CUES})
|
||||
public @interface Flags {}
|
||||
|
||||
/**
|
||||
* Flag to disable seeking for cues.
|
||||
*
|
||||
@ -260,7 +259,6 @@ public class MatroskaExtractor implements Extractor {
|
||||
* https://www.matroska.org/technical/codec_specs.html.
|
||||
*/
|
||||
private static final int BLOCK_ADD_ID_TYPE_DVCC = 0x64766343;
|
||||
|
||||
/**
|
||||
* BlockAddIdType value for Dolby Vision configuration with profile > 7. See also
|
||||
* https://www.matroska.org/technical/codec_specs.html.
|
||||
@ -292,10 +290,8 @@ public class MatroskaExtractor implements Extractor {
|
||||
49, 10, 48, 48, 58, 48, 48, 58, 48, 48, 44, 48, 48, 48, 32, 45, 45, 62, 32, 48, 48, 58, 48,
|
||||
48, 58, 48, 48, 44, 48, 48, 48, 10
|
||||
};
|
||||
|
||||
/** The byte offset of the end timecode in {@link #SUBRIP_PREFIX}. */
|
||||
private static final int SUBRIP_PREFIX_END_TIMECODE_OFFSET = 19;
|
||||
|
||||
/**
|
||||
* The value by which to divide a time in microseconds to convert it to the unit of the last value
|
||||
* in a subrip timecode (milliseconds).
|
||||
@ -310,7 +306,6 @@ public class MatroskaExtractor implements Extractor {
|
||||
Util.getUtf8Bytes(
|
||||
"Format: Start, End, "
|
||||
+ "ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text");
|
||||
|
||||
/**
|
||||
* A template for the prefix that must be added to each SSA sample.
|
||||
*
|
||||
@ -327,16 +322,13 @@ public class MatroskaExtractor implements Extractor {
|
||||
68, 105, 97, 108, 111, 103, 117, 101, 58, 32, 48, 58, 48, 48, 58, 48, 48, 58, 48, 48, 44,
|
||||
48, 58, 48, 48, 58, 48, 48, 58, 48, 48, 44
|
||||
};
|
||||
|
||||
/** The byte offset of the end timecode in {@link #SSA_PREFIX}. */
|
||||
private static final int SSA_PREFIX_END_TIMECODE_OFFSET = 21;
|
||||
|
||||
/**
|
||||
* The value by which to divide a time in microseconds to convert it to the unit of the last value
|
||||
* in an SSA timecode (1/100ths of a second).
|
||||
*/
|
||||
private static final long SSA_TIMECODE_LAST_VALUE_SCALING_FACTOR = 10_000;
|
||||
|
||||
/** The format of an SSA timecode. */
|
||||
private static final String SSA_TIMECODE_FORMAT = "%01d:%02d:%02d:%02d";
|
||||
|
||||
@ -359,13 +351,11 @@ public class MatroskaExtractor implements Extractor {
|
||||
|
||||
/** The byte offset of the end timecode in {@link #VTT_PREFIX}. */
|
||||
private static final int VTT_PREFIX_END_TIMECODE_OFFSET = 25;
|
||||
|
||||
/**
|
||||
* The value by which to divide a time in microseconds to convert it to the unit of the last value
|
||||
* in a VTT timecode (milliseconds).
|
||||
*/
|
||||
private static final long VTT_TIMECODE_LAST_VALUE_SCALING_FACTOR = 1000;
|
||||
|
||||
/** The format of a VTT timecode. */
|
||||
private static final String VTT_TIMECODE_FORMAT = "%02d:%02d:%02d.%03d";
|
||||
|
||||
@ -374,10 +364,8 @@ public class MatroskaExtractor implements Extractor {
|
||||
|
||||
/** Format tag indicating a WAVEFORMATEXTENSIBLE structure. */
|
||||
private static final int WAVE_FORMAT_EXTENSIBLE = 0xFFFE;
|
||||
|
||||
/** Format tag for PCM. */
|
||||
private static final int WAVE_FORMAT_PCM = 1;
|
||||
|
||||
/** Sub format for PCM. */
|
||||
private static final UUID WAVE_SUBFORMAT_PCM = new UUID(0x0100000000001000L, 0x800000AA00389B71L);
|
||||
|
||||
@ -1996,7 +1984,6 @@ public class MatroskaExtractor implements Extractor {
|
||||
|
||||
private static final int DISPLAY_UNIT_PIXELS = 0;
|
||||
private static final int MAX_CHROMATICITY = 50_000; // Defined in CTA-861.3.
|
||||
|
||||
/** Default max content light level (CLL) that should be encoded into hdrStaticInfo. */
|
||||
private static final int DEFAULT_MAX_CLL = 1000; // nits.
|
||||
|
||||
@ -2308,14 +2295,14 @@ public class MatroskaExtractor implements Extractor {
|
||||
@Nullable ColorInfo colorInfo = null;
|
||||
if (hasColorInfo) {
|
||||
@Nullable byte[] hdrStaticInfo = getHdrStaticInfo();
|
||||
colorInfo =
|
||||
new ColorInfo(
|
||||
colorSpace,
|
||||
colorRange,
|
||||
colorTransfer,
|
||||
hdrStaticInfo,
|
||||
bitsPerChannel,
|
||||
bitsPerChannel);
|
||||
colorInfo = new ColorInfo.Builder()
|
||||
.setColorSpace(colorSpace)
|
||||
.setColorRange(colorRange)
|
||||
.setColorTransfer(colorTransfer)
|
||||
.setHdrStaticInfo(hdrStaticInfo)
|
||||
.setLumaBitdepth(bitsPerChannel)
|
||||
.setChromaBitdepth(bitsPerChannel)
|
||||
.build();
|
||||
}
|
||||
int rotationDegrees = Format.NO_VALUE;
|
||||
|
||||
|
@ -1225,7 +1225,6 @@ import java.util.List;
|
||||
mimeType = MimeTypes.VIDEO_AV1;
|
||||
parent.setPosition(childStartPosition + Atom.HEADER_SIZE);
|
||||
parent.skipBytes(1);
|
||||
; // marker(1), version(7)
|
||||
int byte2 = parent.readUnsignedByte();
|
||||
int seqProfile = byte2 >> 5;
|
||||
int byte3 = parent.readUnsignedByte();
|
||||
@ -1368,13 +1367,14 @@ import java.util.List;
|
||||
// Note that if either mdcv or clli are missing, we leave the corresponding HDR static
|
||||
// metadata bytes with value zero. See [Internal ref: b/194535665].
|
||||
.setColorInfo(
|
||||
new ColorInfo(
|
||||
colorSpace,
|
||||
colorRange,
|
||||
colorTransfer,
|
||||
hdrStaticInfo != null ? hdrStaticInfo.array() : null,
|
||||
bitdepthLuma,
|
||||
bitdepthChroma));
|
||||
new ColorInfo.Builder()
|
||||
.setColorSpace(colorSpace)
|
||||
.setColorRange(colorRange)
|
||||
.setColorTransfer(colorTransfer)
|
||||
.setHdrStaticInfo(hdrStaticInfo != null ? hdrStaticInfo.array() : null)
|
||||
.setLumaBitdepth(bitdepthLuma)
|
||||
.setChromaBitdepth(bitdepthChroma)
|
||||
.build());
|
||||
|
||||
if (esdsData != null) {
|
||||
formatBuilder
|
||||
|
@ -221,13 +221,13 @@ public final class H264Reader implements ElementaryStreamReader {
|
||||
.setWidth(spsData.width)
|
||||
.setHeight(spsData.height)
|
||||
.setColorInfo(
|
||||
new ColorInfo(
|
||||
spsData.colorSpace,
|
||||
spsData.colorRange,
|
||||
spsData.colorTransfer,
|
||||
null,
|
||||
spsData.bitDepthLumaMinus8 + 8,
|
||||
spsData.bitDepthChromaMinus8 + 8))
|
||||
new ColorInfo.Builder()
|
||||
.setColorSpace(spsData.colorSpace)
|
||||
.setColorRange(spsData.colorRange)
|
||||
.setColorTransfer(spsData.colorTransfer)
|
||||
.setLumaBitdepth(spsData.bitDepthLumaMinus8 + 8)
|
||||
.setChromaBitdepth(spsData.bitDepthChromaMinus8 + 8)
|
||||
.build())
|
||||
.setPixelWidthHeightRatio(spsData.pixelWidthHeightRatio)
|
||||
.setInitializationData(initializationData)
|
||||
.build());
|
||||
|
@ -266,13 +266,13 @@ public final class H265Reader implements ElementaryStreamReader {
|
||||
.setWidth(spsData.width)
|
||||
.setHeight(spsData.height)
|
||||
.setColorInfo(
|
||||
new ColorInfo(
|
||||
spsData.colorSpace,
|
||||
spsData.colorRange,
|
||||
spsData.colorTransfer,
|
||||
null,
|
||||
spsData.bitDepthLumaMinus8 + 8,
|
||||
spsData.bitDepthChromaMinus8 + 8))
|
||||
new ColorInfo.Builder()
|
||||
.setColorSpace(spsData.colorSpace)
|
||||
.setColorRange(spsData.colorRange)
|
||||
.setColorTransfer(spsData.colorTransfer)
|
||||
.setLumaBitdepth(spsData.bitDepthLumaMinus8 + 8)
|
||||
.setChromaBitdepth(spsData.bitDepthChromaMinus8 + 8)
|
||||
.build())
|
||||
.setPixelWidthHeightRatio(spsData.pixelWidthHeightRatio)
|
||||
.setInitializationData(Collections.singletonList(csdData))
|
||||
.build();
|
||||
|
Loading…
x
Reference in New Issue
Block a user