cuEGLStreamProducerPresentFrame results in CUDA_ERROR_INVALID_HANDLE

Hi,

I try to use cudaEglStreamProducer to push cuda data over EGL into gstreamer nveglstreamsrc for encoding. I started with example:

  • tegra_multimedia_api/argus/samples/gstVideoEncode

However I needed a way to create a producer to push cuda data in so I found this example which helps me a lot:

  • /cuda/samples/3_Imaging/EGLStreams_CUDA_Interop

I also found some helpful EGLStream Example provided by DaneLLL here:

I think I got most of the infrastructure running but I didnt got the frames into the producer.

This is how I initialized everything:

CUresult cuResult;
CUdevice cudaDevice;
cuResult = cuInit(0);
cuResult = cuDeviceGet(&cudaDevice, 0);
cuResult = cuCtxCreate(&cu_ctx, 0, cudaDevice);
eglSetupExtensions();
EGLStreamInit();
display = g_display;
streamEGL = eglStream;


cuEGLStreamProducerConnect (&conn, streamEGL, source_width, source_height);

And this is how I want to fill the producer with dummy data:

void* data[3];
cudaMalloc(&data[0],source_width*source_height);
cudaMalloc(&data[1],source_width*source_height/4);
cudaMalloc(&data[2],source_width*source_height/4);
    
CUeglFrame eglFrame;
eglFrame.width = source_width;
eglFrame.height = source_height;
eglFrame.depth = 1;
eglFrame.pitch = source_width;
eglFrame.planeCount = 3;
eglFrame.numChannels = 1;
eglFrame.frameType = CU_EGL_FRAME_TYPE_PITCH;
eglFrame.eglColorFormat = CU_EGL_COLOR_FORMAT_YUV420_PLANAR;
eglFrame.cuFormat = CU_AD_FORMAT_UNSIGNED_INT8;
eglFrame.frame.pPitch[0] = data[0];
eglFrame.frame.pPitch[1] = data[1];
eglFrame.frame.pPitch[2] = data[2];
CUresult cuStatus = cuEGLStreamProducerPresentFrame(&conn, eglFrame, 0);
if (cuStatus != CUDA_SUCCESS)
    std::cout << "cuda Producer present frame FAILED with custatus " << cuStatus << std::endl;

Now this is what I got as result:

eglDisplay Handle created 
EGLStream initialized
cuda Producer present frame FAILED with custatus 400
cuda Producer present frame FAILED with custatus 400
cuda Producer present frame FAILED with custatus 400
cuda Producer present frame FAILED with custatus 400
cuda Producer present frame FAILED with custatus 400
cuda Producer present frame FAILED with custatus 400
cuda Producer present frame FAILED with custatus 400
cuda Producer present frame FAILED with custatus 400
cuda Producer present frame FAILED with custatus 400
cuda Producer present frame FAILED with custatus 400
cuda Producer present frame FAILED with custatus 400
cuda Producer present frame FAILED with custatus 400
cuda Producer present frame FAILED with custatus 400
cuda Producer present frame FAILED with custatus 400
cuda Producer present frame FAILED with custatus 400
cuda Producer present frame FAILED with custatus 400
cuda Producer present frame FAILED with custatus 400
cuda Producer present frame FAILED with custatus 400

From documentation I can see that error code 400 refers to CUDA_ERROR_INVALID_HANDLE.
So my question is:

  1. What could this error mean? the only handles that I give to the function are the CUeglConnection and the CUeglFrame. The connection seems to be fine (cuEGLStreamProducerConnect returns 0) so is there some error with my eglFrame?
  2. Did I forgot something when initializing EGLStreamKHR?

Unfortunately, I could not find anything about cuEGLStreamProducerPresentFrame but the samples I provided above.

Hi,
Do you run it with nvgstcapture-1.0 as shown in readme.txt?

Hi Dane,

nvgstcapture-1.0 --camsrc=3 --prev-res=3

