changeset 26047:1ce297c8923b

Added media functions to set input and output volume.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Sat, 13 Dec 2008 08:37:57 +0000
parents 99055b8db16b
children 93cc8982d4e5
files libpurple/media.c libpurple/media.h pidgin/gtkprefs.c
diffstat 3 files changed, 83 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/media.c	Sat Dec 06 02:20:09 2008 +0000
+++ b/libpurple/media.c	Sat Dec 13 08:37:57 2008 +0000
@@ -451,6 +451,25 @@
 	return NULL;
 }
 
+static GList *
+purple_media_get_streams(PurpleMedia *media, const gchar *session,
+		const gchar *participant)
+{
+	GList *streams = media->priv->streams;
+	GList *ret = NULL;
+
+	for (; streams; streams = g_list_next(streams)) {
+		PurpleMediaStream *stream = streams->data;
+		if ((session == NULL ||
+				!strcmp(stream->session->id, session)) &&
+				(participant == NULL ||
+				!strcmp(stream->participant, participant)))
+			ret = g_list_append(ret, stream);
+	}
+
+	return ret;
+}
+
 static void
 purple_media_add_session(PurpleMedia *media, PurpleMediaSession *session)
 {
@@ -1378,4 +1397,46 @@
 	}
 }
 
+void purple_media_set_input_volume(PurpleMedia *media,
+		const gchar *session_id, double level)
+{
+	GList *sessions;
+
+	if (session_id == NULL)
+		sessions = g_hash_table_get_values(media->priv->sessions);
+	else
+		sessions = g_list_append(NULL,
+				purple_media_get_session(media, session_id));
+
+	for (; sessions; sessions = g_list_delete_link(sessions, sessions)) {
+		PurpleMediaSession *session = sessions->data;
+
+		if (session->type & PURPLE_MEDIA_SEND_AUDIO) {
+			GstElement *volume = gst_bin_get_by_name(
+					GST_BIN(session->src),
+					"purpleaudioinputvolume");
+			g_object_set(volume, "volume", level, NULL);
+		}
+	}
+}
+
+void purple_media_set_output_volume(PurpleMedia *media,
+		const gchar *session_id, const gchar *participant,
+		double level)
+{
+	GList *streams = purple_media_get_streams(media,
+				session_id, participant);
+
+	for (; streams; streams = g_list_delete_link(streams, streams)) {
+		PurpleMediaStream *stream = streams->data;
+
+		if (stream->session->type & PURPLE_MEDIA_RECV_AUDIO) {
+			GstElement *volume = gst_bin_get_by_name(
+					GST_BIN(stream->session->sink),
+					"purpleaudiooutputvolume");
+			g_object_set(volume, "volume", level, NULL);
+		}
+	}
+}
+
 #endif  /* USE_VV */
--- a/libpurple/media.h	Sat Dec 06 02:20:09 2008 +0000
+++ b/libpurple/media.h	Sat Dec 13 08:37:57 2008 +0000
@@ -479,6 +479,26 @@
  */
 void purple_media_mute(PurpleMedia *media, gboolean active);
 
+/**
+ * Sets the input volume of all the selected sessions.
+ *
+ * @param media The media object the sessions are in.
+ * @param session_id The session to select (if any).
+ * @param level The level to set the volume to.
+ */
+void purple_media_set_input_volume(PurpleMedia *media, const gchar *session_id, double level);
+
+/**
+ * Sets the output volume of all the selected streams.
+ *
+ * @param media The media object the streams are in.
+ * @param session_id The session to limit the streams to (if any).
+ * @param participant The participant to limit the streams to (if any).
+ * @param level The level to set the volume to.
+ */
+void purple_media_set_output_volume(PurpleMedia *media, const gchar *session_id,
+		const gchar *participant, double level);
+
 #ifdef __cplusplus
 }
 #endif
--- a/pidgin/gtkprefs.c	Sat Dec 06 02:20:09 2008 +0000
+++ b/pidgin/gtkprefs.c	Sat Dec 13 08:37:57 2008 +0000
@@ -2197,17 +2197,7 @@
 	val /= 10.0;
 	for (; medias; medias = g_list_next(medias)) {
 		PurpleMedia *media = PURPLE_MEDIA(medias->data);
-		GList *sessions = purple_media_get_session_names(media);
-		for (; sessions; sessions = g_list_delete_link(sessions, sessions)) {
-			const gchar *session = sessions->data;
-			if (purple_media_get_session_type(media, session)
-					& PURPLE_MEDIA_SEND_AUDIO) {
-				GstElement *volume = gst_bin_get_by_name(
-						GST_BIN(purple_media_get_src(media, session)),
-						"purpleaudioinputvolume");
-				g_object_set(volume, "volume", val, NULL);
-			}
-		}
+		purple_media_set_input_volume(media, NULL, val);
 	}
 }
 
@@ -2221,17 +2211,7 @@
 	val /= 10.0;
 	for (; medias; medias = g_list_next(medias)) {
 		PurpleMedia *media = PURPLE_MEDIA(medias->data);
-		GList *sessions = purple_media_get_session_names(media);
-		for (; sessions; sessions = g_list_delete_link(sessions, sessions)) {
-			const gchar *session = sessions->data;
-			if (purple_media_get_session_type(media, session)
-					& PURPLE_MEDIA_RECV_AUDIO) {
-				GstElement *volume = gst_bin_get_by_name(
-						GST_BIN(purple_media_get_sink(media, session)),
-						"purpleaudiooutputvolume");
-				g_object_set(volume, "volume", val, NULL);
-			}
-		}
+		purple_media_set_output_volume(media, NULL, NULL, val);
 	}
 }