Skip to contentSkip to conversation

Is there a function I can call from my ISR to tell ALSA to abort playback?

DISCUSSION Timur Tabi 3 participants 9 messages Nov 15, 2007 – Nov 16, 2007

lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

In my ISR, I call snd_pcm_period_elapsed() to tell it that a period has elapsed.
I can also detect if playback has aborted for some reason (e.g. DMA controller
has died). Is there a function I can call in my ISR to tell ALSA to abort playback or capture?

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#1 lore raw
Quoted 5 lines · Timur Tabi

In my ISR, I call snd_pcm_period_elapsed() to tell it that a period has elapsed.
I can also detect if playback has aborted for some reason (e.g. DMA
controller has died). Is there a function I can call in my ISR to tell ALSA to abort playback or capture?

Yes, call snd_pcm_stop() function. The call must be protected with snd_pcm_stream_lock... See to i2c/other/ak4117.c for an example.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project

author
#2 lore raw
Quoted 2 lines · Jaroslav Kysela

Yes, call snd_pcm_stop() function. The call must be protected with snd_pcm_stream_lock... See to i2c/other/ak4117.c for an example.

That code calls snd_pcm_stop() from a timer, not an ISR. Do I need the call to wake_up() as well?

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#3 lore raw

At Thu, 15 Nov 2007 09:00:54 -0600,

Quoted 8 lines · Timur Tabi
Quoted 2 lines · Jaroslav Kysela

Yes, call snd_pcm_stop() function. The call must be protected with snd_pcm_stream_lock... See to i2c/other/ak4117.c for an example.

That code calls snd_pcm_stop() from a timer, not an ISR. Do I need the call to wake_up() as well?

snd_pcm_stop() can be called from ISR, too (e.g. snd_pcm_period_elapsed() may call snd_pcm_stop() when XRUN occurs). You only need to protect it via snd_pcm_stream_lock*().

Takashi

author
#4 lore raw
Quoted 4 lines · Takashi Iwai

At Thu, 15 Nov 2007 09:00:54 -0600,

Quoted 2 lines · Timur Tabi

Jaroslav Kysela wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, call snd_pcm_stop() function. The call must be protected with snd_pcm_stream_lock... See to i2c/other/ak4117.c for an example.

That code calls snd_pcm_stop() from a timer, not an ISR. Do I need the call to wake_up() as well?

snd_pcm_stop() can be called from ISR, too (e.g. snd_pcm_period_elapsed() may call snd_pcm_stop() when XRUN occurs). You only need to protect it via snd_pcm_stream_lock*().

It doesn't seem to do much. Here's the function I wrote:

static void fsl_dma_abort_stream(struct snd_pcm_substream *substream)

{
	unsigned long flags;

	snd_pcm_stream_lock_irqsave(substream, flags);
	if (snd_pcm_running(substream)) {
		snd_pcm_stop(substream, SNDRV_PCM_STATE_DRAINING);
		wake_up(&substream->runtime->sleep);
	}
	snd_pcm_stream_unlock_irqrestore(substream, flags);
}

When I play a file, my DMA controller is incorrectly programmed (test case) and this function gets triggered. The application (aplay) does not terminate.

I tried it with the wake_up() call, but it didn't make a difference.

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#5 lore raw

At Thu, 15 Nov 2007 14:28:14 -0600,

Quoted 17 lines · Timur Tabi
Quoted 4 lines · Takashi Iwai

At Thu, 15 Nov 2007 09:00:54 -0600,

Quoted 2 lines · Timur Tabi

Jaroslav Kysela wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, call snd_pcm_stop() function. The call must be protected with snd_pcm_stream_lock... See to i2c/other/ak4117.c for an example.

That code calls snd_pcm_stop() from a timer, not an ISR. Do I need the call to wake_up() as well?

snd_pcm_stop() can be called from ISR, too (e.g. snd_pcm_period_elapsed() may call snd_pcm_stop() when XRUN occurs). You only need to protect it via snd_pcm_stream_lock*().

It doesn't seem to do much. Here's the function I wrote:

Quoted 7 lines

static void fsl_dma_abort_stream(struct snd_pcm_substream *substream)

{
	unsigned long flags;

	snd_pcm_stream_lock_irqsave(substream, flags);
	if (snd_pcm_running(substream)) {
		snd_pcm_stop(substream, SNDRV_PCM_STATE_DRAINING);

You passed a wrong state. Usually snd_pcm_stop() passes either SNDRV_PCM_STATE_SETUP (for post-draining) or SNDRV_PCM_STATE_XRUN (for errors).

Quoted 4 lines
		wake_up(&substream->runtime->sleep);
	}
	snd_pcm_stream_unlock_irqrestore(substream, flags);
}

This wake_up is superfluous. Now I understand your question in the last mail...

Quoted 2 lines

When I play a file, my DMA controller is incorrectly programmed (test case) and this function gets triggered. The application (aplay) does not terminate.

The app is *not* terminated, of course, but it must get an error when it accesses to the PCM (-EPIPE in the case XRUN).

Takashi

#6 lore raw
Quoted 31 lines · Takashi Iwai

At Thu, 15 Nov 2007 14:28:14 -0600,

Quoted 17 lines · Timur Tabi
Quoted 4 lines · Takashi Iwai

At Thu, 15 Nov 2007 09:00:54 -0600,

Quoted 2 lines · Timur Tabi

Jaroslav Kysela wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, call snd_pcm_stop() function. The call must be protected with snd_pcm_stream_lock... See to i2c/other/ak4117.c for an example.

That code calls snd_pcm_stop() from a timer, not an ISR. Do I need the call to wake_up() as well?

