Skip to contentSkip to conversation

snd_pcm_status() does not update status->avail

PATCH Jonas Holmberg 2 participants 4 messages Oct 9, 2020

lore
Share & tools
lore
#0 lore raw

Hi,
I have a problem with status->avail not being updated when using multiple extplug plugins and softvol. I managed to get it to work with the following patch:

src/pcm/pcm_plugin.c +2 -0
index ea60eb98..89e819d6 100644
@@ -551,6 +551,8 @@ static int snd_pcm_plugin_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
                return err;
        status->appl_ptr = *pcm->appl.ptr;
        status->hw_ptr = *pcm->hw.ptr;
+       status->avail = snd_pcm_mmap_capture_avail(pcm);
+       status->delay = snd_pcm_mmap_capture_delay(pcm);
        return 0;
 }
 

My question is if this is the correct solution?

BR
/Jonas

#1 lore raw

Dne 09. 10. 20 v 16:02 Jonas Holmberg napsal(a):

Quoted 19 lines

Hi,
I have a problem with status->avail not being updated when using multiple extplug plugins and softvol. I managed to get it to work with the following patch:

src/pcm/pcm_plugin.c +2 -0
index ea60eb98..89e819d6 100644
@@ -551,6 +551,8 @@ static int snd_pcm_plugin_status(snd_pcm_t *pcm, 
 snd_pcm_status_t * status)
                 return err;
         status->appl_ptr = *pcm->appl.ptr;
         status->hw_ptr = *pcm->hw.ptr;
+       status->avail = snd_pcm_mmap_capture_avail(pcm);
+       status->delay = snd_pcm_mmap_capture_delay(pcm);
         return 0;
  }
Quoted 1 line

My question is if this is the correct solution?

It seems that nobody is using those status fields. Usually, snd_pcm_avail_update() is used by apps. Anyway, this should be fixed for both directions. The avail should be probably synced to snd_pcm_plugin_avail_update() output:

src/pcm/pcm_plugin.c +0 -0
index ea60eb98..5739cfc2 100644
@@ -541,16 +541,20 @@ static snd_pcm_sframes_t

snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
static int snd_pcm_plugin_status(snd_pcm_t *pcm, snd_pcm_status_t * status)

 {
        snd_pcm_plugin_t *plugin = pcm->private_data;

- snd_pcm_sframes_t err;
+ snd_pcm_sframes_t err, avail;

        /* sync with the latest hw and appl ptrs */
-       snd_pcm_plugin_avail_update(pcm);
+       avail = snd_pcm_plugin_avail_update(pcm);
+       if (avail < 0)

+ return avail;

        err = snd_pcm_status(plugin->gen.slave, status);
        if (err < 0)
                return err;
        status->appl_ptr = *pcm->appl.ptr;
        status->hw_ptr = *pcm->hw.ptr;
+       status->avail = avail;
+       status->delay = snd_pcm_mmap_delay(pcm);
        return 0;

}

Jaroslav

Quoted 4 lines

BR
/Jonas

Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
#2 lore raw
Quoted 35 lines · Jaroslav Kysela

It seems that nobody is using those status fields. Usually, snd_pcm_avail_update() is used by apps. Anyway, this should be fixed for both directions. The avail should be probably synced to snd_pcm_plugin_avail_update() output:

src/pcm/pcm_plugin.c +6 -2
index ea60eb98..5739cfc2 100644
@@ -541,16 +541,20 @@ static snd_pcm_sframes_t
 snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
  static int snd_pcm_plugin_status(snd_pcm_t *pcm, snd_pcm_status_t * 
 status)
  {
         snd_pcm_plugin_t *plugin = pcm->private_data;
-       snd_pcm_sframes_t err;
+       snd_pcm_sframes_t err, avail;
 
         /* sync with the latest hw and appl ptrs */
-       snd_pcm_plugin_avail_update(pcm);
+       avail = snd_pcm_plugin_avail_update(pcm);
+       if (avail < 0)
+               return avail;
 
         err = snd_pcm_status(plugin->gen.slave, status);
         if (err < 0)
                 return err;
         status->appl_ptr = *pcm->appl.ptr;
         status->hw_ptr = *pcm->hw.ptr;
+       status->avail = avail;
+       status->delay = snd_pcm_mmap_delay(pcm);
         return 0;

 }

Quoted 2 lines

                                        Jaroslav

I have tested your patch and it solves my problem. Are you going to push it?

Thanks!
/Jonas

#3 lore raw

Dne 09. 10. 20 v 17:10 Jonas Holmberg napsal(a):

Quoted 38 lines · Jaroslav Kysela
Quoted 37 lines

It seems that nobody is using those status fields. Usually, snd_pcm_avail_update() is used by apps. Anyway, this should be fixed for both
directions. The avail should be probably synced to snd_pcm_plugin_avail_update() output:

src/pcm/pcm_plugin.c +6 -2
index ea60eb98..5739cfc2 100644
@@ -541,16 +541,20 @@ static snd_pcm_sframes_t
 snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
  static int snd_pcm_plugin_status(snd_pcm_t *pcm, snd_pcm_status_t * 
 status)
  {
         snd_pcm_plugin_t *plugin = pcm->private_data;
-       snd_pcm_sframes_t err;
+       snd_pcm_sframes_t err, avail;
 
         /* sync with the latest hw and appl ptrs */
-       snd_pcm_plugin_avail_update(pcm);
+       avail = snd_pcm_plugin_avail_update(pcm);
+       if (avail < 0)
+               return avail;
 
         err = snd_pcm_status(plugin->gen.slave, status);
         if (err < 0)
                 return err;
         status->appl_ptr = *pcm->appl.ptr;
         status->hw_ptr = *pcm->hw.ptr;
+       status->avail = avail;
+       status->delay = snd_pcm_mmap_delay(pcm);
         return 0;

 }

Quoted 4 lines
Quoted 2 lines

                                        Jaroslav

I have tested your patch and it solves my problem. Are you going to push it?

Yes, applied to alsa-lib's repo:

https://lore.kernel.org/alsa-devel/[email protected]/

Thank you for your report.

Jaroslav

Quoted 4 lines

Thanks!
/Jonas

Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.