changeset 23824:bfaad8393463

Added some utility functions to convert PurpleMediaStreamType to and from FsMediaType and FsStreamDirection.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Fri, 06 Jun 2008 19:08:04 +0000
parents 9983353706b8
children c984acc6c392
files libpurple/media.c libpurple/media.h libpurple/protocols/jabber/jingle.c pidgin/gtkmedia.c
diffstat 4 files changed, 57 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/media.c	Fri Jun 06 08:26:57 2008 +0000
+++ b/libpurple/media.c	Fri Jun 06 19:08:04 2008 +0000
@@ -46,7 +46,7 @@
 	GstElement *sink;
 	FsSession *session;
 	GHashTable *streams;		/* FsStream list map to participant's name */
-	FsMediaType type;
+	PurpleMediaStreamType type;
 	GHashTable *local_candidates;	/* map to participant's name? */
 	FsCandidate *local_candidate;
 	FsCandidate *remote_candidate;
@@ -276,6 +276,51 @@
 
 }
 
+FsMediaType
+purple_media_to_fs_media_type(PurpleMediaStreamType type)
+{
+	if (type & PURPLE_MEDIA_AUDIO)
+		return FS_MEDIA_TYPE_AUDIO;
+	else if (type & PURPLE_MEDIA_VIDEO)
+		return FS_MEDIA_TYPE_VIDEO;
+	else
+		return FS_MEDIA_TYPE_APPLICATION;
+}
+
+FsStreamDirection
+purple_media_to_fs_stream_direction(PurpleMediaStreamType type)
+{
+	if ((type & PURPLE_MEDIA_AUDIO) == PURPLE_MEDIA_AUDIO ||
+			(type & PURPLE_MEDIA_VIDEO) == PURPLE_MEDIA_VIDEO)
+		return FS_DIRECTION_BOTH;
+	else if ((type & PURPLE_MEDIA_SEND_AUDIO) ||
+			(type & PURPLE_MEDIA_SEND_VIDEO))
+		return FS_DIRECTION_SEND;
+	else if ((type & PURPLE_MEDIA_RECV_AUDIO) ||
+			(type & PURPLE_MEDIA_RECV_VIDEO))
+		return FS_DIRECTION_RECV;
+	else
+		return FS_DIRECTION_NONE;
+}
+
+PurpleMediaStreamType
+purple_media_from_fs(FsMediaType type, FsStreamDirection direction)
+{
+	PurpleMediaStreamType result = PURPLE_MEDIA_NONE;
+	if (type == FS_MEDIA_TYPE_AUDIO) {
+		if (direction & FS_DIRECTION_SEND)
+			result |= PURPLE_MEDIA_SEND_AUDIO;
+		if (direction & FS_DIRECTION_RECV)
+			result |= PURPLE_MEDIA_RECV_AUDIO;
+	} else if (type == FS_MEDIA_TYPE_VIDEO) {
+		if (direction & FS_DIRECTION_SEND)
+			result |= PURPLE_MEDIA_SEND_VIDEO;
+		if (direction & FS_DIRECTION_RECV)
+			result |= PURPLE_MEDIA_RECV_VIDEO;
+	}
+	return result;
+}
+
 static PurpleMediaSession*
 purple_media_get_session(PurpleMedia *media, const gchar *sess_id)
 {
@@ -824,7 +869,7 @@
 
 		session->id = g_strdup(sess_id);
 		session->media = media;
-		session->type = type;
+		session->type = purple_media_from_fs(type, type_direction);
 
 		purple_media_add_session(media, session);
 	}
