# AudioProcessingPipeline

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

*** ** * ** ***


```
@UnstableApi
public final class AudioProcessingPipeline
```

<br />

*** ** * ** ***

Handles passing buffers through multiple `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor` instances.

Two instances of `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline` are considered `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#equals(java.lang.Object)` if they have the same underlying `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor` references, in the same order.

To make use of this class, the caller must:

- Initialize an instance, passing in all audio processors that may be used for processing.
- Call `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#configure(androidx.media3.common.audio.AudioProcessor.AudioFormat)` with the `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat` of the input data. This method will give back the `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat` that will be output from the pipeline when this configuration is in use.
- Call `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#flush(androidx.media3.common.audio.AudioProcessor.StreamMetadata)` to apply the pending configuration.
- Check if the pipeline `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#isOperational()`. If not, then the pipeline can not be used to process buffers in the current configuration. This is because none of the underlying `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor` instances are `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor#isActive()`.
- If the pipeline `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#isOperational()`, `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#queueInput(java.nio.ByteBuffer)` then `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#getOutput()` to process buffers.
- `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#queueEndOfStream()` to inform the pipeline the current input stream is at an end.
- Repeatedly call `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#getOutput()` and handle those buffers until `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#isEnded()` returns true.
- When finished with the pipeline, call `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#reset()` to release underlying resources.

If underlying `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor` instances have pending configuration changes, or the `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat` of the input is changing:

- Call `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#configure(androidx.media3.common.audio.AudioProcessor.AudioFormat)` to configure the pipeline for the new input stream. You can still `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#queueInput(java.nio.ByteBuffer)` and `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#getOutput()` in the old setup at this time.
- `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#queueEndOfStream()` to inform the pipeline the current input stream is at an end.
- Repeatedly call `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#getOutput()` until `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#isEnded()` returns true.
- Call `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#flush(androidx.media3.common.audio.AudioProcessor.StreamMetadata)` to apply the new configuration and flush the pipeline.
- Begin `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#queueInput(java.nio.ByteBuffer)` and handling the `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#getOutput()` in the new configuration.

## Summary

| ### Public fields |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat` | `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#outputAudioFormat()` The `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat` currently being output by the pipeline. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#AudioProcessingPipeline(com.google.common.collect.ImmutableList<androidx.media3.common.audio.AudioProcessor>)(https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor> audioProcessors)` Creates an instance. |

| ### Public methods |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#configure(androidx.media3.common.audio.AudioProcessor.AudioFormat)(https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat inputAudioFormat)` Configures the pipeline to process input audio with the specified format. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#equals(java.lang.Object)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html o)` Indicates whether some other object is "equal to" this one. |
| `void` | `[flush](https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#flush())()` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#flush(androidx.media3.common.audio.AudioProcessor.StreamMetadata)` instead. <br /> |
| `void` | `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#flush(androidx.media3.common.audio.AudioProcessor.StreamMetadata)(https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.StreamMetadata streamMetadata)` Clears any buffered data and pending output. |
| `https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#getOutput()()` Returns a `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing processed output data between its position and limit. |
| `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat` | `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#getOutputAudioFormat()()` Returns the `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat` of data being output through `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#getOutput()`. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#hashCode()()` |
| `boolean` | `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#isEnded()()` Returns whether the pipeline has ended. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#isOperational()()` Whether the pipeline can be used for processing buffers. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#queueEndOfStream()()` Queues an end of stream signal. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#queueInput(java.nio.ByteBuffer)(https://developer.android.com/reference/java/nio/ByteBuffer.html inputBuffer)` Queues audio data between the position and limit of the `inputBuffer` for processing. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#reset()()` Resets the pipeline and its underlying `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor` instances to their unconfigured state, releasing any resources. |

## Public fields

### outputAudioFormat

```
public AudioProcessor.AudioFormat outputAudioFormat
```

The `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat` currently being output by the pipeline.

## Public constructors

### AudioProcessingPipeline

```
public AudioProcessingPipeline(ImmutableList<AudioProcessor> audioProcessors)
```

Creates an instance.

| Parameters |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor> audioProcessors` | The `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor` instances to be used for processing buffers. |

## Public methods

### configure

```
@CanIgnoreReturnValue
public AudioProcessor.AudioFormat configure(AudioProcessor.AudioFormat inputAudioFormat)
```

Configures the pipeline to process input audio with the specified format. Returns the configured output audio format.

To apply the new configuration for use, the pipeline must be `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#flush(androidx.media3.common.audio.AudioProcessor.StreamMetadata)`. Before applying the new configuration, it is safe to queue input and get output in the old input/output formats/configuration. Call `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#queueEndOfStream()` when no more input will be supplied for processing in the old configuration.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat inputAudioFormat` | The format of audio that will be queued after the next call to `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#flush(androidx.media3.common.audio.AudioProcessor.StreamMetadata)`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat` | The configured output audio format. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.UnhandledAudioFormatException` | If the specified format is not supported by the pipeline. |

