Commit graph

199 commits

Author SHA1 Message Date
Guillaume Desmottes d2f7e21ab9 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.

https://bugzilla.gnome.org/show_bug.cgi?id=796918
2018-08-30 10:59:30 +02:00
Guillaume Desmottes 457e1b9a5e 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.

https://bugzilla.gnome.org/show_bug.cgi?id=796918
2018-08-30 10:59:30 +02:00
Guillaume Desmottes 998bfbb906 omx: add pBuffer to OMX_PERFORMANCE logs
Can be useful to check the fd being passed when using dmabuf.

https://bugzilla.gnome.org/show_bug.cgi?id=796918
2018-08-30 10:59:30 +02:00
Guillaume Desmottes f0964dfbdb omx: factor out gst_omx_port_set_dmabuf()
No semantic change. I also made the debug message a bit clearer.

https://bugzilla.gnome.org/show_bug.cgi?id=796918
2018-08-30 10:59:30 +02:00
Guillaume Desmottes 40ae47df5e omx: wait for flush complete and buffers being released when flushing
When flusing we should wait for OMX to send the flush command complete event
AND all ports being released.
We were stopping as soon as one of those condition was met.

Fix a race between FillThisBufferDone/EmptyBufferDone and the flush
EventCmdComplete messages. The OMX implementation is supposed to release
its buffers before posting the EventCmdComplete event but the ordering
isn't guaranteed as the FillThisBufferDone/EmptyBufferDone and
EventHandler callbacks can be called from different threads (cf 2.7
'Thread Safety' in the spec).

Only wait for buffers currently used by OMX as some buffers may not be
in the pending queue because they are held downstream.

https://bugzilla.gnome.org/show_bug.cgi?id=789475
2018-08-29 12:18:39 -04:00
Guillaume Desmottes 3d55051da3 omx: factor out should_wait_until_flushed()
No semantic change. Makes the code easier to understand and I'm about to
change the waiting condition.

https://bugzilla.gnome.org/show_bug.cgi?id=789475
2018-08-29 12:18:39 -04:00
Guillaume Desmottes c8969b0dbe omxvideoenc: implement decide_allocation
Increase the number of output buffers by the number of buffers requested
downstream.
Prevent buffers starvation if downstream is going to use dynamic buffer
mode on its input.

https://bugzilla.gnome.org/show_bug.cgi?id=795746
2018-06-08 09:53:01 +02:00
Guillaume Desmottes 9a8e863862 omxvideodec/enc: add hack updating nBufferCountActual before allocating
The OMX specs states that the nBufferCountActual of a port has to default
to its nBufferCountMin. If we don't change nBufferCountActual we purely rely
on this default. But in some cases, OMX may change nBufferCountMin before we
allocate buffers. Like for example when configuring the input ports with the
actual format, it may decrease the number of minimal buffers required.
This method checks this and update nBufferCountActual if needed so we'll use
less buffers than the worst case in such scenarios.

SetParameter() needs to be called when the port is either disabled or
the component in the Loaded state.

Don't do this for the decoder output as
gst_omx_video_dec_allocate_output_buffers() already check
nBufferCountMin when computing the number of output buffers.

On some platform, like rpi, the default nBufferCountActual is much
higher than nBufferCountMin so only enable this using a specific gst-omx
hack.

https://bugzilla.gnome.org/show_bug.cgi?id=791211
2018-06-08 09:44:49 +02:00
Guillaume Desmottes 3498f81d1f omx: always consider component in 'invalid' state when an error occured
gst_omx_component_get_state() used to early return if there was no
pending state change. So if the component raised an error it wasn't
considered in the invalid state until the next requested state change.

Fix this by checking first if we received an error.

https://bugzilla.gnome.org/show_bug.cgi?id=795874
2018-06-08 09:36:56 +02:00
Guillaume Desmottes 021b66878a log_omx_performance: convert pointers to strings
G_TYPE_POINTER are not serialized in logs.

https://bugzilla.gnome.org/show_bug.cgi?id=794331
2018-04-06 13:39:42 +02:00
Nicolas Dufresne 32660fd294 omx: Free empty buffers list in use_dynamic_buffers
To indicate we are doing dynamic buffers importation, we pass
a list of NULL pointers, but we forgot to free that list.
2018-03-05 13:50:08 -05:00
Nicolas Dufresne 5eed1a7eb2 Revert "omx: wait for flush complete and buffers being released when flushing"
This reverts commit 4211e4c29a.
2018-03-02 11:06:08 -05:00
Guillaume Desmottes 2ca3cf5cfa omxvideodec: add hack to pass color format from caps to OMX decoder
This hack tries to pass as much information as possible from caps to the
decoder before it receives any buffer. These information can be used by
the OMX decoder to, for example, pre-allocate its internal buffers
before starting to decode and so reduce its initial latency.

This mechanism is currently supported by the zynqultrascaleplus decoder.

https://bugzilla.gnome.org/show_bug.cgi?id=792040
2018-01-30 09:23:59 +00:00
Guillaume Desmottes 0f702d0503 log failing OMX calls as errors
I find it confusing when debugging that OMX calls returning an error
where not logged as GST_LEVEL_ERROR making them harder to spot.
Fix this by introducing simple log macros checking the return value of
the OMX call and logging failures as errors.

https://bugzilla.gnome.org/show_bug.cgi?id=791069
2018-01-29 17:47:56 +00:00
Guillaume Desmottes 65cc312aa8 add OMX_PERFORMANCE debug category
Can be used to log buffers exchange between OMX and gst-omx to profile
performances of the OMX component.
Ideally this should be done using tracer hooks but it's currently not
possible to define custom hooks outside of core.

Use GST_DEBUG="OMX_PERFORMANCE:8" to enable it.
See also
https://github.com/gdesmott/gst-log-parser/blob/master/src/bin/omx-perf.rs
as a simple program consuming those logs to generate gnuplot files and
stats.

https://bugzilla.gnome.org/show_bug.cgi?id=791093
2018-01-29 17:16:35 +00:00
Guillaume Desmottes 9f87b987ef omxvideoenc: implement dmabuf import on zynqultrascaleplus
The Zynq UltraScale+ encoder implements a custom OMX extension to
directly import dmabuf saving the need of mapping input buffers.

This can be use with either 'v4l2src io-mode=dmabuf' or an OMX video
decoder upstream.

https://bugzilla.gnome.org/show_bug.cgi?id=792361
2018-01-29 15:21:02 +00:00
Guillaume Desmottes da07a647b8 omx: add API to implement dynamic buffers support
OMX 1.2.0 introduced a third way to manage buffers by allowing
components to only allocate buffers header during their initialization
and change their pBuffer pointer at runtime.
This new feature can save us a copy between GStreamer and OMX for each
input buffer.

This patch adds API to allocate and use such buffers.

https://bugzilla.gnome.org/show_bug.cgi?id=787093
2017-12-14 09:00:02 +00:00
Guillaume Desmottes 4211e4c29a omx: wait for flush complete and buffers being released when flushing
As stated in the existing comment, when flusing we should wait for OMX
to send the flush command complete event AND all ports being released.
We were stopping as soon as one of those condition was met.

Fix a race between FillThisBufferDone/EmptyBufferDone and the flush
EventCmdComplete messages. The OMX implementation is supposed to release
its buffers before posting the EventCmdComplete event but the ordering
isn't guaranteed as the FillThisBufferDone/EmptyBufferDone and
EventHandler callbacks can be called from different threads (cf 2.7
'Thread Safety' in the spec).

https://bugzilla.gnome.org/show_bug.cgi?id=789475
2017-11-28 13:35:07 -05:00
Guillaume Desmottes 4c0a8a6d90 gst_omx_port_set_flushing: simplify waiting loop
No semantic change so far, I just made the 'while' end condition easier
to understand as a first step before changing it.
- move error/time out checks inside the loop to make it clearer on what
we are actually waiting for.
- group port->buffers checks together with parenthesis as they are part
of the same conceptual check: waiting for all buffers to be released.

https://bugzilla.gnome.org/show_bug.cgi?id=789475
2017-11-28 13:35:07 -05:00
Guillaume Desmottes 6d44c0add5 omx: fix build on rpi
The nTimeStamp field is a OMX_TICKS struct on the rpi so use the proper
macro to set it.
Fix build on the build which has been broken by
b3173144b7

https://bugzilla.gnome.org/show_bug.cgi?id=789052
2017-10-19 16:23:01 +02:00
Guillaume Desmottes b3173144b7 omx: also reset nTimeStamp when re-using buffers
Some OMX implementations may check if the timestamp of the output buffers
they receive is actually not set.

https://bugzilla.gnome.org/show_bug.cgi?id=788711
2017-10-11 13:51:55 -04:00
Guillaume Desmottes 514699594d omx: factor out gst_omx_buffer_reset()
https://bugzilla.gnome.org/show_bug.cgi?id=788711
2017-10-11 13:51:55 -04:00
Guillaume Desmottes 3a0e4bc35d add gst_omx_buffer_flags_to_string()
Make debug logs more readable so users don't have to manually figure out
the meaning of flags.

https://bugzilla.gnome.org/show_bug.cgi?id=788767
2017-10-11 13:49:30 -04:00
Guillaume Desmottes 5751001ddc omxh265dec: add H265 decoder
Add HEVC decoder for the zynqultrascaleplus platform.

I used the H264 decoder code as a template.

https://bugzilla.gnome.org/show_bug.cgi?id=785434
2017-09-06 14:50:18 -04:00
Guillaume Desmottes cf9f1903db omxh265enc: add H265 encoder
The OMX spec doesn't support HEVC but the OMX stack of the
zynqultrascaleplus adds it as a custom extension.
It uses the same API as the one of Android's OMX stack.

I used the H264 encoder code as a template.

https://bugzilla.gnome.org/show_bug.cgi?id=785434
2017-09-06 14:50:18 -04:00
Guillaume Desmottes 318ef5b357 omx: display states as string if changing failed
Improve the error message by displaying the states in their string
representation rather than their numerical value.

https://bugzilla.gnome.org/show_bug.cgi?id=787235
2017-09-04 08:46:07 +01:00
Guillaume Desmottes 7a0949b750 omx: also reset nFilledLen before calling OMX_FillThisBuffer()
The spec states that the buffer passed to OMX_FillThisBuffer() needs to be
empty. Some implementation may check it actually is by checking its
nFilledLen field, so best to reset it as well.

https://bugzilla.gnome.org/show_bug.cgi?id=785623
2017-08-01 11:26:11 -04:00
Satya Prakash Gupta 5e6c3f170f omx: Possible Memory leak in gst_caps_from_string
https://bugzilla.gnome.org/show_bug.cgi?id=784978
2017-07-17 16:46:29 +03:00
Julien Isorce e60ac7e1c0 omx: do not always print an error if OMX_{UseBuffer,EGLImage} fails
Let the caller decide to print an error. Because it can be part of
a normal trial path.

https://bugzilla.gnome.org/show_bug.cgi?id=784069
2017-07-12 16:26:36 +01:00
Julien Isorce 02d493e859 omx: add gstomxmp3enc
Initial support and only tested with the software based
encoder OMX.Aratelia.audio_encoder.mp3 from Tizonia which
internally uses libmp3lame.

https://bugzilla.gnome.org/show_bug.cgi?id=782988
2017-07-12 14:29:44 +01:00
Guillaume Desmottes 0aa4c9db4e h264dec: add hack to pass profile and level to OMX
This information can be useful to zynqultrascaleplus decoders. They may
use this information to reduce startup latency by configuring itself
before receiving the first frames.

We also have a custom OMX extension allowing the decoder to report the
latency. The profile/level information helps it reporting a more
accurate latency earlier.

https://bugzilla.gnome.org/show_bug.cgi?id=783114
2017-07-11 11:57:50 -04:00
Gurkirpal Singh 065878a5d4 omx: always ignore OMX_ErrorPortUnpopulated
It is safe to ignore it always. Tizonia notifies this error to pass
some khronos conformance tests. Problem is that gst-omx saves this
error in comp->last_error and then gst_omx_port_set_enabled early
error out which fails the pipeline.

