CodecSpecificDataUtil


@UnstableApi
class CodecSpecificDataUtil


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

Summary

Nested types

A tuple of profile and level constants for MediaCodec.

Public functions

java-static String!
buildApvCodecString(initializationData: ByteArray!)

Returns an APV codec string based on the provided initialization data.

java-static String!
buildAvcCodecString(
    profileIdc: Int,
    constraintsFlagsAndReservedZero2Bits: Int,
    levelIdc: Int
)

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

java-static (Mutable)List<ByteArray<Byte>!>!

Returns initialization data for formats with MIME type APPLICATION_CEA708.

java-static String!
buildDolbyVisionCodecString(profile: Int, level: Int)

Builds a Dolby Vision codec string using profile and level.

java-static ByteArray<Byte>!

Returns initialization data for Dolby Vision according to Dolby Vision ISO MediaFormat (section 2.2) specification.

java-static String!
buildH263CodecString(profile: Int, level: Int)

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

java-static String!
buildHevcCodecString(
    generalProfileSpace: Int,
    generalTierFlag: Boolean,
    generalProfileIdc: Int,
    generalProfileCompatibilityFlags: Int,
    constraintBytes: IntArray!,
    generalLevelIdc: Int
)

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

java-static String?
buildIamfCodecString(initializationData: ByteArray!)

Builds an RFC 6381 IAMF codec string from the given initializationData.

java-static ByteArray<Byte>!
buildNalUnit(data: ByteArray!, offset: Int, length: Int)

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

java-static ByteArray<Byte>?

Builds VP9 CodecPrivate from the uncompressed header of the first frame.

java-static ImmutableList<ByteArray<Byte>!>!
buildVp9CodecPrivateInitializationData(
    profile: Byte,
    level: Byte,
    bitDepth: Byte,
    chromaSubsampling: Byte
)

Returns initialization data in CodecPrivate format of VP9.

java-static Int
calculateMediaCodecDolbyVisionLevel(
    width: Int,
    height: Int,
    frameRate: Float
)

Calculates the Dolby Vision level based on resolution and frame rate.

java-static Int

Returns Dolby Vision level number corresponding to the level constant.

java-static Int

Returns Dolby Vision profile number corresponding to the profile constant.

java-static Pair<Int!, Int!>?

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

java-static String?

Returns a Dolby Vision base layer codec MIME type of the provided Format.

java-static CodecSpecificDataUtil.MediaCodecProfileAndLevel?
getHevcProfileAndLevel(
    codec: String!,
    parts: Array<String!>!,
    colorInfo: ColorInfo?
)

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

java-static CodecSpecificDataUtil.MediaCodecProfileAndLevel?

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

java-static ByteArray<Byte>!

Returns initialization data for Opus according to RFC 7845: 5.1.

java-static Pair<Int!, Int!>!

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

java-static ByteBuffer!

Creates the Vorbis initialization data (CodecPrivate).

java-static Int

Maps Android MediaCodec constants to H.263 Level numbers.

java-static Int

Maps Android MediaCodec constants to H.263 Profile numbers.

java-static IntArray<Int>!
parseAlacAudioSpecificConfig(audioSpecificConfig: ByteArray!)

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

java-static Boolean
parseCea708InitializationData(
    initializationData: (Mutable)List<ByteArray!>!
)

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

java-static Array<ByteArray<Byte>!>?

Splits an array of NAL units.

Public functions

buildApvCodecString

java-static fun buildApvCodecString(initializationData: ByteArray!): String!

Returns an APV codec string based on the provided initialization data.

Reference: Codecs Parameter in APV ISO Base Media File Format

Parameters
initializationData: ByteArray!

The initialization data containing profile, level, and band information.

Returns
String!

The generated APV codec string.

buildAvcCodecString

java-static fun buildAvcCodecString(
    profileIdc: Int,
    constraintsFlagsAndReservedZero2Bits: Int,
    levelIdc: Int
): String!

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

Parameters
profileIdc: Int

The encoding profile.

constraintsFlagsAndReservedZero2Bits: Int

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

levelIdc: Int

The encoding level.

Returns
String!

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

buildCea708InitializationData

java-static fun buildCea708InitializationData(isWideAspectRatio: Boolean): (Mutable)List<ByteArray<Byte>!>!

Returns initialization data for formats with MIME type APPLICATION_CEA708.

Parameters
isWideAspectRatio: Boolean

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

Returns
(Mutable)List<ByteArray<Byte>!>!

