From 5e87e2e0210dd6bd97cbfdfa94a537f31adaaaf6 Mon Sep 17 00:00:00 2001 From: Marcin Rajwa Date: Fri, 7 Aug 2020 17:35:44 +0200 Subject: [PATCH] aplay: pcm_read(): return read samples instead of requested upon abort This patch changes the logic of pcm_read() when abort signal has been detected. During such condition we should return the amount of frames actually read instead of the size requested by caller. Currently functions pcm_read() and pcm_readv() when aborted (in_aborting flag set) return the amount of requested frames instead of those actually read prior to interrupt. The consequence of this is repetition of recent X frames where X stands for amount of frames in one period. This problem is barely visible or rather audible when the period is small like few milliseconds because repetition of 1 [ms] of data is not-noticeable however if we use buffer and period sizes in seconds then the problem becomes apparent. Signed-off-by: Marcin Rajwa Signed-off-by: Jaroslav Kysela --- aplay/aplay.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/aplay/aplay.c b/aplay/aplay.c index 6e7f4ae..d71035c 100644 --- a/aplay/aplay.c +++ b/aplay/aplay.c @@ -2135,7 +2135,9 @@ static ssize_t pcm_read(u_char *data, size_t rcount) count = chunk_size; } - while (count > 0 && !in_aborting) { + while (count > 0) { + if (in_aborting) + goto abort; if (test_position) do_test_position(); check_stdin(); @@ -2161,6 +2163,7 @@ static ssize_t pcm_read(u_char *data, size_t rcount) data += r * bits_per_frame / 8; } } +abort: return rcount; }