ext: alsa: Fix fallback paths for setting buffer and period times
authorDevarsh Thakkar <devarsh.thakkar@xilinx.com>
Thu, 10 Jun 2021 07:55:23 +0000 (00:55 -0700)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 17 Aug 2021 19:52:59 +0000 (19:52 +0000)
commit297b1e68e230bc750fc7c593d4005e06580d5517
treeed1e50982651ccbb7ce8983aa231f9a7829bba89
parentb4a00f78bc438b9a2b0121cc47ae7b6817ea3060
ext: alsa: Fix fallback paths for setting buffer and period times

Below fallback paths were introduced in
https://github.com/GStreamer/gst-plugins-base/commit/9759810d8206b5f1aa199f98599caec3630a1813
if setting period time after buffer time failed :
1) Set period time and then buffer time if it doesn't work
2) Set only buffer time
3) Set only period time

These all were not functioning properly since they were using old
copy of snd_pcm_hw_params_t which already had some fields set
as per previous try and this was causing issues as driver was
referring to that old value while trying to set them again in
fallback paths.

So now we always use the initial copy of snd_pcm_hw_params_t
for every fallback  and same is also being done at
https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/557c4295107dc7374c850b0bd5331dd35e8fdd0f

Also we change the sequence to set period time earlier than
buffer time since period bytes being the smaller unit, most of the times
if underlying alsa device has a dependency then it is of period bytes
to be a multiple of some value (as per underlying DMA constraint)
and rest of the parameters like buffer bytes need to be adjusted
as per period bytes.

The same sequence is also followed in alsa-utils at
https://github.com/alsa-project/alsa-utils/commit/9b621eeac4d55c4e881f093be5b163ca07d01b63

Fix 2) and 3) scenarios by returning success if the exclusive setting is passed
and not doing any further setting for buffer time or period time.

Add new fallback path of not setting any buffer time and period time
if all above fallback paths fail. The same is also being
followed at aforementioned pulseaudio commit.

In case of alsasink, remove the retry goto label, since it is not
required anymore as fallback paths take care of setting default
values if driver is not accepting any of the fallback paths.

Use separate label for exit to free params structs and return err
code. This also fixes leak in no_rate goto path in alsasink

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1212>
ext/alsa/gstalsasink.c
ext/alsa/gstalsasrc.c