It now use the play date argument to delay the first render until this date is
reached (TimeGet() will return -1 in during this step).
This aout module now respect the jitter delay from the new output clock.
This callback is not mandatory. If it is NULL, the core will wait for the delay
returned by time_get(). This was already the case for most aout plugins:
PulseAudio, coreaudio, Android, DirectSound, Wasapi, and Jack.
This is a partial revert of f18fef325a
This commit fixes the delay imprecision that was depending on the number of
frames asked by the render callback. This also fixes audio glitches (due to
flush/resampling) when this number of frames was changed (when the screen is
OFF for example).
Remove the usage of TPCircularBuffer and multiple atomic variables that start
to make this code way too complicated. Replace it by os_unfair_lock and a block
chain.
os_unfair_lock is a safe spinlock that waits in the kernel in case of thread
contention.
Fallback to pthread_mutex_t if os_unfair_lock is not availaible (before macOS
10.12 / iOS 10.0).
The unfairness of this new lock is not an issue here since both locking threads
(the render callback and the VLC DecoderThread calling aout_DecPlay) will be
automatically paced (and will let the other thread take the lock). Indeed, the
render thread need a sample every 22 or 88ms, and the DecoderThread will wait
for the decoder, wait in the decoder lock, or wait from the aout if the FIFO is
full.
On iOS, the render callback is called by default with 1024 frames, and 4096
when the screen is OFF. 4096 frames @ 44.1Hhz is around 88ms, which is higher
than AOUT_MAX_PTS_DELAY (60ms). This caused the resampler to be started/stopped
very often when the screen was OFF due to the imprecision of 88ms from the
TimeGet callback.
To fix this issue, this commit disable the TimeGet callback when the latency is
too high.
This will also save some CPU time by disabling any synchronisation when the
screen is OFF. From my tests, high latency is only triggered by switching OFF
the display.
Fixes#18939
Rename ca_Init() to ca_Initialize() and ca_Clean() to ca_Uninitialize().
au_Initialize() calls now ca_Initialize().
Add au_Uninitialize() that calls ca_Uninitialize().
Functions starting with ca_ are generic and used by AudioUnit (auhal and
audiounit_ios) or AudioDevice (only auhal for passthrough on macOS).
The pause state need to be known by ca_Play in order to don't wait indefinitely
when the RenderCallback is paused. A deadlock could happen with asynchronous
audio decoders.