Replaced snd_pcm_avail() with snd_pcm_hwsync()

This commit is contained in:
Jaroslav Kysela 2002-10-12 11:49:53 +00:00
parent dac0626b9f
commit 8205a95376
14 changed files with 48 additions and 67 deletions

View file

@ -468,6 +468,9 @@ static int pcm_shm_cmd(client_t *client)
case SND_PCM_IOCTL_STATE: case SND_PCM_IOCTL_STATE:
ctrl->result = snd_pcm_state(pcm); ctrl->result = snd_pcm_state(pcm);
break; break;
case SND_PCM_IOCTL_HWSYNC:
ctrl->result = snd_pcm_hwsync(pcm);
break;
case SNDRV_PCM_IOCTL_DELAY: case SNDRV_PCM_IOCTL_DELAY:
ctrl->result = snd_pcm_delay(pcm, (snd_pcm_sframes_t *) &ctrl->u.delay.frames); ctrl->result = snd_pcm_delay(pcm, (snd_pcm_sframes_t *) &ctrl->u.delay.frames);
break; break;

View file

@ -39,7 +39,7 @@ typedef enum _snd_transport_type {
SND_TRANSPORT_TYPE_TCP, SND_TRANSPORT_TYPE_TCP,
} snd_transport_type_t; } 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_STATE _IO ('A', 0xf1)
#define SND_PCM_IOCTL_MMAP _IO ('A', 0xf2) #define SND_PCM_IOCTL_MMAP _IO ('A', 0xf2)
#define SND_PCM_IOCTL_MUNMAP _IO ('A', 0xf3) #define SND_PCM_IOCTL_MUNMAP _IO ('A', 0xf3)

View file

@ -405,7 +405,7 @@ int snd_pcm_drop(snd_pcm_t *pcm);
int snd_pcm_drain(snd_pcm_t *pcm); int snd_pcm_drain(snd_pcm_t *pcm);
int snd_pcm_pause(snd_pcm_t *pcm, int enable); int snd_pcm_pause(snd_pcm_t *pcm, int enable);
snd_pcm_state_t snd_pcm_state(snd_pcm_t *pcm); 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_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp);
int snd_pcm_resume(snd_pcm_t *pcm); int snd_pcm_resume(snd_pcm_t *pcm);
snd_pcm_sframes_t snd_pcm_avail_update(snd_pcm_t *pcm); snd_pcm_sframes_t snd_pcm_avail_update(snd_pcm_t *pcm);

View file

