Package com.google.android.exoplayer2.audio

## Class BaseAudioProcessor

- java.lang.Object
- - com.google.android.exoplayer2.audio.BaseAudioProcessor

- All Implemented Interfaces:
    `AudioProcessor`
  Direct Known Subclasses:
    `SilenceSkippingAudioProcessor`, `TeeAudioProcessor`

      public abstract class BaseAudioProcessor
      extends Object
      implements AudioProcessor

  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(AudioFormat)` to return the output audio format for the processor if it's active.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface com.google.android.exoplayer2.audio.AudioProcessor

      `AudioProcessor.AudioFormat, AudioProcessor.UnhandledAudioFormatException`

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected AudioProcessor.AudioFormat` | `inputAudioFormat` | The current input audio format.
    `protected AudioProcessor.AudioFormat` | `outputAudioFormat` | The current output audio format.

    - ### Fields inherited from interface com.google.android.exoplayer2.audio.AudioProcessor

      `EMPTY_BUFFER`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `BaseAudioProcessor()` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `AudioProcessor.AudioFormat` | `configure​(AudioProcessor.AudioFormat inputAudioFormat)` | Configures the processor to process input audio with the specified format.
    `void` | `flush()` | Clears any buffered data and pending output.
    `ByteBuffer` | `getOutput()` | Returns a buffer containing processed output data between its position and limit.
    `protected boolean` | `hasPendingOutput()` | Returns whether the current output buffer has any data remaining.
    `boolean` | `isActive()` | Returns whether the processor is configured and will process input buffers.
    `boolean` | `isEnded()` | Returns whether this processor will return no more output from `AudioProcessor.getOutput()` until `AudioProcessor.flush()` has been called and more input has been queued.
    `protected AudioProcessor.AudioFormat` | `onConfigure​(AudioProcessor.AudioFormat inputAudioFormat)` | Called when the processor is configured for a new input format.
    `protected void` | `onFlush()` | Called when the processor is flushed, directly or as part of resetting.
    `protected void` | `onQueueEndOfStream()` | Called when the end-of-stream is queued to the processor.
    `protected void` | `onReset()` | Called when the processor is reset.
    `void` | `queueEndOfStream()` | Queues an end of stream signal.
    `protected ByteBuffer` | `replaceOutputBuffer​(int size)` | Replaces the current output buffer with a buffer of at least `size` bytes and returns it.
    `void` | `reset()` | Resets the processor to its unconfigured state, releasing any resources.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.google.android.exoplayer2.audio.AudioProcessor

      `queueInput`

- - ### Field Detail

    - #### inputAudioFormat

          protected AudioProcessor.AudioFormat inputAudioFormat

      The current input audio format.

    - #### outputAudioFormat

          protected AudioProcessor.AudioFormat outputAudioFormat

      The current output audio format.

  - ### Constructor Detail

    - #### BaseAudioProcessor

          public BaseAudioProcessor()

  - ### Method Detail

    - #### configure

          @CanIgnoreReturnValue
          public final AudioProcessor.AudioFormat configure​(AudioProcessor.AudioFormat inputAudioFormat)
                                                     throws AudioProcessor.UnhandledAudioFormatException

      Description copied from interface: `AudioProcessor`
      Configures the processor to process input audio with the specified format. After calling this method, call `AudioProcessor.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 `AudioProcessor.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 `AudioProcessor.queueEndOfStream()` when no more input will be supplied in the old input format.

      Specified by:
        `configure` in interface `AudioProcessor`
      Parameters:
        `inputAudioFormat` - The format of audio that will be queued after the next call to `AudioProcessor.flush()`.
      Returns:
        The configured output audio format if this instance is `active`.
      Throws:
        `AudioProcessor.UnhandledAudioFormatException` - Thrown if the specified format can't be handled as input.

    - #### isActive

          public boolean isActive()

      Description copied from interface: `AudioProcessor`
      Returns whether the processor is configured and will process input buffers.
      Specified by:
        `isActive` in interface `AudioProcessor`

    - #### queueEndOfStream

          public final void queueEndOfStream()

      Description copied from interface: `AudioProcessor`
      Queues an end of stream signal. After this method has been called, `AudioProcessor.queueInput(ByteBuffer)` may not be called until after the next call to `AudioProcessor.flush()`. Calling `AudioProcessor.getOutput()` will return any remaining output data. Multiple calls may be required to read all of the remaining output data. `AudioProcessor.isEnded()` will return `true` once all remaining output data has been read.
      Specified by:
        `queueEndOfStream` in interface `AudioProcessor`

    - #### getOutput

          @CallSuper
          public ByteBuffer getOutput()

      Description copied from interface: `AudioProcessor`
      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.
      Specified by:
        `getOutput` in interface `AudioProcessor`
      Returns:
        A buffer containing processed output data between its position and limit.

    - #### isEnded

          @CallSuper
          public boolean isEnded()

      Description copied from interface: `AudioProcessor`
      Returns whether this processor will return no more output from `AudioProcessor.getOutput()` until `AudioProcessor.flush()` has been called and more input has been queued.
      Specified by:
        `isEnded` in interface `AudioProcessor`

    - #### flush

          public final void flush()

      Description copied from interface: `AudioProcessor`
      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.
      Specified by:
        `flush` in interface `AudioProcessor`

    - #### reset

          public final void reset()

      Description copied from interface: `AudioProcessor`
      Resets the processor to its unconfigured state, releasing any resources.
      Specified by:
        `reset` in interface `AudioProcessor`

    - #### 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 `ByteBuffer.flip()` it so it can be read via `getOutput()`.

    - #### hasPendingOutput

          protected final boolean hasPendingOutput()

      Returns whether the current output buffer has any data remaining.

    - #### onConfigure

          @CanIgnoreReturnValue
          protected AudioProcessor.AudioFormat onConfigure​(AudioProcessor.AudioFormat inputAudioFormat)
                                                    throws AudioProcessor.UnhandledAudioFormatException

      Called when the processor is configured for a new input format.
      Throws:
        `AudioProcessor.UnhandledAudioFormatException`

    - #### onQueueEndOfStream

          protected void onQueueEndOfStream()

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

    - #### onFlush

          protected void onFlush()

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

    - #### onReset

          protected void onReset()

      Called when the processor is reset.