From 0393e9f0ff0bc9718a792d0be014e92f9a53aec6 Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Thu, 21 Jul 2016 15:06:33 +0200 Subject: [PATCH] Clamp OSX latency up and down to work around getting weird number on mozilla test slaves --- src/cubeb_audiounit.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/cubeb_audiounit.cpp b/src/cubeb_audiounit.cpp index 202f852..22a42ca 100644 --- a/src/cubeb_audiounit.cpp +++ b/src/cubeb_audiounit.cpp @@ -67,6 +67,12 @@ typedef UInt32 AudioFormatFlags; #define LOG(...) #endif + +/* Testing empirically, some headsets report a minimal latency that is very + * low, but this does not work in practice. Lie and say the minimum is 256 + * frames. */ +const uint32_t SAFE_MIN_LATENCY_FRAMES = 256; + extern cubeb_ops const audiounit_ops; struct cubeb { @@ -781,10 +787,8 @@ audiounit_get_min_latency(cubeb * ctx, cubeb_stream_params params, uint32_t * la return CUBEB_ERROR; } - /* Testing empirically, some headsets report a minimal latency that is very - * low, but this does not work in practice. Lie and say the minimum is 256 - * frames. */ - *latency_frames = std::max(latency_range.mMinimum, 256); + *latency_frames = std::max(latency_range.mMinimum, + SAFE_MIN_LATENCY_FRAMES); #endif return CUBEB_OK; @@ -1085,7 +1089,11 @@ audiounit_stream_init(cubeb * context, LOG("Default buffer size: %u frames\n", default_frame_count); - latency_frames = std::min(latency_frames, default_frame_count); + latency_frames = std::max(std::min(latency_frames, + default_frame_count), + SAFE_MIN_LATENCY_FRAMES); + + LOG("Clamped buffer size: %u frames\n", latency_frames); /* Setup Input Stream! */ if (input_stream_params != NULL) {