After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 796918 - omxvideoenc: implement dmabuf export on encoder input buffers
omxvideoenc: implement dmabuf export on encoder input buffers
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-omx
git master
Other Linux
: Normal enhancement
: 1.15.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2018-08-03 11:21 UTC by Guillaume Desmottes
Modified: 2018-08-31 07:11 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
omx: factor out gst_omx_port_set_dmabuf() (4.84 KB, patch)
2018-08-03 11:22 UTC, Guillaume Desmottes
committed Details | Review
omx: add pBuffer to OMX_PERFORMANCE logs (1.59 KB, patch)
2018-08-03 11:22 UTC, Guillaume Desmottes
committed Details | Review
omxvideoenc: factor out gst_omx_video_enc_deallocate_in_buffers() (1.87 KB, patch)
2018-08-03 11:22 UTC, Guillaume Desmottes
committed Details | Review
omxvideoenc: factor out gst_omx_video_enc_set_to_idle() (3.32 KB, patch)
2018-08-03 11:22 UTC, Guillaume Desmottes
committed Details | Review
omx: factor out gst_omx_buffer_get/set_omx_buf() (5.06 KB, patch)
2018-08-03 11:22 UTC, Guillaume Desmottes
committed Details | Review
omxvideo{enc,dec}: stop calling shutdown() in change_state (1.87 KB, patch)
2018-08-03 11:22 UTC, Guillaume Desmottes
committed Details | Review
omx: call gst_omx_buffer_unmap() when handling BUFFER_DONE (2.46 KB, patch)
2018-08-03 11:22 UTC, Guillaume Desmottes
committed Details | Review
omxbufferpool: deallocate OMX buffers when stopping (3.59 KB, patch)
2018-08-03 11:22 UTC, Guillaume Desmottes
committed Details | Review
turn GstOMXComponent to a GstMiniObject (5.75 KB, patch)
2018-08-03 11:22 UTC, Guillaume Desmottes
committed Details | Review
omxbufferpool: reference the OMX component (1.37 KB, patch)
2018-08-03 11:23 UTC, Guillaume Desmottes
committed Details | Review
omxvideodec: prevent timeout when shutting down because of pending out buffers (1.61 KB, patch)
2018-08-03 11:23 UTC, Guillaume Desmottes
committed Details | Review
omxvideodec: fix pool caps reference stealing (950 bytes, patch)
2018-08-03 11:23 UTC, Guillaume Desmottes
committed Details | Review
omxvideodec: fix gst_video_info_from_caps() caps assertion (907 bytes, patch)
2018-08-03 11:23 UTC, Guillaume Desmottes
committed Details | Review
omxvideodec: factor out gst_omx_try_importing_buffer() (4.45 KB, patch)
2018-08-03 11:23 UTC, Guillaume Desmottes
none Details | Review
omxvideodec: don't import not dmabuf when dec is in dmabuf mode (997 bytes, patch)
2018-08-03 11:23 UTC, Guillaume Desmottes
needs-work Details | Review
omxvideoenc: implement dmabuf export on input buffers (19.51 KB, patch)
2018-08-03 11:23 UTC, Guillaume Desmottes
none Details | Review
omxbufferpool: check if pool->buffers still exist when stopping (1.96 KB, patch)
2018-08-03 11:23 UTC, Guillaume Desmottes
none Details | Review
omxvideodec: don't import OMX buffers from downstream (2.24 KB, patch)
2018-08-03 11:23 UTC, Guillaume Desmottes
none Details | Review
omxvideodec: factor out gst_omx_try_importing_buffer() (4.44 KB, patch)
2018-08-07 09:48 UTC, Guillaume Desmottes
committed Details | Review
omxvideodec: don't import OMX buffers from downstream (2.26 KB, patch)
2018-08-07 09:49 UTC, Guillaume Desmottes
none Details | Review
omx: allow gst_omx_port_acquire_buffer() to not wait for buffers (10.15 KB, patch)
2018-08-16 08:31 UTC, Guillaume Desmottes
committed Details | Review
omxvideoenc: implement dmabuf export on input buffers (22.66 KB, patch)
2018-08-16 08:31 UTC, Guillaume Desmottes
committed Details | Review
omxvideodec: don't import OMX buffers from downstream (2.26 KB, patch)
2018-08-16 08:31 UTC, Guillaume Desmottes
committed Details | Review

