# SampleConsumer

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/transformer/SampleConsumer "View this page in Java")

<br />

```
@UnstableApi
interface SampleConsumer
```

<br />

*** ** * ** ***

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

## Summary

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

|                                    ### Constants                                    |
|-------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [INPUT_RESULT_END_OF_STREAM](https://developer.android.com/reference/kotlin/androidx/media3/transformer/SampleConsumer#INPUT_RESULT_END_OF_STREAM())` = 3` The operation of queueing input successful and end of input has been automatically signalled. |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [INPUT_RESULT_SUCCESS](https://developer.android.com/reference/kotlin/androidx/media3/transformer/SampleConsumer#INPUT_RESULT_SUCCESS())` = 1` The operation of queueing input was successful.                                                           |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [INPUT_RESULT_TRY_AGAIN_LATER](https://developer.android.com/reference/kotlin/androidx/media3/transformer/SampleConsumer#INPUT_RESULT_TRY_AGAIN_LATER())` = 2` The operation of queueing/registering input was unsuccessful.                             |

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

## Constants

### INPUT_RESULT_END_OF_STREAM

```
const val INPUT_RESULT_END_OF_STREAM = 3: Int
```

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

The caller should not[signal end of input](https://developer.android.com/reference/kotlin/androidx/media3/transformer/SampleConsumer#signalEndOfVideoInput())as this has already been done internally.  

### INPUT_RESULT_SUCCESS

```
const val INPUT_RESULT_SUCCESS = 1: Int
```

The operation of queueing input was successful.

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

### INPUT_RESULT_TRY_AGAIN_LATER

```
const val INPUT_RESULT_TRY_AGAIN_LATER = 2: Int
```

The operation of queueing/registering input was unsuccessful.

The caller should queue try again later.  

## Public functions

### getInputBuffer

```
fun getInputBuffer(): DecoderInputBuffer?
```

Returns a[DecoderInputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer), if available.

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

If this method returns a non-null buffer:

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

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

### getInputSurface

```
fun getInputSurface(): Surface!
```

Returns the input[Surface](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

```
fun getPendingVideoFrameCount(): Int
```

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

Should only be used for raw video data.  

### queueInputBitmap

```
@SampleConsumer.InputResult
fun queueInputBitmap(
    inputBitmap: Bitmap!,
    timestampIterator: TimestampIterator!
): Int
```

Attempts to provide an input[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)to the consumer.

Should only be used for image data.  

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

|                                   Returns                                   |
|-----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The[InputResult](https://developer.android.com/reference/kotlin/androidx/media3/transformer/SampleConsumer.InputResult)describing the result of the operation. |

### queueInputBuffer

```
fun queueInputBuffer(): Boolean
```

Attempts to queue new input to the consumer.

The input buffer from[getInputBuffer](https://developer.android.com/reference/kotlin/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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether the input was successfully queued. If`false`, the caller should try again later. |

### queueInputTexture

```
@SampleConsumer.InputResult
fun queueInputTexture(texId: Int, presentationTimeUs: Long): Int
```

Attempts to provide an input texture to the consumer.

Should only be used for raw video data.  

|                                             Parameters                                              |
|-----------------------------------------------------------------------------------------------------|---------------------------------------------------------|
| `texId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                | The ID of the texture to queue to the consumer.         |
| `presentationTimeUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The presentation time for the texture, in microseconds. |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The[InputResult](https://developer.android.com/reference/kotlin/androidx/media3/transformer/SampleConsumer.InputResult)describing the result of the operation. |

### registerVideoFrame

```
fun registerVideoFrame(presentationTimeUs: Long): Boolean
```

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[input surface](https://developer.android.com/reference/kotlin/androidx/media3/transformer/SampleConsumer#getInputSurface()).

Should only be used for raw video data.  

|                                             Parameters                                              |
|-----------------------------------------------------------------------------------------------------|------------------------------------------------------------------|
| `presentationTimeUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The presentation time of the frame to register, in microseconds. |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether the frame was successfully registered. If`false`, the caller should try again later. |

### setOnInputFrameProcessedListener

```
fun setOnInputFrameProcessedListener(
    listener: OnInputFrameProcessedListener!
): Unit
```

Provides a[OnInputFrameProcessedListener](https://developer.android.com/reference/kotlin/androidx/media3/common/OnInputFrameProcessedListener)to the consumer.

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

|                                                                     Parameters                                                                      |
|-----------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------|
| `listener: `[OnInputFrameProcessedListener](https://developer.android.com/reference/kotlin/androidx/media3/common/OnInputFrameProcessedListener)`!` | The[OnInputFrameProcessedListener](https://developer.android.com/reference/kotlin/androidx/media3/common/OnInputFrameProcessedListener). |

### setOnInputSurfaceReadyListener

```
fun setOnInputSurfaceReadyListener(runnable: Runnable!): Unit
```

Sets a listener that's called when the[input surface](https://developer.android.com/reference/kotlin/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                                         |
|--------------------------------------------------------------------------------------------|---------------------------------------------------------|
| `runnable: `[Runnable](https://developer.android.com/reference/java/lang/Runnable.html)`!` | Listener that's called when the input surface is ready. |

### signalEndOfVideoInput

```
fun signalEndOfVideoInput(): Unit
```

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

Should only be used for raw video data.