VorbisUtil
@UnstableApi
public final class VorbisUtil
Utility methods for parsing Vorbis streams.
Summary
Nested types |
|---|
public final class VorbisUtil.CommentHeaderVorbis comment header. |
public final class VorbisUtil.ModeVorbis setup header modes. |
public final class VorbisUtil.VorbisIdHeaderVorbis identification header. |
Public methods |
|
|---|---|
static @Nullable int[] |
getVorbisToAndroidChannelLayoutMapping(int channelCount)Returns the mapping from VORBIS channel layout to the channel layout expected by Android, or null if the mapping is unchanged. |
static int |
iLog(int x)Returns ilog(x), which is the index of the highest set bit in |
static @Nullable Metadata |
parseVorbisComments(List<String> vorbisComments)Builds a |
static ImmutableList<byte[]> |
parseVorbisCsdFromEsdsInitializationData(byte[] initializationData)Returns codec-specific data for configuring a media codec for decoding Vorbis. |
static VorbisUtil.CommentHeader |
readVorbisCommentHeader(ParsableByteArray headerData)Reads a Vorbis comment header. |
static VorbisUtil.CommentHeader |
readVorbisCommentHeader(Reads a Vorbis comment header. |
static VorbisUtil.VorbisIdHeader |
readVorbisIdentificationHeader(ParsableByteArray headerData)Reads a Vorbis identification header from |
static VorbisUtil.Mode[] |
readVorbisModes(ParsableByteArray headerData, int channels)This method reads the modes which are located at the very end of the Vorbis setup header. |
static boolean |
verifyVorbisHeaderCapturePattern(Verifies whether the next bytes in |
Public methods
getVorbisToAndroidChannelLayoutMapping
public static @Nullable int[] getVorbisToAndroidChannelLayoutMapping(int channelCount)
Returns the mapping from VORBIS channel layout to the channel layout expected by Android, or null if the mapping is unchanged.
See https://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-810004.3.9 and https://developer.android.com/reference/android/media/AudioFormat#channelMask.
iLog
public static int iLog(int x)
Returns ilog(x), which is the index of the highest set bit in x.
See the Vorbis spec
| Parameters | |
|---|---|
int x |
the value of which the ilog should be calculated. |
| Returns | |
|---|---|
int |
ilog(x) |
parseVorbisComments
public static @Nullable Metadata parseVorbisComments(List<String> vorbisComments)
Builds a Metadata instance from a list of Vorbis Comments.
METADATA_BLOCK_PICTURE comments will be transformed into PictureFrame entries. All others will be transformed into VorbisComment entries.
parseVorbisCsdFromEsdsInitializationData
public static ImmutableList<byte[]> parseVorbisCsdFromEsdsInitializationData(byte[] initializationData)
Returns codec-specific data for configuring a media codec for decoding Vorbis.
| Parameters | |
|---|---|
byte[] initializationData |
The initialization data from the ESDS box. |
| Returns | |
|---|---|
ImmutableList<byte[]> |
Codec-specific data for configuring a media codec for decoding Vorbis. |
readVorbisCommentHeader
public static VorbisUtil.CommentHeader readVorbisCommentHeader(ParsableByteArray headerData)
Reads a Vorbis comment header.
See the Vorbis spec/Comment header
| Parameters | |
|---|---|
ParsableByteArray headerData |
A |
| Returns | |
|---|---|
VorbisUtil.CommentHeader |
A |
| Throws | |
|---|---|
androidx.media3.common.ParserException |
If an error occurs parsing the comment header. |
readVorbisCommentHeader
public static VorbisUtil.CommentHeader readVorbisCommentHeader(
ParsableByteArray headerData,
boolean hasMetadataHeader,
boolean hasFramingBit
)
Reads a Vorbis comment header.
The data provided may not contain the Vorbis metadata common header and the framing bit.
See the Vorbis spec/Comment header
| Parameters | |
|---|---|
ParsableByteArray headerData |
A |
boolean hasMetadataHeader |
Whether the |
boolean hasFramingBit |
Whether the |
| Returns | |
|---|---|
VorbisUtil.CommentHeader |
A |
| Throws | |
|---|---|
androidx.media3.common.ParserException |
If an error occurs parsing the comment header. |
readVorbisIdentificationHeader
public static VorbisUtil.VorbisIdHeader readVorbisIdentificationHeader(ParsableByteArray headerData)
Reads a Vorbis identification header from headerData.
See the Vorbis spec/Identification header
| Parameters | |
|---|---|
ParsableByteArray headerData |
a |
| Returns | |
|---|---|
VorbisUtil.VorbisIdHeader |
a |
| Throws | |
|---|---|
androidx.media3.common.ParserException |
thrown if invalid capture pattern is detected. |
readVorbisModes
public static VorbisUtil.Mode[] readVorbisModes(ParsableByteArray headerData, int channels)
This method reads the modes which are located at the very end of the Vorbis setup header. That's why we need to partially decode or at least read the entire setup header to know where to start reading the modes.
See the Vorbis spec/Setup header
| Parameters | |
|---|---|
ParsableByteArray headerData |
a |
int channels |
the number of channels. |
| Returns | |
|---|---|
VorbisUtil.Mode[] |
an array of |
| Throws | |
|---|---|
androidx.media3.common.ParserException |
thrown if bit stream is invalid. |
verifyVorbisHeaderCapturePattern
public static boolean verifyVorbisHeaderCapturePattern(
int headerType,
ParsableByteArray header,
boolean quiet
)
Verifies whether the next bytes in header are a Vorbis header of the given
headerType.
| Parameters | |
|---|---|
int headerType |
the type of the header expected. |
ParsableByteArray header |
the alleged header bytes. |
boolean quiet |
if |
| Returns | |
|---|---|
boolean |
Whether the header is a Vorbis header. |
| Throws | |
|---|---|
androidx.media3.common.ParserException |
thrown if header type or capture pattern is not as expected. |