diff options
author | Paul Adenot <[email protected]> | 2021-07-12 14:54:10 +0200 |
---|---|---|
committer | Paul Adenot <[email protected]> | 2021-07-13 13:51:30 +0200 |
commit | b2f60c983df34f8cac0e061ef32da531c6d82536 (patch) | |
tree | 993edbd3811590f1b066f505f5aeb1c2e3432ab3 | |
parent | 1437a53f8b492ed08830b9f60f27bb48a923c426 (diff) | |
download | cubeb-b2f60c983df34f8cac0e061ef32da531c6d82536.tar.gz cubeb-b2f60c983df34f8cac0e061ef32da531c6d82536.zip |
Address review comments.
-rw-r--r-- | src/cubeb_wasapi.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/cubeb_wasapi.cpp b/src/cubeb_wasapi.cpp index e0b931f..da0fd98 100644 --- a/src/cubeb_wasapi.cpp +++ b/src/cubeb_wasapi.cpp @@ -354,6 +354,8 @@ struct cubeb_stream { * first audio input callback. */ std::atomic<int64_t> input_latency_hns { LATENCY_NOT_AVAILABLE_YET }; + /* Those attributes count the number of frames requested (resp. received) by + the OS, to be able to detect drifts. This is only used for logging for now. */ size_t total_input_frames = 0; size_t total_output_frames = 0; }; @@ -911,8 +913,7 @@ int trigger_async_reconfigure(cubeb_stream * stm) /* This helper grabs all the frames available from a capture client, put them in - * the linear_input_buffer. This helper does not work with exclusive mode - * streams. */ + * the linear_input_buffer. This helper does not work with exclusive mode streams. */ bool get_input_buffer(cubeb_stream * stm) { XASSERT(has_input(stm)); @@ -1093,6 +1094,13 @@ refill_callback_duplex(cubeb_stream * stm) XASSERT(has_input(stm) && has_output(stm)); + if (stm->input_stream_params.prefs & CUBEB_STREAM_PREF_LOOPBACK) { + HRESULT rv = get_input_buffer(stm); + if (FAILED(rv)) { + return rv; + } + } + input_frames = stm->linear_input_buffer->length() / stm->input_stream_params.channels; rv = get_output_buffer(stm, output_buffer, output_frames); @@ -2164,6 +2172,7 @@ int setup_wasapi_stream_one_side(cubeb_stream * stm, } else { stm->input_bluetooth_handsfree = false; } + // This multiplicator has been found empirically. latency_frames = default_period_frames * 8; LOG("Input: latency increased to %u frames from a default of %u", latency_frames, default_period_frames); } @@ -2637,6 +2646,9 @@ void close_wasapi_stream(cubeb_stream * stm) stm->output_mixer.reset(); stm->input_mixer.reset(); stm->mix_buffer.clear(); + if (stm->linear_input_buffer) { + stm->linear_input_buffer->clear(); + } } void wasapi_stream_destroy(cubeb_stream * stm) |