From a84cb976a03e7c5bf0f6031b273e8d957d97d08b Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 14 Sep 2021 21:25:44 +0200 Subject: [PATCH] Add API to query I/O latency from port-engine This allows to get public latency ranges for any port including Ardour's latency-compensation as well as including any latency induced by external JACK applications. It is mainly useful to detect ambiguous latency and to forward public port latency of connected ports. --- libs/ardour/ardour/port.h | 2 ++ libs/ardour/port.cc | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/libs/ardour/ardour/port.h b/libs/ardour/ardour/port.h index e1fcbcd536..c7c9aafb89 100644 --- a/libs/ardour/ardour/port.h +++ b/libs/ardour/ardour/port.h @@ -107,6 +107,8 @@ public: void get_connected_latency_range (LatencyRange& range, bool playback) const; + void collect_latency_from_backend (LatencyRange& range, bool playback) const; + void set_private_latency_range (LatencyRange& range, bool playback); const LatencyRange& private_latency_range (bool playback) const; diff --git a/libs/ardour/port.cc b/libs/ardour/port.cc index 25510a92ae..0c55e86074 100644 --- a/libs/ardour/port.cc +++ b/libs/ardour/port.cc @@ -452,6 +452,44 @@ Port::public_latency_range (bool playback) const return r; } +void +Port::collect_latency_from_backend (LatencyRange& range, bool playback) const +{ + vector connections; + get_connections (connections); + + DEBUG_TRACE (DEBUG::LatencyIO, string_compose ("%1: %2 connections to check for real %3 latency range\n", + name(), connections.size(), + playback ? "PLAYBACK" : "CAPTURE")); + + for (vector::const_iterator c = connections.begin(); c != connections.end(); ++c) { + PortEngine::PortHandle ph = port_engine.get_port_by_name (*c); + if (!ph) { + continue; + } + + LatencyRange lr = port_engine.get_latency_range (ph, playback); + + if (!AudioEngine::instance()->port_is_mine (*c)) { + if (externally_connected () && 0 == (_flags & TransportSyncPort) && sends_output () == playback) { + if (type () == DataType::AUDIO) { + lr.min += (_resampler_quality - 1); + lr.max += (_resampler_quality - 1); + } + } + } + + DEBUG_TRACE (DEBUG::LatencyIO, string_compose ( + "\t%1 <-> %2 : latter has latency range %3 .. %4\n", + name(), *c, lr.min, lr.max)); + + range.min = min (range.min, lr.min); + range.max = max (range.max, lr.max); + } + + DEBUG_TRACE (DEBUG::LatencyIO, string_compose ("%1: real latency range now [ %2 .. %3 ] \n", name(), range.min, range.max)); +} + void Port::get_connected_latency_range (LatencyRange& range, bool playback) const {