Skip to content

Commit

Permalink
ALSA: pcm: Preprocess PAUSED or SUSPENDED stream before PREPARE
Browse files Browse the repository at this point in the history
Calling PREPARE ioctl to the stream in either PAUSED or SUSPENDED
state may confuse some drivers that don't handle the state properly.
Instead of fixing each driver, PCM core should take care of the proper
state change before actually trying to (re-)prepare the stream.
Namely, when the stream is in PAUSED state, it triggers PAUSE_RELEASE,
and when in SUSPENDED state, it triggers STOP, before calling prepare
callbacks.

Reviewed-by: Takashi Sakamoto <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
tiwai committed Jun 14, 2017
1 parent 4b95ff7 commit 1b745cd
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sound/core/pcm_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,17 @@ static int snd_pcm_prepare(struct snd_pcm_substream *substream,
else
f_flags = substream->f_flags;

snd_pcm_stream_lock_irq(substream);
switch (substream->runtime->status->state) {
case SNDRV_PCM_STATE_PAUSED:
snd_pcm_pause(substream, 0);
/* fallthru */
case SNDRV_PCM_STATE_SUSPENDED:
snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP);
break;
}
snd_pcm_stream_unlock_irq(substream);

return snd_pcm_action_nonatomic(&snd_pcm_action_prepare,
substream, f_flags);
}
Expand Down

0 comments on commit 1b745cd

Please sign in to comment.