https://bugzilla.gnome.org/show_bug.cgi?id=782800
2017-07-05 17:27:27 -04:00
Gurkirpal Singh fc1a8229b0 omx: guard some omx enums with IL version
Some enums that existed in 1.1.2 just do not exit in 1.2.0
See https://www.khronos.org/registry/OpenMAX-IL/specs/OpenMAX_IL_1_2_0_Specification_redline.pdf

https://bugzilla.gnome.org/show_bug.cgi?id=782800
2017-07-05 17:27:27 -04:00
Julien Isorce 1c8f069e42 omx: allow 0 feature
Previously the omx plugin was blacklisted if GST_OMX_CONFIG_DIR
points to an invalid path or if the gstomx.conf contains 0 valid
component.
Problem is that once the plugin is blacklisted, a rescan is not
triggered upon changes of the env var or the gstomx.conf file
despite being setup with gst_plugin_add_dependency.

This also makes it more consistent with other plugins that auto
generate features. For example gst-{ffmeg,libav}, gstreamer-vaapi,
v4l2 video dec.

To clarify the diff, the plugin_init func will return TRUE even if
g_key_file_get_groups returns 0 element and even if
g_key_file_load_from_dirs fails.

https://bugzilla.gnome.org/show_bug.cgi?id=782867
2017-05-21 15:40:11 +01:00
Jan Schmidt 413f05269c omxvideoenc: Add GST_OMX_HACK_HEIGHT_MULTIPLE_16 for Rpi
The Raspberry Pi encoder produces corrupt output unless
the input height is a multiple of 16. Add a hack that adds
zero padding when needed.
2017-03-14 03:00:49 +11:00
Reynaldo H. Verdejo Pinochet 7925355d72 Fix broken build due to syntax error
Problem was introduced by 8716c23e2b
2016-12-14 13:32:16 -08:00
Graham Leggett 8716c23e2b Prevent early EOS by resetting eos flag once GST_OMX_ACQUIRE_BUFFER_EOS is triggered
https://bugzilla.gnome.org/show_bug.cgi?id=774600
2016-12-13 11:38:38 +02:00
Graham Leggett 5d5fbcd8f6 Add clear debug logging on all the paths out of gst_omx_port_acquire_buffer()
https://bugzilla.gnome.org/show_bug.cgi?id=774600
2016-12-13 11:38:36 +02:00
George Kiagiadakis 05b137a256 Add a signals-premature-eos hack for egl_render
egl_render seems to have a bug and signals EOS before it has finished
pushing out all data; this hack simply makes acquire_buffer() wait
a bit more before signalling EOS, in case egl_render decides to spit
out some more data.

https://bugzilla.gnome.org/show_bug.cgi?id=741856
2016-12-13 11:38:26 +02:00
Sebastian Dröge 53d8d353f0 omx: Fix compiler warning with latest clang
gstomx.c:1376:42: error: implicit conversion from enumeration type 'GstOMXAcquireBufferReturn' to different enumeration type 'OMX_ERRORTYPE'
      (aka 'enum OMX_ERRORTYPE') [-Werror,-Wenum-conversion]
  g_return_val_if_fail (!port->tunneled, GST_OMX_ACQUIRE_BUFFER_ERROR);
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

https://bugzilla.gnome.org/show_bug.cgi?id=775112
2016-11-26 00:07:13 +02:00
Sebastian Dröge cb9078627c omx: Also search for gstomx.conf in the autoconf --sysconfdir
https://bugzilla.gnome.org/show_bug.cgi?id=770743
2016-09-14 11:28:36 +02:00
Enrique Ocaña González 271093d633 Remember the last_error after a failed set state call to avoid blocking the next get state call
gst_omx_video_dec_flush() blocks forever in
http://cgit.freedesktop.org/gstreamer/gst-omx/tree/omx/gstomxvideodec.c?id=9adf0ff82903cad5331e40975ae91ed5d11bc102#n2110
when the previous call to gst_omx_component_set_state() fails in
http://cgit.freedesktop.org/gstreamer/gst-omx/tree/omx/gstomx.c?id=9adf0ff82903cad5331e40975ae91ed5d11bc102#n827.
To mitigate that, I set "last_error" to true, so the code in
http://cgit.freedesktop.org/gstreamer/gst-omx/tree/omx/gstomx.c?id=9adf0ff82903cad5331e40975ae91ed5d11bc102#n862
exits early and doesn't block.

