HardwareBufferFrame


@ExperimentalApi
public final class HardwareBufferFrame


A frame backed by a HardwareBuffer.

Frames of this type may be mappable to memory accessible by various hardware systems, such as GPU, media codecs, NPU, or other auxiliary processing units.

On API levels before 26, where HardwareBuffer is not defined, internalFrame will be set for use within this package. internalFrame is not intended for use by third party apps.

Summary

Nested types

public final class HardwareBufferFrame.Builder

A builder for HardwareBufferFrame instances.

A marker interface for storing arbitrary metadata associated with a HardwareBufferFrame.

A callback to be invoked when the HardwareBufferFrame is released.

Constants

static final HardwareBufferFrame

Public fields

final @Nullable SyncFenceWrapper

An acquire SyncFenceWrapper for the HardwareBuffer.

final Format

The format of the frame.

final @Nullable HardwareBuffer

Returns the HardwareBuffer which holds the frame data, or null if hardware buffers are not supported on the current API level.

final @Nullable Object

An optional internal frame type that is used when hardwareBuffer is not supported.

final HardwareBufferFrame.Metadata
final long

The presentation time of the frame relative to the start of the media item it belongs to, in microseconds.

final long

The release time of the frame, in nanoseconds.

final long

The presentation time of the frame relative to the start of the entire sequence, in microseconds.

Public methods

HardwareBufferFrame.Builder

Returns a Builder initialized with the values of this instance.

HardwareBufferFrame.Metadata
void

Releases the frame and its underlying resources.

synchronized HardwareBufferFrame

Creates a new reference to this frame.

Constants

END_OF_STREAM_FRAME

public static final HardwareBufferFrame END_OF_STREAM_FRAME

Public fields

acquireFence

public final @Nullable SyncFenceWrapper acquireFence

An acquire SyncFenceWrapper for the HardwareBuffer.

Callers should ensure that the acquire fence has signaled before accessing HardwareBuffer.

If the acquire fence is null, it's safe to access HardwareBuffer.

format

public final Format format

The format of the frame.

hardwareBuffer

public final @Nullable HardwareBuffer hardwareBuffer

Returns the HardwareBuffer which holds the frame data, or null if hardware buffers are not supported on the current API level.

internalFrame

public final @Nullable Object internalFrame

An optional internal frame type that is used when hardwareBuffer is not supported.

metadata

public final HardwareBufferFrame.Metadata metadata

presentationTimeUs

public final long presentationTimeUs

The presentation time of the frame relative to the start of the media item it belongs to, in microseconds.

releaseTimeNs

public final long releaseTimeNs

The release time of the frame, in nanoseconds.

sequencePresentationTimeUs

public final long sequencePresentationTimeUs

The presentation time of the frame relative to the start of the entire sequence, in microseconds. This time is monotonically increasing across all media items in the sequence.

Public methods

buildUpon

public HardwareBufferFrame.Builder buildUpon()

Returns a Builder initialized with the values of this instance. This method does not increase the reference count.

The returned builder creates handles that share the same underlying reference count as this instance. To create a new reference that increments the reference count, call retain instead.

getMetadata

public HardwareBufferFrame.Metadata getMetadata()

release

public void release(@Nullable SyncFenceWrapper releaseFence)

Releases the frame and its underlying resources.

This implementation is idempotent if called after the frame has already been released. It will strictly release the underlying resources only when the count transitions from 1 to 0.

Parameters
@Nullable SyncFenceWrapper releaseFence

A SyncFenceWrapper that must signal before the underlying resources can be fully released, or null if the resources can be released immediately.

retain

synchronized public HardwareBufferFrame retain()

Creates a new reference to this frame.

For every call to this method there must be an extra release call. The underlying buffer will only be released when the reference count drops to zero.

Throws
java.lang.IllegalStateException

if called after the frame has been released.