@UnstableApi
class NalUnitUtil


Utility methods for handling H.264/AVC and H.265/HEVC NAL units.

Summary

Nested types

Holds data that maps NAL unit header layer ID to the internal layer info specified in VPS.

Holds data parsed from a H.265 NAL unit header.

Holds data parsed from a H.265 profile_tier_level() of either VPS or SPS.

Holds a list of H.265 profile_tier_level()s and a corresponding list of indices.

Holds data parsed from a H.265 rep_format() of VPS extension - vps_extension().

Holds a list of H.265 rep_format()s and a corresponding list of indices.

Holds data parsed from a H.265 3D reference displays information SEI message.

Holds data parsed from a H.265 sequence parameter set NAL unit.

Holds data parsed from a H.265 video_signal_info() of vps_vui() of vps_extension().

Holds a list of H.265 video_signal_info()s and a corresponding list of indices.

Holds data parsed from a H.265 video parameter set NAL unit.

Holds data parsed from a picture parameter set NAL unit.

Holds data parsed from a H.264 sequence parameter set NAL unit.

Constants

const FloatArray<Float>!

Aspect ratios indexed by aspect_ratio_idc, in H.264 and H.265 SPSs.

const Int

Value for aspect_ratio_idc indicating an extended aspect ratio, in H.264 and H.265 SPSs.

const Int

H.264 access unit delimiter.

const Int

H.264 coded slice of an IDR picture.

const Int

H.264 coded slice of a non-IDR picture.

const Int

H.264 coded slice data partition A.

const Int

H.264 picture parameter set.

const Int

H.264 prefix NAL unit.

const Int

H.264 supplemental enhancement information.

const Int

H.264 sequence parameter set.

const Int

H.265 access unit delimiter (AUD_NUT).

const Int

H.265 coded slice segment of a broken link access picture (BLA_W_LP).

const Int

H.265 coded slice segment of a clean random access picture (CRA_NUT).

const Int

H.265 picture parameter set (PPS_NUT).

const Int

H.265 prefixed supplemental enhancement information (PREFIX_SEI_NUT).

const Int

H.265 coded slice segment of a random access skipped leading picture (RASL_R).

const Int

H.265 sequence parameter set (SPS_NUT).

const Int

H.265 suffixed supplemental enhancement information (SUFFIX_SEI_NUT).

const Int

H.265 video parameter set (VPS_NUT).

const ByteArray<Byte>!

Four initial bytes that must prefix NAL units for decoding.

const Int

This property is deprecated.

Use H264_NAL_UNIT_TYPE_AUD

const Int

This property is deprecated.

Use H264_NAL_UNIT_TYPE_IDR

const Int

This property is deprecated.

Use H264_NAL_UNIT_TYPE_NON_IDR

const Int

This property is deprecated.

Use H264_NAL_UNIT_TYPE_PARTITION_A

const Int

This property is deprecated.

Use H264_NAL_UNIT_TYPE_PPS

const Int

This property is deprecated.

Use H264_NAL_UNIT_TYPE_PREFIX

const Int

This property is deprecated.

Use H264_NAL_UNIT_TYPE_SEI

const Int

This property is deprecated.

Use H264_NAL_UNIT_TYPE_SPS

Public functions

java-static Unit

Clears prefix flags, as used by findNalUnit.

java-static Unit

Discards data from the buffer up to the first SPS, where data.position() is interpreted as the length of the buffer.

java-static Int
findNalUnit(
    data: ByteArray!,
    startOffset: Int,
    endOffset: Int,
    prefixFlags: BooleanArray!
)

Finds the first NAL unit in data.

java-static String?

Returns a new RFC 6381 codecs description string specifically for the single-layer HEVC case.

java-static Int
getH265NalUnitType(data: ByteArray!, offset: Int)

Returns the type of the H.265 NAL unit in data that starts at offset.

java-static Int
getNalUnitType(data: ByteArray!, offset: Int)

Returns the type of the NAL unit in data that starts at offset.

java-static Boolean
isH264NalUnitDependedOn(nalUnitHeaderFirstByte: Byte)

Returns whether the H.264 NAL unit can be depended on by subsequent NAL units in decoding order.

java-static Boolean
isNalUnitSei(format: Format!, nalUnitHeaderFirstByte: Byte)

Returns whether the NAL unit with the specified header contains supplemental enhancement information.

java-static Boolean
isNalUnitSei(mimeType: String?, nalUnitHeaderFirstByte: Byte)

Returns whether the NAL unit with the specified header contains supplemental enhancement information.

java-static NalUnitUtil.H265Sei3dRefDisplayInfoData?
parseH265Sei3dRefDisplayInfo(
    nalData: ByteArray!,
    nalOffset: Int,
    nalLimit: Int
)

Parses a H.265 3D reference displays information SEI message syntax defined in ITU-T Recommendation H.265 (2019) subsection G.14.2.3.

java-static NalUnitUtil.H265SpsData!
parseH265SpsNalUnit(
    nalData: ByteArray!,
    nalOffset: Int,
    nalLimit: Int,
    vpsData: NalUnitUtil.H265VpsData?
)

Parses a H.265 SPS NAL unit using the syntax defined in ITU-T Recommendation H.265 (2019) subsections 7.3.2.2.1 and F.7.3.2.2.1.

java-static NalUnitUtil.H265SpsData!
parseH265SpsNalUnitPayload(
    nalData: ByteArray!,
    nalOffset: Int,
    nalLimit: Int,
    nalHeader: NalUnitUtil.H265NalHeader!,
    vpsData: NalUnitUtil.H265VpsData?
)

Parses a H.265 SPS NAL unit payload (excluding the NAL unit header) using the syntax defined in ITU-T Recommendation H.265 (2019) subsections 7.3.2.2.1 and F.7.3.2.2.1.

java-static NalUnitUtil.H265VpsData!
parseH265VpsNalUnit(nalData: ByteArray!, nalOffset: Int, nalLimit: Int)

Parses a H.265 VPS NAL unit using the syntax defined in ITU-T Recommendation H.265 (2019) subsections 7.3.2.1 and F.7.3.2.1.

java-static NalUnitUtil.PpsData!
parsePpsNalUnit(nalData: ByteArray!, nalOffset: Int, nalLimit: Int)

Parses a PPS NAL unit using the syntax defined in ITU-T Recommendation H.264 (2013) subsection 7.3.2.2.

java-static NalUnitUtil.PpsData!
parsePpsNalUnitPayload(nalData: ByteArray!, nalOffset: Int, nalLimit: Int)

Parses a PPS NAL unit payload (excluding the NAL unit header) using the syntax defined in ITU-T Recommendation H.264 (2013) subsection 7.3.2.2.

java-static NalUnitUtil.SpsData!
parseSpsNalUnit(nalData: ByteArray!, nalOffset: Int, nalLimit: Int)

Parses a SPS NAL unit using the syntax defined in ITU-T Recommendation H.264 (2013) subsection 7.3.2.1.1.

java-static NalUnitUtil.SpsData!
parseSpsNalUnitPayload(nalData: ByteArray!, nalOffset: Int, nalLimit: Int)

Parses a SPS NAL unit payload (excluding the NAL unit header) using the syntax defined in ITU-T Recommendation H.264 (2013) subsection 7.3.2.1.1.

java-static Int
unescapeStream(data: ByteArray!, limit: Int)

Unescapes data up to the specified limit, replacing occurrences of [0, 0, 3] with [0, 0].

Constants

ASPECT_RATIO_IDC_VALUES

const val ASPECT_RATIO_IDC_VALUESFloatArray<Float>!

Aspect ratios indexed by aspect_ratio_idc, in H.264 and H.265 SPSs.

EXTENDED_SAR

const val EXTENDED_SAR = 255: Int

Value for aspect_ratio_idc indicating an extended aspect ratio, in H.264 and H.265 SPSs.

H264_NAL_UNIT_TYPE_AUD

const val H264_NAL_UNIT_TYPE_AUD = 9: Int

H.264 access unit delimiter.

H264_NAL_UNIT_TYPE_IDR

const val H264_NAL_UNIT_TYPE_IDR = 5: Int

H.264 coded slice of an IDR picture.

H264_NAL_UNIT_TYPE_NON_IDR

const val H264_NAL_UNIT_TYPE_NON_IDR = 1: Int

H.264 coded slice of a non-IDR picture.

H264_NAL_UNIT_TYPE_PARTITION_A

const val H264_NAL_UNIT_TYPE_PARTITION_A = 2: Int

H.264 coded slice data partition A.

H264_NAL_UNIT_TYPE_PPS

const val H264_NAL_UNIT_TYPE_PPS = 8: Int

H.264 picture parameter set.

H264_NAL_UNIT_TYPE_PREFIX

const val H264_NAL_UNIT_TYPE_PREFIX = 14: Int

H.264 prefix NAL unit.

H264_NAL_UNIT_TYPE_SEI

const val H264_NAL_UNIT_TYPE_SEI = 6: Int

H.264 supplemental enhancement information.

H264_NAL_UNIT_TYPE_SPS

const val H264_NAL_UNIT_TYPE_SPS = 7: Int

H.264 sequence parameter set.

H265_NAL_UNIT_TYPE_AUD

const val H265_NAL_UNIT_TYPE_AUD = 35: Int

H.265 access unit delimiter (AUD_NUT).

H265_NAL_UNIT_TYPE_BLA_W_LP

const val H265_NAL_UNIT_TYPE_BLA_W_LP = 16: Int

H.265 coded slice segment of a broken link access picture (BLA_W_LP).

H265_NAL_UNIT_TYPE_CRA

const val H265_NAL_UNIT_TYPE_CRA = 21: Int

H.265 coded slice segment of a clean random access picture (CRA_NUT).

H265_NAL_UNIT_TYPE_PPS

const val H265_NAL_UNIT_TYPE_PPS = 34: Int

H.265 picture parameter set (PPS_NUT).

H265_NAL_UNIT_TYPE_PREFIX_SEI

const val H265_NAL_UNIT_TYPE_PREFIX_SEI = 39: Int

H.265 prefixed supplemental enhancement information (PREFIX_SEI_NUT).

H265_NAL_UNIT_TYPE_RASL_R

const val H265_NAL_UNIT_TYPE_RASL_R = 9: Int

H.265 coded slice segment of a random access skipped leading picture (RASL_R).

H265_NAL_UNIT_TYPE_SPS

const val H265_NAL_UNIT_TYPE_SPS = 33: Int

H.265 sequence parameter set (SPS_NUT).

H265_NAL_UNIT_TYPE_SUFFIX_SEI

const val H265_NAL_UNIT_TYPE_SUFFIX_SEI = 40: Int

H.265 suffixed supplemental enhancement information (SUFFIX_SEI_NUT).

H265_NAL_UNIT_TYPE_VPS

const val H265_NAL_UNIT_TYPE_VPS = 32: Int

H.265 video parameter set (VPS_NUT).

NAL_START_CODE

const val NAL_START_CODEByteArray<Byte>!

Four initial bytes that must prefix NAL units for decoding.

NAL_UNIT_TYPE_AUD

const val NAL_UNIT_TYPE_AUD = 9: Int

NAL_UNIT_TYPE_IDR

const val NAL_UNIT_TYPE_IDR = 5: Int

NAL_UNIT_TYPE_NON_IDR

const val NAL_UNIT_TYPE_NON_IDR = 1: Int

NAL_UNIT_TYPE_PARTITION_A

const val NAL_UNIT_TYPE_PARTITION_A = 2: Int

NAL_UNIT_TYPE_PPS

const val NAL_UNIT_TYPE_PPS = 8: Int

NAL_UNIT_TYPE_PREFIX

const val NAL_UNIT_TYPE_PREFIX = 14: Int

NAL_UNIT_TYPE_SEI

const val NAL_UNIT_TYPE_SEI = 6: Int

NAL_UNIT_TYPE_SPS

const val NAL_UNIT_TYPE_SPS = 7: Int

Public functions

clearPrefixFlags

java-static fun clearPrefixFlags(prefixFlags: BooleanArray!): Unit

Clears prefix flags, as used by findNalUnit.

Parameters
prefixFlags: BooleanArray!

The flags to clear.

discardToSps

java-static fun discardToSps(data: ByteBuffer!): Unit

Discards data from the buffer up to the first SPS, where data.position() is interpreted as the length of the buffer.

When the method returns, data.position() will contain the new length of the buffer. If the buffer is not empty it is guaranteed to start with an SPS.

Parameters
data: ByteBuffer!

Buffer containing start code delimited NAL units.

findNalUnit

java-static fun findNalUnit(
    data: ByteArray!,
    startOffset: Int,
    endOffset: Int,
    prefixFlags: BooleanArray!
): Int

Finds the first NAL unit in data.

If prefixFlags is null then the first three bytes of a NAL unit must be entirely contained within the part of the array being searched in order for it to be found.

When prefixFlags is non-null, this method supports finding NAL units whose first four bytes span data arrays passed to successive calls. To use this feature, pass the same prefixFlags parameter to successive calls. State maintained in this parameter enables the detection of such NAL units. Note that when using this feature, the return value may be 3, 2 or 1 less than startOffset, to indicate a NAL unit starting 3, 2 or 1 bytes before the first byte in the current array.

Parameters
data: ByteArray!

The data to search.

startOffset: Int

The offset (inclusive) in the data to start the search.

endOffset: Int

The offset (exclusive) in the data to end the search.

prefixFlags: BooleanArray!

