From: Takashi Iwai Subject: Re: snd_pcm_hw_params_free() immediately after snd_pcm_hw_params() ??? Date: Thu, 21 Jan 2010 07:59:41 +0100 Message-ID: References: <4f3252891001202032o59ff0bc1q79b023d80c6dcd17@mail.gmail.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 mx1.suse.de (cantor.suse.de [195.135.220.2]) by alsa0.perex.cz (Postfix) with ESMTP id 3EB7810384C for ; Thu, 21 Jan 2010 07:59:42 +0100 (CET) In-Reply-To: <4f3252891001202032o59ff0bc1q79b023d80c6dcd17@mail.gmail.com> 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: Raymond Yau Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org At Thu, 21 Jan 2010 12:32:20 +0800, Raymond Yau wrote: > > Refer to > http://www.alsa-project.org/~tiwai/writing-an-alsa-driver/ch05s06.html#pcm-interface-operators-hw-free-callback > > hw_free callback > > static int snd_xxx_hw_free(struct snd_pcm_substream *substream); > > This is called to release the resources allocated via > *hw_params*. For example, releasing the > buffer via snd_pcm_lib_malloc_pages() is done by > calling the following: > snd_pcm_lib_free_pages(substream); > > This function is always called before the close callback is called. > Also, the callback may be called multiple times, too. > Keep track whether the resource was already released. > Nearly all the examples in those ALSA tutorials in the web sites have the code > > > if ((err = snd_pcm_hw_params (playback_handle, hw_params)) < 0) { > fprintf (stderr, "cannot set parameters (%s)\n", > snd_strerror (err)); > exit (1); > } > > snd_pcm_hw_params_free (hw_params); > > This seem to violate "This function is always called before the close > callback is called." > > and those hardware mixing sound cards (e.g cs46xx , au88x0, ... ) use > snd_xxx_hw_free() to deallocate the hardware mixing path in the DSP. > > There are a number of audio package (e.g. gstreamer , wine , .... ) > call snd_pcm_hw_params_free immediately after snd_pcm_hw_params() > > Is this a bug of snd_pcm_hw_params_free() not change the state of the > PCM stream ? Confusingly, snd_pcm_hw_params_free() and snd_pcm_hw_free() are different. The former is just to free the malloced snd_pcm_hw_params struct while the latter corresponds to snd_xxx_hw_free(). Takashi