public final class NalUnitUtil extends Object
| Modifier and Type | Class | Description |
|---|---|---|
static class |
NalUnitUtil.PpsData |
Holds data parsed from a picture parameter set NAL unit.
|
static class |
NalUnitUtil.SpsData |
Holds data parsed from a sequence parameter set NAL unit.
|
| Modifier and Type | Field | Description |
|---|---|---|
static float[] |
ASPECT_RATIO_IDC_VALUES |
Aspect ratios indexed by aspect_ratio_idc, in H.264 and H.265 SPSs.
|
static int |
EXTENDED_SAR |
Value for aspect_ratio_idc indicating an extended aspect ratio, in H.264 and H.265 SPSs.
|
static byte[] |
NAL_START_CODE |
Four initial bytes that must prefix NAL units for decoding.
|
| Modifier and Type | Method | Description |
|---|---|---|
static void |
clearPrefixFlags(boolean[] prefixFlags) |
Clears prefix flags, as used by
findNalUnit(byte[], int, int, boolean[]). |
static void |
discardToSps(ByteBuffer data) |
Discards data from the buffer up to the first SPS, where
data.position() is interpreted
as the length of the buffer. |
static int |
findNalUnit(byte[] data,
int startOffset,
int endOffset,
boolean[] prefixFlags) |
Finds the first NAL unit in
data. |
static int |
getH265NalUnitType(byte[] data,
int offset) |
Returns the type of the H.265 NAL unit in
data that starts at offset. |
static int |
getNalUnitType(byte[] data,
int offset) |
Returns the type of the NAL unit in
data that starts at offset. |
static boolean |
isNalUnitSei(String mimeType,
byte nalUnitHeaderFirstByte) |
Returns whether the NAL unit with the specified header contains supplemental enhancement
information.
|
static NalUnitUtil.PpsData |
parsePpsNalUnit(byte[] nalData,
int nalOffset,
int nalLimit) |
Parses a PPS NAL unit using the syntax defined in ITU-T Recommendation H.264 (2013) subsection
7.3.2.2.
|
static NalUnitUtil.SpsData |
parseSpsNalUnit(byte[] nalData,
int nalOffset,
int nalLimit) |
Parses an SPS NAL unit using the syntax defined in ITU-T Recommendation H.264 (2013) subsection
7.3.2.1.1.
|
static int |
unescapeStream(byte[] data,
int limit) |
Unescapes
data up to the specified limit, replacing occurrences of [0, 0, 3] with
[0, 0]. |
public static final byte[] NAL_START_CODE
public static final int EXTENDED_SAR
public static final float[] ASPECT_RATIO_IDC_VALUES
public static int unescapeStream(byte[] data,
int limit)
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.
data - The data to unescape.limit - The limit (exclusive) of the data to unescape.public static void discardToSps(ByteBuffer data)
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.
data - Buffer containing start code delimited NAL units.public static boolean isNalUnitSei(@Nullable
String mimeType,
byte nalUnitHeaderFirstByte)
mimeType - The sample MIME type, or null if unknown.nalUnitHeaderFirstByte - The first byte of nal_unit().MimeType is null.public static int getNalUnitType(byte[] data,
int offset)
data that starts at offset.data - The data to search.offset - The start offset of a NAL unit. Must lie between -3 (inclusive) and
data.length - 3 (exclusive).public static int getH265NalUnitType(byte[] data,
int offset)
data that starts at offset.data - The data to search.offset - The start offset of a NAL unit. Must lie between -3 (inclusive) and
data.length - 3 (exclusive).public static NalUnitUtil.SpsData parseSpsNalUnit(byte[] nalData, int nalOffset, int nalLimit)
nalData - A buffer containing escaped SPS data.nalOffset - The offset of the NAL unit header in nalData.nalLimit - The limit of the NAL unit in nalData.public static NalUnitUtil.PpsData parsePpsNalUnit(byte[] nalData, int nalOffset, int nalLimit)
nalData - A buffer containing escaped PPS data.nalOffset - The offset of the NAL unit header in nalData.nalLimit - The limit of the NAL unit in nalData.public static int findNalUnit(byte[] data,
int startOffset,
int endOffset,
boolean[] prefixFlags)
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.
data - The data to search.startOffset - The offset (inclusive) in the data to start the search.endOffset - The offset (exclusive) in the data to end the search.prefixFlags - 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.endOffset if a NAL unit was not found.public static void clearPrefixFlags(boolean[] prefixFlags)
findNalUnit(byte[], int, int, boolean[]).prefixFlags - The flags to clear.