mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-06 13:29:59 -05:00
Removed snd_pcm_hwptr().
Added snd_pcm_hwdiff() and snd_pcm_forward(). Returned the behaviour for snd_pcm_mmap_begin().
This commit is contained in:
parent
fbd99fdec0
commit
2dab1dfbc3
17 changed files with 327 additions and 246 deletions
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* \file pcm/pcm_share.c
|
||||
* \ingroup PCM_Plugins
|
||||
* \brief PCM Share Plugin Interface
|
||||
|
|
@ -737,36 +737,6 @@ static int snd_pcm_share_hwsync(snd_pcm_t *pcm)
|
|||
return err;
|
||||
}
|
||||
|
||||
static int _snd_pcm_share_hwptr(snd_pcm_t *pcm, snd_pcm_uframes_t *hwptr)
|
||||
{
|
||||
snd_pcm_share_t *share = pcm->private_data;
|
||||
snd_pcm_share_slave_t *slave = share->slave;
|
||||
switch (share->state) {
|
||||
case SND_PCM_STATE_RUNNING:
|
||||
case SND_PCM_STATE_DRAINING:
|
||||
case SND_PCM_STATE_PREPARED:
|
||||
case SND_PCM_STATE_PAUSED:
|
||||
case SND_PCM_STATE_SUSPENDED:
|
||||
*hwptr = *pcm->hw.ptr;
|
||||
return 0;
|
||||
case SND_PCM_STATE_XRUN:
|
||||
return -EPIPE;
|
||||
default:
|
||||
return -EBADFD;
|
||||
}
|
||||
}
|
||||
|
||||
static int snd_pcm_share_hwptr(snd_pcm_t *pcm, snd_pcm_uframes_t *hwptr)
|
||||
{
|
||||
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_hwptr(pcm, hwptr);
|
||||
Pthread_mutex_unlock(&slave->mutex);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int _snd_pcm_share_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
|
||||
{
|
||||
snd_pcm_share_t *share = pcm->private_data;
|
||||
|
|
@ -1027,19 +997,15 @@ static snd_pcm_sframes_t _snd_pcm_share_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t
|
|||
}
|
||||
n = snd_pcm_mmap_hw_avail(pcm);
|
||||
assert(n >= 0);
|
||||
if (n > 0) {
|
||||
if ((snd_pcm_uframes_t)n > frames)
|
||||
n = frames;
|
||||
frames -= n;
|
||||
}
|
||||
if (share->state == SND_PCM_STATE_RUNNING &&
|
||||
frames > 0) {
|
||||
int ret = snd_pcm_rewind(slave->pcm, frames);
|
||||
if ((snd_pcm_uframes_t)n > frames)
|
||||
frames = n;
|
||||
if (share->state == SND_PCM_STATE_RUNNING && frames > 0) {
|
||||
snd_pcm_sframes_t ret = snd_pcm_rewind(slave->pcm, frames);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
n += ret;
|
||||
frames = ret;
|
||||
}
|
||||
snd_pcm_mmap_appl_backward(pcm, n);
|
||||
snd_pcm_mmap_appl_backward(pcm, frames);
|
||||
_snd_pcm_share_update(pcm);
|
||||
return n;
|
||||
}
|
||||
|
|
@ -1055,6 +1021,52 @@ static snd_pcm_sframes_t snd_pcm_share_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t
|
|||
return ret;
|
||||
}
|
||||
|
||||
static snd_pcm_sframes_t _snd_pcm_share_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
|
||||
{
|
||||
snd_pcm_share_t *share = pcm->private_data;
|
||||
snd_pcm_share_slave_t *slave = share->slave;
|
||||
snd_pcm_sframes_t n;
|
||||
switch (share->state) {
|
||||
case SND_PCM_STATE_RUNNING:
|
||||
break;
|
||||
case SND_PCM_STATE_PREPARED:
|
||||
if (pcm->stream != SND_PCM_STREAM_PLAYBACK)
|
||||
return -EBADFD;
|
||||
break;
|
||||
case SND_PCM_STATE_DRAINING:
|
||||
if (pcm->stream != SND_PCM_STREAM_CAPTURE)
|
||||
return -EBADFD;
|
||||
break;
|
||||
case SND_PCM_STATE_XRUN:
|
||||
return -EPIPE;
|
||||
default:
|
||||
return -EBADFD;
|
||||
}
|
||||
n = snd_pcm_mmap_avail(pcm);
|
||||
if ((snd_pcm_uframes_t)n > frames)
|
||||
frames = n;
|
||||
if (share->state == SND_PCM_STATE_RUNNING && frames > 0) {
|
||||
snd_pcm_sframes_t ret = snd_pcm_forward(slave->pcm, frames);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
frames = ret;
|
||||
}
|
||||
snd_pcm_mmap_appl_forward(pcm, frames);
|
||||
_snd_pcm_share_update(pcm);
|
||||
return n;
|
||||
}
|
||||
|
||||
static snd_pcm_sframes_t snd_pcm_share_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
|
||||
{
|
||||
snd_pcm_share_t *share = pcm->private_data;
|
||||
snd_pcm_share_slave_t *slave = share->slave;
|
||||
snd_pcm_sframes_t ret;
|
||||
Pthread_mutex_lock(&slave->mutex);
|
||||
ret = _snd_pcm_share_forward(pcm, frames);
|
||||
Pthread_mutex_unlock(&slave->mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Warning: take the mutex before to call this */
|
||||
static void _snd_pcm_share_stop(snd_pcm_t *pcm, snd_pcm_state_t state)
|
||||
{
|
||||
|
|
@ -1264,7 +1276,6 @@ static snd_pcm_fast_ops_t snd_pcm_share_fast_ops = {
|
|||
status: snd_pcm_share_status,
|
||||
state: snd_pcm_share_state,
|
||||
hwsync: snd_pcm_share_hwsync,
|
||||
hwptr: snd_pcm_share_hwptr,
|
||||
delay: snd_pcm_share_delay,
|
||||
prepare: snd_pcm_share_prepare,
|
||||
reset: snd_pcm_share_reset,
|
||||
|
|
@ -1277,6 +1288,7 @@ static snd_pcm_fast_ops_t snd_pcm_share_fast_ops = {
|
|||
readi: snd_pcm_mmap_readi,
|
||||
readn: snd_pcm_mmap_readn,
|
||||
rewind: snd_pcm_share_rewind,
|
||||
forward: snd_pcm_share_forward,
|
||||
resume: snd_pcm_share_resume,
|
||||
avail_update: snd_pcm_share_avail_update,
|
||||
mmap_commit: snd_pcm_share_mmap_commit,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue