Fix non-buffered PA backend. Wait for backend to become active
authorRobin Gareus <robin@gareus.org>
Mon, 7 Aug 2017 21:23:39 +0000 (23:23 +0200)
committerRobin Gareus <robin@gareus.org>
Mon, 7 Aug 2017 21:23:39 +0000 (23:23 +0200)
This hopefully fixes an issue with port-registration (new session)
being skipped because PortAudioBackend::available() still false
until the first callback.

libs/backends/portaudio/portaudio_backend.cc

index b9ef48fd4f0fc83b98873cbe1d90cdccb979a35d..5bb8ecb08dd22a82ae919c5e880fd1b057737526 100644 (file)
@@ -581,6 +581,8 @@ PortAudioBackend::_start (bool for_latency_measurement)
        }
 
        /* reset internal state */
+       assert (_run == false);
+       _run = false;
        _dsp_load = 0;
        _freewheeling = false;
        _freewheel = false;
@@ -658,7 +660,6 @@ PortAudioBackend::_start (bool for_latency_measurement)
 
        if (register_system_midi_ports () != 0) {
                DEBUG_PORTS("Failed to register system midi ports.\n")
-               _run = false;
                return PortRegistrationError;
        }
 
@@ -666,7 +667,6 @@ PortAudioBackend::_start (bool for_latency_measurement)
 
        if (register_system_audio_ports()) {
                DEBUG_PORTS("Failed to register system audio ports.\n");
-               _run = false;
                return PortRegistrationError;
        }
 
@@ -675,7 +675,6 @@ PortAudioBackend::_start (bool for_latency_measurement)
 
        if (engine.reestablish_ports ()) {
                DEBUG_PORTS("Could not re-establish ports.\n");
-               _run = false;
                return PortReconnectError;
        }
 
@@ -699,6 +698,16 @@ PortAudioBackend::_start (bool for_latency_measurement)
                        stop();
                        return ProcessThreadStartError;
                }
+
+               /* wait for backend to become active */
+               int timeout = 5000;
+               while (!_active && --timeout > 0) { Glib::usleep (1000); }
+
+               if (timeout == 0 || !_active) {
+                       PBD::error << _("PortAudio:: failed to start device.") << endmsg;
+                       stop ();
+                       return ProcessThreadStartError;
+               }
        }
 
        return NoError;