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

<br />

*** ** * ** ***

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

Two instances of `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessingPipeline` are considered `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#equals(java.lang.Object)` if they have the same underlying `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#configure(androidx.media3.common.audio.AudioProcessor.AudioFormat)` with the `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessor.AudioFormat` of the input data. This method will give back the `https://developer.android.com/reference/kotlin/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/kotlin/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/kotlin/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/kotlin/androidx/media3/common/audio/AudioProcessor` instances are `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessor#isActive()`.
- If the pipeline `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#isOperational()`, `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#queueInput(java.nio.ByteBuffer)` then `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#getOutput()` to process buffers.
- `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#getOutput()` and handle those buffers until `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#isEnded()` returns true.
- When finished with the pipeline, call `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#reset()` to release underlying resources.

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

- Call `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#queueInput(java.nio.ByteBuffer)` and `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#getOutput()` in the old setup at this time.
- `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#getOutput()` until `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#isEnded()` returns true.
- Call `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#queueInput(java.nio.ByteBuffer)` and handling the `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#getOutput()` in the new configuration.

## Summary

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

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

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

## Public constructors

### AudioProcessingPipeline

```
AudioProcessingPipeline(audioProcessors: ImmutableList<AudioProcessor!>!)
```

Creates an instance.

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

## Public functions

### configure

```
@CanIgnoreReturnValue
fun configure(inputAudioFormat: AudioProcessor.AudioFormat!): AudioProcessor.AudioFormat!
```

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/kotlin/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/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#queueEndOfStream()` when no more input will be supplied for processing in the old configuration.

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

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

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

### equals

```
fun equals(o: Any?): Boolean
```

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

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

### flush

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

> [!CAUTION]
> **This function is deprecated.**   
>
> Use `https://developer.android.com/reference/kotlin/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/kotlin/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/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#configure(androidx.media3.common.audio.AudioProcessor.AudioFormat)` (pending) format.

`https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#reset()` before calling this.

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

### flush

```
fun flush(streamMetadata: AudioProcessor.StreamMetadata!): Unit
```

Clears any buffered data and pending output. If any underlying audio processors are `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#configure(androidx.media3.common.audio.AudioProcessor.AudioFormat)` (pending) format.

`https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#reset()` before calling this.

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

### getOutput

```
fun getOutput(): ByteBuffer!
```

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

### hashCode

```
fun hashCode(): Int
```

### isEnded

```
fun isEnded(): Boolean
```

Returns whether the pipeline has ended.

The pipeline is considered ended when:

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

### isOperational

```
fun isOperational(): Boolean
```

Whether the pipeline can be used for processing buffers.

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

### queueEndOfStream

```
fun queueEndOfStream(): Unit
```

Queues an end of stream signal. After this method has been called, `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#queueInput(java.nio.ByteBuffer)` should not be called until after the next call to `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#flush(androidx.media3.common.audio.AudioProcessor.StreamMetadata)`. Calling `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#isEnded()` will return `true` once all remaining output data has been read.

### queueInput

```
fun queueInput(inputBuffer: ByteBuffer!): Unit
```

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/kotlin/androidx/media3/common/audio/AudioProcessingPipeline#getOutput()`.

| Parameters |
|---|---|
| `inputBuffer: https://developer.android.com/reference/java/nio/ByteBuffer.html!` | 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

```
fun reset(): Unit
```

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

## Public properties

### outputAudioFormat

```
val outputAudioFormat: AudioProcessor.AudioFormat!
```

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