OSDN Git Service

pcm_plugin: set the initial hw_ptr/appl_ptr from the child pcm
authorJaroslav Kysela <perex@perex.cz>
Mon, 18 Jan 2021 20:09:43 +0000 (21:09 +0100)
committerJaroslav Kysela <perex@perex.cz>
Wed, 20 Jan 2021 16:04:49 +0000 (17:04 +0100)
The direct plugins (dmix & etc.) sets own initial
hw_ptr and appl_ptr. Use this initial settings
to export correct values in snd_pcm_status().

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
src/pcm/pcm_plugin.c

index 7ed6f25..ff254eb 100644 (file)
@@ -146,15 +146,14 @@ static int snd_pcm_plugin_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
        return 0;
 }
 
-static int snd_pcm_plugin_prepare(snd_pcm_t *pcm)
+static int snd_pcm_plugin_call_init_cb(snd_pcm_t *pcm, snd_pcm_plugin_t *plugin)
 {
-       snd_pcm_plugin_t *plugin = pcm->private_data;
+       snd_pcm_t *slave = plugin->gen.slave;
        int err;
-       err = snd_pcm_prepare(plugin->gen.slave);
-       if (err < 0)
-               return err;
-       *pcm->hw.ptr = 0;
-       *pcm->appl.ptr = 0;
+
+       assert(pcm->boundary == slave->boundary);
+       *pcm->hw.ptr = *slave->hw.ptr;
+       *pcm->appl.ptr = *slave->appl.ptr;
        if (plugin->init) {
                err = plugin->init(pcm);
                if (err < 0)
@@ -163,6 +162,16 @@ static int snd_pcm_plugin_prepare(snd_pcm_t *pcm)
        return 0;
 }
 
+static int snd_pcm_plugin_prepare(snd_pcm_t *pcm)
+{
+       snd_pcm_plugin_t *plugin = pcm->private_data;
+       int err;
+       err = snd_pcm_prepare(plugin->gen.slave);
+       if (err < 0)
+               return err;
+       return snd_pcm_plugin_call_init_cb(pcm, plugin);
+}
+
 static int snd_pcm_plugin_reset(snd_pcm_t *pcm)
 {
        snd_pcm_plugin_t *plugin = pcm->private_data;
@@ -170,14 +179,7 @@ static int snd_pcm_plugin_reset(snd_pcm_t *pcm)
        err = snd_pcm_reset(plugin->gen.slave);
        if (err < 0)
                return err;
-       *pcm->hw.ptr = 0;
-       *pcm->appl.ptr = 0;
-       if (plugin->init) {
-               err = plugin->init(pcm);
-               if (err < 0)
-                       return err;
-       }
-       return 0;
+       return snd_pcm_plugin_call_init_cb(pcm, plugin);
 }
 
 static snd_pcm_sframes_t snd_pcm_plugin_rewindable(snd_pcm_t *pcm)