I want to use buffer streams with my ligargus application. However, I run into problem while creating the DMA buffers and EGLImages.
I use this code to create the buffers:
for (size_t i = 0; i < NUM_BUFFERS; i++)
{
NvBufferCreateParams params = {0};
params.width = width;
params.height = height;
params.layout = NvBufferLayout_Pitch;
params.colorFormat = NvBufferColorFormat_NV12;
params.payloadType = NvBufferPayload_SurfArray;
params.nvbuf_tag = NvBufferTag_CAMERA;
int ret = NvBufferCreateEx(&m_dmaBuffer[i], ¶ms);
if (ret)
{
ERR("Failed to allocate NativeBuffer '%d'", port);
return false;
}
m_image[i] = NvEGLImageFromFd(EGL_NO_DISPLAY, m_dmaBuffer[i]);
if (m_image[i] == EGL_NO_IMAGE_KHR)
{
ERR("Failed to allocate EGLImage '%d'", port);
return false;
}
}
which works fine if I use it in my main thread, but if I put the same code in a sub thread I get a Segmentation fault (core dumped) with the NvBufferCreateEx(&m_dmaBuffer[i], ¶ms); call.
Sometimes the buffer creation succeeds, but then I get a cannot set thread specific data error with the NvEGLImageFromFd(EGL_NO_DISPLAY, m_dmaBuffer[i]);call.
Do I have to perform some extra sync operation when creating nvbuffes in a thread?