Description Guillaume Desmottes 2018-08-03 11:21:52 UTC
The following patches adds support for exporting buffers dmabuf input buffers to upstream enabling use to do things like 'v4l2src io-mode=dmabuf-import ! omxh264enc'.

This feature has only be tested on the zynq but should be easily re-usable on other platforms as well.

While doing so I also improved the buffers life cycle management and fixed various related issues.

I did some testing on the pi and didn't spot any regression.
Comment 1 Guillaume Desmottes 2018-08-03 11:22:20 UTC
Created attachment 373254 [details] [review]
omx: factor out gst_omx_port_set_dmabuf()

No semantic change. I also made the debug message a bit clearer.
Comment 2 Guillaume Desmottes 2018-08-03 11:22:23 UTC
Created attachment 373255 [details] [review]
omx: add pBuffer to OMX_PERFORMANCE logs

Can be useful to check the fd being passed when using dmabuf.
Comment 3 Guillaume Desmottes 2018-08-03 11:22:27 UTC
Created attachment 373256 [details] [review]
omxvideoenc: factor out gst_omx_video_enc_deallocate_in_buffers()

Will add extra code when adding input buffer pool.
Comment 4 Guillaume Desmottes 2018-08-03 11:22:31 UTC
Created attachment 373257 [details] [review]
omxvideoenc: factor out gst_omx_video_enc_set_to_idle()

No semantic change. We'll have to use this when the input pool is
activated so we can allocate buffers.
Comment 5 Guillaume Desmottes 2018-08-03 11:22:37 UTC
Created attachment 373258 [details] [review]
omx: factor out gst_omx_buffer_get/set_omx_buf()

Move the qdata code to helper functions as I'm going to need them in
omxvideoenc to implement dmabuf export.
Comment 6 Guillaume Desmottes 2018-08-03 11:22:41 UTC
Created attachment 373259 [details] [review]
omxvideo{enc,dec}: stop calling shutdown() in change_state

This is no longer needed since we implemented close() vfuncs as the
encoder/decoder base class already take care of calling close() (which
is calling shutdown()) in its own change_state implementation.

We also move the shut down of the component from PAUSED_TO_READY to READY_TO_NULL.
By doing so upstream will have already deactivated the pool from the
encoder and so won't be preventing the OMX state change as the buffers
will all be released.
Comment 7 Guillaume Desmottes 2018-08-03 11:22:45 UTC
Created attachment 373260 [details] [review]
omx: call gst_omx_buffer_unmap() when handling BUFFER_DONE

When using a input buffer pool, the buffer may be released to the pool when
gst_omx_buffer_unmap() is called. We need to have buf->used unset at
this point as the pool may use it to check the status of the pool.

{Empty,Fill}BufferDone is called from OMX internal threads while
messages are handled from gst elements' thread. Best to do all this
when handling the message so we don't mess with OMX threads and keep
the original thread/logic split.
Comment 8 Guillaume Desmottes 2018-08-03 11:22:50 UTC
Created attachment 373261 [details] [review]
omxbufferpool: deallocate OMX buffers when stopping

The pool is stopped when all the buffers have been released. Deallocate
when stopping so we are sure that the buffers aren't still used by
another element.
Comment 9 Guillaume Desmottes 2018-08-03 11:22:55 UTC
Created attachment 373262 [details] [review]
turn GstOMXComponent to a GstMiniObject

Will use it for refcounting.
Comment 10 Guillaume Desmottes 2018-08-03 11:23:00 UTC
Created attachment 373263 [details] [review]
omxbufferpool: reference the OMX component

Now that the pool is responsible of freeing the OMX buffers, we need to
ensure that the OMX component stay alive while the pool is as we rely on
the component to free the buffers.
The GstOMXPort is owned by the component so no need to ref this one.
Comment 11 Guillaume Desmottes 2018-08-03 11:23:04 UTC
Created attachment 373264 [details] [review]
omxvideodec: prevent timeout when shutting down because of pending out buffers

