1 From 45658f75e61da47b274f2eba3a55e62d016f8b42 Mon Sep 17 00:00:00 2001
2 From: Walter Lozano <walter.lozano@collabora.com>
3 Date: Mon, 24 Aug 2020 12:08:32 -0300
4 Subject: [PATCH 8/9] alsa: add warning in case of partial read/write
6 Currently alsa_read and alsa_write assumes that all the frames committed
7 using snd_pcm_mmap_commit are read or written, which is probably true.
8 However, as it could be some corner cases add a warning to notice this
11 Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
13 spa/plugins/alsa/alsa-pcm.c | 28 ++++++++++++++++++++--------
14 1 file changed, 20 insertions(+), 8 deletions(-)
16 diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c
17 index ed9bf42b..92ef2151 100644
18 --- a/spa/plugins/alsa/alsa-pcm.c
19 +++ b/spa/plugins/alsa/alsa-pcm.c
20 @@ -721,6 +721,7 @@ int spa_alsa_write(struct state *state, snd_pcm_uframes_t silence)
21 snd_pcm_t *hndl = state->hndl;
22 const snd_pcm_channel_area_t *my_areas;
23 snd_pcm_uframes_t written, frames, offset, off, to_write, total_written;
24 + snd_pcm_sframes_t commitres;
27 if (state->position && state->duration != state->position->clock.duration) {
28 @@ -834,11 +835,16 @@ again:
29 state, offset, written, state->sample_count);
30 total_written += written;
32 - if ((res = snd_pcm_mmap_commit(hndl, offset, written)) < 0) {
33 + if ((commitres = snd_pcm_mmap_commit(hndl, offset, written)) < 0) {
34 spa_log_error(state->log, NAME" %p: snd_pcm_mmap_commit error: %s",
35 - state, snd_strerror(res));
36 - if (res != -EPIPE && res != -ESTRPIPE)
38 + state, snd_strerror(commitres));
39 + if (commitres != -EPIPE && commitres != -ESTRPIPE)
43 + if (commitres > 0 && written != (snd_pcm_uframes_t) commitres) {
44 + spa_log_warn(state->log, NAME" %p: mmap_commit wrote %ld instead of %ld",
45 + state, commitres, written);
48 if (!spa_list_is_empty(&state->ready) && written > 0)
49 @@ -922,6 +928,7 @@ int spa_alsa_read(struct state *state, snd_pcm_uframes_t silence)
50 snd_pcm_uframes_t total_read = 0, to_read;
51 const snd_pcm_channel_area_t *my_areas;
52 snd_pcm_uframes_t read, frames, offset;
53 + snd_pcm_sframes_t commitres;
56 if (state->position) {
57 @@ -994,11 +1001,16 @@ int spa_alsa_read(struct state *state, snd_pcm_uframes_t silence)
58 offset, read, state->sample_count);
61 - if ((res = snd_pcm_mmap_commit(hndl, offset, read)) < 0) {
62 + if ((commitres = snd_pcm_mmap_commit(hndl, offset, read)) < 0) {
63 spa_log_error(state->log, NAME" %p: snd_pcm_mmap_commit error: %s",
64 - state, snd_strerror(res));
65 - if (res != -EPIPE && res != -ESTRPIPE)
67 + state, snd_strerror(commitres));
68 + if (commitres != -EPIPE && commitres != -ESTRPIPE)
72 + if (commitres > 0 && read != (snd_pcm_uframes_t) commitres) {
73 + spa_log_warn(state->log, NAME" %p: mmap_commit read %ld instead of %ld",
74 + state, commitres, read);
77 state->sample_count += total_read;