Hi,
I’m working on a PX2 project.
We need to connect the camera video and other applications.
Right now our approach is to use EGLStream to bridge the video streaming.
We do this based on the sample code of img_cap_eglprod (image producer) and eglstream (image consumer).
In the eglstream, we try to retrieve the image buffer by using below codes after NvMediaEglStreamConsumerAcquireImage.
if (image) {
LOG_ERR("%s %d\n", __func__, __LINE__);
NvMediaImageSurfaceMap surfaceMap;
NvMediaStatus status;
if ((status = NvMediaImageLock(image, NVMEDIA_IMAGE_ACCESS_WRITE, &surfaceMap)) !=
NVMEDIA_STATUS_OK) {
LOG_ERR("%s: NvMediaImageLock failed %d\n", __func__, status);
goto fail;
}
LOG_ERR("%s %d %d %d\n", __func__, __LINE__, surfaceMap.height, surfaceMap.width);
NvU32 srcPitch = 3840*4;
if(NVMEDIA_STATUS_OK != (status = NvMediaImageGetBits(image, NULL, (void **)&inputBuffer, &srcPitch))) {
LOG_ERR("Nvmedia image get bits fail %d\n", status);
goto fail;
}
NvMediaImageUnlock(image);
NvMediaEglStreamConsumerReleaseImage(display->consumer, image);
}
However, every time we call NvMediaImageLock, we get a segmentation fault. Looking into the core dump, we found the issue was caused by NvMediaImageLock function. Is there any suggestion or direction we can check?
Thanks in advance.
PS. the producer and consumer are two different processes, the producer generates the image buffer, and we try to lock in the consumer process. don’t know if this matters.
Best,
Krammer
Dear chenghul,
May I know what is the objective of your project? Also, Is it possible to share a sample code to reproduce the issue on our side?
Hi Siva,
Thank you for your reply.
Our objective is to connect camera streaming with two different applications and use those camera frames to do the perception jobs. Specifically, we need to find a way to share the same camera streaming with two different applications (processes) and these applications might copy the entire frame buffer and do some operations based on the image.
Right now we are using img_cap_eglprod as the source application to capture camera streaming, and we use eglstream to mimic the two consumer applications. Everything goes well and we can get the NvMediaImage from EglStream. However, when we wanted to retrieve the real image buffer (so that our applications could do their works), we got a segmentation fault when calling NvMediaImageLock. Does our current approach make sense to you?
Regarding the sample code, do you have an email or any server which I could upload onto?
Thanks,
Krammer
Dear Chenghul,
If possible can you paste sample code here.
Hi Siva,
Thank you for your reply.
I’m afraid that I can share my code here.
Right now we already found the root cause of this issue. We didn’t initiate a NvMedia device before using the EGLStream. This was what caused the segmentation fault.
We still have a doubt about our approach. Right now from our measurement, the time it takes to do the NvMediaImageGetBits is around 80ms for a 1920x1208 resolution. This is considered too long for us. From the scenario I described before, do you have any suggestions or is there any other options we have?
Thanks,
Krammer
Hi Siva,
One update. After I changed the surface attributes of NVM_SURF_ATTR_CPU_ACCESS from NVM_SURF_ATTR_CPU_ASSESS_UNCACHED to NVM_SURF_CPU_ASSESS_CACHED, the time we spent in NvMediaImageGetBits reduced from 80ms to 16ms. Is there any side effect to make this kind of modification?
I can’t find many descriptions for this attribute, but I guess if we don’t use any hardware mechanism to modify our buffer, this is safe, right?
Best,
Krammer
Hi Siva,
Understood. Thank you for your help.
Krammer