BaseAudioProcessor


@UnstableApi
public abstract class BaseAudioProcessor implements AudioProcessor

Known direct subclasses
BaseAudioProcessor

This class is deprecated.

Use androidx.media3.common.audio.BaseAudioProcessor.

ChannelMixingAudioProcessor

An AudioProcessor that handles mixing and scaling audio channels.

SilenceSkippingAudioProcessor

An AudioProcessor that skips silence in the input stream.

SpeedChangingAudioProcessor

An AudioProcessor that changes the speed of audio samples depending on their timestamp.

TeeAudioProcessor

Audio processor that outputs its input unmodified and also outputs its input to a given sink.

ToInt16PcmAudioProcessor

An AudioProcessor that converts different PCM audio encodings to 16-bit integer PCM.


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

Protected fields

AudioProcessor.AudioFormat

The current input audio format.

AudioProcessor.AudioFormat

The current output audio format.

Public constructors

Public methods

final AudioProcessor.AudioFormat

Configures the processor to process input audio with the specified format.

final void

Clears any buffered data and pending output.

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 getOutput until flush has been called and more input has been queued.

final void

Queues an end of stream signal.

final void

Resets the processor to its unconfigured state, releasing any resources.

Protected methods

final boolean

Returns whether the current output buffer has any data remaining.

AudioProcessor.AudioFormat

Called when the processor is configured for a new input format.

void

Called when the processor is flushed, directly or as part of resetting.

void

Called when the end-of-stream is queued to the processor.

void

Called when the processor is reset.

final ByteBuffer

Replaces the current output buffer with a buffer of at least size bytes and returns it.

Inherited Constants

From androidx.media3.common.audio.AudioProcessor
static final ByteBuffer

An empty, direct ByteBuffer.

Inherited methods

From androidx.media3.common.audio.AudioProcessor
long

Returns the expected duration of the output stream when the processor is applied given a input durationUs.

abstract void
queueInput(ByteBuffer inputBuffer)

Queues audio data between the position and limit of the inputBuffer for processing.

Protected fields

inputAudioFormat

protected AudioProcessor.AudioFormat inputAudioFormat

The current input audio format.

outputAudioFormat

protected AudioProcessor.AudioFormat outputAudioFormat

The current output audio format.

Public constructors

BaseAudioProcessor

public BaseAudioProcessor()

Public methods

configure

public final AudioProcessor.AudioFormat configure(AudioProcessor.AudioFormat inputAudioFormat)

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
AudioProcessor.AudioFormat inputAudioFormat

The format of audio that will be queued after the next call to flush.

Returns
AudioProcessor.AudioFormat

The configured output audio format if this instance is active.

Throws
androidx.media3.common.audio.AudioProcessor.UnhandledAudioFormatException

Thrown if the specified format can't be handled as input.

flush

public final void flush()

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.

getOutput

@CallSuper
public ByteBuffer getOutput()

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
public boolean isActive()

Returns whether the processor is configured and will process input buffers.

isEnded

@CallSuper
public boolean isEnded()

Returns whether this processor will return no more output from getOutput until flush has been called and more input has been queued.

queueEndOfStream

public final void queueEndOfStream()

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.

reset

public final void reset()

Resets the processor to its unconfigured state, releasing any resources.

Protected methods

hasPendingOutput

protected final boolean hasPendingOutput()

Returns whether the current output buffer has any data remaining.

onConfigure

protected AudioProcessor.AudioFormat onConfigure(AudioProcessor.AudioFormat inputAudioFormat)

Called when the processor is configured for a new input format.

onFlush

protected void onFlush()

Called when the processor is flushed, directly or as part of resetting.

onQueueEndOfStream

protected void onQueueEndOfStream()

Called when the end-of-stream is queued to the processor.

onReset

protected void onReset()

Called when the processor is reset.

replaceOutputBuffer

protected final ByteBuffer replaceOutputBuffer(int size)

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.