From 61378e271725dfb10a84097e24bb2cda3675385b Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Mon, 30 May 2011 18:45:32 +0200 Subject: Set "cmumble [%user%]" name for sinks if type is pulse --- src/cmumble.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/cmumble.c b/src/cmumble.c index a629fd5..0cb8a97 100644 --- a/src/cmumble.c +++ b/src/cmumble.c @@ -265,12 +265,46 @@ read_cb(GSocket *socket, GIOCondition condition, gpointer data) return TRUE; } +void +set_pulse_states(gpointer data, gpointer user_data) +{ + GstElement *elm = data; + struct user *user = user_data; + GstStructure *props; + gchar *name; + + if (g_strcmp0(G_OBJECT_TYPE_NAME(elm), "GstPulseSink") != 0 || + g_object_class_find_property(G_OBJECT_GET_CLASS(elm), + "stream-properties") == NULL) + goto out; + + /* configure pulseaudio to use: + * load-module module-device-manager "do_routing=1" + * or new users may join to default output which is not headset? + * Also consider setting device.intended_roles = "phone" for your + * wanted default output (if you dont have a usb headset dev). */ + + name = g_strdup_printf("cmumble [%s]", user->name); + + props = gst_structure_new("props", + "application.name", G_TYPE_STRING, name, + "media.role", G_TYPE_STRING, "phone", + NULL); + + g_object_set(elm, "stream-properties", props, NULL); + gst_structure_free(props); + g_free(name); + +out: + g_object_unref(G_OBJECT(elm)); +} + static int user_create_playback_pipeline(struct context *ctx, struct user *user) { - GstElement *pipeline; + GstElement *pipeline, *sink_bin, *sink; GError *error = NULL; - char *desc = "appsrc name=src ! celtdec ! audioconvert ! autoaudiosink"; + char *desc = "appsrc name=src ! celtdec ! audioconvert ! autoaudiosink name=sink"; pipeline = gst_parse_launch(desc, &error); if (error) { @@ -290,6 +324,11 @@ user_create_playback_pipeline(struct context *ctx, struct user *user) gst_element_set_state(pipeline, GST_STATE_PLAYING); + sink_bin = gst_bin_get_by_name(GST_BIN(pipeline), "sink"); + GstIterator *iter = gst_bin_iterate_sinks(GST_BIN(sink_bin)); + gst_iterator_foreach(iter, set_pulse_states, user); + gst_iterator_free(iter); + /* Setup Celt Decoder */ appsrc_push(user->src, ctx->celt_header_packet, sizeof(CELTHeader)); /* fake vorbiscomment buffer */ -- cgit