Determine whether a new frame is available for EGL streams with no display

Hello everyone.

I have a producer consumer system, with an argus producer from one side and a cuda consumer from the other side. The argus producer is setted to repeated request mode and the cuda consumer has been conected to the output stream in a different thread. What I want to do is to check if there is a new frame in the EGL buffer before Cuda consumer tries to acquire a new frame. I managed to do that with this reference
http://gis.gha-engineers.com/pub/visionworks/nvvwx_docs/group__nvx__tutorial__eglstream__interoperability__3.html
and by assigning an EGL display to the output stream like this :

Argus producer:

ArgusSamples::Window &window = ArgusSamples::Window::getInstance();
window.setWindowRect(0, 0, 1200, 500);
g_display.initialize(window.getEGLNativeDisplay());
....
iStreamSettings->setEGLDisplay(g_display.get());
....

Cuda consumer:

/* Query the EGL stream state to determine whether a new frame is available */
EGLint streamState = 0;
if (!eglQueryStreamKHR(iStream->getEGLDisplay(), iStream->getEGLStream(), EGL_STREAM_STATE_KHR, &streamState))
{
    CUDACONSUMER_ERROR("eglQueryStreamKHR EGL_STREAM_STATE_KHR failed");
    continue;
}

if (streamState == EGL_STREAM_STATE_DISCONNECTED_KHR)
{
    CUDACONSUMER_ERROR("EGL_STREAM_STATE_DISCONNECTED_KHR received");
    continue;
}
else if (streamState != EGL_STREAM_STATE_NEW_FRAME_AVAILABLE_KHR)
{
    CUDACONSUMER_DEBUG("No frames available");
    continue;
}

/* Acquire the newly produced frame */
CUresult cuResult;
CUgraphicsResource cudaResource = 0;
CUstream cudaStream = 0;
cuResult = cuEGLStreamConsumerAcquireFrame(&cudaConnection, &cudaResource, &cudaStream, 32000);
if (cuResult != CUDA_SUCCESS)
{
    CUDACONSUMER_ERROR("Acquire failed: (CUresult " + std::string(ArgusSamples::getCudaErrorString(cuResult)) + ")");
    continue;
}

How can I do the same action but without assigning a display to the output stream ?
I tried to give a NULL argument to the eglQueryStreamKHR like this

eglQueryStreamKHR(NULL, iStream->getEGLStream(), EGL_STREAM_STATE_KHR, &streamState)

but fails with: eglQueryStreamKHR EGL_STREAM_STATE_KHR failed

Any idea ? Thanks in advance!

Hi,
The may not work. We have tried to run tegra_multimedia_api sample without lightdm:

$ sudo service lightdm stop
$ cd tegra_multimedia_api/samples/02_video_dec_cuda
$ ./video_dec_cuda ~/videoplayback1_track1.h264 H264 --disable-rendering -o a.yuv

However, it still needs to call

// Get defalut EGL display
ctx.egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

In my case, the CudaConsumer fails to connect to the outputstream of the argus producer if I set the EGL_DEFAULT_DISPLAY and stop the lightdm service

Argus producer

...
iStreamSettings->setEGLDisplay(eglGetDisplay(EGL_DEFAULT_DISPLAY));
...

Cuda Consumer

...
cuResult = cuEGLStreamConsumerConnect(&cudaConnection, iStream->getEGLStream());
if (cuResult != CUDA_SUCCESS)
{
    CUDACONSUMER_ERROR("Unable to connect CUDA as a consumer from EGLStream (CUresult "
        + std::string(ArgusSamples::getCudaErrorString(cuResult)) + ").");
    return false;
}
...

Error message:
Error: Unable to connect CUDA as a consumer from EGLStream (CUresult invalid resource handle).

On the other hand, if I disconnect my display and use the code that I posted at the first post (the one that implies that I have a display) without stopping the lighdm service, it works, but I dont know if this is the right way to do it