A boolean array whose first three elements are used to store the state required to detect NAL units where the NAL unit prefix spans array boundaries. The array must be at least 3 elements long.

Returns
Int

The offset of the NAL unit, or endOffset if a NAL unit was not found.

getH265BaseLayerCodecsString

java-static fun getH265BaseLayerCodecsString(csdBuffers: (Mutable)List<ByteArray!>!): String?

Returns a new RFC 6381 codecs description string specifically for the single-layer HEVC case. When falling back to single-layer HEVC from L-HEVC, both profile and level should be adjusted for the base layer case and the codecs description string should represent that. For the single-layer HEVC case, the string is derived from the SPS of the base layer.

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

The CSD buffers that include the SPS of the base layer.

Returns
String?

A RFC 6381 codecs string derived from the SPS of the base layer if such information is available, or null otherwise.

getH265NalUnitType

java-static fun getH265NalUnitType(data: ByteArray!, offset: Int): Int

Returns the type of the H.265 NAL unit in data that starts at offset.

Parameters
data: ByteArray!

The data to search.

offset: Int

The start offset of a NAL unit. Must lie between -3 (inclusive) and data.length - 3 (exclusive).

Returns
Int

The type of the unit.

getNalUnitType

java-static fun getNalUnitType(data: ByteArray!, offset: Int): Int

Returns the type of the NAL unit in data that starts at offset.

Parameters
data: ByteArray!

The data to search.

offset: Int

The start offset of a NAL unit. Must lie between -3 (inclusive) and data.length - 3 (exclusive).

Returns
Int

The type of the unit.

isH264NalUnitDependedOn

java-static fun isH264NalUnitDependedOn(nalUnitHeaderFirstByte: Byte): Boolean

Returns whether the H.264 NAL unit can be depended on by subsequent NAL units in decoding order.

Parameters
nalUnitHeaderFirstByte: Byte

The first byte of nal_unit().

isNalUnitSei

java-static fun isNalUnitSei(format: Format!, nalUnitHeaderFirstByte: Byte): Boolean

Returns whether the NAL unit with the specified header contains supplemental enhancement information.

Parameters
format: Format!

The sample Format.

nalUnitHeaderFirstByte: Byte

The first byte of nal_unit().

Returns
Boolean

Whether the NAL unit with the specified header is an SEI NAL unit. False is returned if the MimeType is null.

isNalUnitSei

java-static fun isNalUnitSei(mimeType: String?, nalUnitHeaderFirstByte: Byte): Boolean

Returns whether the NAL unit with the specified header contains supplemental enhancement information.

Parameters
mimeType: String?

The sample MIME type, or null if unknown.

nalUnitHeaderFirstByte: Byte

The first byte of nal_unit().

Returns
Boolean

Whether the NAL unit with the specified header is an SEI NAL unit. False is returned if the MimeType is null.

parseH265Sei3dRefDisplayInfo

java-static fun parseH265Sei3dRefDisplayInfo(
    nalData: ByteArray!,
    nalOffset: Int,
    nalLimit: Int
): NalUnitUtil.H265Sei3dRefDisplayInfoData?

Parses a H.265 3D reference displays information SEI message syntax defined in ITU-T Recommendation H.265 (2019) subsection G.14.2.3. Given a generic PREFIX_SEI NAL unit, only 3D reference displays information SEI is parsed, if exists.

Parameters
nalData: ByteArray!

A buffer containing escaped prefix SEI data.

nalOffset: Int

The offset of the NAL unit header in nalData.

nalLimit: Int

The limit of the NAL unit in nalData.

Returns
NalUnitUtil.H265Sei3dRefDisplayInfoData?

A parsed representation of the PPS data.

parseH265SpsNalUnit

java-static fun parseH265SpsNalUnit(
    nalData: ByteArray!,
    nalOffset: Int,
    nalLimit: Int,
    vpsData: NalUnitUtil.H265VpsData?
): NalUnitUtil.H265SpsData!

Parses a H.265 SPS NAL unit using the syntax defined in ITU-T Recommendation H.265 (2019) subsections 7.3.2.2.1 and F.7.3.2.2.1.

Parameters
nalData: ByteArray!

A buffer containing escaped SPS data.

nalOffset: Int

The offset of the NAL unit header in nalData.

nalLimit: Int

The limit of the NAL unit in nalData.

vpsData: NalUnitUtil.H265VpsData?

The VPS that the SPS refers to or null if unavailable.

Returns
NalUnitUtil.H265SpsData!

A parsed representation of the SPS data.

parseH265SpsNalUnitPayload