The OMX transition state to Loaded won't be complete until all buffers
have been freed. There is no point waiting, and timeout, if we know that
output buffers haven't been freed yet.

The typical scenario is output buffers being still used downstream
and being freed later when released back to the pool.
Comment 12 Guillaume Desmottes 2018-08-03 11:23:08 UTC
Created attachment 373265 [details] [review]
omxvideodec: fix pool caps reference stealing

gst_buffer_pool_config_get_params() doesn't ref the returning caps;
so gst_caps_replace() was unreffing the reference owned by the pool.
Comment 13 Guillaume Desmottes 2018-08-03 11:23:12 UTC
Created attachment 373266 [details] [review]
omxvideodec: fix gst_video_info_from_caps() caps assertion

The "use buffers" code path uses gst_video_info_from_caps() which is
asserting if caps is NULL (because pool was rejected).
Comment 14 Guillaume Desmottes 2018-08-03 11:23:18 UTC
Created attachment 373267 [details] [review]
omxvideodec: factor out gst_omx_try_importing_buffer()

No semantic change, just make the code clearer and improve debug output.
Comment 15 Guillaume Desmottes 2018-08-03 11:23:22 UTC
Created attachment 373268 [details] [review]
omxvideodec: don't import not dmabuf when dec is in dmabuf mode

Fix 'omxh264 ! videocrop' pipeline.
Comment 16 Guillaume Desmottes 2018-08-03 11:23:26 UTC
Created attachment 373269 [details] [review]
omxvideoenc: implement dmabuf export on input buffers

Propose pool upstream so input buffers can be allocated by the port and
exported as dmabuf.

The actual OMX buffers are allocated when the pool is activated, so we
don't end up doing useless allocations if the pool isn't used.
Comment 17 Guillaume Desmottes 2018-08-03 11:23:30 UTC
Created attachment 373270 [details] [review]
omxbufferpool: check if pool->buffers still exist when stopping

The pool can be deactivated as part of its finalizing process, in much
case pool->buffers may no longer exist.
Comment 18 Guillaume Desmottes 2018-08-03 11:23:35 UTC
Created attachment 373271 [details] [review]
omxvideodec: don't import OMX buffers from downstream

We already have code configuring the encoder stride and slice height
when receiving the first buffer from upstream.
We don't have an equivalent when the encoder is exporting its buffers to the
decoder.

There is no point adding it and making the code even more
complex as we wouldn't gain anything by exporting from the encoder to
the decoder. The dynamic buffer mode already ensures 0-copy between OMX
components.
Comment 19 Guillaume Desmottes 2018-08-07 09:48:56 UTC
Created attachment 373279 [details] [review]
omxvideodec: factor out gst_omx_try_importing_buffer()

No semantic change, just make the code clearer and improve debug output.
Comment 20 Guillaume Desmottes 2018-08-07 09:49:22 UTC
Created attachment 373280 [details] [review]
omxvideodec: don't import OMX buffers from downstream

We already have code configuring the encoder stride and slice height
when receiving the first buffer from upstream.
We don't have an equivalent when the encoder is exporting its buffers to the
decoder.

There is no point adding it and making the code even more
complex as we wouldn't gain anything by exporting from the encoder to
the decoder. The dynamic buffer mode already ensures 0-copy between OMX
components.
Comment 21 Guillaume Desmottes 2018-08-07 09:51:24 UTC
Branch also available here: https://gitlab.collabora.com/cassidy/gst-omx/commits/dma-export
Comment 22 Guillaume Desmottes 2018-08-16 08:31:02 UTC
Created attachment 373350 [details] [review]
omx: allow gst_omx_port_acquire_buffer() to not wait for buffers

Will be needed to implement GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT.

Upstream-Status: Pending
Signed-off-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Comment 23 Guillaume Desmottes 2018-08-16 08:31:09 UTC
Created attachment 373351 [details] [review]
omxvideoenc: implement dmabuf export on input buffers

