aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPaul Adenot <[email protected]>2024-05-22 15:08:36 +0200
committerPaul Adenot <[email protected]>2024-05-23 15:25:52 +0200
commitd3ff5982f8da5f964bb27dd7b5b020070594f673 (patch)
treeaee64899fbdf7155f3212783d8edd2a4d2078d8f
parentc3a7500d7a79b9a1609c70bf0f69cf5bc5011994 (diff)
downloadcubeb-d3ff5982f8da5f964bb27dd7b5b020070594f673.tar.gz
cubeb-d3ff5982f8da5f964bb27dd7b5b020070594f673.zip
Clamp to positive value when computing latency for an output stream
Diagnosed by [email protected], the same code is also found in Chromium.
-rw-r--r--src/cubeb_aaudio.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/cubeb_aaudio.cpp b/src/cubeb_aaudio.cpp
index 9c3b32c..915faee 100644
--- a/src/cubeb_aaudio.cpp
+++ b/src/cubeb_aaudio.cpp
@@ -646,8 +646,9 @@ aaudio_get_latency(cubeb_stream * stm, aaudio_direction_t direction,
// For an output stream, the latency is positive, for an input stream, it's
// negative. It can happen in some instances, e.g. around start of the stream
// that the latency for output is negative, return 0 in this case.
- int64_t latency_ns = is_output ? std::max(0ll, app_frame_hw_time - signed_tstamp_ns)
- : signed_tstamp_ns - app_frame_hw_time;
+ int64_t latency_ns = is_output
+ ? std::max(0ll, app_frame_hw_time - signed_tstamp_ns)
+ : signed_tstamp_ns - app_frame_hw_time;
int64_t latency_frames = stm->sample_rate * latency_ns / NS_PER_S;
LOGV("Latency in frames (%s): %d (%dms)", is_output ? "output" : "input",