https://bugzilla.gnome.org/show_bug.cgi?id=758274
2015-11-18 15:18:02 +02:00
Nicolas Huet 9adf0ff829 omx: fix hacks leak on class init 2015-11-18 12:02:44 +00:00
Luis de Bethencourt 70c48cf85f omx: handle both errors in the two steps of update_port_definition
Also consider potential errors in the _get_parameter() in the return of the
update_port_definition function.

CID #1287052
2015-03-06 12:06:22 +00:00
George Kiagiadakis 0ef1e90b34 omx: call handle_messages() only once in acquire_buffer() to avoid potential deadlock
There is one rare case where calling handle_messages() more than once can cause a deadlock
in the video decoder element:

- sink pad thread starts the src pad task (gst_omx_video_dec_loop())
- _video_dec_loop() calls gst_omx_port_acquire_buffer() on dec_out_port
- blocks in gst_omx_component_wait_message() releasing comp->lock and comp->messages_lock
  (initially, there are no buffers configured on that port, so it waits for OMX_EventPortSettingsChanged)
- the sink pad thread pushes a buffer to the decoder with gst_omx_port_release_buffer()
- _release_buffer() grabs comp->lock and sends the buffer to OMX, which consumes it immediately
- EmptyBufferDone gets called at this point, which signals _wait_message() to unblock
- the message from EmptyBufferDone is processed in gst_omx_component_handle_messages()
  called from gst_omx_port_release_buffer()
- gst_omx_port_release_buffer releases comp->lock
- the src pad thread now gets to run, grabbing comp->lock while it exits from _wait_message()
- _acquire_buffer() calls the _handle_messages() on the next line after _wait_message(),
  which does nothing (no pending messages)
- then it goes to "retry:" and calls _handle_messages() again, which also does nothing
  (still no pending messages)
- scheduler switches to a videocore thread that calls EventHandler, informing us about the
  OMX_EventPortSettingsChanged event that just arrived
- EventHandler graps comp->messages_lock, but not comp->lock, so it can run in parallel at
  this point just fine.
- scheduler switches back to the src pad thread (which is in the middle of _acquire_buffer())
- the next _handle_messages() which is right before if (g_queue_is_empty (&port->pending_buffers))
  processes the OMX_EventPortSettingsChanged
- the buffer queue is still empty, so that thread blocks again in _wait_message()
- the sink pad thread tries to acquire the next input port buffer
- _acquire_buffer() also blocks this thread in:
   if (comp->pending_reconfigure_outports) { ... _wait_message() ... }
- DEADLOCK. gstreamer is waiting for omx to do something, omx waits for gstreamer to do something.

By removing those extra _handle_messages() calls, we can ensure that all the checks of
_acquire_buffer() will re-run. In the above case, after the scheduler switches back to
the middle of _acquire_buffer(), the code will enter _wait_message(), which will see that
there are pending messages and will return immediately, going back to "retry:" and
re-doing all the checks properly.

https://bugzilla.gnome.org/show_bug.cgi?id=741854
2015-03-04 09:51:03 +01:00
Wonchul Lee df58d8baac omx: cleanup code a bit to remove else statement
https://bugzilla.gnome.org/show_bug.cgi?id=745191
2015-02-26 11:15:37 +02:00
Jun Ji 8936f6634c omx: Add omxamrdec
https://bugzilla.gnome.org/show_bug.cgi?id=739333
2014-11-13 13:32:16 +01:00
Sebastian Dröge 03cf0bc9a4 omx: Add AAC audio decoder 2014-07-13 18:22:39 +02:00
Sebastian Dröge 0c3b3ef3d0 omx: Add audio decoder base class and a subclass for MP3 2014-07-02 09:21:00 +02:00
Kazunori Kobayashi 4c488d425d omx: Fix a missing g_free() in error path
This fixes a memory leak with g_strdup() when an error occurs.

https://bugzilla.gnome.org/show_bug.cgi?id=731141
2014-06-03 09:23:41 +02:00