### equals

```
public boolean equals(@Nullable Object o)
```

Indicates whether some other object is "equal to" this one.

Two instances of `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline` are considered equal if they have the same underlying `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor` references in the same order.

### flush

```
public void [flush](https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#flush())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#flush(androidx.media3.common.audio.AudioProcessor.StreamMetadata)` instead.

Clears any buffered data and pending output. If any underlying audio processors are `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor#isActive()`, this also prepares them to receive a new stream of input in the last `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#configure(androidx.media3.common.audio.AudioProcessor.AudioFormat)` (pending) format.

`https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#configure(androidx.media3.common.audio.AudioProcessor.AudioFormat)` must have been called at least once since the last call to `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#reset()` before calling this.

This method is equivalent to `flush(new StreamMetadata(C.TIME_UNSET))`.

### flush

```
public void flush(AudioProcessor.StreamMetadata streamMetadata)
```

Clears any buffered data and pending output. If any underlying audio processors are `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor#isActive()`, this also prepares them to receive a new stream of input in the last `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#configure(androidx.media3.common.audio.AudioProcessor.AudioFormat)` (pending) format.

`https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#configure(androidx.media3.common.audio.AudioProcessor.AudioFormat)` must have been called at least once since the last call to `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#reset()` before calling this.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.StreamMetadata streamMetadata` | Information about the input stream to be processed after the flush. |

### getOutput

```
public ByteBuffer getOutput()
```

Returns a `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing processed output data between its position and limit. The buffer will be empty if no output is available.

Buffers returned from this method are retained by pipeline, and it is necessary to consume the data (or copy it into another buffer) to allow the pipeline to progress.

| Returns |
|---|---|
| `https://developer.android.com/reference/java/nio/ByteBuffer.html` | A buffer containing processed output data between its position and limit. |

### getOutputAudioFormat

```
public AudioProcessor.AudioFormat getOutputAudioFormat()
```

Returns the `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat` of data being output through `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#getOutput()`.

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat` | The `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat` currently being output, or `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat#NOT_SET()` if no `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#configure(androidx.media3.common.audio.AudioProcessor.AudioFormat)` has been `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#flush(androidx.media3.common.audio.AudioProcessor.StreamMetadata)`. |

### hashCode

```
public int hashCode()
```

### isEnded

```
public boolean isEnded()
```

Returns whether the pipeline has ended.

The pipeline is considered ended when:

- End of stream has been `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#queueEndOfStream()`.
- Every `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#queueInput(java.nio.ByteBuffer)` has been processed.
- Every `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#getOutput()` has been fully consumed.

### isOperational

```
public boolean isOperational()
```

Whether the pipeline can be used for processing buffers.

For this to happen the pipeline must be `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#configure(androidx.media3.common.audio.AudioProcessor.AudioFormat)`, `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#flush(androidx.media3.common.audio.AudioProcessor.StreamMetadata)` and have `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor#isActive()``https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor` that are ready to process buffers with the current configuration.

### queueEndOfStream

```
public void queueEndOfStream()
```

Queues an end of stream signal. After this method has been called, `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#queueInput(java.nio.ByteBuffer)` should not be called until after the next call to `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#flush(androidx.media3.common.audio.AudioProcessor.StreamMetadata)`. Calling `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#getOutput()` will return any remaining output data. Multiple calls may be required to read all of the remaining output data. `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#isEnded()` will return `true` once all remaining output data has been read.

### queueInput

```
public void queueInput(ByteBuffer inputBuffer)
```

Queues audio data between the position and limit of the `inputBuffer` for processing. After calling this method, processed output may be available via `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessingPipeline#getOutput()`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/nio/ByteBuffer.html inputBuffer` | The input buffer to process. It must be a direct `https://developer.android.com/reference/java/nio/ByteBuffer.html` with native byte order. Its contents are treated as read-only. Its position will be advanced by the number of bytes consumed (which may be zero). The caller retains ownership of the provided buffer. |

### reset

```
public void reset()
```

Resets the pipeline and its underlying `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor` instances to their unconfigured state, releasing any resources.