Commit Graph

31 Commits

Author SHA1 Message Date
Thomas Guillem f7c4d13f71 auhal: use ca_MuteSet
Fix data race with au_unit. Indeed, the aout can be muted from any
threads.

SPDIF playback can now be muted.
2021-05-27 08:59:51 +00:00
Thomas Guillem 33a04f1c59 coreaudio: notify when the output is silence
It can be used as a hint to whether the buffer needs to be processed or
not.
2021-05-27 08:59:51 +00:00
Thomas Guillem 09de6e91d3 coreaudio: add ca_MuteSet()
This will write 0s from the render callback without touching at the
playback buffer state.
2021-05-27 08:59:51 +00:00
Marvin Scholz 6ad7ac4c4b auhal: rename i_dev_latency_us to i_dev_latency_ticks
The type is actually vlc_tick_t, so in order to prevent
confusion, it should be named accordingly.
2021-04-27 17:32:05 +00:00
Marvin Scholz 050c788d2b auhal: use #include instead of #import in C files 2021-04-27 17:32:05 +00:00
Marvin Scholz b13c3c10d6 aout/coreaudio: use vlc_mutex_t instead of pthread_mutex_t
The fact that currently vlc_mutex_t is the same as pthread_mutex_t
is an implementation detail, there is no reason not to use vlc_mutex_t
here.
2020-02-24 14:56:34 +01:00
Rémi Denis-Courmont a3226cf890 thread: remove vlc_mutex_destroy() 2020-02-21 19:16:09 +02:00
Thomas Guillem 965dfdcea0 coreaudio: move tinfo into p_sys
It doesn't need to be static since it is initialized from ca_Open().
2019-11-20 14:01:15 +01:00
Thomas Guillem fe2e975508 coreaudio: start deferred
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.
2019-08-21 09:57:36 +02:00
Thomas Guillem b625ef0b02 coreaudio: a valid timebase is now mandatory 2019-08-21 09:02:32 +02:00
Thomas Guillem b46f49a81c audiounit: update device latency when the route changes
This commit fixes airplay delay that may not be updated.
2019-07-17 16:54:31 +02:00
Thomas Guillem a34bf45cd6 coreaudio: don't print underrun warning before first play
It's perfectly OK to send 0s before the first buffer is played.
2019-07-16 11:51:20 +02:00
Thomas Guillem 2049d40876 aout: use a separate drain callback
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.
2019-03-19 16:01:53 +01:00
Steve Lhomme ff56c92a5e rename mtime_t to vlc_tick_t
Keep a copy of vlc_tick_tfor backward compatibility.
2018-06-22 13:19:24 +02:00
Marvin Scholz 04bd028324 coreaudio_common: fix ca_Play declaration 2018-05-04 20:46:57 +02:00
Thomas Guillem feaa3e792b coreaudio: finer audio delay
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).
2018-03-14 14:50:46 +01:00
Thomas Guillem 9bb14edac4 coreaudio: replace TPCircularBuffer by os_unfair_lock and a block chain
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.
2018-03-14 14:50:46 +01:00
Thomas Guillem f18fef325a coreaudio: disable resampling when latency is too high
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
2018-03-12 17:57:20 +01:00
Thomas Guillem 796689c4ba coreaudio: move auhal specific code in auhal.c
refs #19949
2018-03-09 11:20:38 +01:00
Rémi Denis-Courmont 72bfe44f98 Include <stdatomic.h> or <atomic> directly where applicable 2017-12-19 19:34:56 +02:00
Carola Nitz 7e4c7f35ec audiounit_ios: fix deadlock on interruption
Add ca_setAliveState() that sets the b_paused to true and unblock ca_Play() or
ca_Flush() that could wait for ca_Render().
2017-12-12 15:15:33 +01:00
Thomas Guillem 0e518afc95 aout: coreaudio: add Open/Close helpers 2017-09-08 13:42:03 +02:00
Thomas Guillem 9ad50ca913 coreaudio: fix undefined behavior when flushing
Don't consume (calling TPCircularBufferClear()) from the producer thread
(ca_Flush()).
2017-09-06 14:45:16 +02:00
Thomas Guillem 5a42b5e669 coreaudio: refactor and fix error output 2017-03-03 15:44:39 +01:00
Thomas Guillem d4853bc8a6 coreaudio: handle latency and circular size in ca_Initialize
The maximum latency changed from 2 seconds to 1 second.
2017-03-02 18:40:42 +01:00
Thomas Guillem f3d6aec4ea coreaudio: rework initialization
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).
2017-03-02 18:16:43 +01:00
Thomas Guillem 5e9498f1fe coreaudio: add a way to set latency in us 2017-03-01 17:49:39 +01:00
Thomas Guillem 854a3caea1 coreaudio: factor AudioUnit initialization
Factor StartAnalog for both iOS and macOS into au_Initialize().
2017-03-01 17:49:39 +01:00
Thomas Guillem 61686a07d1 coreaudio: fix unlikely but possible deadlock on pause
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.
2017-03-01 17:49:39 +01:00
Thomas Guillem 13765817b9 coreaudio: factor AudioUnit creation 2017-03-01 17:49:39 +01:00
Thomas Guillem d3a9c12e58 auhal/audiounit_ios: factor common code
coreaudio_common.c/.h contains the common code for auhal.c and audiounit_ios.m.

TODO: factor StartAnalog.
2017-02-24 11:41:00 +01:00