]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
ALSA: pcm: Preprocess PAUSED or SUSPENDED stream before PREPARE
authorTakashi Iwai <tiwai@suse.de>
Tue, 24 May 2016 13:40:03 +0000 (15:40 +0200)
committerTakashi Iwai <tiwai@suse.de>
Wed, 14 Jun 2017 05:44:00 +0000 (07:44 +0200)
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 <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/pcm_native.c

index 69cf9b02ac70763a746e3bedb2fe8219f4e45222..0941b9c92b3f0b1c7594fd4102cec1ea73525869 100644 (file)
@@ -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);
 }