Propose pool upstream so input buffers can be allocated by the port and
exported as dmabuf.

The actual OMX buffers are allocated when the pool is activated, so we
don't end up doing useless allocations if the pool isn't used.
Comment 24 Guillaume Desmottes 2018-08-16 08:31:15 UTC
Created attachment 373352 [details] [review]
omxvideodec: don't import OMX buffers from downstream

We already have code configuring the encoder stride and slice height
when receiving the first buffer from upstream.
We don't have an equivalent when the encoder is exporting its buffers to the
decoder.

There is no point adding it and making the code even more
complex as we wouldn't gain anything by exporting from the encoder to
the decoder. The dynamic buffer mode already ensures 0-copy between OMX
components.
Comment 25 Nicolas Dufresne (ndufresne) 2018-08-27 19:47:37 UTC
Review of attachment 373254 [details] [review]:

Lgtm
Comment 26 Nicolas Dufresne (ndufresne) 2018-08-27 19:48:06 UTC
Review of attachment 373255 [details] [review]:

Lgtm
Comment 27 Nicolas Dufresne (ndufresne) 2018-08-27 19:48:46 UTC
Review of attachment 373256 [details] [review]:

Lgtm
Comment 28 Nicolas Dufresne (ndufresne) 2018-08-27 19:49:18 UTC
Review of attachment 373257 [details] [review]:

Lgtm
Comment 29 Nicolas Dufresne (ndufresne) 2018-08-27 19:50:27 UTC
Review of attachment 373258 [details] [review]:

Lgtm.
Comment 30 Nicolas Dufresne (ndufresne) 2018-08-27 19:51:00 UTC
Review of attachment 373259 [details] [review]:

Lgtm
Comment 31 Nicolas Dufresne (ndufresne) 2018-08-27 19:51:59 UTC
Review of attachment 373260 [details] [review]:

Lgtm.
Comment 32 Nicolas Dufresne (ndufresne) 2018-08-27 19:53:03 UTC
Review of attachment 373261 [details] [review]:

An intermediate, as I remember there is some state check added later. Lgtm.
Comment 33 Nicolas Dufresne (ndufresne) 2018-08-27 19:53:39 UTC
Review of attachment 373262 [details] [review]:

Lgtm.
Comment 34 Nicolas Dufresne (ndufresne) 2018-08-27 19:53:51 UTC
Review of attachment 373262 [details] [review]:

.
Comment 35 Nicolas Dufresne (ndufresne) 2018-08-27 19:54:10 UTC
Review of attachment 373263 [details] [review]:

Lgtm.
Comment 36 Nicolas Dufresne (ndufresne) 2018-08-27 19:54:53 UTC
Review of attachment 373264 [details] [review]:

Lgtm.
Comment 37 Nicolas Dufresne (ndufresne) 2018-08-27 19:55:22 UTC
Review of attachment 373265 [details] [review]:

Lgtm.
Comment 38 Nicolas Dufresne (ndufresne) 2018-08-27 19:55:54 UTC
Review of attachment 373266 [details] [review]:

Make sense.
Comment 39 Nicolas Dufresne (ndufresne) 2018-08-27 19:56:50 UTC
Review of attachment 373268 [details] [review]:

Just need to fix the commit here, "don't export non-dmabuf" ?
Comment 40 Nicolas Dufresne (ndufresne) 2018-08-27 19:58:05 UTC
Review of attachment 373279 [details] [review]:

Wow, I can read this code now !
Comment 41 Nicolas Dufresne (ndufresne) 2018-08-27 19:59:58 UTC
Review of attachment 373350 [details] [review]:

Please drop the Upstream-Status: and Signed-off-by:. It's fascinating when moving from one patch to the other to see how identical some of the baseclass code can be.
Comment 42 Nicolas Dufresne (ndufresne) 2018-08-27 20:04:02 UTC
Review of attachment 373351 [details] [review]:

This one I'll go through again tomorrowm but didn't found or think of anything wrong atm.
Comment 43 Nicolas Dufresne (ndufresne) 2018-08-27 20:05:39 UTC
Review of attachment 373352 [details] [review]:

