CodecSpecificDataUtil


@UnstableApi
public final class CodecSpecificDataUtil


Provides utilities for handling various types of codec-specific data.

Summary

Public methods

static String
buildAvcCodecString(
    int profileIdc,
    int constraintsFlagsAndReservedZero2Bits,
    int levelIdc
)

Builds an RFC 6381 AVC codec string using the provided parameters.

static List<byte[]>
buildCea708InitializationData(boolean isWideAspectRatio)

Returns initialization data for formats with MIME type APPLICATION_CEA708.

static String
buildH263CodecString(int profile, int level)

Builds an RFC 6381 H263 codec string using profile and level.

static String
buildHevcCodecString(
    int generalProfileSpace,
    boolean generalTierFlag,
    int generalProfileIdc,
    int generalProfileCompatibilityFlags,
    int[] constraintBytes,
    int generalLevelIdc
)

Builds an RFC 6381 HEVC codec string using the provided parameters.

static byte[]
buildNalUnit(byte[] data, int offset, int length)

Constructs a NAL unit consisting of the NAL start code followed by the specified data.

static ImmutableList<byte[]>
buildVp9CodecPrivateInitializationData(
    byte profile,
    byte level,
    byte bitDepth,
    byte chromaSubsampling
)

Returns initialization data in CodecPrivate format of VP9.

static @Nullable Pair<IntegerInteger>

Returns profile and level (as defined by MediaCodecInfo.CodecProfileLevel) corresponding to the codec description string (as defined by RFC 6381) of the given format.

static @Nullable Pair<IntegerInteger>
getHevcProfileAndLevel(
    String codec,
    String[] parts,
    @Nullable ColorInfo colorInfo
)

Returns Hevc profile and level corresponding to the codec description string (as defined by RFC 6381) and it ColorInfo.

static Pair<IntegerInteger>
getVideoResolutionFromMpeg4VideoConfig(byte[] videoSpecificConfig)

Parses an MPEG-4 Visual configuration information, as defined in ISO/IEC14496-2.

static Pair<IntegerInteger>
parseAlacAudioSpecificConfig(byte[] audioSpecificConfig)

Parses an ALAC AudioSpecificConfig (i.e. an ALACSpecificConfig).

static boolean
parseCea708InitializationData(List<byte[]> initializationData)

Returns whether the CEA-708 closed caption service with the given initialization data is formatted for displays with 16:9 aspect ratio.

static @Nullable byte[][]
splitNalUnits(byte[] data)

Splits an array of NAL units.

Public methods

buildAvcCodecString

public static String buildAvcCodecString(
    int profileIdc,
    int constraintsFlagsAndReservedZero2Bits,
    int levelIdc
)

Builds an RFC 6381 AVC codec string using the provided parameters.

Parameters
int profileIdc

The encoding profile.

int constraintsFlagsAndReservedZero2Bits

The constraint flags followed by the reserved zero 2 bits, all contained in the least significant byte of the integer.

int levelIdc

The encoding level.

Returns
String

An RFC 6381 AVC codec string built using the provided parameters.

buildCea708InitializationData

public static List<byte[]> buildCea708InitializationData(boolean isWideAspectRatio)

Returns initialization data for formats with MIME type APPLICATION_CEA708.

Parameters
boolean isWideAspectRatio

Whether the CEA-708 closed caption service is formatted for displays with 16:9 aspect ratio.

Returns
List<byte[]>

Initialization data for formats with MIME type APPLICATION_CEA708.

buildH263CodecString

public static String buildH263CodecString(int profile, int level)

Builds an RFC 6381 H263 codec string using profile and level.

buildHevcCodecString

public static String buildHevcCodecString(
    int generalProfileSpace,
    boolean generalTierFlag,
    int generalProfileIdc,
    int generalProfileCompatibilityFlags,
    int[] constraintBytes,
    int generalLevelIdc
)

Builds an RFC 6381 HEVC codec string using the provided parameters.

