gstreamer/omx
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
..
openmax openmax: Add OpenMAX IL 1.1.2 headers 2011-07-06 08:42:09 +02:00
gstomx.c omx: call handle_messages() only once in acquire_buffer() to avoid potential deadlock 2015-03-04 09:51:03 +01:00
gstomx.h omx: Only include OMX_VideoExt.h conditionally 2014-06-24 14:52:43 +02:00
gstomxaacdec.c omxaudiodec: Implement setting of fallback channel positions 2014-07-13 22:15:44 +02:00
gstomxaacdec.h omx: Add AAC audio decoder 2014-07-13 18:22:39 +02:00
gstomxaacenc.c omx: Don't set profile/level in other encoders if downstream caps don't specify any 2013-03-11 13:59:15 +01:00
gstomxaacenc.h omxaacenc: Add initial version of OpenMAX AAC encoder element 2011-08-16 10:49:21 +02:00
gstomxamrdec.c omx: Add omxamrdec 2014-11-13 13:32:16 +01:00
gstomxamrdec.h omx: Add omxamrdec 2014-11-13 13:32:16 +01:00
gstomxanalogaudiosink.c omxaudiosink: Implements OpenMAX based audio sinks 2014-05-09 13:15:18 +02:00
gstomxanalogaudiosink.h omxaudiosink: Implements OpenMAX based audio sinks 2014-05-09 13:15:18 +02:00
gstomxaudiodec.c omxaudiodec: Clean up code a bit to get rid of useless NULL checks 2014-09-30 10:47:20 +03:00
gstomxaudiodec.h omx: Let base classes handle EOS 2014-08-14 17:36:11 +03:00
gstomxaudioenc.c omxaudioenc: Implement the hack flag GST_OMX_HACK_NO_COMPONENT_RECONFIGURE 2014-08-28 10:45:37 +03:00
gstomxaudioenc.h omx: Let base classes handle EOS 2014-08-14 17:36:11 +03:00
gstomxaudiosink.c omxaudiosink: Set port to not flushing in prepare() and keep it at flushing in unprepare() 2014-07-20 17:47:50 +02:00
gstomxaudiosink.h omxaudiosink: Implements OpenMAX based audio sinks 2014-05-09 13:15:18 +02:00
gstomxbufferpool.c omxbufferpool: Copy buffers if the stride does not match and we can't use video meta 2014-06-24 15:11:53 +02:00
gstomxbufferpool.h omxbufferpool: Copy buffers if the stride does not match and we can't use video meta 2014-06-24 15:11:53 +02:00
gstomxh263dec.c omx: Add more constraints to the default sink template caps 2013-03-19 13:28:30 +01:00
gstomxh263dec.h omxh263dec: Add H.263 decoder element 2011-07-25 11:44:56 +02:00
gstomxh263enc.c omx: more printf format fixes 2013-04-18 23:10:13 +01:00
gstomxh263enc.h omxh263enc: Add H.263 encoder element 2011-07-29 12:06:21 +02:00
gstomxh264dec.c omx: Add more constraints to the default sink template caps 2013-03-19 13:28:30 +01:00
gstomxh264dec.h omxh264dec: Rename from omxh264videodec to omxh264dec 2011-07-12 08:54:22 +02:00
gstomxh264enc.c omxh264enc: Properly accumulate headers and push before the next frame 2014-06-29 19:10:19 +02:00
gstomxh264enc.h omxh264enc: Properly accumulate headers and push before the next frame 2014-06-29 19:10:19 +02:00
gstomxhdmiaudiosink.c omxaudiosink: Implements OpenMAX based audio sinks 2014-05-09 13:15:18 +02:00
gstomxhdmiaudiosink.h omxaudiosink: Implements OpenMAX based audio sinks 2014-05-09 13:15:18 +02:00
gstomxmjpegdec.c omx: Add more constraints to the default sink template caps 2013-03-19 13:28:30 +01:00
gstomxmjpegdec.h omx: Add MJPEG decoder support 2013-03-18 16:34:51 +01:00
gstomxmp3dec.c omxaudiodec: Implement setting of fallback channel positions 2014-07-13 22:15:44 +02:00
gstomxmp3dec.h omx: Add audio decoder base class and a subclass for MP3 2014-07-02 09:21:00 +02:00
gstomxmpeg2videodec.c omx: Add more constraints to the default sink template caps 2013-03-19 13:28:30 +01:00
gstomxmpeg2videodec.h omx: Rename MPEG2 decoder for consistency everywhere 2013-03-18 16:34:51 +01:00
gstomxmpeg4videodec.c omx: Add more constraints to the default sink template caps 2013-03-19 13:28:30 +01:00
gstomxmpeg4videodec.h omx: Add initial version of OpenMAX framework, video decoder base class and MPEG4 video decoder 2011-07-09 11:06:05 +02:00
gstomxmpeg4videoenc.c omx: more printf format fixes 2013-04-18 23:10:13 +01:00
gstomxmpeg4videoenc.h omxvideoenc: Add video encoder base class and MPEG4 video encoder 2011-07-20 11:08:18 +02:00
gstomxtheoradec.c omx: Add more constraints to the default sink template caps 2013-03-19 13:28:30 +01:00
gstomxtheoradec.h omx: fix typo in copyright headers 2013-03-19 16:40:09 +00:00
gstomxvideo.c omx: add an helper to convert OMX color format to GStreamer color format 2014-04-15 15:09:23 +01:00
gstomxvideo.h omxvideo: Include the separate headers too for compatibility with 1.0.x 2014-06-24 10:22:37 +02:00
gstomxvideodec.c omx: Let base classes handle EOS 2014-08-14 17:36:11 +03:00
gstomxvideodec.h omx: Let base classes handle EOS 2014-08-14 17:36:11 +03:00
gstomxvideoenc.c omxvideoenc: Setup aspect ratio on RPi 2014-09-01 12:18:58 +03:00
gstomxvideoenc.h omx: Let base classes handle EOS 2014-08-14 17:36:11 +03:00
gstomxvp8dec.c omx: Add more constraints to the default sink template caps 2013-03-19 13:28:30 +01:00
gstomxvp8dec.h omx: Only include OMX_VideoExt.h conditionally 2014-06-24 14:52:43 +02:00
gstomxwmvdec.c omx: Add more constraints to the default sink template caps 2013-03-19 13:28:30 +01:00
gstomxwmvdec.h omxwmvdec: Add WMV video decoder element 2011-07-25 12:01:05 +02:00
Makefile.am omx: Add omxamrdec 2014-11-13 13:32:16 +01:00