From: Takashi Iwai Subject: Re: [PATCH 1/2] [ALSA] add SNDRV_PCM_TRIGGER_DRAIN trigger Date: Thu, 18 Dec 2014 09:29:37 +0100 Message-ID: References: <1418888164-41117-1-git-send-email-libin.yang@intel.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 0CA84260528 for ; Thu, 18 Dec 2014 09:29:39 +0100 (CET) In-Reply-To: <1418888164-41117-1-git-send-email-libin.yang@intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: libin.yang@intel.com Cc: liam.r.girdwood@linux.intel.com, alsa-devel@alsa-project.org, broonie@kernel.org List-Id: alsa-devel@alsa-project.org At Thu, 18 Dec 2014 15:36:03 +0800, libin.yang@intel.com wrote: > > From: Libin Yang > > Add SNDRV_PCM_TRIGGER_DRAIN trigger for pcm drain. > > Some audio devices require notification of drain events > in order to properly drain and shutdown an audio stream. > > Signed-off-by: Libin Yang > --- > include/sound/pcm.h | 1 + > sound/core/pcm_native.c | 5 +++++ > 2 files changed, 6 insertions(+) > > diff --git a/include/sound/pcm.h b/include/sound/pcm.h > index 8bb00a2..bb77aa3 100644 > --- a/include/sound/pcm.h > +++ b/include/sound/pcm.h > @@ -109,6 +109,7 @@ struct snd_pcm_ops { > #define SNDRV_PCM_TRIGGER_PAUSE_RELEASE 4 > #define SNDRV_PCM_TRIGGER_SUSPEND 5 > #define SNDRV_PCM_TRIGGER_RESUME 6 > +#define SNDRV_PCM_TRIGGER_DRAIN 7 > > #define SNDRV_PCM_POS_XRUN ((snd_pcm_uframes_t)-1) > > diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c > index 166d59c..15fe682 100644 > --- a/sound/core/pcm_native.c > +++ b/sound/core/pcm_native.c > @@ -1517,6 +1517,11 @@ static int snd_pcm_do_drain_init(struct snd_pcm_substream *substream, int state) > { > struct snd_pcm_runtime *runtime = substream->runtime; > if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { > + > + if (substream->runtime->trigger_master == substream) > + substream->ops->trigger(substream, > + SNDRV_PCM_TRIGGER_DRAIN); The return value check is missing. Besides, this patch will break many drivers. Many of them will spew errors if an unexpected trigger command is issued. So, you have to limit this trigger only to some drivers. A typical workaround is to add a new SNDRV_PCM_INFO_* and issue the trigger only when the flag is set, as done for resume and pause operations. Also, do you want to see this trigger even if the stream isn't started before drain is issued? Also, why no need for this trigger for capture streams? (BTW, while looking at this patch, I found a bug in the current draining code. Will submit the fix...) Takashi