Fix flow for measuring latencies of live backends
authorRobin Gareus <robin@gareus.org>
Thu, 27 Apr 2017 19:07:18 +0000 (21:07 +0200)
committerRobin Gareus <robin@gareus.org>
Thu, 27 Apr 2017 19:07:18 +0000 (21:07 +0200)
libs/ardour/audioengine.cc

index 1a09a7f0eb3ded9f632dc65b5e96fb9e960e5c0e..999fbc0fcdebe58cd179c233c4c58c26fe70c2db 100644 (file)
@@ -922,6 +922,9 @@ AudioEngine::stop (bool for_latency)
 
        if (for_latency && _backend->can_change_systemic_latency_when_running()) {
                stop_engine = false;
+               if (_running) {
+                       _backend->start (false); // keep running, reload latencies
+               }
        } else {
                if (_backend->stop ()) {
                        if (pl.locked ()) {
@@ -943,14 +946,18 @@ AudioEngine::stop (bool for_latency)
                _session->engine_halted ();
        }
 
-       if (stop_engine) {
+       if (stop_engine && _running) {
                _running = false;
+               if (!for_latency) {
+                       _started_for_latency = false;
+               } else if (!_started_for_latency) {
+                       _stopped_for_latency = true;
+               }
        }
        _processed_frames = 0;
        _measuring_latency = MeasureNone;
        _latency_output_port = 0;
        _latency_input_port = 0;
-       _started_for_latency = false;
 
        if (stop_engine) {
                Port::PortDrop ();
@@ -1336,16 +1343,16 @@ AudioEngine::prepare_for_latency_measurement ()
        }
 
        if (_backend->can_change_systemic_latency_when_running()) {
-               if (start()) {
+               if (_running) {
+                       _backend->start (true); // zero latency reporting of running backend
+               } else if (start (true)) {
                        return -1;
                }
-               _backend->set_systemic_input_latency (0);
-               _backend->set_systemic_output_latency (0);
+               _started_for_latency = true;
                return 0;
        }
 
        if (running()) {
-               _stopped_for_latency = true;
                stop (true);
        }
 
@@ -1353,7 +1360,6 @@ AudioEngine::prepare_for_latency_measurement ()
                return -1;
        }
        _started_for_latency = true;
-
        return 0;
 }
 
@@ -1468,6 +1474,18 @@ AudioEngine::stop_latency_detection ()
                _latency_input_port = 0;
        }
 
+       if (_running && _backend->can_change_systemic_latency_when_running()) {
+               if (_started_for_latency) {
+                       _running = false; // force reload: reset latencies and emit Running()
+                       start ();
+               }
+       }
+
+       if (_running && !_started_for_latency) {
+               assert (!_stopped_for_latency);
+               return;
+       }
+
        if (!_backend->can_change_systemic_latency_when_running()) {
                stop (true);
        }