OpusUtil
@UnstableApi
class OpusUtil
Utility methods for handling Opus audio streams.
Summary
Constants |
|
|---|---|
const Int |
MAX_BYTES_PER_SECOND = 63750Maximum achievable Opus bitrate. |
const Int |
SAMPLE_RATE = 48000Opus streams are always 48000 Hz. |
Public functions |
|
|---|---|
java-static (Mutable)List<ByteArray<Byte>!>! |
buildInitializationData(header: ByteArray!)Builds codec initialization data from an Opus Identification Header. |
java-static Int |
getChannelCount(header: ByteArray!)Parses the channel count from an Opus Identification Header. |
java-static Long |
getPacketDurationUs(buffer: ByteArray!)Returns the duration of the given audio packet. |
java-static Int |
getPreSkipSamples(header: ByteArray!)Returns the number of pre-skip samples specified by the given Opus codec initialization data. |
java-static Boolean |
needToDecodeOpusFrame(startTimeUs: Long, frameTimeUs: Long)Returns whether an Opus frame should be sent to the decoder as it is either past the start position or within the seek-preroll duration. |
java-static Int |
parseOggPacketAudioSampleCount(buffer: ByteBuffer!)Returns the number of audio samples in the given Ogg encapuslated Opus packet. |
java-static Int |
Calculate the offset from the start of the buffer to audio sample Ogg packets. |
java-static Int |
parsePacketAudioSampleCount(buffer: ByteBuffer!)Returns the number of audio samples in the given audio packet. |
Constants
Public functions
buildInitializationData
java-static fun buildInitializationData(header: ByteArray!): (Mutable)List<ByteArray<Byte>!>!
Builds codec initialization data from an Opus Identification Header.
| Parameters | |
|---|---|
header: ByteArray! |
An Opus Identification Header, as defined by RFC 7845. |
| Returns | |
|---|---|
(Mutable)List<ByteArray<Byte>!>! |
Codec initialization data suitable for an Opus MediaCodec. |
getChannelCount
java-static fun getChannelCount(header: ByteArray!): Int
Parses the channel count from an Opus Identification Header.
| Parameters | |
|---|---|
header: ByteArray! |
An Opus Identification Header, as defined by RFC 7845. |
| Returns | |
|---|---|
Int |
The parsed channel count. |
getPacketDurationUs
java-static fun getPacketDurationUs(buffer: ByteArray!): Long
Returns the duration of the given audio packet.
| Parameters | |
|---|---|
buffer: ByteArray! |
The audio packet. |
| Returns | |
|---|---|
Long |
Returns the duration of the given audio packet, in microseconds. |
getPreSkipSamples
java-static fun getPreSkipSamples(header: ByteArray!): Int
Returns the number of pre-skip samples specified by the given Opus codec initialization data.
| Parameters | |
|---|---|
header: ByteArray! |
The Opus Identification header. |
| Returns | |
|---|---|
Int |
The number of pre-skip samples. |
needToDecodeOpusFrame
java-static fun needToDecodeOpusFrame(startTimeUs: Long, frameTimeUs: Long): Boolean
Returns whether an Opus frame should be sent to the decoder as it is either past the start position or within the seek-preroll duration.
The measure of whether an Opus frame should not be decoded is if its time precedes the start position by more than the default seek-preroll value.
| Parameters | |
|---|---|
startTimeUs: Long |
The time to start playing at. |
frameTimeUs: Long |
The time of the Opus sample. |
| Returns | |
|---|---|
Boolean |
Whether the frame should be decoded. |
parseOggPacketAudioSampleCount
java-static fun parseOggPacketAudioSampleCount(buffer: ByteBuffer!): Int
Returns the number of audio samples in the given Ogg encapuslated Opus packet.
The buffer's position is not modified.
| Parameters | |
|---|---|
buffer: ByteBuffer! |
The audio packet. |
| Returns | |
|---|---|
Int |
Returns the number of audio samples in the packet. |
parseOggPacketForPreAudioSampleByteCount
java-static fun parseOggPacketForPreAudioSampleByteCount(buffer: ByteBuffer!): Int
Calculate the offset from the start of the buffer to audio sample Ogg packets.
| Parameters | |
|---|---|
buffer: ByteBuffer! |
containing the Ogg Encapsulated Opus audio bitstream. |
| Returns | |
|---|---|
Int |
the offset before the Ogg packet containing audio samples. |
parsePacketAudioSampleCount
java-static fun parsePacketAudioSampleCount(buffer: ByteBuffer!): Int
Returns the number of audio samples in the given audio packet.
The buffer's position is not modified.
| Parameters | |
|---|---|
buffer: ByteBuffer! |
The audio packet. |
| Returns | |
|---|---|
Int |
Returns the number of audio samples in the packet. |