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;
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)
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);
}
/**
- * \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);
}
/**
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)
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,
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)
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,
#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);
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;
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,
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);
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)
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,
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)
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,
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;
}
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,
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)
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,
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;
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;
}
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,
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)
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,