gstreamer/sys/opensles
Sebastian Dröge c842df1c3d opensles: Work around race condition in Android < 4.2 that leads to deadlocks on shutdown
We need to sleep a bit before destroying the player object
because of a bug in Android in versions < 4.2.

OpenSLES is using AudioTrack for rendering the sound. AudioTrack
has a thread that pulls raw audio from the buffer queue and then
passes it forward to AudioFlinger (AudioTrack::processAudioBuffer()).
This thread is calling various callbacks on events, e.g. when
an underrun happens or to request data. OpenSLES sets this callback
on AudioTrack (audioTrack_callBack_pullFromBuffQueue() from
android_AudioPlayer.cpp). Among other things this is taking a lock
on the player interface.

Now if we destroy the player interface object, it will first of all
take the player interface lock (IObject_Destroy()). Then it destroys
the audio player instance (android_audioPlayer_destroy()) which then
calls stop() on the AudioTrack and deletes it. Now the destructor of
AudioTrack will wait until the rendering thread (AudioTrack::processAudioBuffer())
has finished.

If all this happens with bad timing it can happen that the rendering
thread is currently e.g. handling underrun but did not lock the player
interface object yet. Then destroying happens and takes the lock and waits
for the thread to finish. Then the thread tries to take the lock and waits
forever.

We wait a bit before destroying the player object to make sure that
the rendering thread finished whatever it was doing, and then stops
(note: we called gst_opensles_ringbuffer_stop() before this already).
2014-05-16 09:10:48 +02:00
..
Makefile.am opensles: Port to 1.0 2012-10-25 14:05:49 +02:00
opensles.c Fix FSF address 2012-11-04 00:09:59 +00:00
opensles.h Fix FSF address 2012-11-04 00:09:59 +00:00
openslesringbuffer.c opensles: Work around race condition in Android < 4.2 that leads to deadlocks on shutdown 2014-05-16 09:10:48 +02:00
openslesringbuffer.h opensles: Only include <gst/audio/audio.h> 2013-03-03 12:30:44 +01:00
openslessink.c Fix FSF address 2012-11-04 00:09:59 +00:00
openslessink.h opensles: Only include <gst/audio/audio.h> 2013-03-03 12:30:44 +01:00
openslessrc.c Fix FSF address 2012-11-04 00:09:59 +00:00
openslessrc.h opensles: Only include <gst/audio/audio.h> 2013-03-03 12:30:44 +01:00