Here's a patch that adds the idea of a stream "class" to alsa-streams. It's
against alsa-plugins-1.0.14a. All it does is prepend the name of the ALSA
stream with the class that you indicated. You can put a default class in the
asound.conf file, and also reconfigure it on the fly.

Asound.conf example:

pcm.pulse{
       type pulse
       class app
}

Runtime configuration example:

* 1:*     int err;
* 2:*     snd_config_t* classconf;
* 3:*
* 4:*     snd_config_update();
* 5:*     //you can replace "pulse" with "default" if pulse is set up
as your default device
* 6:*     err=snd_config_search(snd_config, "pcm.pulse.class", &classconf);
* 7:*
* 8:*     if(!err)
* 9:*         snd_config_set_string(classconf, "alert");
*10:*     else
*11:*     {
*12:*         snd_config_make(&classconf, "pcm.pulse.class",
SND_CONFIG_TYPE_STRING);
*13:*         snd_config_set_string(classconf, "alert");
*14:*         snd_config_add(snd_config, classconf);
*15:*     }

Let me know if you have any problems or questions.

Justin
diff -Naur alsa-plugins-1.0.14/pulse/pcm_pulse.c alsa-plugins-1.0.14.patched/pulse/pcm_pulse.c
--- alsa-plugins-1.0.14/pulse/pcm_pulse.c	2007-05-31 01:06:51.000000000 -0700
+++ alsa-plugins-1.0.14.patched/pulse/pcm_pulse.c	2007-07-03 20:06:22.000000000 -0700
@@ -32,6 +32,7 @@
     snd_pulse_t *p;
 
     char *device;
+    char *class;
 
     /* Since ALSA expects a ring buffer we must do some voodoo. */
     size_t last_size;
@@ -430,6 +431,7 @@
     pa_channel_map map;
     snd_pcm_pulse_t *pcm = io->private_data;
     int err = 0;
+    char* strmname;
 
     assert(pcm);
     assert(pcm->p);
@@ -450,12 +452,56 @@
     assert(pcm->stream == NULL);
 
     if (io->stream == SND_PCM_STREAM_PLAYBACK)
-        pcm->stream = pa_stream_new(pcm->p->context, "ALSA Playback", &pcm->ss,
+    {
+        /* 
+         * Added to support different "classes" that can be attenuated
+         * accordingly using module-match
+         */
+        if (pcm->class)
+        {
+            strmname = malloc(strlen(pcm->class)+14);
+            memset(strmname, 0, strlen(pcm->class) + 14);
+            strcat(strmname, pcm->class);
+            strcat(strmname, ":ALSA Playback");
+        }
+        else
+        {
+           strmname = malloc(13);
+           memset(strmname, 0, 13);
+           strcat(strmname, "ALSA Playback");
+        }
+        /*******End of additions*****/
+
+        pcm->stream = pa_stream_new(pcm->p->context, strmname, &pcm->ss,
             pa_channel_map_init_auto(&map, pcm->ss.channels, PA_CHANNEL_MAP_ALSA));
+        free(strmname);
+    }
     else
-        pcm->stream = pa_stream_new(pcm->p->context, "ALSA Capture", &pcm->ss,
+    {
+        /* 
+         * Added to support different "classes" that can be attenuated
+         * accordingly using module-match
+         */
+        if (pcm->class)
+        {
+            strmname = malloc(strlen(pcm->class)+13);
+            memset(strmname, 0, strlen(pcm->class) + 13);
+            strcat(strmname, pcm->class);
+            strcat(strmname, ":ALSA Capture");
+        }
+        else
+        {
+           strmname = malloc(12);
+           memset(strmname, 0, 12);
+           strcat(strmname, "ALSA Capture");
+        }
+        /*******End of additions*****/
+
+        pcm->stream = pa_stream_new(pcm->p->context, strmname, &pcm->ss,
             pa_channel_map_init_auto(&map, pcm->ss.channels, PA_CHANNEL_MAP_ALSA));
     assert(pcm->stream);
+        free(strmname);
+    }
 
     pa_stream_set_state_callback(pcm->stream, pulse_stream_state_cb, pcm->p);
 
@@ -567,6 +613,9 @@
     if (pcm->device)
         free(pcm->device);
 
+    if (pcm->class)
+        free(pcm->class);
+
 	free(pcm);
 
 	return 0;
@@ -656,6 +705,7 @@
 	snd_config_iterator_t i, next;
 	const char *server = NULL;
 	const char *device = NULL;
+    const char *class = NULL;
 	int err;
 	snd_pcm_pulse_t *pcm;
 
@@ -680,6 +730,13 @@
             }
             continue;
         }
+        if (strcmp(id, "class") == 0) {
+            if (snd_config_get_string(n, &class) < 0) {
+                SNDERR("Invalid type for %s", id);
+                return -EINVAL;
+            }
+            continue;
+        }
 		SNDERR("Unknown field %s", id);
 		return -EINVAL;
 	}
@@ -689,6 +746,9 @@
     if (device)
         pcm->device = strdup(device);
 
+    if (class)
+        pcm->class = strdup(class);
+
     pcm->p = pulse_new();
     if (!pcm->p) {
         err = -EIO;
_______________________________________________
pulseaudio-discuss mailing list
[email protected]
https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss

Reply via email to