From b6acb7fa47d8dc2acee56f996f4beef59aa2abe9 Mon Sep 17 00:00:00 2001 From: Terry Cheong Date: Thu, 26 Sep 2024 16:08:27 +0800 Subject: [PATCH] floop: fill zeroes to fix level instead of calculating realtime Flexible loopback device originally fills zeroes according to the rate it runs on each time input_frames_queued is called. This mechanism fills zeroes in a irregular manner, causing flexible loopback device need to frquently wake up instead of its original schedule. Always fill the buffer to min_cb_level to ensure it was running in its original schedule. This will also create a delay when next output stream starts. BUG=b:362679648 TEST=cras_test_client --pin_device -C /dev/null \ and check wakeup time with cras_test_client --follow_a Change-Id: I149b7b738474ef59ff567d75932cbb608c736a70 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/5892521 Tested-by: chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com Commit-Queue: Curtis Malainey Reviewed-by: Curtis Malainey Reviewed-by: Yu-Hsuan Hsu --- cras/src/server/cras_floop_iodev.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cras/src/server/cras_floop_iodev.c b/cras/src/server/cras_floop_iodev.c index c9aab0c96..ed50152cb 100644 --- a/cras/src/server/cras_floop_iodev.c +++ b/cras/src/server/cras_floop_iodev.c @@ -112,17 +112,15 @@ static int input_frames_queued(const struct cras_iodev* iodev, unsigned int frame_bytes = cras_get_format_bytes(iodev->format); /* - * When there is no output stream, fill the buffer with frames until it - * reaches the number of frames that is expected according to frame rate. + * When there is no output stream, fill the buffer with frames to + * min_cb_level. This creates a delay for 1 min_cb_level when another + * output stream attached. */ if (floop->input_active && !floop->pair.output.streams) { - unsigned int frames_since_start = cras_frames_since_time( - &floop->dev_start_time, iodev->format->frame_rate); unsigned int frames_in_buffer = buf_queued(floop->buffer) / frame_bytes; - unsigned int frames_to_fill = - frames_since_start > (floop->read_frames + frames_in_buffer) - ? frames_since_start - (floop->read_frames + frames_in_buffer) - : 0; + unsigned int frames_to_fill = iodev->min_cb_level > frames_in_buffer + ? iodev->min_cb_level - frames_in_buffer + : 0; frames_to_fill = MIN(buf_writable(floop->buffer) / frame_bytes, frames_to_fill); if (frames_to_fill > 0) {