DefaultAudioTrackBufferSizeProvider


@UnstableApi
public class DefaultAudioTrackBufferSizeProvider implements DefaultAudioSink.AudioTrackBufferSizeProvider


Provide the buffer size to use when creating an AudioTrack.

Summary

Nested types

A builder to create DefaultAudioTrackBufferSizeProvider instances.

Public fields

final int

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

final int

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

Protected fields

final int

The maximum length for PCM AudioTrack buffers, in microseconds.

final int

The minimum length for PCM AudioTrack buffers, in microseconds.

final int

The length for offload AudioTrack buffers, in microseconds.

final int

The length for passthrough AudioTrack buffers, in microseconds.

final int

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

Public methods

int
getBufferSizeInBytes(
    int minBufferSizeInBytes,
    @C.Encoding int encoding,
    @DefaultAudioSink.OutputMode int outputMode,
    int pcmFrameSize,
    int sampleRate,
    int bitrate,
    double maxAudioTrackPlaybackSpeed
)

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

Protected methods

static int
durationUsToBytes(int durationUs, int samplingRate, int frameSize)
int
get1xBufferSizeInBytes(
    int minBufferSizeInBytes,
    int encoding,
    int outputMode,
    int pcmFrameSize,
    int sampleRate,
    int bitrate
)

Returns the buffer size for playback at 1x speed.

static int
int

Returns the buffer size for offload playback.

int
getPassthroughBufferSizeInBytes(@C.Encoding int encoding, int bitrate)

Returns the buffer size for passthrough playback.

int
getPcmBufferSizeInBytes(
    int minBufferSizeInBytes,
    int samplingRate,
    int frameSize
)

Returns the buffer size for PCM playback.

Public fields

ac3BufferMultiplicationFactor

public final int ac3BufferMultiplicationFactor

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

dtshdBufferMultiplicationFactor

public final int dtshdBufferMultiplicationFactor

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

Protected fields

maxPcmBufferDurationUs

protected final int maxPcmBufferDurationUs

The maximum length for PCM AudioTrack buffers, in microseconds.

minPcmBufferDurationUs

protected final int minPcmBufferDurationUs

The minimum length for PCM AudioTrack buffers, in microseconds.

offloadBufferDurationUs

protected final int offloadBufferDurationUs

The length for offload AudioTrack buffers, in microseconds.

passthroughBufferDurationUs

protected final int passthroughBufferDurationUs

The length for passthrough AudioTrack buffers, in microseconds.

pcmBufferMultiplicationFactor

protected final int pcmBufferMultiplicationFactor

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

Protected constructors

DefaultAudioTrackBufferSizeProvider

protected DefaultAudioTrackBufferSizeProvider(
    DefaultAudioTrackBufferSizeProvider.Builder builder
)

Public methods

getBufferSizeInBytes

public int getBufferSizeInBytes(
    int minBufferSizeInBytes,
    @C.Encoding int encoding,
    @DefaultAudioSink.OutputMode int outputMode,
    int pcmFrameSize,
    int sampleRate,
    int bitrate,
    double maxAudioTrackPlaybackSpeed
)

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

Parameters
int minBufferSizeInBytes

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

@C.Encoding int encoding

The C.Encoding of the format.

@DefaultAudioSink.OutputMode int outputMode

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

int pcmFrameSize

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

int sampleRate

The sample rate of the format, in Hz.

int bitrate

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

double maxAudioTrackPlaybackSpeed

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 methods

durationUsToBytes

protected static int durationUsToBytes(int durationUs, int samplingRate, int frameSize)

get1xBufferSizeInBytes

protected int get1xBufferSizeInBytes(
    int minBufferSizeInBytes,
    int encoding,
    int outputMode,
    int pcmFrameSize,
    int sampleRate,
    int bitrate
)

Returns the buffer size for playback at 1x speed.

getMaximumEncodedRateBytesPerSecond

protected static int getMaximumEncodedRateBytesPerSecond(@C.Encoding int encoding)

getOffloadBufferSizeInBytes

protected int getOffloadBufferSizeInBytes(@C.Encoding int encoding)

Returns the buffer size for offload playback.

getPassthroughBufferSizeInBytes

protected int getPassthroughBufferSizeInBytes(@C.Encoding int encoding, int bitrate)

Returns the buffer size for passthrough playback.

getPcmBufferSizeInBytes

protected int getPcmBufferSizeInBytes(
    int minBufferSizeInBytes,
    int samplingRate,
    int frameSize
)

Returns the buffer size for PCM playback.