From eb0498bb28612760e3ba4016bba21a3bc03bb542 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 8 Sep 2021 21:50:57 +0200 Subject: [PATCH] Overhaul ambiguous latency detection Simply comparing connected latency min/max is insufficient and allows for false positives. get_connected_latency_range() reports private, uncompensated latency for internal ports. In this case an additional test is required to match it against the reported latency of connected ports. Since 13b8a9727bb05 remote connected ports now correctly report latency for both internal as well as external ports. --- libs/ardour/port_manager.cc | 51 +++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/libs/ardour/port_manager.cc b/libs/ardour/port_manager.cc index cc7d688cf4..90934b085d 100644 --- a/libs/ardour/port_manager.cc +++ b/libs/ardour/port_manager.cc @@ -1680,7 +1680,8 @@ PortManager::check_for_ambiguous_latency (bool log) const boost::shared_ptr plist = _ports.reader(); for (Ports::iterator pi = plist->begin(); pi != plist->end(); ++pi) { boost::shared_ptr const& p (pi->second); - if (! p->sends_output () || (p->flags () & IsTerminal)) { + /* check one to many connections on the receiving side */ + if (p->sends_output () || (p->flags () & IsTerminal)) { continue; } if (boost::dynamic_pointer_cast(p)) { @@ -1688,11 +1689,51 @@ PortManager::check_for_ambiguous_latency (bool log) const } assert (port_is_mine (p->name ())); - LatencyRange range; - p->get_connected_latency_range (range, true); - if (range.min != range.max) { + LatencyRange rangeA; + p->get_connected_latency_range (rangeA, true); + + if (rangeA.min == rangeA.max) { + continue; + } + + /* check if latency-range of connected ports matches our own */ + + vector connections; + p->get_connections (connections); + + assert (!connections.empty()); + + for (vector::const_iterator c = connections.begin(); c != connections.end(); ++c) { + LatencyRange rangeB; + + if (!AudioEngine::instance()->port_is_mine (*c)) { + PortEngine::PortHandle ph = _backend->get_port_by_name (*c); + if (!ph) { + continue; + } + rangeB = _backend->get_latency_range (ph, true); + } else { + Ports::iterator x = plist->find (make_port_name_relative (*c)); + if (x == plist->end()) { + continue; + } + boost::shared_ptr const& pb (x->second); + if (pb->flags () & (IsTerminal | Hidden | TransportSyncPort)) { + continue; + } + pb->get_connected_latency_range (rangeB, true); + } + + if (rangeA == rangeB) { + continue; + } if (log) { - warning << string_compose(_("Ambiguous latency for port '%1' (%2, %3)"), p->name(), range.min, range.max) << endmsg; + warning << string_compose( + _("Ambiguous latency for input '%1' (%2, %3)," + "receiving from port '%4' (%5, %6)"), + p->name(), rangeA.min, rangeA.max, + *c, rangeB.min, rangeB.max) + << endmsg; rv = true; } else { return true;