buildNalUnit

public static byte[] buildNalUnit(byte[] data, int offset, int length)

Constructs a NAL unit consisting of the NAL start code followed by the specified data.

Parameters
byte[] data

An array containing the data that should follow the NAL start code.

int offset

The start offset into data.

int length

The number of bytes to copy from data

Returns
byte[]

The constructed NAL unit.

buildVp9CodecPrivateInitializationData

public static ImmutableList<byte[]> buildVp9CodecPrivateInitializationData(
    byte profile,
    byte level,
    byte bitDepth,
    byte chromaSubsampling
)

Returns initialization data in CodecPrivate format of VP9.

Each feature of VP9 CodecPrivate is defined by the binary format of ID (1 byte), length (1 byte), and data (1 byte). See href="https://www.webmproject.org/docs/container/#vp9-codec-feature-metadata-codecprivate", >, CodecPrivate format of VP9 for more details.

Parameters
byte profile

The VP9 codec profile.

byte level

The VP9 codec level.

byte bitDepth

The bit depth of the luma and color components.

byte chromaSubsampling

The chroma subsampling.

getCodecProfileAndLevel

public static @Nullable Pair<IntegerIntegergetCodecProfileAndLevel(Format format)

Returns profile and level (as defined by MediaCodecInfo.CodecProfileLevel) corresponding to the codec description string (as defined by RFC 6381) of the given format.

Parameters
Format format

Media format with a codec description string, as defined by RFC 6381.

Returns
@Nullable Pair<IntegerInteger>

A pair (profile constant, level constant) if the codec of the format is well-formed and recognized, or null otherwise.

getHevcProfileAndLevel

public static @Nullable Pair<IntegerIntegergetHevcProfileAndLevel(
    String codec,
    String[] parts,
    @Nullable ColorInfo colorInfo
)

Returns Hevc profile and level corresponding to the codec description string (as defined by RFC 6381) and it ColorInfo.

Parameters
String codec

The codec description string (as defined by RFC 6381).

String[] parts

The codec string split by ".".

@Nullable ColorInfo colorInfo

The ColorInfo.

Returns
@Nullable Pair<IntegerInteger>

A pair (profile constant, level constant) if profile and level are recognized, or null otherwise.

getVideoResolutionFromMpeg4VideoConfig

public static Pair<IntegerIntegergetVideoResolutionFromMpeg4VideoConfig(byte[] videoSpecificConfig)

Parses an MPEG-4 Visual configuration information, as defined in ISO/IEC14496-2.

Parameters
byte[] videoSpecificConfig

A byte array containing the MPEG-4 Visual configuration information to parse.

Returns
Pair<IntegerInteger>

A pair of the video's width and height.

parseAlacAudioSpecificConfig

public static Pair<IntegerIntegerparseAlacAudioSpecificConfig(byte[] audioSpecificConfig)

Parses an ALAC AudioSpecificConfig (i.e. an ALACSpecificConfig).

Parameters
byte[] audioSpecificConfig

A byte array containing the AudioSpecificConfig to parse.

Returns
Pair<IntegerInteger>

A pair consisting of the sample rate in Hz and the channel count.

parseCea708InitializationData

public static boolean parseCea708InitializationData(List<byte[]> initializationData)

Returns whether the CEA-708 closed caption service with the given initialization data is formatted for displays with 16:9 aspect ratio.

Parameters
List<byte[]> initializationData

The initialization data to parse.

Returns
boolean

Whether the CEA-708 closed caption service is formatted for displays with 16:9 aspect ratio.

splitNalUnits

public static @Nullable byte[][] splitNalUnits(byte[] data)

Splits an array of NAL units.

If the input consists of NAL start code delimited units, then the returned array consists of the split NAL units, each of which is still prefixed with the NAL start code. For any other input, null is returned.

Parameters
byte[] data

An array of data.

Returns
@Nullable byte[][]

The individual NAL units, or null if the input did not consist of NAL start code delimited units.