java-static fun parseH265SpsNalUnitPayload(
    nalData: ByteArray!,
    nalOffset: Int,
    nalLimit: Int,
    nalHeader: NalUnitUtil.H265NalHeader!,
    vpsData: NalUnitUtil.H265VpsData?
): NalUnitUtil.H265SpsData!

Parses a H.265 SPS NAL unit payload (excluding the NAL unit header) using the syntax defined in ITU-T Recommendation H.265 (2019) subsections 7.3.2.2.1 and F.7.3.2.2.1.

Parameters
nalData: ByteArray!

A buffer containing escaped SPS data.

nalOffset: Int

The offset of the NAL unit payload in nalData.

nalLimit: Int

The limit of the NAL unit in nalData.

nalHeader: NalUnitUtil.H265NalHeader!

The parsed representation of the NAL header.

vpsData: NalUnitUtil.H265VpsData?

The VPS that the SPS refers to or null if unavailable.

Returns
NalUnitUtil.H265SpsData!

A parsed representation of the SPS data.

parseH265VpsNalUnit

java-static fun parseH265VpsNalUnit(nalData: ByteArray!, nalOffset: Int, nalLimit: Int): NalUnitUtil.H265VpsData!

Parses a H.265 VPS NAL unit using the syntax defined in ITU-T Recommendation H.265 (2019) subsections 7.3.2.1 and F.7.3.2.1.

Parameters
nalData: ByteArray!

A buffer containing escaped VPS data.

nalOffset: Int

The offset of the NAL unit header in nalData.

nalLimit: Int

The limit of the NAL unit in nalData.

Returns
NalUnitUtil.H265VpsData!

A parsed representation of the VPS data.

parsePpsNalUnit

java-static fun parsePpsNalUnit(nalData: ByteArray!, nalOffset: Int, nalLimit: Int): NalUnitUtil.PpsData!

Parses a PPS NAL unit using the syntax defined in ITU-T Recommendation H.264 (2013) subsection 7.3.2.2.

Parameters
nalData: ByteArray!

A buffer containing escaped PPS data.

nalOffset: Int

The offset of the NAL unit header in nalData.

nalLimit: Int

The limit of the NAL unit in nalData.

Returns
NalUnitUtil.PpsData!

A parsed representation of the PPS data.

parsePpsNalUnitPayload

java-static fun parsePpsNalUnitPayload(nalData: ByteArray!, nalOffset: Int, nalLimit: Int): NalUnitUtil.PpsData!

Parses a PPS NAL unit payload (excluding the NAL unit header) using the syntax defined in ITU-T Recommendation H.264 (2013) subsection 7.3.2.2.

Parameters
nalData: ByteArray!

A buffer containing escaped PPS data.

nalOffset: Int

The offset of the NAL unit payload in nalData.

nalLimit: Int

The limit of the NAL unit in nalData.

Returns
NalUnitUtil.PpsData!

A parsed representation of the PPS data.

parseSpsNalUnit

java-static fun parseSpsNalUnit(nalData: ByteArray!, nalOffset: Int, nalLimit: Int): NalUnitUtil.SpsData!

Parses a SPS NAL unit using the syntax defined in ITU-T Recommendation H.264 (2013) subsection 7.3.2.1.1.

Parameters
nalData: ByteArray!

A buffer containing escaped SPS data.

nalOffset: Int

The offset of the NAL unit header in nalData.

nalLimit: Int

The limit of the NAL unit in nalData.

Returns
NalUnitUtil.SpsData!

A parsed representation of the SPS data.

parseSpsNalUnitPayload

java-static fun parseSpsNalUnitPayload(nalData: ByteArray!, nalOffset: Int, nalLimit: Int): NalUnitUtil.SpsData!

Parses a SPS NAL unit payload (excluding the NAL unit header) using the syntax defined in ITU-T Recommendation H.264 (2013) subsection 7.3.2.1.1.

Parameters
nalData: ByteArray!

A buffer containing escaped SPS data.

nalOffset: Int

The offset of the NAL unit payload in nalData.

nalLimit: Int

The limit of the NAL unit in nalData.

Returns
NalUnitUtil.SpsData!

A parsed representation of the SPS data.

unescapeStream

java-static fun unescapeStream(data: ByteArray!, limit: Int): Int

Unescapes data up to the specified limit, replacing occurrences of [0, 0, 3] with [0, 0]. The unescaped data is returned in-place, with the return value indicating its length.

Executions of this method are mutually exclusive, so it should not be called with very large buffers.

Parameters
data: ByteArray!

The data to unescape.

limit: Int

The limit (exclusive) of the data to unescape.

Returns
Int

The length of the unescaped data.