From: Takashi Iwai Subject: Re: Third time: Unlink PCM resource ? Date: Tue, 07 Jul 2009 17:06:23 +0200 Message-ID: References: <4A1AB98B.9010604@yellowcouch.org> <4A1ADAEF.3070803@yellowcouch.org> <4A1AE302.8080702@yellowcouch.org> <4A1BA500.2080907@yellowcouch.org> 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 mx1.suse.de (cantor.suse.de [195.135.220.2]) by alsa0.perex.cz (Postfix) with ESMTP id BFF822448F for ; Tue, 7 Jul 2009 17:06:23 +0200 (CEST) In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@alsa-project.org Errors-To: alsa-devel-bounces@alsa-project.org To: Werner Van Belle Cc: "alsa-devel@alsa-project.org" List-Id: alsa-devel@alsa-project.org At Tue, 26 May 2009 10:17:41 +0200, I wrote: > > At Tue, 26 May 2009 10:14:56 +0200, > Werner Van Belle wrote: > > > > Takashi Iwai wrote: > > > OK, in a case without exec, we need an explicit call. > > > But I guess snd_pcm_close() isn't appropriate (as Werner experienced) > > > since it calls snd_pcm_drop() there. I guess this call isn't needed > > > as the driver itself takes care? > > > > > You mean: modifying the snd_pcm_close routine to not call snd_pcm_drop ? > > Yes. > > > I guess that might work as well to solve my problem. > > Will such a fix appear in a new alsa release ? > > We need more tests :) I might overlook something. Finally had some time to take a look at this pending issue... Through tests, I found that this can be really a problem, too. The below is a quick fix, adding a new function, snd_pcm_detach(). This works like snd_pcm_close() but without stopping it. Give it a try. If anyone sees a problem with it, let me know. thanks, Takashi --- >From bdbce35b6d582d4ee4a0813190f09232bd8dc02c Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 7 Jul 2009 16:59:09 +0200 Subject: [PATCH] Add snd_pcm_detach() function Added a new function, snd_pcm_detach(). This function closes the given PCM stream without stopping. It's useful for closing the inherited PCM stream after forking without interfering the parent process. Signed-off-by: Takashi Iwai --- include/pcm.h | 1 + src/pcm/pcm.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 0 deletions(-) diff --git a/include/pcm.h b/include/pcm.h index 15e9cb2..9992d53 100644 --- a/include/pcm.h +++ b/include/pcm.h @@ -412,6 +412,7 @@ int snd_pcm_open_lconf(snd_pcm_t **pcm, const char *name, snd_config_t *lconf); int snd_pcm_close(snd_pcm_t *pcm); +int snd_pcm_detach(snd_pcm_t *pcm); const char *snd_pcm_name(snd_pcm_t *pcm); snd_pcm_type_t snd_pcm_type(snd_pcm_t *pcm); snd_pcm_stream_t snd_pcm_stream(snd_pcm_t *pcm); diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index e63bbe9..059840f 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -713,6 +713,22 @@ int snd_pcm_close(snd_pcm_t *pcm) } /** + * \brief close PCM handle without stopping the assigned stream + * \param pcm PCM handle + * \return 0 on success otherwise a negative error code + * + * Closes the specified PCM handle without stopping the stream. + * This can be useful if you need to close and release the inherited + * PCM stream after forking. Unlike snd_pcm_stop(), this function + * doesn't influence the PCM stream of the parent. + */ +int snd_pcm_detach(snd_pcm_t *pcm) +{ + pcm->donot_close = 1; + return snd_pcm_close(pcm); +} + +/** * \brief set nonblock mode * \param pcm PCM handle * \param nonblock 0 = block, 1 = nonblock mode -- 1.6.3.2