From 8205a95376d442f916b4eb062e9714e1c45d88ce Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Sat, 12 Oct 2002 11:49:53 +0000 Subject: [PATCH] Replaced snd_pcm_avail() with snd_pcm_hwsync() --- aserver/aserver.c | 3 +++ include/aserver.h | 2 +- include/pcm.h | 2 +- src/pcm/pcm.c | 14 +++----------- src/pcm/pcm_file.c | 6 +++--- src/pcm/pcm_hooks.c | 6 +++--- src/pcm/pcm_hw.c | 28 +++++++++++++--------------- src/pcm/pcm_local.h | 2 +- src/pcm/pcm_meter.c | 6 +++--- src/pcm/pcm_multi.c | 6 +++--- src/pcm/pcm_null.c | 5 ++--- src/pcm/pcm_plugin.c | 13 +++---------- src/pcm/pcm_share.c | 10 +++++----- src/pcm/pcm_shm.c | 12 ++++-------- 14 files changed, 48 insertions(+), 67 deletions(-) diff --git a/aserver/aserver.c b/aserver/aserver.c index 230c9ebf..60af87bf 100644 --- a/aserver/aserver.c +++ b/aserver/aserver.c @@ -468,6 +468,9 @@ static int pcm_shm_cmd(client_t *client) case SND_PCM_IOCTL_STATE: ctrl->result = snd_pcm_state(pcm); break; + case SND_PCM_IOCTL_HWSYNC: + ctrl->result = snd_pcm_hwsync(pcm); + break; case SNDRV_PCM_IOCTL_DELAY: ctrl->result = snd_pcm_delay(pcm, (snd_pcm_sframes_t *) &ctrl->u.delay.frames); break; diff --git a/include/aserver.h b/include/aserver.h index 3561495d..0a2dfbeb 100644 --- a/include/aserver.h +++ b/include/aserver.h @@ -39,7 +39,7 @@ typedef enum _snd_transport_type { SND_TRANSPORT_TYPE_TCP, } snd_transport_type_t; -#define SND_PCM_IOCTL_AVAIL _IOR('A', 0x22, sndrv_pcm_uframes_t) +#define SND_PCM_IOCTL_HWSYNC _IO ('A', 0x22) #define SND_PCM_IOCTL_STATE _IO ('A', 0xf1) #define SND_PCM_IOCTL_MMAP _IO ('A', 0xf2) #define SND_PCM_IOCTL_MUNMAP _IO ('A', 0xf3) diff --git a/include/pcm.h b/include/pcm.h index 0c94caf1..3079787c 100644 --- a/include/pcm.h +++ b/include/pcm.h @@ -405,7 +405,7 @@ int snd_pcm_drop(snd_pcm_t *pcm); int snd_pcm_drain(snd_pcm_t *pcm); int snd_pcm_pause(snd_pcm_t *pcm, int enable); snd_pcm_state_t snd_pcm_state(snd_pcm_t *pcm); -int snd_pcm_avail(snd_pcm_t *pcm, snd_pcm_uframes_t *availp); +int snd_pcm_hwsync(snd_pcm_t *pcm); int snd_pcm_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp); int snd_pcm_resume(snd_pcm_t *pcm); snd_pcm_sframes_t snd_pcm_avail_update(snd_pcm_t *pcm); diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index baea5164..aff878b4 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -859,27 +859,19 @@ snd_pcm_state_t snd_pcm_state(snd_pcm_t *pcm) } /** - * \brief Obtain available frames for a running PCM handle + * \brief Synchronize stream position with hardware * \param pcm PCM handle - * \param availp Returned available frames * \return 0 on success otherwise a negative error code * - * Returns available frames to be filled inside ring buffer. - * This value might be greater than buffer size when - * underrun (playback) or overrun (capture) occurs. - * - * This function returns accurate value, because it updates - * stream position from hardware. - * * Note this function does not update the actual r/w pointer * for applications. The function \link ::snd_pcm_avail_update \endlink * have to be called before any read/write/begin+commit operation. */ -int snd_pcm_avail(snd_pcm_t *pcm, snd_pcm_uframes_t *availp) +int snd_pcm_hwsync(snd_pcm_t *pcm) { assert(pcm); assert(pcm->setup); - return pcm->fast_ops->avail(pcm->fast_op_arg, availp); + return pcm->fast_ops->hwsync(pcm->fast_op_arg); } /** diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c index d8ed59d8..0eee4c32 100644 --- a/src/pcm/pcm_file.c +++ b/src/pcm/pcm_file.c @@ -162,10 +162,10 @@ static snd_pcm_state_t snd_pcm_file_state(snd_pcm_t *pcm) return snd_pcm_state(file->slave); } -static int snd_pcm_file_avail(snd_pcm_t *pcm, snd_pcm_uframes_t *availp) +static int snd_pcm_file_hwsync(snd_pcm_t *pcm) { snd_pcm_file_t *file = pcm->private_data; - return snd_pcm_avail(file->slave, availp); + return snd_pcm_hwsync(file->slave); } static int snd_pcm_file_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp) @@ -412,7 +412,7 @@ static snd_pcm_ops_t snd_pcm_file_ops = { static snd_pcm_fast_ops_t snd_pcm_file_fast_ops = { status: snd_pcm_file_status, state: snd_pcm_file_state, - avail: snd_pcm_file_avail, + hwsync: snd_pcm_file_hwsync, delay: snd_pcm_file_delay, prepare: snd_pcm_file_prepare, reset: snd_pcm_file_reset, diff --git a/src/pcm/pcm_hooks.c b/src/pcm/pcm_hooks.c index 0cd74de0..4770fb9a 100644 --- a/src/pcm/pcm_hooks.c +++ b/src/pcm/pcm_hooks.c @@ -116,10 +116,10 @@ static snd_pcm_state_t snd_pcm_hooks_state(snd_pcm_t *pcm) return snd_pcm_state(h->slave); } -static int snd_pcm_hooks_avail(snd_pcm_t *pcm, snd_pcm_uframes_t *availp) +static int snd_pcm_hooks_hwsync(snd_pcm_t *pcm) { snd_pcm_hooks_t *h = pcm->private_data; - return snd_pcm_avail(h->slave, availp); + return snd_pcm_hwsync(h->slave); } static int snd_pcm_hooks_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp) @@ -298,7 +298,7 @@ static snd_pcm_ops_t snd_pcm_hooks_ops = { static snd_pcm_fast_ops_t snd_pcm_hooks_fast_ops = { status: snd_pcm_hooks_status, state: snd_pcm_hooks_state, - avail: snd_pcm_hooks_avail, + hwsync: snd_pcm_hooks_hwsync, delay: snd_pcm_hooks_delay, prepare: snd_pcm_hooks_prepare, reset: snd_pcm_hooks_reset, diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index b2c872b6..c1e9a348 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -77,8 +77,8 @@ struct sndrv_pcm_hw_params_old { #define SND_PCM_IOCTL_HW_REFINE_OLD _IOWR('A', 0x10, struct sndrv_pcm_hw_params_old) #define SND_PCM_IOCTL_HW_PARAMS_OLD _IOWR('A', 0x11, struct sndrv_pcm_hw_params_old) -#define SND_PCM_IOCTL_AVAIL _IOR('A', 0x22, sndrv_pcm_uframes_t) -#define SND_PCM_IOCTL_XRUN _IO ('A', 0x48) +#define SND_PCM_IOCTL_HWSYNC _IO ('A', 0x22) +#define SND_PCM_IOCTL_XRUN _IO ('A', 0x48) static int use_old_hw_params_ioctl(int fd, unsigned int cmd, snd_pcm_hw_params_t *params); static snd_pcm_sframes_t snd_pcm_hw_avail_update(snd_pcm_t *pcm); @@ -395,28 +395,26 @@ static int snd_pcm_hw_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp) return 0; } -static int snd_pcm_hw_avail(snd_pcm_t *pcm, snd_pcm_uframes_t *availp) +static int snd_pcm_hw_hwsync(snd_pcm_t *pcm) { snd_pcm_hw_t *hw = pcm->private_data; int fd = hw->fd; if (SNDRV_PROTOCOL_VERSION(2, 0, 3) <= hw->version) { - if (ioctl(fd, SND_PCM_IOCTL_AVAIL, availp) < 0) { - // SYSERR("SND_PCM_IOCTL_AVAIL failed"); + if (ioctl(fd, SND_PCM_IOCTL_HWSYNC) < 0) { + // SYSERR("SND_PCM_IOCTL_HWSYNC failed"); return -errno; } } else { snd_pcm_sframes_t delay; int err = snd_pcm_hw_delay(pcm, &delay); if (err < 0) { - delay = snd_pcm_hw_avail_update(pcm); - if (delay < 0) - return delay; - *availp = delay; - } else { - delay = pcm->stream == SND_PCM_STREAM_PLAYBACK ? pcm->buffer_size - delay : delay; - if (delay < 0) - delay = 0; - *availp = delay; + switch (snd_pcm_state(pcm)) { + case SND_PCM_STATE_PREPARED: + case SND_PCM_STATE_SUSPENDED: + return 0; + default: + return err; + } } } return 0; @@ -786,7 +784,7 @@ static snd_pcm_ops_t snd_pcm_hw_ops = { static snd_pcm_fast_ops_t snd_pcm_hw_fast_ops = { status: snd_pcm_hw_status, state: snd_pcm_hw_state, - avail: snd_pcm_hw_avail, + hwsync: snd_pcm_hw_hwsync, delay: snd_pcm_hw_delay, prepare: snd_pcm_hw_prepare, reset: snd_pcm_hw_reset, diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h index 14f9589a..13c0c77d 100644 --- a/src/pcm/pcm_local.h +++ b/src/pcm/pcm_local.h @@ -144,7 +144,7 @@ typedef struct { int (*drain)(snd_pcm_t *pcm); int (*pause)(snd_pcm_t *pcm, int enable); snd_pcm_state_t (*state)(snd_pcm_t *pcm); - int (*avail)(snd_pcm_t *pcm, snd_pcm_uframes_t *availp); + int (*hwsync)(snd_pcm_t *pcm); int (*delay)(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp); int (*resume)(snd_pcm_t *pcm); snd_pcm_sframes_t (*rewind)(snd_pcm_t *pcm, snd_pcm_uframes_t frames); diff --git a/src/pcm/pcm_meter.c b/src/pcm/pcm_meter.c index 820f733f..15b75db1 100644 --- a/src/pcm/pcm_meter.c +++ b/src/pcm/pcm_meter.c @@ -319,10 +319,10 @@ static snd_pcm_state_t snd_pcm_meter_state(snd_pcm_t *pcm) return snd_pcm_state(meter->slave); } -static int snd_pcm_meter_avail(snd_pcm_t *pcm, snd_pcm_uframes_t *availp) +static int snd_pcm_meter_hwsync(snd_pcm_t *pcm) { snd_pcm_meter_t *meter = pcm->private_data; - return snd_pcm_avail(meter->slave, availp); + return snd_pcm_hwsync(meter->slave); } static int snd_pcm_meter_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp) @@ -599,7 +599,7 @@ static snd_pcm_ops_t snd_pcm_meter_ops = { static snd_pcm_fast_ops_t snd_pcm_meter_fast_ops = { status: snd_pcm_meter_status, state: snd_pcm_meter_state, - avail: snd_pcm_meter_avail, + hwsync: snd_pcm_meter_hwsync, delay: snd_pcm_meter_delay, prepare: snd_pcm_meter_prepare, reset: snd_pcm_meter_reset, diff --git a/src/pcm/pcm_multi.c b/src/pcm/pcm_multi.c index 57aca7d1..c52f094e 100644 --- a/src/pcm/pcm_multi.c +++ b/src/pcm/pcm_multi.c @@ -351,11 +351,11 @@ static snd_pcm_state_t snd_pcm_multi_state(snd_pcm_t *pcm) return snd_pcm_state(slave); } -static int snd_pcm_multi_avail(snd_pcm_t *pcm, snd_pcm_uframes_t *availp) +static int snd_pcm_multi_hwsync(snd_pcm_t *pcm) { snd_pcm_multi_t *multi = pcm->private_data; snd_pcm_t *slave = multi->slaves[0].pcm; - return snd_pcm_avail(slave, availp); + return snd_pcm_hwsync(slave); } static int snd_pcm_multi_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp) @@ -601,7 +601,7 @@ static snd_pcm_ops_t snd_pcm_multi_ops = { static snd_pcm_fast_ops_t snd_pcm_multi_fast_ops = { status: snd_pcm_multi_status, state: snd_pcm_multi_state, - avail: snd_pcm_multi_avail, + hwsync: snd_pcm_multi_hwsync, delay: snd_pcm_multi_delay, prepare: snd_pcm_multi_prepare, reset: snd_pcm_multi_reset, diff --git a/src/pcm/pcm_null.c b/src/pcm/pcm_null.c index 3edd58df..78c800d5 100644 --- a/src/pcm/pcm_null.c +++ b/src/pcm/pcm_null.c @@ -102,9 +102,8 @@ static snd_pcm_state_t snd_pcm_null_state(snd_pcm_t *pcm) return null->state; } -static int snd_pcm_null_avail(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_uframes_t *availp) +static int snd_pcm_null_hwsync(snd_pcm_t *pcm ATTRIBUTE_UNUSED) { - *availp = pcm->buffer_size; return 0; } @@ -326,7 +325,7 @@ static snd_pcm_ops_t snd_pcm_null_ops = { static snd_pcm_fast_ops_t snd_pcm_null_fast_ops = { status: snd_pcm_null_status, state: snd_pcm_null_state, - avail: snd_pcm_null_avail, + hwsync: snd_pcm_null_hwsync, delay: snd_pcm_null_delay, prepare: snd_pcm_null_prepare, reset: snd_pcm_null_reset, diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c index 656e41e9..010f26ba 100644 --- a/src/pcm/pcm_plugin.c +++ b/src/pcm/pcm_plugin.c @@ -188,17 +188,10 @@ snd_pcm_state_t snd_pcm_plugin_state(snd_pcm_t *pcm) return snd_pcm_state(plugin->slave); } -int snd_pcm_plugin_avail(snd_pcm_t *pcm, snd_pcm_uframes_t *availp) +int snd_pcm_plugin_hwsync(snd_pcm_t *pcm) { snd_pcm_plugin_t *plugin = pcm->private_data; - snd_pcm_uframes_t sd; - int err = snd_pcm_avail(plugin->slave, &sd); - if (err < 0) - return err; - if (plugin->client_frames) - sd = plugin->client_frames(pcm, sd); - *availp = sd; - return 0; + return snd_pcm_hwsync(plugin->slave); } int snd_pcm_plugin_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp) @@ -640,7 +633,7 @@ int snd_pcm_plugin_hw_params_slave(snd_pcm_t *pcm, snd_pcm_hw_params_t *params) snd_pcm_fast_ops_t snd_pcm_plugin_fast_ops = { status: snd_pcm_plugin_status, state: snd_pcm_plugin_state, - avail: snd_pcm_plugin_avail, + hwsync: snd_pcm_plugin_hwsync, delay: snd_pcm_plugin_delay, prepare: snd_pcm_plugin_prepare, reset: snd_pcm_plugin_reset, diff --git a/src/pcm/pcm_share.c b/src/pcm/pcm_share.c index 2195f175..52f7fea9 100644 --- a/src/pcm/pcm_share.c +++ b/src/pcm/pcm_share.c @@ -713,7 +713,7 @@ static snd_pcm_state_t snd_pcm_share_state(snd_pcm_t *pcm) return share->state; } -static int _snd_pcm_share_avail(snd_pcm_t *pcm, snd_pcm_uframes_t *availp) +static int _snd_pcm_share_hwsync(snd_pcm_t *pcm) { snd_pcm_share_t *share = pcm->private_data; snd_pcm_share_slave_t *slave = share->slave; @@ -723,16 +723,16 @@ static int _snd_pcm_share_avail(snd_pcm_t *pcm, snd_pcm_uframes_t *availp) default: break; } - return snd_pcm_avail(slave->pcm, availp); + return snd_pcm_hwsync(slave->pcm); } -static int snd_pcm_share_avail(snd_pcm_t *pcm, snd_pcm_uframes_t *availp) +static int snd_pcm_share_hwsync(snd_pcm_t *pcm) { snd_pcm_share_t *share = pcm->private_data; snd_pcm_share_slave_t *slave = share->slave; int err; Pthread_mutex_lock(&slave->mutex); - err = _snd_pcm_share_avail(pcm, availp); + err = _snd_pcm_share_hwsync(pcm); Pthread_mutex_unlock(&slave->mutex); return err; } @@ -1233,7 +1233,7 @@ static snd_pcm_ops_t snd_pcm_share_ops = { static snd_pcm_fast_ops_t snd_pcm_share_fast_ops = { status: snd_pcm_share_status, state: snd_pcm_share_state, - avail: snd_pcm_share_avail, + hwsync: snd_pcm_share_hwsync, delay: snd_pcm_share_delay, prepare: snd_pcm_share_prepare, reset: snd_pcm_share_reset, diff --git a/src/pcm/pcm_shm.c b/src/pcm/pcm_shm.c index cf126fbb..a9558e36 100644 --- a/src/pcm/pcm_shm.c +++ b/src/pcm/pcm_shm.c @@ -443,17 +443,12 @@ static snd_pcm_state_t snd_pcm_shm_state(snd_pcm_t *pcm) return snd_pcm_shm_action(pcm); } -static int snd_pcm_shm_avail(snd_pcm_t *pcm, snd_pcm_uframes_t *availp) +static int snd_pcm_shm_hwsync(snd_pcm_t *pcm) { snd_pcm_shm_t *shm = pcm->private_data; volatile snd_pcm_shm_ctrl_t *ctrl = shm->ctrl; - int err; - ctrl->cmd = SND_PCM_IOCTL_AVAIL; - err = snd_pcm_shm_action(pcm); - if (err < 0) - return err; - *availp = ctrl->u.avail.frames; - return err; + ctrl->cmd = SND_PCM_IOCTL_HWSYNC; + return snd_pcm_shm_action(pcm); } static int snd_pcm_shm_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp) @@ -623,6 +618,7 @@ static snd_pcm_ops_t snd_pcm_shm_ops = { static snd_pcm_fast_ops_t snd_pcm_shm_fast_ops = { status: snd_pcm_shm_status, state: snd_pcm_shm_state, + hwsync: snd_pcm_shm_hwsync, delay: snd_pcm_shm_delay, prepare: snd_pcm_shm_prepare, reset: snd_pcm_shm_reset, -- 2.47.1