Skip to content

Commit

Permalink
floop: fill zeroes to fix level instead of calculating realtime
Browse files Browse the repository at this point in the history
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 <dev> -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 <chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com>
Commit-Queue: Curtis Malainey <cujomalainey@chromium.org>
Reviewed-by: Curtis Malainey <cujomalainey@chromium.org>
Reviewed-by: Yu-Hsuan Hsu <yuhsuan@chromium.org>
  • Loading branch information
terry182 authored and Chromeos LUCI committed Sep 26, 2024
1 parent 9c4b84a commit b6acb7f
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions cras/src/server/cras_floop_iodev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b6acb7f

Please sign in to comment.