Initialization data for formats with MIME type APPLICATION_CEA708.

buildDolbyVisionCodecString

java-static fun buildDolbyVisionCodecString(profile: Int, level: Int): String!

Builds a Dolby Vision codec string using profile and level.

Reference: href="https://professionalsupport.dolby.com/s/article/What-is-Dolby-Vision-Profile?language=en_US", >, Dolby Vision Profile and Level (section 2.3)

buildDolbyVisionInitializationData

java-static fun buildDolbyVisionInitializationData(profile: Int, level: Int): ByteArray<Byte>!

Returns initialization data for Dolby Vision according to Dolby Vision ISO MediaFormat (section 2.2) specification.

Parameters
profile: Int

The Dolby Vision codec profile. This is the integer profile, not the MediaCodecInfo.CodecProfileLevel constant.

level: Int

The Dolby Vision codec level. This is the integer level, not the MediaCodecInfo.CodecProfileLevel constant.

buildH263CodecString

java-static fun buildH263CodecString(profile: Int, level: Int): String!

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

buildHevcCodecString

java-static fun buildHevcCodecString(
    generalProfileSpace: Int,
    generalTierFlag: Boolean,
    generalProfileIdc: Int,
    generalProfileCompatibilityFlags: Int,
    constraintBytes: IntArray!,
    generalLevelIdc: Int
): String!

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

buildIamfCodecString

java-static fun buildIamfCodecString(initializationData: ByteArray!): String?

Builds an RFC 6381 IAMF codec string from the given initializationData.

The format is defined by the IAMF Codec Parameters String specification.

buildNalUnit

java-static fun buildNalUnit(data: ByteArray!, offset: Int, length: Int): ByteArray<Byte>!

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

Parameters
data: ByteArray!

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

offset: Int

The start offset into data.

length: Int

The number of bytes to copy from data

Returns
ByteArray<Byte>!

The constructed NAL unit.

buildVp9CodecPrivateFromUncompressedHeader

java-static fun buildVp9CodecPrivateFromUncompressedHeader(sample: ByteBuffer!): ByteArray<Byte>?

Builds VP9 CodecPrivate from the uncompressed header of the first frame.

This method parses the uncompressed header of the first frame to extract the VP9 profile, bit depth, and chroma subsampling.

Refer to 6.2 of the VP9 bitstream specification and VP9 in ISO Media File Format for more details.

Parameters
sample: ByteBuffer!

The first frame's data.

Returns
ByteArray<Byte>?

The CodecPrivate data for VP9 if parsing is successful, null otherwise.

buildVp9CodecPrivateInitializationData

java-static fun buildVp9CodecPrivateInitializationData(
    profile: Byte,
    level: Byte,
    bitDepth: Byte,
    chromaSubsampling: Byte
): ImmutableList<ByteArray<Byte>!>!

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
profile: Byte

The VP9 codec profile.

level: Byte

The VP9 codec level.

bitDepth: Byte

The bit depth of the luma and color components.

chromaSubsampling: Byte

The chroma subsampling.

calculateMediaCodecDolbyVisionLevel

java-static fun calculateMediaCodecDolbyVisionLevel(
    width: Int,
    height: Int,
    frameRate: Float
): Int

Calculates the Dolby Vision level based on resolution and frame rate.

Refer to Dolby Vision profiles and levels for more details.

Parameters
width: Int

The video width in pixels.

height: Int

The video height in pixels.

frameRate: Float

The video frame rate in frames per second.

Returns
Int

The Android MediaCodec constants for the Dolby Vision level, or -1 if it could not be determined.

dolbyVisionConstantToLevelNumber

java-static fun dolbyVisionConstantToLevelNumber(levelConstant: Int): Int

Returns Dolby Vision level number corresponding to the level constant.

Parameters
levelConstant: Int

The Dolby Vision level constant.

Returns
Int

The Dolby Vision level number.

Throws
java.lang.IllegalArgumentException

if the level constant is not recognized.

dolbyVisionConstantToProfileNumber

java-static fun dolbyVisionConstantToProfileNumber(profileConstant: Int): Int

Returns Dolby Vision profile number corresponding to the profile constant.

Parameters
profileConstant: Int

The Dolby Vision profile constant.

Returns
Int

The Dolby Vision profile number.

Throws
java.lang.IllegalArgumentException

if the profile constant is not recognized.

getCodecProfileAndLevel

java-static fun getCodecProfileAndLevel(format: Format!): Pair<Int!, Int!>?

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

