mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-18 03:06:43 +00:00
ALSA: pcm: Check PCM state by a common helper function
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
2ae48354a1
commit
6ba63929ae
@ -2019,6 +2019,22 @@ typedef int (*transfer_f)(struct snd_pcm_substream *substream, unsigned int hwof
|
|||||||
unsigned long data, unsigned int off,
|
unsigned long data, unsigned int off,
|
||||||
snd_pcm_uframes_t size);
|
snd_pcm_uframes_t size);
|
||||||
|
|
||||||
|
static int pcm_accessible_state(struct snd_pcm_runtime *runtime)
|
||||||
|
{
|
||||||
|
switch (runtime->status->state) {
|
||||||
|
case SNDRV_PCM_STATE_PREPARED:
|
||||||
|
case SNDRV_PCM_STATE_RUNNING:
|
||||||
|
case SNDRV_PCM_STATE_PAUSED:
|
||||||
|
return 0;
|
||||||
|
case SNDRV_PCM_STATE_XRUN:
|
||||||
|
return -EPIPE;
|
||||||
|
case SNDRV_PCM_STATE_SUSPENDED:
|
||||||
|
return -ESTRPIPE;
|
||||||
|
default:
|
||||||
|
return -EBADFD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream,
|
static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream,
|
||||||
unsigned long data,
|
unsigned long data,
|
||||||
snd_pcm_uframes_t size,
|
snd_pcm_uframes_t size,
|
||||||
@ -2035,21 +2051,9 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
snd_pcm_stream_lock_irq(substream);
|
snd_pcm_stream_lock_irq(substream);
|
||||||
switch (runtime->status->state) {
|
err = pcm_accessible_state(runtime);
|
||||||
case SNDRV_PCM_STATE_PREPARED:
|
if (err < 0)
|
||||||
case SNDRV_PCM_STATE_RUNNING:
|
|
||||||
case SNDRV_PCM_STATE_PAUSED:
|
|
||||||
break;
|
|
||||||
case SNDRV_PCM_STATE_XRUN:
|
|
||||||
err = -EPIPE;
|
|
||||||
goto _end_unlock;
|
goto _end_unlock;
|
||||||
case SNDRV_PCM_STATE_SUSPENDED:
|
|
||||||
err = -ESTRPIPE;
|
|
||||||
goto _end_unlock;
|
|
||||||
default:
|
|
||||||
err = -EBADFD;
|
|
||||||
goto _end_unlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
runtime->twake = runtime->control->avail_min ? : 1;
|
runtime->twake = runtime->control->avail_min ? : 1;
|
||||||
if (runtime->status->state == SNDRV_PCM_STATE_RUNNING)
|
if (runtime->status->state == SNDRV_PCM_STATE_RUNNING)
|
||||||
@ -2085,16 +2089,9 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream,
|
|||||||
snd_pcm_stream_lock_irq(substream);
|
snd_pcm_stream_lock_irq(substream);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto _end_unlock;
|
goto _end_unlock;
|
||||||
switch (runtime->status->state) {
|
err = pcm_accessible_state(runtime);
|
||||||
case SNDRV_PCM_STATE_XRUN:
|
if (err < 0)
|
||||||
err = -EPIPE;
|
|
||||||
goto _end_unlock;
|
goto _end_unlock;
|
||||||
case SNDRV_PCM_STATE_SUSPENDED:
|
|
||||||
err = -ESTRPIPE;
|
|
||||||
goto _end_unlock;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
appl_ptr += frames;
|
appl_ptr += frames;
|
||||||
if (appl_ptr >= runtime->boundary)
|
if (appl_ptr >= runtime->boundary)
|
||||||
appl_ptr -= runtime->boundary;
|
appl_ptr -= runtime->boundary;
|
||||||
@ -2265,27 +2262,14 @@ static snd_pcm_sframes_t snd_pcm_lib_read1(struct snd_pcm_substream *substream,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
snd_pcm_stream_lock_irq(substream);
|
snd_pcm_stream_lock_irq(substream);
|
||||||
switch (runtime->status->state) {
|
err = pcm_accessible_state(runtime);
|
||||||
case SNDRV_PCM_STATE_PREPARED:
|
if (err < 0)
|
||||||
if (size >= runtime->start_threshold) {
|
|
||||||
err = snd_pcm_start(substream);
|
|
||||||
if (err < 0)
|
|
||||||
goto _end_unlock;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SNDRV_PCM_STATE_DRAINING:
|
|
||||||
case SNDRV_PCM_STATE_RUNNING:
|
|
||||||
case SNDRV_PCM_STATE_PAUSED:
|
|
||||||
break;
|
|
||||||
case SNDRV_PCM_STATE_XRUN:
|
|
||||||
err = -EPIPE;
|
|
||||||
goto _end_unlock;
|
|
||||||
case SNDRV_PCM_STATE_SUSPENDED:
|
|
||||||
err = -ESTRPIPE;
|
|
||||||
goto _end_unlock;
|
|
||||||
default:
|
|
||||||
err = -EBADFD;
|
|
||||||
goto _end_unlock;
|
goto _end_unlock;
|
||||||
|
if (runtime->status->state == SNDRV_PCM_STATE_PREPARED &&
|
||||||
|
size >= runtime->start_threshold) {
|
||||||
|
err = snd_pcm_start(substream);
|
||||||
|
if (err < 0)
|
||||||
|
goto _end_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime->twake = runtime->control->avail_min ? : 1;
|
runtime->twake = runtime->control->avail_min ? : 1;
|
||||||
@ -2329,16 +2313,9 @@ static snd_pcm_sframes_t snd_pcm_lib_read1(struct snd_pcm_substream *substream,
|
|||||||
snd_pcm_stream_lock_irq(substream);
|
snd_pcm_stream_lock_irq(substream);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto _end_unlock;
|
goto _end_unlock;
|
||||||
switch (runtime->status->state) {
|
err = pcm_accessible_state(runtime);
|
||||||
case SNDRV_PCM_STATE_XRUN:
|
if (err < 0)
|
||||||
err = -EPIPE;
|
|
||||||
goto _end_unlock;
|
goto _end_unlock;
|
||||||
case SNDRV_PCM_STATE_SUSPENDED:
|
|
||||||
err = -ESTRPIPE;
|
|
||||||
goto _end_unlock;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
appl_ptr += frames;
|
appl_ptr += frames;
|
||||||
if (appl_ptr >= runtime->boundary)
|
if (appl_ptr >= runtime->boundary)
|
||||||
appl_ptr -= runtime->boundary;
|
appl_ptr -= runtime->boundary;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user