# DefaultAudioTrackBufferSizeProvider

Artifact: [androidx.media3:media3-exoplayer](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider.java+class:androidx.media3.exoplayer.audio.DefaultAudioTrackBufferSizeProvider)

*** ** * ** ***


```
@UnstableApi
public class DefaultAudioTrackBufferSizeProvider implements DefaultAudioSink.AudioTrackBufferSizeProvider
```

<br />

*** ** * ** ***

Provide the buffer size to use when creating an `https://developer.android.com/reference/android/media/AudioTrack.html`.

## Summary

| ### Nested types |
|---|
| `public class https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider.Builder` A builder to create `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider` instances. |

| ### Public fields |
|---|---|
| `final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#ac3BufferMultiplicationFactor()` The multiplication factor to apply to AC3 passthrough buffer to avoid underruns on some devices (e.g., Broadcom 7271). |
| `final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#dtshdBufferMultiplicationFactor()` The multiplication factor to apply to DTS-HD (DTS Express) passthrough buffer to avoid underruns. |

| ### Protected fields |
|---|---|
| `final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#maxPcmBufferDurationUs()` **This field is deprecated.** This constraint does not apply to the new default fixed buffer size logic. <br /> |
| `final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#minPcmBufferDurationUs()` **This field is deprecated.** This constraint does not apply to the new default fixed buffer size logic. <br /> |
| `final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#offloadBufferDurationUs()` The length for offload `https://developer.android.com/reference/android/media/AudioTrack.html` buffers, in microseconds. |
| `final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#passthroughBufferDurationUs()` The length for passthrough `https://developer.android.com/reference/android/media/AudioTrack.html` buffers, in microseconds. |
| `final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#pcmBufferMultiplicationFactor()` **This field is deprecated.** Use the default fixed buffer size logic instead, or `https://developer.android.com/reference/androidx/media3/common/C#LENGTH_UNSET()` to not use this factor. <br /> |
| `final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#targetPcmBufferDurationUs()` The target length for PCM `https://developer.android.com/reference/android/media/AudioTrack.html` buffers, in microseconds. |

| ### Protected constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#DefaultAudioTrackBufferSizeProvider(androidx.media3.exoplayer.audio.DefaultAudioTrackBufferSizeProvider.Builder)( https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider.Builder builder )` |

| ### Public methods |
|---|---|
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#getBufferSizeInBytes(int,int,int,int,int,int,double)( int minBufferSizeInBytes, @https://developer.android.com/reference/androidx/media3/common/C.Encoding int encoding, @https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioSink.OutputMode int outputMode, int pcmFrameSize, int sampleRate, int bitrate, double maxAudioTrackPlaybackSpeed )` Returns the buffer size to use when creating an `https://developer.android.com/reference/android/media/AudioTrack.html` for a specific format and output mode. |

| ### Protected methods |
|---|---|
| `static int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#durationUsToBytes(int,int,int)(int durationUs, int samplingRate, int frameSize)` |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#get1xBufferSizeInBytes(int,int,int,int,int,int)( int minBufferSizeInBytes, int encoding, int outputMode, int pcmFrameSize, int sampleRate, int bitrate )` Returns the buffer size for playback at 1x speed. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#getOffloadBufferSizeInBytes(int)(@https://developer.android.com/reference/androidx/media3/common/C.Encoding int encoding)` Returns the buffer size for offload playback. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#getPassthroughBufferSizeInBytes(int,int)(@https://developer.android.com/reference/androidx/media3/common/C.Encoding int encoding, int bitrate)` Returns the buffer size for passthrough playback. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#getPcmBufferSizeInBytes(int,int,int)( int minBufferSizeInBytes, int samplingRate, int frameSize )` Returns the buffer size for PCM playback. |

### Inherited Constants

From [androidx.media3.exoplayer.audio.DefaultAudioSink.AudioTrackBufferSizeProvider](https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioSink.AudioTrackBufferSizeProvider) `static final https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioSink.AudioTrackBufferSizeProvider` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioSink.AudioTrackBufferSizeProvider#DEFAULT()`

Default instance.

## 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
```

> [!CAUTION]
> **This field is deprecated.**   
>
> This constraint does not apply to the new default fixed buffer size logic. Use `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#targetPcmBufferDurationUs()` to configure a fixed buffer size instead. This is only used if `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#pcmBufferMultiplicationFactor()` is set to enable deprecated dynamic logic.

The maximum length for PCM `https://developer.android.com/reference/android/media/AudioTrack.html` buffers, in microseconds.

### minPcmBufferDurationUs

```
protected final int minPcmBufferDurationUs
```

> [!CAUTION]
> **This field is deprecated.**   
>
> This constraint does not apply to the new default fixed buffer size logic. Use `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#targetPcmBufferDurationUs()` to configure a fixed buffer size instead. This is only used if `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#pcmBufferMultiplicationFactor()` is set to enable deprecated dynamic logic.

The minimum length for PCM `https://developer.android.com/reference/android/media/AudioTrack.html` buffers, in microseconds.

### offloadBufferDurationUs

```
protected final int offloadBufferDurationUs
```

The length for offload `https://developer.android.com/reference/android/media/AudioTrack.html` buffers, in microseconds.

### passthroughBufferDurationUs

```
protected final int passthroughBufferDurationUs
```

The length for passthrough `https://developer.android.com/reference/android/media/AudioTrack.html` buffers, in microseconds.

### pcmBufferMultiplicationFactor

```
protected final int pcmBufferMultiplicationFactor
```

> [!CAUTION]
> **This field is deprecated.**   
>
> Use the default fixed buffer size logic instead, or `https://developer.android.com/reference/androidx/media3/common/C#LENGTH_UNSET()` to not use this factor.

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

### targetPcmBufferDurationUs

```
protected final int targetPcmBufferDurationUs
```

The target length for PCM `https://developer.android.com/reference/android/media/AudioTrack.html` buffers, in microseconds.

## 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 `https://developer.android.com/reference/android/media/AudioTrack.html` for a specific format and output mode.

| Parameters |
|---|---|
| `int minBufferSizeInBytes` | The minimum buffer size in bytes required to play this format. See `https://developer.android.com/reference/android/media/AudioTrack.html#getMinBufferSize(int, int, int)`. |
| `@https://developer.android.com/reference/androidx/media3/common/C.Encoding int encoding` | The `https://developer.android.com/reference/androidx/media3/common/C.Encoding` of the format. Value is one of the following: - `Format.NO_VALUE` <br /> |
| `@https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioSink.OutputMode int outputMode` | How the audio will be played. One of the `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioSink.OutputMode`. |
| `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 `https://developer.android.com/reference/androidx/media3/common/Format#NO_VALUE()` if `encoding` is PCM or the bitrate is not known. |
| `double maxAudioTrackPlaybackSpeed` | The maximum speed the content will be played using `https://developer.android.com/reference/android/media/AudioTrack.html#setPlaybackParams(android.media.PlaybackParams)`. 0.5 is 2x slow motion, 1 is real time, 2 is 2x fast forward, etc. This will be `1` unless `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioSink.Builder#setEnableAudioOutputPlaybackParameters(boolean)` 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.

### 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.