BaseAudioProcessor
@UnstableApi
abstract class BaseAudioProcessor : AudioProcessor
ChannelMappingAudioProcessor |
An |
ChannelMixingAudioProcessor |
An |
GainProcessor |
Applies |
PassthroughAudioProcessor |
A |
SilenceSkippingAudioProcessor |
An |
TeeAudioProcessor |
Audio processor that outputs its input unmodified and also outputs its input to a given sink. |
ToFloatPcmAudioProcessor |
An |
ToInt16PcmAudioProcessor |
An |
TrimmingAudioProcessor |
Audio processor for trimming samples from the start/end of data. |
Base class for audio processors that keep an output buffer and an internal buffer that is reused whenever input is queued. Subclasses should override onConfigure to return the output audio format for the processor if it's active.
Summary
Public constructors |
|---|
Public functions |
|
|---|---|
AudioProcessor.AudioFormat! |
configure(inputAudioFormat: AudioProcessor.AudioFormat!)Configures the processor to process input audio with the specified format. |
Unit |
This function is deprecated. Use |
Unit |
flush(streamMetadata: AudioProcessor.StreamMetadata!)Prepares the audio processor to receive a new stream of input in the last |
ByteBuffer! |
Returns a buffer containing processed output data between its position and limit. |
Boolean |
Returns whether the processor is configured and will process input buffers. |
Boolean |
Returns whether this processor will return no more output from |
Unit |
Queues an end of stream signal. |
Unit |
reset()Resets the processor to its unconfigured state, releasing any resources. |
Protected functions |
|
|---|---|
Boolean |
Returns whether the current output buffer has any data remaining. |
AudioProcessor.AudioFormat! |
onConfigure(inputAudioFormat: AudioProcessor.AudioFormat!)Called when the processor is configured for a new input format. |
Unit |
This function is deprecated. Use |
Unit |
onFlush(streamMetadata: AudioProcessor.StreamMetadata!)Called when the processor is |
Unit |
Called when the end-of-stream is queued to the processor. |
Unit |
onReset()Called when the processor is reset. |
ByteBuffer! |
replaceOutputBuffer(size: Int)Replaces the current output buffer with a buffer of at least |
Protected properties |
|
|---|---|
AudioProcessor.AudioFormat! |
The current input audio format. |
AudioProcessor.AudioFormat! |
The current output audio format. |
Inherited Constants |
||
|---|---|---|
|
Inherited functions |
||||
|---|---|---|---|---|
|
Public constructors
Public functions
configure
fun configure(inputAudioFormat: AudioProcessor.AudioFormat!): AudioProcessor.AudioFormat!
Configures the processor to process input audio with the specified format. After calling this method, call isActive to determine whether the audio processor is active. Returns the configured output audio format if this instance is active.
After calling this method, it is necessary to flush the processor to apply the new configuration. Before applying the new configuration, it is safe to queue input and get output in the old input/output formats. Call queueEndOfStream when no more input will be supplied in the old input format.
| Parameters | |
|---|---|
inputAudioFormat: AudioProcessor.AudioFormat! |
The format of audio that will be queued after the next call to |
| Returns | |
|---|---|
AudioProcessor.AudioFormat! |
The configured output audio format if this instance is |
| Throws | |
|---|---|
androidx.media3.common.audio.AudioProcessor.UnhandledAudioFormatException |
Thrown if the specified format can't be handled as input. |
flush
funflush(): Unit
Clears any buffered data and pending output. If the audio processor is active, also prepares the audio processor to receive a new stream of input in the last configured (pending) format.
This is equivalent to flush(new StreamMetadata(C.TIME_UNSET)).
flush
fun flush(streamMetadata: AudioProcessor.StreamMetadata!): Unit
Prepares the audio processor to receive a new stream of input in the last configured format and clears any buffered data and pending output.
This method is a no-op if the processor is not active.
getOutput
@CallSuper
fun getOutput(): ByteBuffer!
Returns a buffer containing processed output data between its position and limit. The buffer will always be a direct byte buffer with native byte order. Calling this method invalidates any previously returned buffer. The buffer will be empty if no output is available.
| Returns | |
|---|---|
ByteBuffer! |
A buffer containing processed output data between its position and limit. |
isActive
@CallSuper
fun isActive(): Boolean
Returns whether the processor is configured and will process input buffers.
isEnded
@CallSuper
fun isEnded(): Boolean
Returns whether this processor will return no more output from getOutput until flush has been called and more input has been queued.
queueEndOfStream
fun queueEndOfStream(): Unit
Queues an end of stream signal. After this method has been called, queueInput may 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.
Protected functions
hasPendingOutput
protected fun hasPendingOutput(): Boolean
Returns whether the current output buffer has any data remaining.
onConfigure
protected fun onConfigure(inputAudioFormat: AudioProcessor.AudioFormat!): AudioProcessor.AudioFormat!
Called when the processor is configured for a new input format.
onFlush
protected fun onFlush(streamMetadata: AudioProcessor.StreamMetadata!): Unit
Called when the processor is flushed.
onQueueEndOfStream
protected fun onQueueEndOfStream(): Unit
Called when the end-of-stream is queued to the processor.
replaceOutputBuffer
protected fun replaceOutputBuffer(size: Int): ByteBuffer!
Replaces the current output buffer with a buffer of at least size bytes and returns it. Callers should write to the returned buffer then flip it so it can be read via getOutput.
Protected properties
inputAudioFormat
protected val inputAudioFormat: AudioProcessor.AudioFormat!
The current input audio format.
outputAudioFormat
protected val outputAudioFormat: AudioProcessor.AudioFormat!
The current output audio format.