From 1796ee60b249d2ef534826ae36a2b88f2788e40c Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 12 Jul 2020 00:38:56 +0200 Subject: [PATCH] Clean up b5e479df and expose API to queue latency-updates --- libs/ardour/ardour/audioengine.h | 4 +-- libs/ardour/audioengine.cc | 52 +++++++++++++++++++------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/libs/ardour/ardour/audioengine.h b/libs/ardour/ardour/audioengine.h index f99d9bafd1..c2aaafae65 100644 --- a/libs/ardour/ardour/audioengine.h +++ b/libs/ardour/ardour/audioengine.h @@ -210,8 +210,7 @@ class LIBARDOUR_API AudioEngine : public PortManager, public SessionHandlePtr static void destroy(); void died (); - /* The backend will cause these at the appropriate time(s) - */ + /* The backend will cause these at the appropriate time(s) */ int process_callback (pframes_t nframes); int buffer_size_change (pframes_t nframes); int sample_rate_change (pframes_t nframes); @@ -259,6 +258,7 @@ class LIBARDOUR_API AudioEngine : public PortManager, public SessionHandlePtr void reset_silence_countdown (); void add_pending_port_deletion (Port*); + void queue_latency_update (bool); private: AudioEngine (); diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index e7073d63ae..f48f4761cf 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -1416,27 +1416,37 @@ void AudioEngine::latency_callback (bool for_playback) { DEBUG_TRACE (DEBUG::BackendCallbacks, string_compose (X_("latency callback playback ? %1\n"), for_playback)); - if (_session) { - if (in_process_thread ()) { - /* internal backends emit the latency callback in the rt-callback, - * async to connect/disconnect or port creation/deletion. - * All is fine. - * - * However jack 1/2 emit the callback in sync with creating the port - * (or while handling the connection change). - * e.g. JACK2 jack_port_register() blocks and the jack_latency_callback - * from a different thread: https://pastebin.com/mitGBwpq - * but at this point in time Ardour still holds the process callback - * because JACK2 can process in parallel to latency callbacks. - * - * see also Session::update_latency() and git-ref 1983f56592dfea5f7498 - */ - _session->update_latency (for_playback); - } else if (for_playback) { - g_atomic_int_set (&_pending_playback_latency_callback, 1); - } else { - g_atomic_int_set (&_pending_capture_latency_callback, 1); - } + if (!_session) { + return; + } + + if (in_process_thread ()) { + /* internal backends emit the latency callback in the rt-callback, + * async to connect/disconnect or port creation/deletion. + * All is fine. + */ + _session->update_latency (for_playback); + } else { + /* However jack 1/2 emit the callback in sync with creating the port + * (or while handling the connection change). + * e.g. JACK2 jack_port_register() blocks and the jack_latency_callback + * from a different thread: https://pastebin.com/mitGBwpq + * but at this point in time Ardour still holds the process callback + * because JACK2 can process in parallel to latency callbacks. + * + * see also Session::update_latency() and git-ref 1983f56592dfea5f7498 + */ + queue_latency_update (for_playback); + } +} + +void +AudioEngine::queue_latency_update (bool for_playback) +{ + if (for_playback) { + g_atomic_int_set (&_pending_playback_latency_callback, 1); + } else { + g_atomic_int_set (&_pending_capture_latency_callback, 1); } }