@ -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 pcm PCM handle
* \param availp Returned available frames
* \return 0 on success otherwise a negative error code * \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 * Note this function does not update the actual r/w pointer
* for applications. The function \link ::snd_pcm_avail_update \endlink * for applications. The function \link ::snd_pcm_avail_update \endlink
* have to be called before any read/write/begin+commit operation. * 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);
assert(pcm->setup); assert(pcm->setup);
return pcm->fast_ops->avail(pcm->fast_op_arg, availp); return pcm->fast_ops->hwsync(pcm->fast_op_arg);
} }
/** /**

View file

@ -162,10 +162,10 @@ static snd_pcm_state_t snd_pcm_file_state(snd_pcm_t *pcm)
return snd_pcm_state(file->slave); 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; 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 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 = { static snd_pcm_fast_ops_t snd_pcm_file_fast_ops = {
status: snd_pcm_file_status, status: snd_pcm_file_status,
state: snd_pcm_file_state, state: snd_pcm_file_state,
avail: snd_pcm_file_avail, hwsync: snd_pcm_file_hwsync,
delay: snd_pcm_file_delay, delay: snd_pcm_file_delay,
prepare: snd_pcm_file_prepare, prepare: snd_pcm_file_prepare,
reset: snd_pcm_file_reset, reset: snd_pcm_file_reset,

View file

@ -116,10 +116,10 @@ static snd_pcm_state_t snd_pcm_hooks_state(snd_pcm_t *pcm)
return snd_pcm_state(h->slave); 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; 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 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 = { static snd_pcm_fast_ops_t snd_pcm_hooks_fast_ops = {
status: snd_pcm_hooks_status, status: snd_pcm_hooks_status,
state: snd_pcm_hooks_state, state: snd_pcm_hooks_state,
avail: snd_pcm_hooks_avail, hwsync: snd_pcm_hooks_hwsync,
delay: snd_pcm_hooks_delay, delay: snd_pcm_hooks_delay,
prepare: snd_pcm_hooks_prepare, prepare: snd_pcm_hooks_prepare,
reset: snd_pcm_hooks_reset, reset: snd_pcm_hooks_reset,

View file

@ -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_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_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_HWSYNC _IO ('A', 0x22)
#define SND_PCM_IOCTL_XRUN _IO ('A', 0x48) #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 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); 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; 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; snd_pcm_hw_t *hw = pcm->private_data;
int fd = hw->fd; int fd = hw->fd;
if (SNDRV_PROTOCOL_VERSION(2, 0, 3) <= hw->version) { if (SNDRV_PROTOCOL_VERSION(2, 0, 3) <= hw->version) {
if (ioctl(fd, SND_PCM_IOCTL_AVAIL, availp) < 0) { if (ioctl(fd, SND_PCM_IOCTL_HWSYNC) < 0) {
// SYSERR("SND_PCM_IOCTL_AVAIL failed"); // SYSERR("SND_PCM_IOCTL_HWSYNC failed");
return -errno; return -errno;
} }
} else { } else {
snd_pcm_sframes_t delay; snd_pcm_sframes_t delay;
int err = snd_pcm_hw_delay(pcm, &delay); int err = snd_pcm_hw_delay(pcm, &delay);
if (err < 0) { if (err < 0) {
delay = snd_pcm_hw_avail_update(pcm); switch (snd_pcm_state(pcm)) {
if (delay < 0) case SND_PCM_STATE_PREPARED:
return delay; case SND_PCM_STATE_SUSPENDED:
*availp = delay; return 0;
} else { default:
delay = pcm->stream == SND_PCM_STREAM_PLAYBACK ? pcm->buffer_size - delay : delay; return err;
if (delay < 0) }
delay = 0;
*availp = delay;
} }
} }
return 0; 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 = { static snd_pcm_fast_ops_t snd_pcm_hw_fast_ops = {
status: snd_pcm_hw_status, status: snd_pcm_hw_status,
state: snd_pcm_hw_state, state: snd_pcm_hw_state,
avail: snd_pcm_hw_avail, hwsync: snd_pcm_hw_hwsync,
delay: snd_pcm_hw_delay, delay: snd_pcm_hw_delay,
prepare: snd_pcm_hw_prepare, prepare: snd_pcm_hw_prepare,
reset: snd_pcm_hw_reset, reset: snd_pcm_hw_reset,

View file

@ -144,7 +144,7 @@ typedef struct {
int (*drain)(snd_pcm_t *pcm); int (*drain)(snd_pcm_t *pcm);
int (*pause)(snd_pcm_t *pcm, int enable); int (*pause)(snd_pcm_t *pcm, int enable);
snd_pcm_state_t (*state)(snd_pcm_t *pcm); 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 (*delay)(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp);
int (*resume)(snd_pcm_t *pcm); int (*resume)(snd_pcm_t *pcm);
snd_pcm_sframes_t (*rewind)(snd_pcm_t *pcm, snd_pcm_uframes_t frames); snd_pcm_sframes_t (*rewind)(snd_pcm_t *pcm, snd_pcm_uframes_t frames);

View file

@ -319,10 +319,10 @@ static snd_pcm_state_t snd_pcm_meter_state(snd_pcm_t *pcm)
return snd_pcm_state(meter->slave); 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; 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 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 = { static snd_pcm_fast_ops_t snd_pcm_meter_fast_ops = {
status: snd_pcm_meter_status, status: snd_pcm_meter_status,
state: snd_pcm_meter_state, state: snd_pcm_meter_state,
avail: snd_pcm_meter_avail, hwsync: snd_pcm_meter_hwsync,
delay: snd_pcm_meter_delay, delay: snd_pcm_meter_delay,
prepare: snd_pcm_meter_prepare, prepare: snd_pcm_meter_prepare,
reset: snd_pcm_meter_reset, reset: snd_pcm_meter_reset,

View file

@ -351,11 +351,11 @@ static snd_pcm_state_t snd_pcm_multi_state(snd_pcm_t *pcm)
return snd_pcm_state(slave); 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_multi_t *multi = pcm->private_data;
snd_pcm_t *slave = multi->slaves[0].pcm; 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 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 = { static snd_pcm_fast_ops_t snd_pcm_multi_fast_ops = {
status: snd_pcm_multi_status, status: snd_pcm_multi_status,
state: snd_pcm_multi_state, state: snd_pcm_multi_state,
avail: snd_pcm_multi_avail, hwsync: snd_pcm_multi_hwsync,
delay: snd_pcm_multi_delay, delay: snd_pcm_multi_delay,
prepare: snd_pcm_multi_prepare, prepare: snd_pcm_multi_prepare,
reset: snd_pcm_multi_reset, reset: snd_pcm_multi_reset,

View file

@ -102,9 +102,8 @@ static snd_pcm_state_t snd_pcm_null_state(snd_pcm_t *pcm)
return null->state; 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; 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 = { static snd_pcm_fast_ops_t snd_pcm_null_fast_ops = {
status: snd_pcm_null_status, status: snd_pcm_null_status,
state: snd_pcm_null_state, state: snd_pcm_null_state,
avail: snd_pcm_null_avail, hwsync: snd_pcm_null_hwsync,
delay: snd_pcm_null_delay, delay: snd_pcm_null_delay,
prepare: snd_pcm_null_prepare, prepare: snd_pcm_null_prepare,
reset: snd_pcm_null_reset, reset: snd_pcm_null_reset,

View file

@ -188,17 +188,10 @@ snd_pcm_state_t snd_pcm_plugin_state(snd_pcm_t *pcm)
return snd_pcm_state(plugin->slave); 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_plugin_t *plugin = pcm->private_data;
snd_pcm_uframes_t sd; return snd_pcm_hwsync(plugin->slave);
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;
} }
int snd_pcm_plugin_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp) 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 = { snd_pcm_fast_ops_t snd_pcm_plugin_fast_ops = {
status: snd_pcm_plugin_status, status: snd_pcm_plugin_status,
state: snd_pcm_plugin_state, state: snd_pcm_plugin_state,
avail: snd_pcm_plugin_avail, hwsync: snd_pcm_plugin_hwsync,
delay: snd_pcm_plugin_delay, delay: snd_pcm_plugin_delay,
prepare: snd_pcm_plugin_prepare, prepare: snd_pcm_plugin_prepare,
reset: snd_pcm_plugin_reset, reset: snd_pcm_plugin_reset,

View file

@ -713,7 +713,7 @@ static snd_pcm_state_t snd_pcm_share_state(snd_pcm_t *pcm)
return share->state; 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_t *share = pcm->private_data;
snd_pcm_share_slave_t *slave = share->slave; 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: default:
break; 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_t *share = pcm->private_data;
snd_pcm_share_slave_t *slave = share->slave; snd_pcm_share_slave_t *slave = share->slave;
int err; int err;
Pthread_mutex_lock(&slave->mutex); Pthread_mutex_lock(&slave->mutex);
err = _snd_pcm_share_avail(pcm, availp); err = _snd_pcm_share_hwsync(pcm);
Pthread_mutex_unlock(&slave->mutex); Pthread_mutex_unlock(&slave->mutex);
return err; 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 = { static snd_pcm_fast_ops_t snd_pcm_share_fast_ops = {
status: snd_pcm_share_status, status: snd_pcm_share_status,
state: snd_pcm_share_state, state: snd_pcm_share_state,
avail: snd_pcm_share_avail, hwsync: snd_pcm_share_hwsync,
delay: snd_pcm_share_delay, delay: snd_pcm_share_delay,
prepare: snd_pcm_share_prepare, prepare: snd_pcm_share_prepare,
reset: snd_pcm_share_reset, reset: snd_pcm_share_reset,

View file

@ -443,17 +443,12 @@ static snd_pcm_state_t snd_pcm_shm_state(snd_pcm_t *pcm)
return snd_pcm_shm_action(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; snd_pcm_shm_t *shm = pcm->private_data;
volatile snd_pcm_shm_ctrl_t *ctrl = shm->ctrl; volatile snd_pcm_shm_ctrl_t *ctrl = shm->ctrl;
int err; ctrl->cmd = SND_PCM_IOCTL_HWSYNC;
ctrl->cmd = SND_PCM_IOCTL_AVAIL; return snd_pcm_shm_action(pcm);
err = snd_pcm_shm_action(pcm);
if (err < 0)
return err;
*availp = ctrl->u.avail.frames;
return err;
} }
static int snd_pcm_shm_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp) 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 = { static snd_pcm_fast_ops_t snd_pcm_shm_fast_ops = {
status: snd_pcm_shm_status, status: snd_pcm_shm_status,
state: snd_pcm_shm_state, state: snd_pcm_shm_state,
hwsync: snd_pcm_shm_hwsync,
delay: snd_pcm_shm_delay, delay: snd_pcm_shm_delay,
prepare: snd_pcm_shm_prepare, prepare: snd_pcm_shm_prepare,
reset: snd_pcm_shm_reset, reset: snd_pcm_shm_reset,