Back to Filament

Stream

docs/android/dokka/filament-android/com.google.android.filament/-stream/index.md

1.75.03.7 KB
Original Source

//filament-android/com.google.android.filament/Stream

Stream

open class Stream

Stream is used to attach a native video stream to a filament Texture. Stream supports three different configurations:

  • ACQUIRED
  • connects to an Android AHardwareBuffer
  • NATIVE
  • connects to an Android SurfaceTexture

Before explaining these different configurations, let's review the high-level structure of an AR or video application that uses Filament.

kotlin
while (true) {

    // Misc application work occurs here, such as:
    // - Writing the image data for a video frame into a Stream
    // - Moving the Filament Camera

    if (renderer.beginFrame(swapChain)) {
        renderer.render(view);
        renderer.endFrame();
    }
}

Let's say that the video image data at the time of a particular invocation of beginFrame becomes visible to users at time A. The 3D scene state (including the camera) at the time of that same invocation becomes apparent to users at time B.

  • If time A matches time B, we say that the stream is synchronized.
  • Filament invokes low-level graphics commands on the driver thread.
  • The thread that calls beginFrame is called the main thread.

For ACQUIRED streams, there is no need to perform the copy because Filament explictly acquires the stream, then releases it later via a callback function. This configuration is especially useful when the Vulkan backend is enabled.

For NATIVE streams, Filament does not make any synchronization guarantee. However they are simple to use and do not incur a copy. These are often appropriate in video applications.

Please see sample-stream-test and sample-hello-camera for usage examples.

See also

Texture
Engine

Types

NameSummary
Builder[main]
open class Builder
Use Builder to construct an Stream object instance.
StreamType[main]
enum StreamType
Represents the immutable stream type.

Functions

NameSummary
getNativeObject[main]
open fun getNativeObject(): Long
getStreamType[main]
open fun getStreamType(): Stream.StreamType
Indicates whether this Stream is NATIVE or ACQUIRED.
getTimestamp[main]
open fun getTimestamp(): Long
Returns the presentation time of the currently displayed frame in nanosecond.
setAcquiredImage[main]
open fun setAcquiredImage(hwbuffer: Any, handler: Any, callback: Runnable)
Updates an kotlin ACQUIRED stream with an image that is guaranteed to be used in the next frame.
setDimensions[main]
open fun setDimensions(width: Int, height: Int)
Updates the size of the incoming stream.