Hello,
I’m using the multimedia API and am decoding video from a file. What I would like is to use multiple threads to do post processing on each frame, but I am having some issues on getting it to work. With the code below:
while (! m_decoder->isInError())
{
v4l2_buffer v4l2_buf = {};
v4l2_plane planes[MAX_PLANES] = { 0 };
v4l2_buf.m.planes = planes;
NvBuffer* decBuffer;
int ret;
{
std::lock_guard<std::mutex> lock(m_decodeMutex);
ret = m_decoder->capture_plane.dqBuffer(v4l2_buf, &decBuffer, nullptr, 0);
}
if (ret < 0)
{
if (errno == EAGAIN)
{
usleep(1000);
continue;
}
std::cerr << "Error while calling dequeue at capture plane\n";
return;
}
v4l2_buf.m.planes[0].m.fd = m_dmaBufferFds[v4l2_buf.index];
BufferInfo bufferInfo {};
bufferInfo.fileDescriptor = v4l2_buf.m.planes[0].m.fd;
bufferInfo.size = v4l2_buf.m.planes[0].bytesused;
std::thread([bufferInfo, this, v4l2_buf](v4l2_buffer&& v4l2_buf) mutable {
if (m_callback)
{
m_callback(bufferInfo);
}
std::lock_guard<std::mutex> lock(m_decodeMutex);
if (m_decoder->capture_plane.qBuffer(v4l2_buf, nullptr) < 0)
{
std::cerr << "Error while queueing buffer at decoder capture plane\n";
abort();
}
}, std::move(v4l2_buf)).detach();
}
It works fine if I don’t create a new thread and process everything sequentially. With the threads, I often get failures when queuing buffers
nvbuf_utils: dmabuf_fd 0 mapped entry NOT found
nvbuf_utils: Can not get HW buffer from FD... Exiting...
Am I going about this all wrong? Is there an example in the sample code? The closest I could see with in the backend code, but that is just processing multiple files on different threads, not a single file.
Any help appreciated.