How to share NvBufSurface between processes

hi
we want to fulfil zero-copy function across processes.
for example, camera server process create a nvbuffer, put the camera data in the nvbuffer, and send the nvbuffer fd to client process.
client process create EGLImage from dmabuf fd through NvBufSurfaceFromFd(), but NvBufSurfaceFromFd() will return “nvbuf_utils: dmabuf_fd 8 mapped entry NOT found” error.
is there any other solution to fulfil zero-copy function across processes? maybe nvscibuf or eglstream?

Hi,
We have the sample to demonstrate sharing NvBufSurface between processes:

/usr/src/jetson_multimedia_api/samples/13_argus_multi_camera/

However, it does not work on Jetpack 7 r38.2. Will check with our teams to enable it.

ok, thanks.
by the way, as i know, driveos platform use nvscibuf to fulfil the total camera framework, nvscibuf already fulfil zero-copy function.
at jetpack platform, i see JETSON_SIPL_API,there is a coe_camera sample, already use nvsci buf.
does nvsci buf work on jetpack7? can i use nvsci to fulfil zero-copy function between processes?

Hi,
We are checking whether nvscibuf is well supported on AGx Thor Jetpack 7.

Do you prefer using NvBufSurface or nvscibuf?

Hi, Dane
NvBufSurface and nvscibuf both ok to us.
below topic use NvBufSurfaceImport between processes. shall we try it?

Hi,
The reference code is in 13_argus_multi_camera. We are checking with our teams to revive it on Thor Jetpack 7.

Hi, Dane
i check the 13_argus_multi_camera code, it also use NvBufSurfaceImport() api.
so maybe there are two ways to fulfil zero-copy function at jetpack platform.
solution A: nvbuffer+ NvBufSurfaceImport
solution B: nvsci buffer
is there any other possible solution?

Hi, Dane
我在Jetson AGX Orin(jetpack6.1)上使用NvBufSurfaceImport+egl功能,已经可以实现进程间的零拷贝功能了。

请帮忙确认下thor上什么时候可以使用NvBufSurfaceImport功能?我们急需此功能来完成相机功能的导入。

Hi,
We have confirmed 13_argus_multi_camera works on AGX Thor with Jetpack 7.0GA. Please refer to the sample to implement sharing NvBufSurface between processes.

On Thor it takes longer time to initialize sender and you may need to extend this usleep() in receriver:

 usleep(200000); // wait for sneder at accept() 

demo.zip (3.2 KB)

hi, 我这边没有argus的相机,没办法直接执行这个sample.
附件提供了一个demo,是参考argus的逻辑写的,这个demo在agx orin devkit上是可以正常运行的,但是在thor上不能运行。我在connect的时候已经把延时改成1s,依然报错。

[Client] Connected to server
[Client] recv mapParams failed r=0 errno=0
请帮忙看一下

hi,dane
thor好像不支持NVBUF_MEM_SYSTEM格式,换成NVBUF_MEM_SURFACE_ARRAY就可以,现在用默认的200ms延时,好像也没问题,我继续验证一下NvBufSurfaceImport+egl的方案

1 Like

hi, dane

thor上NvBufSurfaceImport+egl没问题了,已经可以实现零拷贝功能了。

不过egl初始化的问题,还想确认一下,有没有推荐的方案?我们是在没显示器的ssh上执行程序,目前通过如下的方式进行初始化,正常的情况下没问题,但是之前ubuntu系统遇到过一次界面乱码问题(鼠标点击右键,菜单全是乱码),下面的方案,egl初始化会失败,重启以后可解决。所以想问一下,egl初始化,有没有更好的方案,来实现在没显示器的ssh上来执行camera相关的程序?

 static bool display_initialize(context_t *ctx) { EGLint major, minor; EGLint numConfigs; EGLConfig config; // 1. get default display ctx->egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (ctx->egl_display == EGL_NO_DISPLAY) { fprintf(stderr, "Failed to get EGL display\n"); return false; } // 2. init display if (!eglInitialize(ctx->egl_display, &major, &minor)) { fprintf(stderr, "Failed to initialize EGL\n"); return false; } // 3. config EGLint attribs[] = { EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE }; if (!eglChooseConfig(ctx->egl_display, attribs, &config, 1, &numConfigs) || numConfigs == 0) { fprintf(stderr, "Failed to choose EGL config\n"); return false; } // 4. create Pbuffer Surface EGLint pbufferAttribs[] = {EGL_WIDTH, 16, EGL_HEIGHT, 16, EGL_NONE}; ctx->eglSurface = eglCreatePbufferSurface(ctx->egl_display, config, pbufferAttribs); if (ctx->eglSurface == EGL_NO_SURFACE) { fprintf(stderr, "Failed to create Pbuffer surface\n"); return false; } // 5. create EGLContext EGLint ctxAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; ctx->egl_context = eglCreateContext(ctx->egl_display, config, EGL_NO_CONTEXT, ctxAttribs); if (ctx->egl_context == EGL_NO_CONTEXT) { fprintf(stderr, "Failed to create EGL context\n"); return false; } // 6. MakeCurrent if (!eglMakeCurrent(ctx->egl_display, ctx->eglSurface, ctx->eglSurface, ctx->egl_context)) { fprintf(stderr, "Failed to make EGL context current\n"); return false; } printf("EGL Pbuffer initialized successfully\n"); return true; } 

hi, Dane

is there any update of egl init?

Hi,
Are you able to reproduce it on developer kit? The sample looks fine and if it fails on developer kit, we can reproduce it and then check with our teams.

Hi, dane

我们的相机无法在devkit上工作。所以没有在devkit上尝试。

如下是错误信息,可否帮忙分析一下?我们是先遇到桌面乱码的问题,鼠标右键显示的菜单全是乱码,然后发现无法进行egl的初始化。
尝试重启下面的两个服务后,egl可以正常初始化。
sudo systemctl restart nvargus-daemon
sudo systemctl restart gdm
感觉是xorg出问题了。

dmesg.txt (130.7 KB)

hi, dane

我们使用argus sample中egl的初始化代码(EGLGlobal.cpp的)initialize函数,如果设置了export DISPLAY=:0,可以正常执行NvBufSurfaceMapEglImage()函数,但是如果不设置export DISPLAY=:0,ssh连接的shell中默认的DISPLAY是localhost:12.0,这个时候egl能初始化成功,但是NvBufSurfaceMapEglImage会报错。
nvbufsurface: Failed to create EGLImage.
ERROR: cuda_postprocess(): (line:704) Failed to map dmabuf fd (0xC) to EGLImage

所以意思是,想使用NvBufSurfaceMapEglImage功能,必须要跟xorg绑定吗,也就是设置export DISPLAY=:0?

i open a new topic about NvBufSurfaceMapEglImage and egl issue.

1 Like