CRAS: loopbacl_iodev - Fix get_buffer callback
Get buffer should not return frames more than requrested.
BUG=chromium:657510
TEST=cras_test_client --loopback_file /tmp/loopback
Change-Id: Ie789cbff30ede279e63e67f5822c36ab8a8c4dc7
Reviewed-on: https://chromium-review.googlesource.com/414750
Commit-Ready: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
diff --git a/cras/src/server/cras_loopback_iodev.c b/cras/src/server/cras_loopback_iodev.c
index f532a80..ead33f1 100644
--- a/cras/src/server/cras_loopback_iodev.c
+++ b/cras/src/server/cras_loopback_iodev.c
@@ -194,8 +194,9 @@
struct loopback_iodev *loopdev = (struct loopback_iodev *)iodev;
struct byte_buffer *sbuf = loopdev->sample_buffer;
unsigned int frame_bytes = cras_get_format_bytes(iodev->format);
+ unsigned int avail_frames = buf_readable_bytes(sbuf) / frame_bytes;
- *frames = buf_readable_bytes(sbuf) / frame_bytes;
+ *frames = MIN(avail_frames, *frames);
iodev->area->frames = *frames;
cras_audio_area_config_buf_pointers(iodev->area, iodev->format,
buf_read_pointer(sbuf));