# SampleConsumer

Artifact: [androidx.media3:media3-transformer](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/transformer/SampleConsumer.java+class:androidx.media3.transformer.SampleConsumer)

*** ** * ** ***


```
@UnstableApi
public interface SampleConsumer
```

<br />

*** ** * ** ***

Consumer of encoded media samples, raw audio or raw video frames.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE) @https://developer.android.com/reference/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer.InputResult` Specifies the result of an input operation. |

| ### Constants |
|---|---|
| `default static final int` | `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#INPUT_RESULT_END_OF_STREAM() = 3` The operation of queueing input successful and end of input has been automatically signalled. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#INPUT_RESULT_SUCCESS() = 1` The operation of queueing input was successful. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#INPUT_RESULT_TRY_AGAIN_LATER() = 2` The operation of queueing/registering input was unsuccessful. |

| ### Public methods |
|---|---|
| `default @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer` | `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#getInputBuffer()()` Returns a `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer`, if available. |
| `default https://developer.android.com/reference/android/view/Surface.html` | `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#getInputSurface()()` Returns the input `https://developer.android.com/reference/android/view/Surface.html`, where the consumer reads input frames from. |
| `default int` | `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#getPendingVideoFrameCount()()` Returns the number of input video frames pending in the consumer. |
| `default int` | `@https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer.InputResult https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#queueInputBitmap(android.graphics.Bitmap,androidx.media3.common.util.TimestampIterator)( https://developer.android.com/reference/android/graphics/Bitmap.html inputBitmap, https://developer.android.com/reference/androidx/media3/common/util/TimestampIterator timestampIterator )` Attempts to provide an input `https://developer.android.com/reference/android/graphics/Bitmap.html` to the consumer. |
| `default boolean` | `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#queueInputBuffer()()` Attempts to queue new input to the consumer. |
| `default int` | `@https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer.InputResult https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#queueInputTexture(int,long)(int texId, long presentationTimeUs)` Attempts to provide an input texture to the consumer. |
| `default boolean` | `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#registerVideoFrame(long)(long presentationTimeUs)` Attempts to register a video frame to the consumer. |
| `default void` | `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#setOnInputFrameProcessedListener(androidx.media3.common.OnInputFrameProcessedListener)( https://developer.android.com/reference/androidx/media3/common/OnInputFrameProcessedListener listener )` Provides a `https://developer.android.com/reference/androidx/media3/common/OnInputFrameProcessedListener` to the consumer. |
| `default void` | `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#setOnInputSurfaceReadyListener(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable.html runnable)` Sets a listener that's called when the `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#getInputSurface()` has been configured with a default input size, if applicable. |
| `default void` | `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#signalEndOfVideoInput()()` Informs the consumer that no further input frames will be rendered. |

## Constants

### INPUT_RESULT_END_OF_STREAM

```
default static final int INPUT_RESULT_END_OF_STREAM = 3
```

The operation of queueing input successful and end of input has been automatically signalled.

The caller should not `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#signalEndOfVideoInput()` as this has already been done internally.

### INPUT_RESULT_SUCCESS

```
default static final int INPUT_RESULT_SUCCESS = 1
```

The operation of queueing input was successful.

The caller can queue more input or signal `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#signalEndOfVideoInput()`.

### INPUT_RESULT_TRY_AGAIN_LATER

```
default static final int INPUT_RESULT_TRY_AGAIN_LATER = 2
```

The operation of queueing/registering input was unsuccessful.

The caller should queue try again later.

## Public methods

### getInputBuffer

```
default @Nullable DecoderInputBuffer getInputBuffer()
```

Returns a `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer`, if available.

This `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer` should be filled with new input data and `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#queueInputBuffer()` to the consumer.

If this method returns a non-null buffer:

- The buffer's `https://developer.android.com/reference/androidx/media3/decoder/DecoderInputBuffer#data()` is non-null.
- The same buffer instance is returned if this method is called multiple times before `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#queueInputBuffer()` input.

Should only be used for compressed data and raw audio data.

### getInputSurface

```
default Surface getInputSurface()
```

Returns the input `https://developer.android.com/reference/android/view/Surface.html`, where the consumer reads input frames from.

Should only be used for raw video data.

### getPendingVideoFrameCount

```
default int getPendingVideoFrameCount()
```

Returns the number of input video frames pending in the consumer. Pending input frames are frames that have been `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#registerVideoFrame(long)` but not processed off the `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#getInputSurface()` yet.

Should only be used for raw video data.

### queueInputBitmap

```
@SampleConsumer.InputResult
default int queueInputBitmap(
    Bitmap inputBitmap,
    TimestampIterator timestampIterator
)
```

Attempts to provide an input `https://developer.android.com/reference/android/graphics/Bitmap.html` to the consumer.

Should only be used for image data.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html inputBitmap` | The `https://developer.android.com/reference/android/graphics/Bitmap.html` to queue to the consumer. |
| `https://developer.android.com/reference/androidx/media3/common/util/TimestampIterator timestampIterator` | A `https://developer.android.com/reference/androidx/media3/common/util/TimestampIterator` generating the exact timestamps that the bitmap should be shown at. |

| Returns |
|---|---|
| `int` | The `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer.InputResult` describing the result of the operation. |

### queueInputBuffer

```
default boolean queueInputBuffer()
```

Attempts to queue new input to the consumer.

The input buffer from `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#getInputBuffer()` should be filled with the new input before calling this method.

An input buffer should not be used anymore after it has been successfully queued.

Should only be used for compressed data and raw audio data.

| Returns |
|---|---|
| `boolean` | Whether the input was successfully queued. If `false`, the caller should try again later. |

### queueInputTexture

```
@SampleConsumer.InputResult
default int queueInputTexture(int texId, long presentationTimeUs)
```

Attempts to provide an input texture to the consumer.

Should only be used for raw video data.

| Parameters |
|---|---|
| `int texId` | The ID of the texture to queue to the consumer. |
| `long presentationTimeUs` | The presentation time for the texture, in microseconds. |

| Returns |
|---|---|
| `int` | The `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer.InputResult` describing the result of the operation. |

### registerVideoFrame

```
default boolean registerVideoFrame(long presentationTimeUs)
```

Attempts to register a video frame to the consumer.

Each frame to consume should be registered using this method. After a frame is successfully registered, it should be rendered to the `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#getInputSurface()`.

Should only be used for raw video data.

| Parameters |
|---|---|
| `long presentationTimeUs` | The presentation time of the frame to register, in microseconds. |

| Returns |
|---|---|
| `boolean` | Whether the frame was successfully registered. If `false`, the caller should try again later. |

### setOnInputFrameProcessedListener

```
default void setOnInputFrameProcessedListener(
    OnInputFrameProcessedListener listener
)
```

Provides a `https://developer.android.com/reference/androidx/media3/common/OnInputFrameProcessedListener` to the consumer.

Should only be used for raw video data when input is provided by texture ID.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/OnInputFrameProcessedListener listener` | The `https://developer.android.com/reference/androidx/media3/common/OnInputFrameProcessedListener`. |

### setOnInputSurfaceReadyListener

```
default void setOnInputSurfaceReadyListener(Runnable runnable)
```

Sets a listener that's called when the `https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer#getInputSurface()` has been configured with a default input size, if applicable.

Should only be used for raw video data when input is provided by the app to a surface.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/Runnable.html runnable` | Listener that's called when the input surface is ready. |

### signalEndOfVideoInput

```
default void signalEndOfVideoInput()
```

Informs the consumer that no further input frames will be rendered.

Should only be used for raw video data.