@ExperimentalApi
public interface FrameWriter extends AutoCloseable

Known direct subclasses
EncoderFrameWriter

An implementation of FrameWriter that uses an ImageWriter to forward frames to a encoder via Surface.

SurfaceHolderFrameWriter

A FrameWriter that outputs frames to a SurfaceHolder.


Allocates Frame instances, allowing callers to dequeue and fill them, before processing the filled frames.

Summary

Nested types

public interface FrameWriter.Info

Describes the capabilities of a FrameWriter.

Public methods

abstract void

Blocks until all resources are released.

abstract void
configure(Format format, @Frame.Usage long usage)

Format and usage support can be checked on the Info before configuring.

abstract @Nullable AsyncFrame
dequeueInputFrame(Executor wakeupExecutor, Runnable wakeupListener)

Dequeues an AsyncFrame storing a Frame of the configured format and usage, and a SyncFenceWrapper that must be waited on before filling the frame.

abstract FrameWriter.Info

Returns the Info for this FrameWriter.

abstract void
queueInputFrame(
    Frame frame,
    @Nullable SyncFenceWrapper writeCompleteFence
)

Queues a filled frame for further processing.

abstract void

Notifies this FrameWriter that the current stream has ended.

Public methods

close

abstract void close()

Blocks until all resources are released.

configure

abstract void configure(Format format, @Frame.Usage long usage)

Format and usage support can be checked on the Info before configuring.

Must be called before dequeueInputFrame.

Parameters
Format format

The format to configure.

@Frame.Usage long usage

The @FrameUsage flags describing how the frame will be used.

Throws
java.lang.IllegalStateException

if any frames are dequeued at the point this method is called.

java.lang.IllegalArgumentException

if the format or usage is unsupported.

dequeueInputFrame

abstract @Nullable AsyncFrame dequeueInputFrame(Executor wakeupExecutor, Runnable wakeupListener)

Dequeues an AsyncFrame storing a Frame of the configured format and usage, and a SyncFenceWrapper that must be waited on before filling the frame.

The returned frame must be filled and queued back for processing.

If the FrameWriter is at capacity, this method returns null and will notify the listener when capacity is available, and it can be called again.

Only the most recent wakeupListener will be notified when capacity is available.

Parameters
Executor wakeupExecutor

The Executor on which the wakeupListener is invoked.

Runnable wakeupListener

A Runnable to be invoked when capacity becomes available.

Returns
@Nullable AsyncFrame

The dequeued frame, or null if the writer is at capacity.

Throws
java.lang.IllegalStateException

if configure has not been called.

getInfo

abstract FrameWriter.Info getInfo()

Returns the Info for this FrameWriter.

queueInputFrame

abstract void queueInputFrame(
    Frame frame,
    @Nullable SyncFenceWrapper writeCompleteFence
)

Queues a filled frame for further processing.

The queued frame must have been previously dequeued from this writer.

Parameters
Frame frame

The filled frame to queue.

@Nullable SyncFenceWrapper writeCompleteFence

A SyncFenceWrapper that will signal when the caller has finished writing to the frame, or null if the write was synchronous.

signalEndOfStream

abstract void signalEndOfStream()

Notifies this FrameWriter that the current stream has ended.

More frames may be queued after calling this method, if the current stream changes.