DefaultAudioTrackBufferSizeProvider


@UnstableApi
class DefaultAudioTrackBufferSizeProvider : DefaultAudioSink.AudioTrackBufferSizeProvider


Provide the buffer size to use when creating an AudioTrack.

Summary

Nested types

A builder to create DefaultAudioTrackBufferSizeProvider instances.

Public functions

Int
getBufferSizeInBytes(
    minBufferSizeInBytes: Int,
    @C.Encoding encoding: Int,
    @DefaultAudioSink.OutputMode outputMode: Int,
    pcmFrameSize: Int,
    sampleRate: Int,
    bitrate: Int,
    maxAudioTrackPlaybackSpeed: Double
)

Returns the buffer size to use when creating an AudioTrack for a specific format and output mode.

Protected functions

java-static Int
durationUsToBytes(durationUs: Int, samplingRate: Int, frameSize: Int)
Int
get1xBufferSizeInBytes(
    minBufferSizeInBytes: Int,
    encoding: Int,
    outputMode: Int,
    pcmFrameSize: Int,
    sampleRate: Int,
    bitrate: Int
)

Returns the buffer size for playback at 1x speed.

java-static Int
Int

Returns the buffer size for offload playback.

Int

Returns the buffer size for passthrough playback.

Int
getPcmBufferSizeInBytes(
    minBufferSizeInBytes: Int,
    samplingRate: Int,
    frameSize: Int
)

Returns the buffer size for PCM playback.

Public properties

Int

The multiplication factor to apply to AC3 passthrough buffer to avoid underruns on some devices (e.g., Broadcom 7271).

Int

The multiplication factor to apply to DTS-HD (DTS Express) passthrough buffer to avoid underruns.

Protected properties

Int

The maximum length for PCM AudioTrack buffers, in microseconds.

Int

The minimum length for PCM AudioTrack buffers, in microseconds.

Int

The length for offload AudioTrack buffers, in microseconds.

Int

The length for passthrough AudioTrack buffers, in microseconds.

Int

The multiplication factor to apply to the minimum buffer size requested.

Protected constructors

DefaultAudioTrackBufferSizeProvider

protected DefaultAudioTrackBufferSizeProvider(
    builder: DefaultAudioTrackBufferSizeProvider.Builder!
)

Public functions

getBufferSizeInBytes

fun getBufferSizeInBytes(
    minBufferSizeInBytes: Int,
    @C.Encoding encoding: Int,
    @DefaultAudioSink.OutputMode outputMode: Int,
    pcmFrameSize: Int,
    sampleRate: Int,
    bitrate: Int,
    maxAudioTrackPlaybackSpeed: Double
): Int

Returns the buffer size to use when creating an AudioTrack for a specific format and output mode.

Parameters
minBufferSizeInBytes: Int

The minimum buffer size in bytes required to play this format. See getMinBufferSize.

@C.Encoding encoding: Int

The C.Encoding of the format.

@DefaultAudioSink.OutputMode outputMode: Int

How the audio will be played. One of the output modes.

pcmFrameSize: Int

The size of the PCM frames if the encoding is PCM, 1 otherwise, in bytes.

sampleRate: Int

The sample rate of the format, in Hz.

bitrate: Int

The bitrate of the audio stream if the stream is compressed, or NO_VALUE if encoding is PCM or the bitrate is not known.

maxAudioTrackPlaybackSpeed: Double

The maximum speed the content will be played using setPlaybackParams. 0.5 is 2x slow motion, 1 is real time, 2 is 2x fast forward, etc. This will be 1 unless setEnableAudioTrackPlaybackParams is enabled.

Returns
Int

The computed buffer size in bytes. It should always be >= minBufferSizeInBytes. The computed buffer size must contain an integer number of frames: bufferSizeInBytes % pcmFrameSize == 0.

Protected functions

durationUsToBytes

protected java-static fun durationUsToBytes(durationUs: Int, samplingRate: Int, frameSize: Int): Int

get1xBufferSizeInBytes

protected fun get1xBufferSizeInBytes(
    minBufferSizeInBytes: Int,
    encoding: Int,
    outputMode: Int,
    pcmFrameSize: Int,
    sampleRate: Int,
    bitrate: Int
): Int

Returns the buffer size for playback at 1x speed.

getMaximumEncodedRateBytesPerSecond

protected java-static fun getMaximumEncodedRateBytesPerSecond(@C.Encoding encoding: Int): Int

getOffloadBufferSizeInBytes

protected fun getOffloadBufferSizeInBytes(@C.Encoding encoding: Int): Int

Returns the buffer size for offload playback.

getPassthroughBufferSizeInBytes

protected fun getPassthroughBufferSizeInBytes(@C.Encoding encoding: Int, bitrate: Int): Int

Returns the buffer size for passthrough playback.

getPcmBufferSizeInBytes

protected fun getPcmBufferSizeInBytes(
    minBufferSizeInBytes: Int,
    samplingRate: Int,
    frameSize: Int
): Int

Returns the buffer size for PCM playback.

Public properties

ac3BufferMultiplicationFactor

val ac3BufferMultiplicationFactorInt

The multiplication factor to apply to AC3 passthrough buffer to avoid underruns on some devices (e.g., Broadcom 7271).

dtshdBufferMultiplicationFactor

val dtshdBufferMultiplicationFactorInt

The multiplication factor to apply to DTS-HD (DTS Express) passthrough buffer to avoid underruns.

Protected properties

maxPcmBufferDurationUs

protected val maxPcmBufferDurationUsInt

The maximum length for PCM AudioTrack buffers, in microseconds.

minPcmBufferDurationUs

protected val minPcmBufferDurationUsInt

The minimum length for PCM AudioTrack buffers, in microseconds.

offloadBufferDurationUs

protected val offloadBufferDurationUsInt

The length for offload AudioTrack buffers, in microseconds.

passthroughBufferDurationUs

protected val passthroughBufferDurationUsInt

The length for passthrough AudioTrack buffers, in microseconds.

pcmBufferMultiplicationFactor

protected val pcmBufferMultiplicationFactorInt

The multiplication factor to apply to the minimum buffer size requested.