# PacketConsumerCaller

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

*** ** * ** ***


```
@ExperimentalApi
public final class PacketConsumerCaller<T extends Object>
```

<br />

*** ** * ** ***

A utility that connects a producer of `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer.Packet` of type `https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller` to a `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer` via a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html`.

This class is experimental and will be renamed or removed in a future release.

The owner of this class is responsible for invoking the `https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller#run()` method, which will start sending the queued `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer.Packet` to the wrapped `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer`. The owner is also responsible for calling `https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller#release()` to close the underlying `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html` once this consumer is no longer needed.

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller#create(androidx.media3.effect.PacketConsumer,java.util.concurrent.ExecutorService,java.util.function.Consumer)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/media3/effect/PacketConsumer<@https://developer.android.com/reference/androidx/annotation/NonNull T> packetConsumer, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/ExecutorService.html executorService, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/function/Consumer.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Exception.html> errorConsumer )` Creates a `https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller` instance. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller#queueEndOfStream()()` Queues end of stream. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller#queuePacket(androidx.media3.effect.PacketConsumer.Packet)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/media3/effect/PacketConsumer.Packet<@https://developer.android.com/reference/androidx/annotation/NonNull T> packet)` Queues a `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer.Packet` for processing. |
| `final void` | `https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller#release()()` Releases the internal `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html` and cancels coroutine to queue `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer.Packet` to the wrapped `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer`. |
| `final void` | `https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller#run()()` Start sending queued `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer.Packet` the wrapped `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer` |
| `final boolean` | `https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller#tryQueuePacket(androidx.media3.effect.PacketConsumer.Packet)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/media3/effect/PacketConsumer.Packet<@https://developer.android.com/reference/androidx/annotation/NonNull T> packet)` Attempts to queue a `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer.Packet` for processing without suspending. |

## Public methods

### create

```
public static final @NonNull PacketConsumerCaller<@NonNull T> <T extends Object> create(
    @NonNull PacketConsumer<@NonNull T> packetConsumer,
    @NonNull ExecutorService executorService,
    @NonNull Consumer<@NonNull Exception> errorConsumer
)
```

Creates a `https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller` instance.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/media3/effect/PacketConsumer<@https://developer.android.com/reference/androidx/annotation/NonNull T> packetConsumer` | The `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer` to wrap. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/ExecutorService.html executorService` | The `https://developer.android.com/reference/java/util/concurrent/ExecutorService.html` on which the `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer#queuePacket(androidx.media3.effect.PacketConsumer.Packet)` is invoked. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/function/Consumer.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Exception.html> errorConsumer` | A `https://developer.android.com/reference/java/util/function/Consumer.html` for thrown `https://developer.android.com/reference/java/lang/Exception.html`. |

### queueEndOfStream

```
@CanIgnoreReturnValue
public final @NonNull ListenableFuture<Void> queueEndOfStream()
```

Queues end of stream.

Reports errors via `https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller#errorConsumer()`.

### queuePacket

```
@CanIgnoreReturnValue
public final @NonNull ListenableFuture<Void> queuePacket(@NonNull PacketConsumer.Packet<@NonNull T> packet)
```

Queues a `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer.Packet` for processing.

The ownership of the `https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller#queuePacket(androidx.media3.effect.PacketConsumer.Packet)` is transferred to the wrapped `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer` and the caller must not modify the `https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller#queuePacket(androidx.media3.effect.PacketConsumer.Packet)`.

Reports errors via `https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller#errorConsumer()`.

### release

```
public final void release()
```

Releases the internal `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html` and cancels coroutine to queue `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer.Packet` to the wrapped `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer`.

### run

```
public final void run()
```

Start sending queued `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer.Packet` the wrapped `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer`

### tryQueuePacket

```
public final boolean tryQueuePacket(@NonNull PacketConsumer.Packet<@NonNull T> packet)
```

Attempts to queue a `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer.Packet` for processing without suspending.

If this method returns `true`, the ownership of the `https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller#tryQueuePacket(androidx.media3.effect.PacketConsumer.Packet)` is transferred to the wrapped `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer` and the caller must not modify the `https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller#tryQueuePacket(androidx.media3.effect.PacketConsumer.Packet)`. If returns `false`, it means the consumer is at capacity and cannot accept the packet at the moment.

| Throws |
|---|---|
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-closed-send-channel-exception/index.html` | If the channel to send `https://developer.android.com/reference/androidx/media3/effect/PacketConsumerCaller#tryQueuePacket(androidx.media3.effect.PacketConsumer.Packet)` to the `https://developer.android.com/reference/androidx/media3/effect/PacketConsumer` is closed. |