AudioProcessingPipeline
@UnstableApi
public final class AudioProcessingPipeline
Handles passing buffers through multiple AudioProcessor instances.
Two instances of AudioProcessingPipeline are considered equal if they have the same underlying 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
configurewith theAudioFormatof the input data. This method will give back theAudioFormatthat will be output from the pipeline when this configuration is in use. - Call
flushto apply the pending configuration. - Check if the pipeline
isOperational. If not, then the pipeline can not be used to process buffers in the current configuration. This is because none of the underlyingAudioProcessorinstances areactive. - If the pipeline
isOperational,queueInputthengetOutputto process buffers. queueEndOfStreamto inform the pipeline the current input stream is at an end.- Repeatedly call
getOutputand handle those buffers untilisEndedreturns true. - When finished with the pipeline, call
resetto release underlying resources.
If underlying AudioProcessor instances have pending configuration changes, or the AudioFormat of the input is changing:
- Call
configureto configure the pipeline for the new input stream. You can stillqueueInputandgetOutputin the old setup at this time. queueEndOfStreamto inform the pipeline the current input stream is at an end.- Repeatedly call
getOutputuntilisEndedreturns true. - Call
flushto apply the new configuration and flush the pipeline. - Begin
queuing inputand handling theoutputin the new configuration.
Summary
Public fields |
|
|---|---|
AudioProcessor.AudioFormat |
The |
Public constructors |
|---|
AudioProcessingPipeline(ImmutableList<AudioProcessor> audioProcessors)Creates an instance. |
Public methods |
|
|---|---|
AudioProcessor.AudioFormat |
@CanIgnoreReturnValueConfigures the pipeline to process input audio with the specified format. |
boolean |
Indicates whether some other object is "equal to" this one. |
void |
This method is deprecated. Use |
void |
flush(AudioProcessor.StreamMetadata streamMetadata)Clears any buffered data and pending output. |
ByteBuffer |
Returns a |
AudioProcessor.AudioFormat |
Returns the |
int |
hashCode() |
boolean |
isEnded()Returns whether the pipeline has ended. |
boolean |
Whether the pipeline can be used for processing buffers. |
void |
Queues an end of stream signal. |
void |
queueInput(ByteBuffer inputBuffer)Queues audio data between the position and limit of the |
void |
reset()Resets the pipeline and its underlying |
Public fields
outputAudioFormat
public AudioProcessor.AudioFormat outputAudioFormat
The AudioFormat currently being output by the pipeline.
Public constructors
AudioProcessingPipeline
public AudioProcessingPipeline(ImmutableList<AudioProcessor> audioProcessors)
Creates an instance.
| Parameters | |
|---|---|
ImmutableList<AudioProcessor> audioProcessors |
The |
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 flushed. Before applying the new configuration, it is safe to queue input and get output in the old input/output formats/configuration. Call queueEndOfStream when no more input will be supplied for processing in the old configuration.
| Parameters | |
|---|---|
AudioProcessor.AudioFormat inputAudioFormat |
The format of audio that will be queued after the next call to |
| Returns | |
|---|---|
AudioProcessor.AudioFormat |
The configured output audio format. |
| Throws | |
|---|---|
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 AudioProcessingPipeline are considered equal if they have the same underlying AudioProcessor references in the same order.
flush
public void flush()Clears any buffered data and pending output. If any underlying audio processors are active, this also prepares them to receive a new stream of input in the last configured (pending) format.
configure must have been called at least once since the last call to 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 active, this also prepares them to receive a new stream of input in the last configured (pending) format.
configure must have been called at least once since the last call to reset before calling this.
| Parameters | |
|---|---|
AudioProcessor.StreamMetadata streamMetadata |
Information about the input stream to be processed after the flush. |
getOutput
public ByteBuffer getOutput()
Returns a ByteBuffer 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 | |
|---|---|
ByteBuffer |
A buffer containing processed output data between its position and limit. |
getOutputAudioFormat
public AudioProcessor.AudioFormat getOutputAudioFormat()
Returns the AudioFormat of data being output through getOutput.
| Returns | |
|---|---|
AudioProcessor.AudioFormat |
The |
isEnded
public boolean isEnded()
Returns whether the pipeline has ended.
The pipeline is considered ended when:
- End of stream has been
queued. - Every
input bufferhas been processed. - Every
output bufferhas been fully consumed.
isOperational
public boolean isOperational()
Whether the pipeline can be used for processing buffers.
For this to happen the pipeline must be configured, flushed and have activeunderlying audio processors 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, queueInput should not be called until after the next call to flush. Calling getOutput will return any remaining output data. Multiple calls may be required to read all of the remaining output data. 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 getOutput.
| Parameters | |
|---|---|
ByteBuffer inputBuffer |
The input buffer to process. It must be a direct |
reset
public void reset()
Resets the pipeline and its underlying AudioProcessor instances to their unconfigured state, releasing any resources.