All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Hofman <pavel.hofman@ivitera.com>
To: "alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>
Cc: Takashi Iwai <tiwai@suse.de>, John Keeping <john@metanate.com>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	Ruslan Bilovol <ruslan.bilovol@gmail.com>,
	Jerome Brunet <jbrunet@baylibre.com>,
	Julian Scheel <julian@jusst.de>,
	Yunhao Tian <t123yh.xyz@gmail.com>,
	Jack Pham <jackp@codeaurora.org>
Subject: Re: Correct stopping capture and playback substreams?
Date: Mon, 3 Jan 2022 09:22:00 +0100	[thread overview]
Message-ID: <9635d70f-dc12-f9ed-29f5-ce34a1d4b112@ivitera.com> (raw)
In-Reply-To: <448e059f-fbac-66ed-204b-f6f9c2c19212@ivitera.com>


Dne 23. 12. 21 v 9:18 Pavel Hofman napsal(a):
> Hi Takashi,
> 
> I am working on stopping alsa streams of audio USB gadget when USB host 
> stops capture/playback/USB cable unplugged.
> 
> For capture I used code from AK4114 SPDIF receiver 
> https://elixir.bootlin.com/linux/latest/source/sound/i2c/other/ak4114.c#L590: 
> 
> 
> static void stop_substream(struct uac_rtd_params *prm)
> {
>      unsigned long _flags;
>      struct snd_pcm_substream *substream;
> 
>      substream = prm->ss;
>      if (substream) {
>          snd_pcm_stream_lock_irqsave(substream, _flags);
>          if (snd_pcm_running(substream))
>              // TODO - correct handling for playback substream?
>              snd_pcm_stop(substream, SNDRV_PCM_STATE_DRAINING);
>          snd_pcm_stream_unlock_irqrestore(substream, _flags);
>      }
> }
> 
> For setup I found calling snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP) 
> (https://elixir.bootlin.com/linux/latest/source/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c#L63) 
>   Or for both capture and playback using SNDRV_PCM_STATE_DISCONNECTED 
> (https://elixir.bootlin.com/linux/latest/source/sound/core/pcm.c#L1103).
> 
> Or perhaps using snd_pcm_dev_disconnect(dev) or snd_pcm_drop(substream)?
> 
> Please what is the recommended way?
> 

Please can I ask for expert view on this issue? E.g. in SoX stopping the 
stream with SNDRV_PCM_STATE_SETUP/SNDRV_PCM_STATE_DRAINING does not stop 
the application, while with SNDRV_PCM_STATE_DISCONNECTED SoX exits with 
non-recoverable status. I am considering implementing both methods and 
letting users choose their suitable snd_pcm_stop operation (none 
(default)/SETUP-DRAINING/DISCONNECTED) for the two events (host 
playback/capture stop, cable disconnection) with a configfs param. Would 
this make sense?

Thanks a lot in advance,

Pavel.

WARNING: multiple messages have this Message-ID (diff)
From: Pavel Hofman <pavel.hofman@ivitera.com>
To: "alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>
Cc: Julian Scheel <julian@jusst.de>, Jack Pham <jackp@codeaurora.org>,
	Takashi Iwai <tiwai@suse.de>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	John Keeping <john@metanate.com>,
	Ruslan Bilovol <ruslan.bilovol@gmail.com>,
	Yunhao Tian <t123yh.xyz@gmail.com>,
	Jerome Brunet <jbrunet@baylibre.com>
Subject: Re: Correct stopping capture and playback substreams?
Date: Mon, 3 Jan 2022 09:22:00 +0100	[thread overview]
Message-ID: <9635d70f-dc12-f9ed-29f5-ce34a1d4b112@ivitera.com> (raw)
In-Reply-To: <448e059f-fbac-66ed-204b-f6f9c2c19212@ivitera.com>


Dne 23. 12. 21 v 9:18 Pavel Hofman napsal(a):
> Hi Takashi,
> 
> I am working on stopping alsa streams of audio USB gadget when USB host 
> stops capture/playback/USB cable unplugged.
> 
> For capture I used code from AK4114 SPDIF receiver 
> https://elixir.bootlin.com/linux/latest/source/sound/i2c/other/ak4114.c#L590: 
> 
> 
> static void stop_substream(struct uac_rtd_params *prm)
> {
>      unsigned long _flags;
>      struct snd_pcm_substream *substream;
> 
>      substream = prm->ss;
>      if (substream) {
>          snd_pcm_stream_lock_irqsave(substream, _flags);
>          if (snd_pcm_running(substream))
>              // TODO - correct handling for playback substream?
>              snd_pcm_stop(substream, SNDRV_PCM_STATE_DRAINING);
>          snd_pcm_stream_unlock_irqrestore(substream, _flags);
>      }
> }
> 
> For setup I found calling snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP) 
> (https://elixir.bootlin.com/linux/latest/source/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c#L63) 
>   Or for both capture and playback using SNDRV_PCM_STATE_DISCONNECTED 
> (https://elixir.bootlin.com/linux/latest/source/sound/core/pcm.c#L1103).
> 
> Or perhaps using snd_pcm_dev_disconnect(dev) or snd_pcm_drop(substream)?
> 
> Please what is the recommended way?
> 

Please can I ask for expert view on this issue? E.g. in SoX stopping the 
stream with SNDRV_PCM_STATE_SETUP/SNDRV_PCM_STATE_DRAINING does not stop 
the application, while with SNDRV_PCM_STATE_DISCONNECTED SoX exits with 
non-recoverable status. I am considering implementing both methods and 
letting users choose their suitable snd_pcm_stop operation (none 
(default)/SETUP-DRAINING/DISCONNECTED) for the two events (host 
playback/capture stop, cable disconnection) with a configfs param. Would 
this make sense?

Thanks a lot in advance,

Pavel.

  reply	other threads:[~2022-01-03  8:22 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-23  8:18 Correct stopping capture and playback substreams? Pavel Hofman
2022-01-03  8:22 ` Pavel Hofman [this message]
2022-01-03  8:22   ` Pavel Hofman
2022-01-03  9:10   ` Jaroslav Kysela
2022-01-03 11:32     ` Pavel Hofman
2022-01-03 12:15       ` Takashi Iwai
2022-01-03 12:15         ` Takashi Iwai
2022-01-03 12:28         ` Jaroslav Kysela
2022-01-03 12:28           ` Jaroslav Kysela
2022-01-03 12:36           ` Takashi Iwai
2022-01-03 12:36             ` Takashi Iwai
2022-01-03 12:54           ` Pavel Hofman
2022-01-03 12:54             ` Pavel Hofman
2022-01-04 15:57             ` John Keeping
2022-01-04 15:57               ` John Keeping
2022-01-04 16:21               ` John Keeping
2022-01-04 16:21                 ` John Keeping
2022-01-05 12:07                 ` Pavel Hofman
2022-01-05 12:07                   ` Pavel Hofman
2022-01-03 12:44         ` Pavel Hofman
2022-01-03 12:44           ` Pavel Hofman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9635d70f-dc12-f9ed-29f5-ce34a1d4b112@ivitera.com \
    --to=pavel.hofman@ivitera.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=jackp@codeaurora.org \
    --cc=jbrunet@baylibre.com \
    --cc=john@metanate.com \
    --cc=julian@jusst.de \
    --cc=linux-usb@vger.kernel.org \
    --cc=ruslan.bilovol@gmail.com \
    --cc=t123yh.xyz@gmail.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.