Xaviernx jp5.1.1 eglFrame.pitch is always 0

int CUDAtransform::map_to_eglimage(int fd, CUeglFrame *eglFrame)
{
    CUresult status;

    if (-1 == NvBufSurfaceFromFd(fd, (void **)(&pSurf)))
    {
        std::cerr << "Unable to NvBufSurfaceFromFd" << std::endl;
        return -5;
    }
    if (pSurf->surfaceList[0].mappedAddr.eglImage == NULL)
    {
        if (NvBufSurfaceMapEglImage(pSurf, 0) != 0)
        {
            std::cerr << "Unable to map EGL Image" << std::endl;
            return -6;
        }
    }
    egl_khr_image = pSurf->surfaceList[0].mappedAddr.eglImage;
    if (!egl_khr_image)
    {
        std::cerr << "egl_khr_image is null" << std::endl;
        return -1;
    }
cudaFree(0);
    status = cuGraphicsEGLRegisterImage(&pResource, egl_khr_image, CU_GRAPHICS_MAP_RESOURCE_FLAGS_READ_ONLY);
    if (status != CUDA_SUCCESS)
    {
        std::cerr << "cuGraphicsEGLRegisterImage failed: " << status
                  << " cuda process stop" << std::endl;
        return -2;
    }

    status = cuGraphicsResourceGetMappedEglFrame(eglFrame, pResource, 0, 0);
    if (status != CUDA_SUCCESS)
    {
        std::cerr << "cuGraphicsSubResourceGetMappedArray failed" << std::endl;
        return -3;
    }

    cudaDeviceSynchronize();
    return 0;
}

Here is my code,eglFrame->pitch is always 0, fd is the capture decode from H264 and the fd is

cParams.width = crop.c.width;
    cParams.height = crop.c.height;
    cParams.layout = NVBUF_LAYOUT_BLOCK_LINEAR;
    cParams.memType = NVBUF_MEM_SURFACE_ARRAY;
    cParams.memtag = NvBufSurfaceTag_VIDEO_DEC;
    if (format.fmt.pix_mp.pixelformat == V4L2_PIX_FMT_NV24M)
    {
        cParams.colorFormat = NVBUF_COLOR_FORMAT_NV24;
        LOG("yuv444");
    }
    else
    {
        LOG("yuv420");
        cParams.colorFormat = NVBUF_COLOR_FORMAT_NV12;
    }

I don’t know why. Width and height works well.

Hi,

It should work like the following:

    ...
    cudaEglFrame frame;
    if (cudaGraphicsResourceGetMappedEglFrame(&frame, resource, 0, 0) != CUDA_SUCCESS)
    {
        return -1;
    }
    ...
    printf("cudaEglFrame: %zux%zu(%zu)\n",
        frame.frame.pPitch[0].xsize, frame.frame.pPitch[0].ysize, frame.frame.pPitch[0].pitch);

Based on our document, only first plane has the valid pitch value.
https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__EGL.html#group__CUDART__EGL_1gdd6215655a241c047d6d4939e242202a

Thanks.

I find that if I need to map the fd to eglframe , the fd must be pitch on jp5.1.1 but it doesn’t nend that on jp4.6.3

Hi,

Since JetPack 5 use CUDA 11 and nvbuffersurface, there might be some API changes.
Do you fix the issue after using the correct mapping way?

Thanks.

Yes! I do.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.