Lgtm.
Comment 44 Guillaume Desmottes 2018-08-28 07:48:15 UTC
Review of attachment 373268 [details] [review]:

No, that's the code trying to use a pool from downstream in the decoder; so it's an importation here.

I did edit the commit message to: " Fix 'omxh264dec ! videocrop' pipeline."
Comment 45 Guillaume Desmottes 2018-08-28 07:49:36 UTC
Review of attachment 373350 [details] [review]:

done.

Yeah, loads of copy/paste between classes. :(
Comment 46 Nicolas Dufresne (ndufresne) 2018-08-28 13:05:04 UTC
Review of attachment 373268 [details] [review]:

Sorry, export was a typo of mine, I wanted not to be changed in non-, or just add the missing verb that allow using not.
Comment 47 Guillaume Desmottes 2018-08-28 13:14:39 UTC
Review of attachment 373268 [details] [review]:

Ah ok! I changed it to:

commit b1d4418eee8d8e0637d5f6847df08fcaf516ee0e
Author: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Date:   Tue Jul 31 15:04:33 2018 +0200

    omxvideodec: don't import non-dmabuf when dec is in dmabuf mode
    
    Fix 'omxh264dec ! videocrop' pipeline.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=796918
Comment 48 Guillaume Desmottes 2018-08-30 09:00:29 UTC
Attachment 373254 [details] pushed as f0964df - omx: factor out gst_omx_port_set_dmabuf()
Attachment 373255 [details] pushed as 998bfbb - omx: add pBuffer to OMX_PERFORMANCE logs
Attachment 373256 [details] pushed as 7d3b0cd - omxvideoenc: factor out gst_omx_video_enc_deallocate_in_buffers()
Attachment 373257 [details] pushed as 092788a - omxvideoenc: factor out gst_omx_video_enc_set_to_idle()
Attachment 373258 [details] pushed as 457e1b9 - omx: factor out gst_omx_buffer_get/set_omx_buf()
Attachment 373259 [details] pushed as 3b92b22 - omxvideo{enc,dec}: stop calling shutdown() in change_state
Attachment 373260 [details] pushed as d2f7e21 - omx: call gst_omx_buffer_unmap() when handling BUFFER_DONE
Attachment 373261 [details] pushed as 7b6be34 - omxbufferpool: deallocate OMX buffers when stopping
Attachment 373262 [details] pushed as 8efa095 - turn GstOMXComponent to a GstMiniObject
Attachment 373263 [details] pushed as 86a6703 - omxbufferpool: reference the OMX component
Attachment 373264 [details] pushed as 0996019 - omxvideodec: prevent timeout when shutting down because of pending out buffers
Attachment 373265 [details] pushed as 9ed1c2e - omxvideodec: fix pool caps reference stealing
Attachment 373266 [details] pushed as 7d8a314 - omxvideodec: fix gst_video_info_from_caps() caps assertion
Attachment 373279 [details] pushed as be5ec66 - omxvideodec: factor out gst_omx_try_importing_buffer()
Attachment 373350 [details] pushed as 34bc02e - omx: allow gst_omx_port_acquire_buffer() to not wait for buffers
Attachment 373351 [details] pushed as 7be54ad - omxvideoenc: implement dmabuf export on input buffers
Attachment 373352 [details] pushed as f108eea - omxvideodec: don't import OMX buffers from downstream
Comment 49 Julien Isorce 2018-08-30 18:31:13 UTC
Hi Guillaume, nice work! Just to confirm, this only works for Zynq right ? Mostly because of the specific flags/struct described here https://bugzilla.gnome.org/show_bug.cgi?id=726325#c48 . Adding generic/similar flags in Tizonia would allow to use 99% of these patches right ? (not accounting the work to make it work on the component side, i.e in mesa/omx)
Comment 50 Guillaume Desmottes 2018-08-31 07:11:09 UTC
Yes, I only enabled it only on the Zynq.
Indeed, I think the only extension API used here is the same one as when producing dmabuf. Implement it and you should be able to re-use export and import modes.