]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Implement missing htimestamp callbacks
authorTakashi Iwai <tiwai@suse.de>
Tue, 15 Jan 2008 13:29:34 +0000 (14:29 +0100)
committerTakashi Iwai <tiwai@suse.de>
Tue, 15 Jan 2008 13:29:34 +0000 (14:29 +0100)
Implemented the missing htimestamp callbacks for ioplug, rate and null
plugins.

src/pcm/pcm_generic.c
src/pcm/pcm_generic.h
src/pcm/pcm_ioplug.c
src/pcm/pcm_null.c
src/pcm/pcm_rate.c

index fd4b2bd4376b509a190245af8fd546f93b91b3be..85b8d4f87fbd3bfdbb911194c8903d970ee2bd86 100644 (file)
@@ -266,6 +266,28 @@ int snd_pcm_generic_htimestamp(snd_pcm_t *pcm, snd_pcm_uframes_t *avail,
        return snd_pcm_htimestamp(generic->slave, avail, tstamp);
 }
 
+/* stand-alone version - similar like snd_pcm_hw_htimestamp but
+ * taking the tstamp via gettimestamp().
+ */
+int snd_pcm_generic_real_htimestamp(snd_pcm_t *pcm, snd_pcm_uframes_t *avail,
+                                   snd_htimestamp_t *tstamp)
+{
+       snd_pcm_sframes_t avail1;
+       int ok = 0;
+
+       while (1) {
+               avail1 = snd_pcm_avail_update(pcm);
+               if (avail1 < 0)
+                       return avail1;
+               if (ok && (snd_pcm_uframes_t)avail1 == *avail)
+                       break;
+               *avail = avail1;
+               gettimestamp(tstamp, pcm->monotonic);
+               ok = 1;
+       }
+       return 0;
+}
+
 int snd_pcm_generic_mmap(snd_pcm_t *pcm)
 {
        if (pcm->mmap_shadow) {
index a77a5b78e4d5890bb7979d869f837482ed18e16f..9874c1b9a58f3575c4f1a6c523f9256cf5a11c67 100644 (file)
@@ -139,5 +139,7 @@ snd_pcm_sframes_t snd_pcm_generic_mmap_commit(snd_pcm_t *pcm,
 snd_pcm_sframes_t snd_pcm_generic_avail_update(snd_pcm_t *pcm);
 int snd_pcm_generic_htimestamp(snd_pcm_t *pcm, snd_pcm_uframes_t *avail,
                               snd_htimestamp_t *timestamp);
+int snd_pcm_generic_real_htimestamp(snd_pcm_t *pcm, snd_pcm_uframes_t *avail,
+                                   snd_htimestamp_t *tstamp);
 int snd_pcm_generic_mmap(snd_pcm_t *pcm);
 int snd_pcm_generic_munmap(snd_pcm_t *pcm);
index 2d08742e53d1918b3101a2f6c0eab6d53dd95a5f..2a8ce5431a10c6c5430a15d0b0ad6ed636b083f7 100644 (file)
@@ -29,6 +29,7 @@
 #include "pcm_local.h"
 #include "pcm_ioplug.h"
 #include "pcm_ext_parm.h"
+#include "pcm_generic.h"
 
 #ifndef PIC
 /* entry for static linking */
@@ -636,13 +637,6 @@ static snd_pcm_sframes_t snd_pcm_ioplug_avail_update(snd_pcm_t *pcm)
        return (snd_pcm_sframes_t)avail;
 }
 
-static int snd_pcm_ioplug_htimestamp(snd_pcm_t *pcm ATTRIBUTE_UNUSED,
-                                    snd_pcm_uframes_t *avail ATTRIBUTE_UNUSED,
-                                    snd_htimestamp_t *tstamp ATTRIBUTE_UNUSED)
-{
-       return -EIO;    /* not implemented yet */
-}
-
 static int snd_pcm_ioplug_nonblock(snd_pcm_t *pcm, int nonblock)
 {
        ioplug_priv_t *io = pcm->private_data;
@@ -781,7 +775,7 @@ static snd_pcm_fast_ops_t snd_pcm_ioplug_fast_ops = {
        .readn = snd_pcm_ioplug_readn,
        .avail_update = snd_pcm_ioplug_avail_update,
        .mmap_commit = snd_pcm_ioplug_mmap_commit,
-       .htimestamp = snd_pcm_ioplug_htimestamp,
+       .htimestamp = snd_pcm_generic_real_htimestamp,
        .poll_descriptors_count = snd_pcm_ioplug_poll_descriptors_count,
        .poll_descriptors = snd_pcm_ioplug_poll_descriptors,
        .poll_revents = snd_pcm_ioplug_poll_revents,
index 66735150c5cc2bc7bf256394c96456b352c14341..0e84f8d4cd232bc8914372845f1d7ac61be5d88f 100644 (file)
@@ -244,13 +244,6 @@ static snd_pcm_sframes_t snd_pcm_null_avail_update(snd_pcm_t *pcm)
        return pcm->buffer_size;
 }
 
-static int snd_pcm_null_htimestamp(snd_pcm_t *pcm ATTRIBUTE_UNUSED,
-                                  snd_pcm_uframes_t *avail ATTRIBUTE_UNUSED,
-                                  snd_htimestamp_t *tstamp ATTRIBUTE_UNUSED)
-{
-       return -EIO;
-}
-
 static int snd_pcm_null_hw_refine(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params)
 {
        int err = snd_pcm_hw_refine_soft(pcm, params);
@@ -319,7 +312,7 @@ static snd_pcm_fast_ops_t snd_pcm_null_fast_ops = {
        .readn = snd_pcm_null_readn,
        .avail_update = snd_pcm_null_avail_update,
        .mmap_commit = snd_pcm_null_mmap_commit,
-       .htimestamp = snd_pcm_null_htimestamp,
+       .htimestamp = snd_pcm_generic_real_htimestamp,
 };
 
 /**
index 9e589ec2188af2447c5ef33269051970fecbe426..9cf090a5b9a49f38d93c5021b6e258d2c9b65347 100644 (file)
@@ -1020,11 +1020,30 @@ static snd_pcm_sframes_t snd_pcm_rate_avail_update(snd_pcm_t *pcm)
  }
 }
 
-static int snd_pcm_rate_htimestamp(snd_pcm_t *pcm ATTRIBUTE_UNUSED,
-                                  snd_pcm_uframes_t *avail ATTRIBUTE_UNUSED,
-                                  snd_htimestamp_t *tstamp ATTRIBUTE_UNUSED)
+static int snd_pcm_rate_htimestamp(snd_pcm_t *pcm,
+                                  snd_pcm_uframes_t *avail,
+                                  snd_htimestamp_t *tstamp)
 {
-       return -EIO; /* not implemented yet */
+       snd_pcm_rate_t *rate = pcm->private_data;
+       snd_pcm_sframes_t avail1;
+       snd_pcm_uframes_t tmp;
+       int ok = 0, err;
+
+       while (1) {
+               /* the position is from this plugin itself */
+               avail1 = snd_pcm_avail_update(pcm);
+               if (avail1 < 0)
+                       return avail1;
+               if (ok && (snd_pcm_uframes_t)avail1 == *avail)
+                       break;
+               *avail = avail1;
+               /* timestamp is taken from the slave PCM */
+               err = snd_pcm_htimestamp(rate->gen.slave, &tmp, tstamp);
+               if (err < 0)
+                       return err;
+               ok = 1;
+       }
+       return 0;
 }
 
 static int snd_pcm_rate_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)