[alsa-devel] View alsa-lib plugins setup for any app?

Takashi Iwai tiwai at suse.de
Wed Oct 22 08:39:34 CEST 2008


At Wed, 22 Oct 2008 07:58:45 +0200,
I wrote:
> 
> At Wed, 22 Oct 2008 09:55:01 +1300,
> Eliot Blennerhassett wrote:
> > 
> > On Tuesday 21 October 2008 19:34:49 Takashi Iwai wrote:
> > > Sorry, I don't understand well your question.  Do you want to see the
> > > alsa-plugin chain of a running application from the outside, 
> > 
> > Yes. Basically see something that looks like the result of "aplay -v", but for 
> > a running app from the outside.  
> > 
> > E.g. to see if the app is using dmix, plughw etc, what parameters the app sees 
> > vs how the card is accessed.
> > 
> > Best if this info was available like the proc files for the driver, but if it 
> > required running the app in a special context (debugger-like or LD_PRELOAD) 
> > that would probably still be useful.
> > 
> > The app should not have to be recompiled.
> 
> Well, right now it's almost impossible because the alsa-lib stuff is
> purely a user-space thing and not exposed to anywhere else.
> 
> An easy hack is to add snd_pcm_dump() to snd_pcm_hw_params() in
> alsa-lib (better with a conditional check, such as a certain
> environment variable).  But this function may be called recursively,
> it should have a certain re-entrace check.

... like the patch below.


Takashi

diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
index 59e433f..1c89d7e 100644
--- a/src/pcm/pcm.c
+++ b/src/pcm/pcm.c
@@ -814,11 +814,27 @@ int snd_pcm_hw_params_current(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
 int snd_pcm_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
 {
 	int err;
+	static int enter;
+
 	assert(pcm && params);
+	enter++;
 	err = _snd_pcm_hw_params(pcm, params);
 	if (err < 0)
-		return err;
+		goto out;
 	err = snd_pcm_prepare(pcm);
+ out:
+	enter--;
+	if (!err && !enter) {
+		const char *v = getenv("ALSA_PCM_DUMP");
+		if (v && *v) {
+			snd_output_t *log;
+			err = snd_output_stdio_attach(&log, stderr, 0);
+			if (!err) {
+				snd_pcm_dump(pcm, log);
+				snd_output_close(log);
+			}
+		}
+	}
 	return err;
 }
 


More information about the Alsa-devel mailing list