Building a Simple EGLStream Pipeline
Before you build a simple EGLStream pipeline, you must initialize the EGL interface on the platform and create the EGLDisplay.
- Create the
EGLDisplay
object for the EGLStream to bind to it. -
Call
eglInitialize()
to initialize EGL on the created display or on the default display.If the GL consumer or EGLOutput consumer is used, you must initialize the rendering window before creating the EGLStream pipeline.
If the CUDA producer-consumer is used, window system initialization is not required.
-
Create an EGLStream.
Example for creating the EGLStream (from
eglstreamcube.c
):client->stream = eglCreateStreamKHR(demoState.display, streamAttr); if (client->stream == EGL_NO_STREAM_KHR) { NvGlDemoLog("Couldn't create EGL stream.\n"); goto fail; }
Depending on whether mailbox mode or FIFO mode is used,
streamAttr
is set accordingly. The attributeEGL_STREAM_FIFO_LENGTH_KHR
is initialized for FIFO mode.if (demoOptions.nFifo > 0) { streamAttr[numAttrs++] = EGL_STREAM_FIFO_LENGTH_KHR; streamAttr[numAttrs++] = demoOptions.nFifo; }
-
Create a consumer and connect it to the EGLStream. It is specific to the consumer type.
Example for connecting a GL consumer to EGLStream (from
eglstreamcube.c
):glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture); if (!eglStreamConsumerGLTextureExternalKHR(demoState.display, client->stream)) { NvGlDemoLog("Couldn't bind texture.\n"); goto fail; }
Once an EGLStream is connected to a consumer, it remains connected to the same consumer until the EGLStream is destroyed.
-
Create a producer and connect it to the EGLStream. It is specific to the producer type.
Example for connecting a GL producer to EGLStream (from
nvgldemo_main.c
):eglCreateStreamProducerSurfaceKHR(demoState.display, demoState.config, demoState.stream, srfAttrs);
Once an EGLStream is connected to a producer, it must remain connected to the same producer until the EGLStream is destroyed.
-
The producer posts the image frame to the consumer, depending on the producer type.
In the GL producer case,
eglSwapBuffers
posts the buffer to the consumer. -
The consumer acquires the image frame posted by the producer, uses it, and then releases the frame back to the stream. Methods for acquiring frames from a stream and releasing them back to a stream are dependent on the type of consumer.
Example for acquiring and releasing the frame in the GL consumer case (from
eglstreamcube.c
):eglStreamConsumerAcquireKHR(demoState.display, clientList[i].stream) eglStreamConsumerReleaseKHR(demoState.display, client->stream)
In the GL consumer case, If
eglStreamConsumerAcquireKHR()
is called twice on the same EGLStream without an intervening call toeglStreamConsumerReleaseKHR()
, theneglStreamConsumerReleaseKHR()
is implicitly called at the start ofeglStreamConsumerAcquireKHR()
.