Avoid calling rt-methods from non-rt context
authorRobin Gareus <robin@gareus.org>
Mon, 18 Mar 2019 05:15:12 +0000 (06:15 +0100)
committerRobin Gareus <robin@gareus.org>
Mon, 18 Mar 2019 05:15:12 +0000 (06:15 +0100)
Since upcoming state-machine transitions are done in rt-context
via ARDOUR::Session::process_event () they should all in rt-context.

set_session() is called from the UI thread (and the process-lock wasn't
even taken)

libs/ardour/ardour/audioengine.h
libs/ardour/audioengine.cc

index 053a6b67505b11d1fde6d387822ea4ae5346f719..f699e019880bb9cf7d7c5d0cb191920fc804abd9 100644 (file)
@@ -307,6 +307,7 @@ class LIBARDOUR_API AudioEngine : public PortManager, public SessionHandlePtr
        Glib::Threads::Mutex       _devicelist_update_lock;
        gint                       _stop_hw_devicelist_processing;
        uint32_t                   _start_cnt;
+       uint32_t                   _init_countdown;
 
        void start_hw_event_processing();
        void stop_hw_event_processing();
index 65a76f745ad495aafe3400a5a58de3b6b85c5669..4ba6f6cf0a9f2998289e188696dee9d3fcaf5c4e 100644 (file)
@@ -100,6 +100,7 @@ AudioEngine::AudioEngine ()
        , _hw_devicelist_update_count(0)
        , _stop_hw_devicelist_processing(0)
        , _start_cnt (0)
+       , _init_countdown (0)
 #ifdef SILENCE_AFTER_SECONDS
        , _silence_countdown (0)
        , _silence_hit_cnt (0)
@@ -248,6 +249,16 @@ AudioEngine::process_callback (pframes_t nframes)
                thread_init_callback (NULL);
        }
 
+       if (_session && _init_countdown > 0) {
+               --_init_countdown;
+               /* Warm up caches */
+               PortManager::cycle_start (nframes);
+               PortManager::silence (nframes);
+               _session->process (nframes);
+               PortManager::cycle_end (nframes);
+               return 0;
+       }
+
        bool return_after_remove_check = false;
 
        if (_measuring_latency == MeasureAudio && _mtdm) {
@@ -643,21 +654,7 @@ AudioEngine::set_session (Session *s)
        SessionHandlePtr::set_session (s);
 
        if (_session) {
-
-               pframes_t blocksize = samples_per_cycle ();
-
-               PortManager::cycle_start (blocksize);
-
-               _session->process (blocksize);
-               _session->process (blocksize);
-               _session->process (blocksize);
-               _session->process (blocksize);
-               _session->process (blocksize);
-               _session->process (blocksize);
-               _session->process (blocksize);
-               _session->process (blocksize);
-
-               PortManager::cycle_end (blocksize);
+               _init_countdown = 8;
        }
 }