snd_pcm_stop() can be called from ISR, too (e.g. snd_pcm_period_elapsed() may call snd_pcm_stop() when XRUN occurs). You only need to protect it via snd_pcm_stream_lock*().

It doesn't seem to do much. Here's the function I wrote:

Quoted 7 lines

static void fsl_dma_abort_stream(struct snd_pcm_substream *substream)

{
	unsigned long flags;

	snd_pcm_stream_lock_irqsave(substream, flags);
	if (snd_pcm_running(substream)) {
		snd_pcm_stop(substream, SNDRV_PCM_STATE_DRAINING);

You passed a wrong state. Usually snd_pcm_stop() passes either SNDRV_PCM_STATE_SETUP (for post-draining) or SNDRV_PCM_STATE_XRUN (for errors).

Quoted 7 lines
Quoted 4 lines
		wake_up(&substream->runtime->sleep);
	}
	snd_pcm_stream_unlock_irqrestore(substream, flags);
}

This wake_up is superfluous. Now I understand your question in the last mail...

I'm not sure if the wake call is superfluous, if driver ends to call elapsed callbacks, there is no way to wakeup process when it sleeps somewhere. I think that code might be covered with a nice macro with a name like 'snd_pcm_hw_stopped()' or so.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project

#7 lore raw

At Fri, 16 Nov 2007 11:41:51 +0100 (CET),

Quoted 39 lines · Jaroslav Kysela
Quoted 36 lines · Takashi Iwai

At Thu, 15 Nov 2007 14:28:14 -0600,

Quoted 17 lines · Timur Tabi
Quoted 4 lines · Takashi Iwai

At Thu, 15 Nov 2007 09:00:54 -0600,

Quoted 2 lines · Timur Tabi

Jaroslav Kysela wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, call snd_pcm_stop() function. The call must be protected with snd_pcm_stream_lock... See to i2c/other/ak4117.c for an example.

That code calls snd_pcm_stop() from a timer, not an ISR. Do I need the call to wake_up() as well?

snd_pcm_stop() can be called from ISR, too (e.g. snd_pcm_period_elapsed() may call snd_pcm_stop() when XRUN occurs). You only need to protect it via snd_pcm_stream_lock*().

It doesn't seem to do much. Here's the function I wrote:

Quoted 7 lines

static void fsl_dma_abort_stream(struct snd_pcm_substream *substream)

{
	unsigned long flags;

	snd_pcm_stream_lock_irqsave(substream, flags);
	if (snd_pcm_running(substream)) {
		snd_pcm_stop(substream, SNDRV_PCM_STATE_DRAINING);

You passed a wrong state. Usually snd_pcm_stop() passes either SNDRV_PCM_STATE_SETUP (for post-draining) or SNDRV_PCM_STATE_XRUN (for errors).

Quoted 4 lines
		wake_up(&substream->runtime->sleep);
	}
	snd_pcm_stream_unlock_irqrestore(substream, flags);
}
Quoted 7 lines
Quoted 2 lines

This wake_up is superfluous. Now I understand your question in the last mail...

I'm not sure if the wake call is superfluous, if driver ends to call elapsed callbacks, there is no way to wakeup process when it sleeps somewhere. I think that code might be covered with a nice macro with a name like 'snd_pcm_hw_stopped()' or so.

But wake_up() is already in snd_pcm_post_stop(). How can this second call help?

thanks,

Takashi

#8 lore raw
Quoted 44 lines · Takashi Iwai

At Fri, 16 Nov 2007 11:41:51 +0100 (CET),

Quoted 42 lines · Jaroslav Kysela
Quoted 38 lines · Takashi Iwai

At Thu, 15 Nov 2007 14:28:14 -0600,

Quoted 17 lines · Timur Tabi
Quoted 4 lines · Takashi Iwai

At Thu, 15 Nov 2007 09:00:54 -0600,

Quoted 2 lines · Timur Tabi

Jaroslav Kysela wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, call snd_pcm_stop() function. The call must be protected with snd_pcm_stream_lock... See to i2c/other/ak4117.c for an example.

That code calls snd_pcm_stop() from a timer, not an ISR. Do I need the call to wake_up() as well?

snd_pcm_stop() can be called from ISR, too (e.g. snd_pcm_period_elapsed() may call snd_pcm_stop() when XRUN occurs). You only need to protect it via snd_pcm_stream_lock*().

It doesn't seem to do much. Here's the function I wrote:

Quoted 7 lines

static void fsl_dma_abort_stream(struct snd_pcm_substream *substream)

{
	unsigned long flags;

	snd_pcm_stream_lock_irqsave(substream, flags);
	if (snd_pcm_running(substream)) {
		snd_pcm_stop(substream, SNDRV_PCM_STATE_DRAINING);

You passed a wrong state. Usually snd_pcm_stop() passes either SNDRV_PCM_STATE_SETUP (for post-draining) or SNDRV_PCM_STATE_XRUN (for errors).

Quoted 4 lines
		wake_up(&substream->runtime->sleep);
	}
	snd_pcm_stream_unlock_irqrestore(substream, flags);
}

This wake_up is superfluous. Now I understand your question in the last mail...

Quoted 7 lines
Quoted 4 lines

I'm not sure if the wake call is superfluous, if driver ends to call elapsed callbacks, there is no way to wakeup process when it sleeps somewhere. I think that code might be covered with a nice macro with a name like 'snd_pcm_hw_stopped()' or so.

But wake_up() is already in snd_pcm_post_stop(). How can this second call help?

Overlooked. Thanks.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project