changeset 26052:01df0829f054

Move sink from PurpleMediaSession to PurpleMediaStream.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Sat, 13 Dec 2008 09:11:08 +0000
parents d03cfec8bf7f
children 99c3489e06b0
files finch/gntmedia.c libpurple/media.c libpurple/media.h
diffstat 3 files changed, 46 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/finch/gntmedia.c	Sat Dec 13 08:49:16 2008 +0000
+++ b/finch/gntmedia.c	Sat Dec 13 09:11:08 2008 +0000
@@ -178,21 +178,17 @@
 finch_media_ready_cb(PurpleMedia *media, FinchMedia *gntmedia)
 {
 	GstElement *sendbin, *sendlevel;
-	GstElement *recvbin, *recvlevel;
 
 	GList *sessions = purple_media_get_session_names(media);
 
 	purple_media_audio_init_src(&sendbin, &sendlevel);
-	purple_media_audio_init_recv(&recvbin, &recvlevel);
 
 	for (; sessions; sessions = sessions->next) {
 		purple_media_set_src(media, sessions->data, sendbin);
-		purple_media_set_sink(media, sessions->data, recvbin);
 	}
 	g_list_free(sessions);
 
 	g_object_set(gntmedia, "send-level", sendlevel,
-		     "recv-level", recvlevel,
 		     NULL);
 }
 
--- a/libpurple/media.c	Sat Dec 13 08:49:16 2008 +0000
+++ b/libpurple/media.c	Sat Dec 13 09:11:08 2008 +0000
@@ -50,7 +50,6 @@
 	gchar *id;
 	PurpleMedia *media;
 	GstElement *src;
-	GstElement *sink;
 	FsSession *session;
 
 	PurpleMediaSessionType type;
@@ -61,6 +60,7 @@
 	PurpleMediaSession *session;
 	gchar *participant;
 	FsStream *stream;
+	GstElement *sink;
 
 	GList *local_candidates;
 
@@ -516,7 +516,7 @@
 	return participant;
 }
 
-static void
+static PurpleMediaStream *
 purple_media_insert_stream(PurpleMediaSession *session, const gchar *name, FsStream *stream)
 {
 	PurpleMediaStream *media_stream = g_new0(PurpleMediaStream, 1);
@@ -526,6 +526,8 @@
 
 	session->media->priv->streams =
 			g_list_append(session->media->priv->streams, media_stream);
+
+	return media_stream;
 }
 
 static void
@@ -553,12 +555,18 @@
 
 		if (session->type & PURPLE_MEDIA_SEND_AUDIO && audio_src)
 			*audio_src = session->src;
-		if (session->type & PURPLE_MEDIA_RECV_AUDIO && audio_sink)
-			*audio_sink = session->sink;
 		if (session->type & PURPLE_MEDIA_SEND_VIDEO && video_src)
 			*video_src = session->src;
-		if (session->type & PURPLE_MEDIA_RECV_VIDEO && video_sink)
-			*video_sink = session->sink;
+	}
+
+	values = media->priv->streams;
+	for (; values; values = g_list_next(values)) {
+		PurpleMediaStream *stream = (PurpleMediaStream*)values->data;
+
+		if (stream->session->type & PURPLE_MEDIA_RECV_AUDIO && audio_sink)
+			*audio_sink = stream->sink;
+		if (stream->session->type & PURPLE_MEDIA_RECV_VIDEO && video_sink)
+			*video_sink = stream->sink;
 	}
 }
 
@@ -583,14 +591,17 @@
 }
 
 void 
-purple_media_set_sink(PurpleMedia *media, const gchar *sess_id, GstElement *sink)
+purple_media_set_sink(PurpleMedia *media, const gchar *sess_id,
+		const gchar *participant, GstElement *sink)
 {
-	PurpleMediaSession *session = purple_media_get_session(media, sess_id);
-	if (session->sink)
-		gst_object_unref(session->sink);
-	session->sink = sink;
+	PurpleMediaStream *stream =
+			purple_media_get_stream(media, sess_id, participant);
+
+	if (stream->sink)
+		gst_object_unref(stream->sink);
+	stream->sink = sink;
 	gst_bin_add(GST_BIN(purple_media_get_pipeline(media)),
-		    session->sink);
+		    stream->sink);
 }
 
 GstElement *
@@ -600,9 +611,9 @@
 }
 
 GstElement *
-purple_media_get_sink(PurpleMedia *media, const gchar *sess_id)
+purple_media_get_sink(PurpleMedia *media, const gchar *sess_id, const gchar *participant)
 {
-	return purple_media_get_session(media, sess_id)->sink;
+	return purple_media_get_stream(media, sess_id, participant)->sink;
 }
 
 static PurpleMediaSession *
@@ -1067,19 +1078,21 @@
 }
 
 static void
-purple_media_src_pad_added_cb(FsStream *stream, GstPad *srcpad,
-			      FsCodec *codec, PurpleMediaSession *session)
+purple_media_src_pad_added_cb(FsStream *fsstream, GstPad *srcpad,
+			      FsCodec *codec, PurpleMediaStream *stream)
 {
 	PurpleMediaSessionType type = purple_media_from_fs(codec->media_type, FS_DIRECTION_RECV);
 	GstPad *sinkpad = NULL;
-	session->sink = purple_media_manager_get_element(purple_media_manager_get(), type);
+
+	stream->sink = purple_media_manager_get_element(
+			purple_media_manager_get(), type);
 
-	gst_bin_add(GST_BIN(purple_media_get_pipeline(session->media)),
-		    session->sink);
-	sinkpad = gst_element_get_static_pad(session->sink, "ghostsink");
+	gst_bin_add(GST_BIN(purple_media_get_pipeline(stream->session->media)),
+		    stream->sink);
+	sinkpad = gst_element_get_static_pad(stream->sink, "ghostsink");
 	purple_debug_info("media", "connecting new src pad: %s\n", 
 			  gst_pad_link(srcpad, sinkpad) == GST_PAD_LINK_OK ? "success" : "failure");
-	gst_element_set_state(session->sink, GST_STATE_PLAYING);
+	gst_element_set_state(stream->sink, GST_STATE_PLAYING);
 }
 
 static gchar *
@@ -1224,11 +1237,11 @@
 			return FALSE;
 		}
 
-		purple_media_insert_stream(session, who, fsstream);
+		stream = purple_media_insert_stream(session, who, fsstream);
 
 		/* callback for source pad added (new stream source ready) */
 		g_signal_connect(G_OBJECT(fsstream),
-				 "src-pad-added", G_CALLBACK(purple_media_src_pad_added_cb), session);
+				 "src-pad-added", G_CALLBACK(purple_media_src_pad_added_cb), stream);
 
 	} else if (*direction != type_direction) {	
 		/* change direction */
@@ -1432,7 +1445,7 @@
 
 		if (stream->session->type & PURPLE_MEDIA_RECV_AUDIO) {
 			GstElement *volume = gst_bin_get_by_name(
-					GST_BIN(stream->session->sink),
+					GST_BIN(stream->sink),
 					"purpleaudiooutputvolume");
 			g_object_set(volume, "volume", level, NULL);
 		}
--- a/libpurple/media.h	Sat Dec 13 08:49:16 2008 +0000
+++ b/libpurple/media.h	Sat Dec 13 09:11:08 2008 +0000
@@ -173,13 +173,15 @@
 void purple_media_set_src(PurpleMedia *media, const gchar *sess_id, GstElement *src);
 
 /**
- * Sets the sink on a session.
+ * Sets the sink on a stream.
  *
  * @param media The media object the session is in.
- * @param sess_id The session id of the session to set the sink on.
+ * @param sess_id The session id the stream belongs to.
+ * @param sess_id The participant the stream is associated with.
  * @param sink The source to set the session sink to.
  */
-void purple_media_set_sink(PurpleMedia *media, const gchar *sess_id, GstElement *sink);
+void purple_media_set_sink(PurpleMedia *media, const gchar *sess_id,
+		const gchar *participant, GstElement *sink);
 
 /**
  * Gets the source from a session
@@ -192,14 +194,15 @@
 GstElement *purple_media_get_src(PurpleMedia *media, const gchar *sess_id);
 
 /**
- * Gets the sink from a session
+ * Gets the sink from a stream
  *
  * @param media The media object the session is in.
- * @param sess_id The session id of the session to get the source from.
+ * @param sess_id The session id the stream belongs to.
+ * @param participant The participant the stream is associated with.
  *
  * @return The sink retrieved.
  */
-GstElement *purple_media_get_sink(PurpleMedia *media, const gchar *sess_id);
+GstElement *purple_media_get_sink(PurpleMedia *media, const gchar *sess_id, const gchar *participant);
 
 /**
  * Gets the pipeline from the media session.