From: Takashi Iwai Date: Tue, 15 Jan 2008 13:29:34 +0000 (+0100) Subject: Implement missing htimestamp callbacks X-Git-Tag: v1.0.16rc1~3 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=91fc64cefb427bce0ac49f7acd2f3cf2d68ebb4b;p=alsa-lib.git Implement missing htimestamp callbacks Implemented the missing htimestamp callbacks for ioplug, rate and null plugins. --- diff --git a/src/pcm/pcm_generic.c b/src/pcm/pcm_generic.c index fd4b2bd4..85b8d4f8 100644 --- a/src/pcm/pcm_generic.c +++ b/src/pcm/pcm_generic.c @@ -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) { diff --git a/src/pcm/pcm_generic.h b/src/pcm/pcm_generic.h index a77a5b78..9874c1b9 100644 --- a/src/pcm/pcm_generic.h +++ b/src/pcm/pcm_generic.h @@ -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); diff --git a/src/pcm/pcm_ioplug.c b/src/pcm/pcm_ioplug.c index 2d08742e..2a8ce543 100644 --- a/src/pcm/pcm_ioplug.c +++ b/src/pcm/pcm_ioplug.c @@ -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, diff --git a/src/pcm/pcm_null.c b/src/pcm/pcm_null.c index 66735150..0e84f8d4 100644 --- a/src/pcm/pcm_null.c +++ b/src/pcm/pcm_null.c @@ -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, }; /** diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c index 9e589ec2..9cf090a5 100644 --- a/src/pcm/pcm_rate.c +++ b/src/pcm/pcm_rate.c @@ -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)