AsyncMediaByteSource

Media bytes from caller code that may answer later: a Fetch response, a network client, a cache. It is the suspending form of MediaByteSource, opened through AsyncMediaRuntime.open.

Calls arrive one at a time. The runtime that opens the source owns it from the call of AsyncMediaRuntime.open, and calls close exactly once. One source object serves one open: the runtime refuses an object that it already holds.

A cancelled operation cancels the call in flight and calls close while that call may still be finishing. close must therefore stop the transport, and a call that returns after its cancellation must not write into the array it was given. Honor coroutine cancellation and put a limit on every wait: the runtime waits for a call to finish before it runs other work.

A source must not call the runtime that is reading it, from any of its methods.

Properties

Link copied to clipboard
open val location: String?

The address the bytes came from when it differs from the address asked for, as after an HTTP redirect, or null. It is read once, when the source is opened. See MediaByteSource.location.

Link copied to clipboard
abstract val seekable: Boolean

False makes the whole input unseekable. seek is then never called.

Functions

Link copied to clipboard
abstract suspend fun close()

Releases the resource. A second call waits for the first and reports the same result. A close finishes even when its caller is cancelled.

Link copied to clipboard
abstract suspend fun read(into: ByteArray, offset: Int, length: Int): Int

Reads at most length bytes into into at offset and advances the cursor.

Link copied to clipboard
abstract suspend fun seek(position: Long)

Moves the cursor to position bytes from the start. Called only when seekable.

Link copied to clipboard
abstract suspend fun size(): Long?

The total size in bytes, or null when it is unknown. It is asked again each time FFmpeg asks for the size. A null after a size keeps the last size.

Link copied to clipboard
open suspend fun takeTags(): Map<String, String>?

The tags that the bytes of the last read brought, or null. It is asked after every read that returned bytes, and only of the source given to AsyncMediaRuntime.open. See MediaByteSource.takeTags.