seems to work I do not get any error from this.

I also managed to get the EGLStreams_CUDA_Interop sample running with some modifications.
So I think I just missed something to initialize.

I think I solved the issue, it was by running the function within the wrong cudaContext.

So, now I am running into this problem:

[url]https://devtalk.nvidia.com/default/topic/1013435/?comment=5164413[/url]

Is there a hotfix for this, so we do not have to wait until the next release?

please try
[url]https://devtalk.nvidia.com/default/topic/1013435/jetson-tx1/nveglstreamsrc-referencing-unknown-handle/post/5170882/#5170882[/url]

Hi Dane,

thank you very much for this fast response.
This seems to fix the issue, and I can connect producer and consumer to the stream.

But now I am getting this output:

eglDisplay Handle created 
EGLStream initialized
Inside NvxLiteH264DecoderLowLatencyInitNvxLiteH264DecoderLowLatencyInit set DPB and MjstreamingInside NvxLiteH265DecoderLowLatencyInitNvxLiteH265DecoderLowLatencyInit set DPB and Mjstreaminggstreamer is not running
Framerate set to : 120 at NvxVideoEncoderSetParameterNvMMLiteOpen : Block : BlockType = 8 
===== MSENC =====
NvMMLiteBlockCreate : Block : BlockType = 8 
Connected producer: 0
Trying to push frame 
SUCCESS 
gst_rmsurface_blit: NvDdk2dBlit failed: 2
Trying to push frame 
SUCCESS 
gst_rmsurface_blit: NvDdk2dBlit failed: 2
gst_rmsurface_blit: NvDdk2dBlit failed: 2
gst_rmsurface_blit: NvDdk2dBlit failed: 2
Trying to push frame 
SUCCESS 
gst_rmsurface_blit: NvDdk2dBlit failed: 2
gst_rmsurface_blit: NvDdk2dBlit failed: 2
gst_rmsurface_blit: NvDdk2dBlit failed: 2
Trying to push frame 
gst_rmsurface_blit: NvDdk2dBlit failed: 2
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
FPS: 84.9652
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
FPS: 77.8124
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
SUCCESS 
Trying to push frame 
cuda Producer present frame FAILED with custatus 999
Trying to push frame 
cuda Producer present frame FAILED with custatus 999
Trying to push frame 
cuda Producer present frame FAILED with custatus 999
Trying to push frame 
cuda Producer present frame FAILED with custatus 999
Trying to push frame 
cuda Producer present frame FAILED with custatus 999
Trying to push frame 
cuda Producer present frame FAILED with custatus 999
Trying to push frame 
cuda Producer present frame FAILED with custatus 999

and the videofile is empty.

Also I can not fully understand how to return the frame back to the producer. I know there is a function cuEGLStreamProducerReturnFrame, but there is nearly no documentation how to use it. Should I just call it in a loop thread? Or will nveglstreamsrc free the resources?

Hi,

I am not getting the error for 720p and 2160p but for 1080p.
It also seems that the colors are not correct.

If I initialize with

eglFrame.pitch = source_width;

How do eglstreamsrc compute the pitch for plane for U/V channel?
Would cudaArray be the better option?

Hi crossfire5,
Could you try RGBA format?

cudaEgl.frame.pPitch[0] = (void *)cudaProducer->cudaPtr[bufferId];
cudaEgl.width = cudaProducer->width;
cudaEgl.depth = 1;
cudaEgl.height = cudaProducer->height;
cudaEgl.pitch = cudaProducer->width * 4;
cudaEgl.frameType = CU_EGL_FRAME_TYPE_PITCH;
cudaEgl.planeCount = 1;
cudaEgl.numChannels = 4;
cudaEgl.eglColorFormat = CU_EGL_COLOR_FORMAT_ARGB;
cudaEgl.cuFormat = CU_AD_FORMAT_UNSIGNED_INT8;