mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
Replaced snd_pcm_avail() with snd_pcm_hwsync()
This commit is contained in:
parent
dac0626b9f
commit
8205a95376
14 changed files with 48 additions and 67 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue