VideoDecoder and DMA-BUF video frames

72 views
Skip to first unread message

Carlos Rafael Giani

unread,
May 26, 2021, 5:26:13 AM5/26/21
to media-dev
I've been looking at the new VideoDecoder base class which has been
recommended to me as an alternative to the VideoDecodeAccelerator.

So far, this seems very interesting, since the hardware decoder I am
writing this code for does not actually need access to any GPU
resources. Instead, it decodes packetized elementary streams (that is,
it is _not_ slice-based) and writes the decoded frames into DMA-BUF buffers.

Now, I see the OutputCB callback in VideoDecoder. And, VideoFrame has
the WrapExternalDmabufs() function. My question now is: How do I know
when I can reuse a DMA-BUF buffer? In the VDA, there's
ReusePictureBuffer(). The PictureBufferManager in the VDAVideoDecoder
uses sync tokens that tie into the GPU. Is it possible for me to know
when I can reuse a DMA-BUF buffer without these GPU based mechanisms? I
realize that I can dup() a DMA-BUF FD, but with this decoder, I still
have to let it know when it can use a buffer again. That's because the
hardware decoder's driver does not directly use dma-buf. Instead, it
uses physical addresses, and thus does not know anything about buffer
sharing. (There are ways on that platform to get the physical address
from a DMA-BUF buffer, and I know having such addresses is very
insecure, but there's no other way on that platform, unfortunately.) So,
I must let the hw decoder know when Chromium is done with that picture.

On a related note, this also means that the buffer must not be reused by
the hw decoder until the GPU itself is fully done with that picture.
When I integrated that hw decoder using a VDA, I added code to manually
use an EGL fence to not return the picture until the EGL sync object was
signaled. With DMA-BUF buffers, do I still have to do something like that?

cheers

Dale Curtis

unread,
May 26, 2021, 12:23:58 PM5/26/21
to Carlos Rafael Giani, Andres Calderon Jaramillo, Dan Sanders, media-dev
+Dan Sanders +Andres Calderon Jaramillo who may have some insight. You may also try looking through the VaapiVideoDecoder and V4L2VideoDecoder classes which utilize (or at least used to) DMA-BUF.

- dale

--
You received this message because you are subscribed to the Google Groups "media-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to media-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/media-dev/42b23c77-8aa0-fccc-efca-7619c6619de5%40gmail.com.

Dan Sanders

unread,
May 26, 2021, 1:25:46 PM5/26/21
to Dale Curtis, Carlos Rafael Giani, Andres Calderon Jaramillo, media-dev
How do I know
when I can reuse a DMA-BUF buffer?

If you set read_lock_fences_enabled, VideoFrame consumers are required to synchronize reads before dropping their VideoFrame reference. You'll see this approach used wherever SyncTokens are insufficient.

Carlos Rafael Giani

unread,
May 26, 2021, 1:32:57 PM5/26/21
to Dan Sanders, Dale Curtis, Andres Calderon Jaramillo, media-dev

And can I get a notification for when all consumers have dropped their VideoFrame references?

Dan Sanders

unread,
May 26, 2021, 1:40:39 PM5/26/21
to Carlos Rafael Giani, Dale Curtis, Andres Calderon Jaramillo, media-dev
If you have mailboxes then you should use the mailbox_holders_release_cb, otherwise use AddDestructionObserver().
Reply all
Reply to author
Forward
0 new messages