@@ -867,14 +912,7 @@
 	FsStreamDirection type_direction;
 
 	if (type & PURPLE_MEDIA_AUDIO) {
-		if (type & PURPLE_MEDIA_SEND_AUDIO && type & PURPLE_MEDIA_RECV_AUDIO)
-			type_direction = FS_DIRECTION_BOTH;
-		else if (type & PURPLE_MEDIA_SEND_AUDIO)
-			type_direction = FS_DIRECTION_SEND;
-		else if (type & PURPLE_MEDIA_RECV_AUDIO)
-			type_direction = FS_DIRECTION_RECV;
-		else
-			type_direction = FS_DIRECTION_NONE;
+		type_direction = purple_media_to_fs_stream_direction(type & PURPLE_MEDIA_AUDIO);
 
 		if (!purple_media_add_stream_internal(media, sess_id, who,
 						      FS_MEDIA_TYPE_AUDIO, type_direction,
@@ -883,14 +921,7 @@
 		}
 	}
 	if (type & PURPLE_MEDIA_VIDEO) {
-		if (type & PURPLE_MEDIA_SEND_VIDEO && type & PURPLE_MEDIA_RECV_VIDEO)
-			type_direction = FS_DIRECTION_BOTH;
-		else if (type & PURPLE_MEDIA_SEND_VIDEO)
-			type_direction = FS_DIRECTION_SEND;
-		else if (type & PURPLE_MEDIA_RECV_VIDEO)
-			type_direction = FS_DIRECTION_RECV;
-		else
-			type_direction = FS_DIRECTION_NONE;
+		type_direction = purple_media_to_fs_stream_direction(type & PURPLE_MEDIA_VIDEO);
 
 		if (!purple_media_add_stream_internal(media, sess_id, who,
 						      FS_MEDIA_TYPE_VIDEO, type_direction,
--- a/libpurple/media.h	Fri Jun 06 08:26:57 2008 +0000
+++ b/libpurple/media.h	Fri Jun 06 19:08:04 2008 +0000
@@ -51,6 +51,7 @@
 typedef struct _PurpleMediaSession PurpleMediaSession;
 
 typedef enum {
+	PURPLE_MEDIA_NONE	= 0,
 	PURPLE_MEDIA_RECV_AUDIO = 1 << 0,
 	PURPLE_MEDIA_SEND_AUDIO = 1 << 1,
 	PURPLE_MEDIA_RECV_VIDEO = 1 << 2,
@@ -72,6 +73,10 @@
 
 GType purple_media_get_type(void);
 
+FsMediaType purple_media_to_fs_media_type(PurpleMediaStreamType type);
+FsStreamDirection purple_media_to_fs_stream_direction(PurpleMediaStreamType type);
+PurpleMediaStreamType purple_media_from_fs(FsMediaType type, FsStreamDirection direction);
+
 GList *purple_media_get_session_names(PurpleMedia *media);
 
 void purple_media_get_elements(PurpleMedia *media, GstElement **audio_src, GstElement **audio_sink,
--- a/libpurple/protocols/jabber/jingle.c	Fri Jun 06 08:26:57 2008 +0000
+++ b/libpurple/protocols/jabber/jingle.c	Fri Jun 06 19:08:04 2008 +0000
@@ -1340,3 +1340,4 @@
 }
 
 #endif /* USE_VV */
+
--- a/pidgin/gtkmedia.c	Fri Jun 06 08:26:57 2008 +0000
+++ b/pidgin/gtkmedia.c	Fri Jun 06 19:08:04 2008 +0000
@@ -272,10 +272,10 @@
 	purple_media_video_init_recv(&videorecvbin);
 
 	for (; sessions; sessions = sessions->next) {
-		if (purple_media_get_session_type(media, sessions->data) == FS_MEDIA_TYPE_AUDIO) {
+		if (purple_media_get_session_type(media, sessions->data) & PURPLE_MEDIA_AUDIO) {
 			purple_media_set_src(media, sessions->data, audiosendbin);
 			purple_media_set_sink(media, sessions->data, audiorecvbin);
-		} else if (purple_media_get_session_type(media, sessions->data) == FS_MEDIA_TYPE_VIDEO) {
+		} else if (purple_media_get_session_type(media, sessions->data) & PURPLE_MEDIA_VIDEO) {
 			purple_media_set_src(media, sessions->data, videosendbin);
 			purple_media_set_sink(media, sessions->data, videorecvbin);
 		}