Consider using getMediaCodecProfileAndLevel instead in order to distinguish between:

  • The format doesn't contain profile and level info, or it is malformed.
  • The format contains profile and level info, but it cannot be represented with constants from MediaCodecInfo.CodecProfileLevel.
Parameters
format: Format!

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

Returns
Pair<Int!, Int!>?

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

getDolbyVisionBaseLayerMimeType

java-static fun getDolbyVisionBaseLayerMimeType(format: Format!): String?

Returns a Dolby Vision base layer codec MIME type of the provided Format.

Parameters
format: Format!

The media format.

Returns
String?

A Dolby Vision base layer MIME type, or null if a Dolby Vision profile is not identified.

getHevcProfileAndLevel

java-static fun getHevcProfileAndLevel(
    codec: String!,
    parts: Array<String!>!,
    colorInfo: ColorInfo?
): CodecSpecificDataUtil.MediaCodecProfileAndLevel?

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

Parameters
codec: String!

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

parts: Array<String!>!

The codec string split by ".".

colorInfo: ColorInfo?

The ColorInfo.

Returns
CodecSpecificDataUtil.MediaCodecProfileAndLevel?

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

getMediaCodecProfileAndLevel

java-static fun getMediaCodecProfileAndLevel(format: Format!): CodecSpecificDataUtil.MediaCodecProfileAndLevel?

Returns the profile and level 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
CodecSpecificDataUtil.MediaCodecProfileAndLevel?

MediaCodecProfileAndLevel if the codec of the format is well-formed, or null otherwise.

getOpusInitializationData

java-static fun getOpusInitializationData(format: Format!): ByteArray<Byte>!

Returns initialization data for Opus according to RFC 7845: 5.1.

Parameters
format: Format!

The Format.

Returns
ByteArray<Byte>!

A byte array containing the Opus initialization data.

getVideoResolutionFromMpeg4VideoConfig

java-static fun getVideoResolutionFromMpeg4VideoConfig(videoSpecificConfig: ByteArray!): Pair<Int!, Int!>!

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

Parameters
videoSpecificConfig: ByteArray!

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

Returns
Pair<Int!, Int!>!

A pair of the video's width and height.

getVorbisInitializationData

java-static fun getVorbisInitializationData(format: Format!): ByteBuffer!

Creates the Vorbis initialization data (CodecPrivate).

The format is as follows:

  • Byte 1: The number of packets minus one. This is 2 for Vorbis, representing the Identification, Comment, and Setup headers.
  • Bytes 2..n: The lengths of the first two packets (Identification and Comment headers), encoded using Xiph lacing. The length of the final packet (Setup header) is not explicitly stored.
  • Bytes n+1 onwards: The Vorbis identification header, Vorbis comment header and the codec setup header.
See A_VORBIS for CodecPrivate format of Vorbis.
Parameters
format: Format!

The Format.

Returns
ByteBuffer!

A ByteBuffer containing the assembled Vorbis CodecPrivate data.

h263ConstToLevelNumber

java-static fun h263ConstToLevelNumber(levelConst: Int): Int

Maps Android MediaCodec constants to H.263 Level numbers.

Parameters
levelConst: Int

The MediaCodec H.263 level constant.

Returns
Int

The H.263 level number, or -1 if the constant is not recognized.

h263ConstToProfileNumber

java-static fun h263ConstToProfileNumber(profileConst: Int): Int

Maps Android MediaCodec constants to H.263 Profile numbers.

Parameters
profileConst: Int

The MediaCodec H.263 profile constant.

Returns
Int

The H.263 profile number, or -1 if the constant is not recognized.

parseAlacAudioSpecificConfig

java-static fun parseAlacAudioSpecificConfig(audioSpecificConfig: ByteArray!): IntArray<Int>!

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

Parameters
audioSpecificConfig: ByteArray!

A byte array containing the AudioSpecificConfig to parse.

Returns
IntArray<Int>!

An int array consisting of the sample rate in Hz, the channel count and the bit depth.

parseCea708InitializationData

java-static fun parseCea708InitializationData(
    initializationData: (Mutable)List<ByteArray!>!
): Boolean

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

Parameters
initializationData: (Mutable)List<ByteArray!>!

The initialization data to parse.

Returns
Boolean

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

splitNalUnits

java-static fun splitNalUnits(data: ByteArray!): Array<ByteArray<Byte>!>?

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
data: ByteArray!

An array of data.

Returns
Array<ByteArray<Byte>!>?

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