@UnstableApi
class VorbisUtil


Utility methods for parsing Vorbis streams.

Summary

Nested types

Vorbis comment header.

Vorbis setup header modes.

Vorbis identification header.

Public functions

java-static Int
getPacketBlockSize(
    firstByteOfAudioPacket: Byte,
    idHeader: VorbisUtil.VorbisIdHeader!,
    modes: Array<VorbisUtil.Mode!>!
)

Returns the block size of the given packet.

java-static Int
getSampleCountInPacket(
    packetBlockSize: Int,
    previousPacketBlockSize: Int,
    seenFirstAudioPacket: Boolean
)

Returns the number of samples in the given packet.

java-static Int
iLog(x: Int)

Returns ilog(x), which is the index of the highest set bit in x.

java-static VorbisUtil.CommentHeader!

Reads a Vorbis comment header.

java-static VorbisUtil.CommentHeader!
readVorbisCommentHeader(
    headerData: ParsableByteArray!,
    hasMetadataHeader: Boolean,
    hasFramingBit: Boolean
)

Reads a Vorbis comment header.

java-static VorbisUtil.VorbisIdHeader!

Reads a Vorbis identification header from headerData.

java-static Array<VorbisUtil.Mode!>!
readVorbisModes(headerData: ParsableByteArray!, channels: Int)

This method reads the modes which are located at the very end of the Vorbis setup header.

java-static Boolean
@CanIgnoreReturnValue
verifyVorbisHeaderCapturePattern(
    headerType: Int,
    header: ParsableByteArray!,
    quiet: Boolean
)

Verifies whether the next bytes in header are a Vorbis header of the given headerType.

Public functions

getPacketBlockSize

java-static fun getPacketBlockSize(
    firstByteOfAudioPacket: Byte,
    idHeader: VorbisUtil.VorbisIdHeader!,
    modes: Array<VorbisUtil.Mode!>!
): Int

Returns the block size of the given packet.

Parameters
firstByteOfAudioPacket: Byte

The first byte of the audio packet.

idHeader: VorbisUtil.VorbisIdHeader!

The Vorbis identification header.

modes: Array<VorbisUtil.Mode!>!

The Vorbis modes.

Returns
Int

The block size of the packet.

getSampleCountInPacket

java-static fun getSampleCountInPacket(
    packetBlockSize: Int,
    previousPacketBlockSize: Int,
    seenFirstAudioPacket: Boolean
): Int

Returns the number of samples in the given packet.

Parameters
packetBlockSize: Int

The block size of the packet.

previousPacketBlockSize: Int

The block size of the previous packet.

seenFirstAudioPacket: Boolean

Whether the first audio packet has been seen.

Returns
Int

The number of samples in the packet.

iLog

java-static fun iLog(x: Int): Int

Returns ilog(x), which is the index of the highest set bit in x.

See the Vorbis spec

Parameters
x: Int

the value of which the ilog should be calculated.

Returns
Int

ilog(x)

readVorbisCommentHeader

java-static fun readVorbisCommentHeader(headerData: ParsableByteArray!): VorbisUtil.CommentHeader!

Reads a Vorbis comment header.

See the Vorbis spec/Comment header

Parameters
headerData: ParsableByteArray!

A ParsableByteArray wrapping the header data.

Returns
VorbisUtil.CommentHeader!

A VorbisUtil.CommentHeader with all the comments.

Throws
androidx.media3.common.ParserException

If an error occurs parsing the comment header.

readVorbisCommentHeader

java-static fun readVorbisCommentHeader(
    headerData: ParsableByteArray!,
    hasMetadataHeader: Boolean,
    hasFramingBit: Boolean
): VorbisUtil.CommentHeader!

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
headerData: ParsableByteArray!

A ParsableByteArray wrapping the header data.

hasMetadataHeader: Boolean

Whether the headerData contains a Vorbis metadata common header preceding the comment header.

hasFramingBit: Boolean

Whether the headerData contains a framing bit.

Returns
VorbisUtil.CommentHeader!

A VorbisUtil.CommentHeader with all the comments.

Throws
androidx.media3.common.ParserException

If an error occurs parsing the comment header.

readVorbisIdentificationHeader

java-static fun readVorbisIdentificationHeader(headerData: ParsableByteArray!): VorbisUtil.VorbisIdHeader!

Reads a Vorbis identification header from headerData.

See the Vorbis spec/Identification header

Parameters
headerData: ParsableByteArray!

a ParsableByteArray wrapping the header data.

Throws
androidx.media3.common.ParserException

thrown if invalid capture pattern is detected.

readVorbisModes

java-static fun readVorbisModes(headerData: ParsableByteArray!, channels: Int): Array<VorbisUtil.Mode!>!

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
headerData: ParsableByteArray!

a ParsableByteArray containing setup header data.

channels: Int

the number of channels.

Returns
Array<VorbisUtil.Mode!>!

an array of Modes.

Throws
androidx.media3.common.ParserException

thrown if bit stream is invalid.

verifyVorbisHeaderCapturePattern

@CanIgnoreReturnValue
java-static fun verifyVorbisHeaderCapturePattern(
    headerType: Int,
    header: ParsableByteArray!,
    quiet: Boolean
): Boolean

Verifies whether the next bytes in header are a Vorbis header of the given headerType.

Parameters
headerType: Int

the type of the header expected.

header: ParsableByteArray!

the alleged header bytes.

quiet: Boolean

if true no exceptions are thrown. Instead false is returned.

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.