From cb90a88d382971a146c4b7413bb6df6563cef7d1 Mon Sep 17 00:00:00 2001 From: Walter Lozano Date: Sun, 30 Aug 2020 00:04:14 -0300 Subject: meta-pipewire: additional improvements for iMX8MQ Include additional improvement related to iMX8MQ, which should help to mitigate audio issues. First, add a warning if not all the committed data is actually read/written. Secondly, if snd_pcm_hw_params_is_batch == 1 tweak the delay to make sure at least a period is available in the buffer to avoid xrun. Bug-AGL: SPEC-3410 Signed-off-by: Walter Lozano Change-Id: Ief2e69960b3e13c1d5085581d1a7c7b3e73570c0 Reviewed-on: https://gerrit.automotivelinux.org/gerrit/c/AGL/meta-agl/+/25164 Tested-by: Jenkins Job builder account ci-image-build: Jenkins Job builder account ci-image-boot-test: Jenkins Job builder account Reviewed-by: Jan-Simon Moeller --- ...9-alsa-adjust-delay-depending-on-hardware.patch | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 meta-pipewire/recipes-multimedia/pipewire/pipewire/0009-alsa-adjust-delay-depending-on-hardware.patch (limited to 'meta-pipewire/recipes-multimedia/pipewire/pipewire/0009-alsa-adjust-delay-depending-on-hardware.patch') diff --git a/meta-pipewire/recipes-multimedia/pipewire/pipewire/0009-alsa-adjust-delay-depending-on-hardware.patch b/meta-pipewire/recipes-multimedia/pipewire/pipewire/0009-alsa-adjust-delay-depending-on-hardware.patch new file mode 100644 index 000000000..a448063f1 --- /dev/null +++ b/meta-pipewire/recipes-multimedia/pipewire/pipewire/0009-alsa-adjust-delay-depending-on-hardware.patch @@ -0,0 +1,64 @@ +From 38cdfa4483de4c2e91bfccb9c22ec72d9c3720f4 Mon Sep 17 00:00:00 2001 +From: Walter Lozano +Date: Sat, 22 Aug 2020 11:51:30 -0300 +Subject: [PATCH 9/9] alsa: adjust delay depending on hardware + +Currently PipeWire is able to reproduce audio in systems where +DMA granularity is not burst but it could face an xrun. + +In order to mitigate this issue, adjust the delay PipeWire +calculates to make sure that a period is available in the buffer +when snd_pcm_hw_params_is_batch == 1. + +Signed-off-by: Walter Lozano +--- + spa/plugins/alsa/alsa-pcm.c | 12 +++++++++++- + spa/plugins/alsa/alsa-pcm.h | 1 + + 2 files changed, 12 insertions(+), 1 deletion(-) + +diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c +index 92ef2151..1f15085f 100644 +--- a/spa/plugins/alsa/alsa-pcm.c ++++ b/spa/plugins/alsa/alsa-pcm.c +@@ -462,8 +462,9 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_ + state->frame_size = info->channels * (snd_pcm_format_physical_width(format) / 8); + + dir = 0; ++ state->pcm_is_batch = snd_pcm_hw_params_is_batch(params); + period_size = 1024; +- if (snd_pcm_hw_params_is_batch(params)) { ++ if (state->pcm_is_batch) { + period_size = 512; + spa_log_warn(state->log, NAME" hardware does double buffering, changing period_size to %ld", period_size); + } +@@ -639,6 +640,15 @@ static int get_status(struct state *state, snd_pcm_uframes_t *delay, snd_pcm_ufr + + if (state->stream == SND_PCM_STREAM_PLAYBACK) { + *delay = state->buffer_frames - avail; ++ if (state->pcm_is_batch) { ++ /* In this case, as we don't have a good granularity in the ++ * avail report try to compensate this by tweaking the delay ++ * and make sure that a period is available in the buffer */ ++ if (*delay > state->period_frames) ++ *delay = *delay - state->period_frames; ++ else ++ *delay = 0; ++ } + } + else { + *delay = avail; +diff --git a/spa/plugins/alsa/alsa-pcm.h b/spa/plugins/alsa/alsa-pcm.h +index b7a2dd29..3b5c0d7b 100644 +--- a/spa/plugins/alsa/alsa-pcm.h ++++ b/spa/plugins/alsa/alsa-pcm.h +@@ -100,6 +100,7 @@ struct state { + + bool have_format; + struct spa_audio_info current_format; ++ bool pcm_is_batch; + + snd_pcm_uframes_t buffer_frames; + snd_pcm_uframes_t period_frames; +-- +2.20.1 + -- cgit 1.2.3-korg