longo92
Posts: 44
Joined: Mon Sep 03, 2018 3:45 pm
Contact: Website Skype

passing the mmal opaque buffer header through IPC(named pipe)

Mon Mar 04, 2019 3:46 pm

Hi,
i have two programs A and Brunning in parallel:
-The program A takes frame from camera as opaque buffer (with encoding variant i420) and passes the mmal buffer header through a named pipe to program B.
-The program B takes such mmal buffer and uses it in an opengl ES 2.0 rendering (using the data field of mmal buffer as an EGL image, like in raspitex example).
The program works perfectly but OpenGL signals the error 0x505, which means "out of memory". If i re-write A and B in only one program (one executable) i don't have the error. The function that rises the error is glEGLimageTargetTexture2DOES.
As far as i know the data field in the mmal buffer header is some kind "understandable" by the GPU (being the buffer opaque, i suppose that is the pointer to GPU memory).
Maybe the GL context of B program sees that buf->data is a pointer out of its GPU memory space?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7008
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: passing the mmal opaque buffer header through IPC(named pipe)

Mon Mar 04, 2019 4:32 pm

Life gets a tad complicated, particularly with buffer lifetimes.

When exactly do you get the 0x505 "out of memory"? On every submission, or after some time?
The opaque buffer has a reference to a GPU resource (table entry, not a raw pointer), and IIRC that should be fine being passed between processes.

However the GPU resource is also tied to the buffer passed from the source component on the GPU to the ARM. When that pool is destroyed the underlying image is released. Even though you have copied the data or pointer from buffer->data it can no longer be interpreted.

A test case would be useful if you want it investigated.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

longo92
Posts: 44
Joined: Mon Sep 03, 2018 3:45 pm
Contact: Website Skype

Re: passing the mmal opaque buffer header through IPC(named pipe)

Tue Mar 05, 2019 8:33 am

When that pool is destroyed the underlying image is released. Even though you have copied the data or pointer from buffer->data it can no longer be interpreted.
Ok let's start from a general question: since i get the mmal buffer header from the callback associated to the video port of camera component (using a pool of buffer allocated on that port with mmal_port_pool_create), is this buffer (and the underlying image) automatically destroyed and recycled by the mmal core or does it exist until mmal_buffer_header_release is called?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7008
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: passing the mmal opaque buffer header through IPC(named pipe)

Tue Mar 05, 2019 9:50 am

The underlying buffer is released for reuse when the buffer header is returned to the output port.
It is also released when the buffer header is destroyed, otherwise should your application crash then the resources would never be released.

I would not recommended trying to use zero copy with opaque buffers. (a) the buffers are tiny anyway and get sent in-band with the control message, and (b) you then can't pass them between processes as vcsm does lock buffer handles to pids.

Sorry, I still can't help further as there are too many unknowns as to what you are doing.
You could add "start_debug=1" to /boot/config.txt so that "sudo vcdbg log assert" will report any asserts that occur on the VPU.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Graphics programming”