pidgin.vv: 96b23045: Add active elements to PurpleMediaManage...

maiku at soc.pidgin.im maiku at soc.pidgin.im
Wed Feb 4 19:20:29 EST 2009


-----------------------------------------------------------------
Revision: 96b230451345d5543554f1d018ab450c76820d01
Ancestor: 7c43abd95fc65dd744e15aa03505ec6914da27be
Author: maiku at soc.pidgin.im
Date: 2009-02-04T09:27:27
Branch: im.pidgin.pidgin.vv
URL: http://d.pidgin.im/viewmtn/revision/info/96b230451345d5543554f1d018ab450c76820d01

Modified files:
        libpurple/mediamanager.c libpurple/mediamanager.h
        pidgin/gtkmedia.c

ChangeLog: 

Add active elements to PurpleMediaManager. These are the elements that 
will be created when media sessions require new srcs or sinks.

-------------- next part --------------
============================================================
--- libpurple/mediamanager.c	2f5c3098b0b030170b62fb82f47198e0b66a790a
+++ libpurple/mediamanager.c	a46b53df7b594ba71a233fea436be82fe2cffe62
@@ -40,6 +40,11 @@ struct _PurpleMediaManagerPrivate
 {
 	GList *medias;
 	GList *elements;
+
+	PurpleMediaElementInfo *video_src;
+	PurpleMediaElementInfo *video_sink;
+	PurpleMediaElementInfo *audio_src;
+	PurpleMediaElementInfo *audio_sink;
 };
 
 #define PURPLE_MEDIA_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_MEDIA_MANAGER, PurpleMediaManagerPrivate))
@@ -208,19 +213,22 @@ purple_media_manager_get_element(PurpleM
 		PurpleMediaSessionType type)
 {
 	GstElement *ret = NULL;
-	GstElement *level = NULL;
 
 	/* TODO: If src, retrieve current src */
 	/* TODO: Send a signal here to allow for overriding the source/sink */
 
-	if (type & PURPLE_MEDIA_SEND_AUDIO)
-		purple_media_audio_init_src(&ret, &level);
-	else if (type & PURPLE_MEDIA_RECV_AUDIO)
-		purple_media_audio_init_recv(&ret, &level);
-	else if (type & PURPLE_MEDIA_SEND_VIDEO)
-		purple_media_video_init_src(&ret);
-	else if (type & PURPLE_MEDIA_RECV_VIDEO)
-		purple_media_video_init_recv(&ret);
+	if (type & PURPLE_MEDIA_SEND_AUDIO
+			&& manager->priv->audio_src != NULL)
+		ret = manager->priv->audio_src->create();
+	else if (type & PURPLE_MEDIA_RECV_AUDIO
+			&& manager->priv->audio_sink != NULL)
+		ret = manager->priv->audio_sink->create();
+	else if (type & PURPLE_MEDIA_SEND_VIDEO
+			&& manager->priv->video_src != NULL)
+		ret = manager->priv->video_src->create();
+	else if (type & PURPLE_MEDIA_RECV_VIDEO
+			&& manager->priv->video_sink != NULL)
+		ret = manager->priv->video_sink->create();
 
 	if (ret == NULL)
 		purple_debug_error("media", "Error creating source or sink\n");
@@ -275,9 +283,75 @@ purple_media_manager_unregister_element(
 	if (info == NULL)
 		return FALSE;
 
+	if (manager->priv->audio_src == info)
+		manager->priv->audio_src = NULL;
+	if (manager->priv->audio_sink == info)
+		manager->priv->audio_sink = NULL;
+	if (manager->priv->video_src == info)
+		manager->priv->video_src = NULL;
+	if (manager->priv->video_sink == info)
+		manager->priv->video_sink = NULL;
+
 	manager->priv->elements = g_list_remove(
 			manager->priv->elements, info);
 	return TRUE;
 }
 
+gboolean
+purple_media_manager_set_active_element(PurpleMediaManager *manager,
+		PurpleMediaElementInfo *info)
+{
+	gboolean ret = FALSE;
+
+	g_return_val_if_fail(PURPLE_IS_MEDIA_MANAGER(manager), FALSE);
+	g_return_val_if_fail(info != NULL, FALSE);
+
+	if (purple_media_manager_get_element_info(manager, info->id) == NULL)
+		purple_media_manager_register_element(manager, info);
+
+	if (info->type & PURPLE_MEDIA_ELEMENT_SRC) {
+		if (info->type & PURPLE_MEDIA_ELEMENT_AUDIO) {
+			manager->priv->audio_src = info;
+			ret = TRUE;
+		}
+		if (info->type & PURPLE_MEDIA_ELEMENT_VIDEO) {
+			manager->priv->video_src = info;
+			ret = TRUE;
+		}
+	}
+	if (info->type & PURPLE_MEDIA_ELEMENT_SINK) {
+		if (info->type & PURPLE_MEDIA_ELEMENT_AUDIO) {
+			manager->priv->audio_sink = info;
+			ret = TRUE;
+		}
+		if (info->type & PURPLE_MEDIA_ELEMENT_VIDEO) {
+			manager->priv->video_sink = info;
+			ret = TRUE;
+		}
+	}
+
+	return ret;
+}
+
+PurpleMediaElementInfo *
+purple_media_manager_get_active_element(PurpleMediaManager *manager,
+		PurpleMediaElementType type)
+{
+	g_return_val_if_fail(PURPLE_IS_MEDIA_MANAGER(manager), NULL);
+
+	if (type & PURPLE_MEDIA_ELEMENT_SRC) {
+		if (type & PURPLE_MEDIA_ELEMENT_AUDIO)
+			return manager->priv->audio_src;
+		else if (type & PURPLE_MEDIA_ELEMENT_VIDEO)
+			return manager->priv->video_src;
+	} else if (type & PURPLE_MEDIA_ELEMENT_SINK) {
+		if (type & PURPLE_MEDIA_ELEMENT_AUDIO)
+			return manager->priv->audio_sink;
+		else if (type & PURPLE_MEDIA_ELEMENT_VIDEO)
+			return manager->priv->video_sink;
+	}
+
+	return NULL;
+}
+
 #endif  /* USE_VV */
============================================================
--- libpurple/mediamanager.h	6528c68bdcdaacd4f4e85fdbf0cf277444cd3648
+++ libpurple/mediamanager.h	0b61baddbe6e8e21f011f00abde70b2b21ea982c
@@ -85,12 +85,16 @@ typedef enum {
 	PURPLE_MEDIA_ELEMENT_UNIQUE = 1 << 8,		/** This element is unique and
 							 only one instance of it should
 							 be created at a time */
+
+	PURPLE_MEDIA_ELEMENT_SRC = 1 << 9,		/** can be set as an active src */
+	PURPLE_MEDIA_ELEMENT_SINK = 1 << 10,		/** can be set as an active sink */
 } PurpleMediaElementType;
 
 struct _PurpleMediaElementInfo
 {
 	const gchar *id;
 	PurpleMediaElementType type;
+	GstElement *(*create)(void);
 };
 
 #ifdef __cplusplus
@@ -166,6 +170,10 @@ gboolean purple_media_manager_unregister
 		PurpleMediaElementInfo *info);
 gboolean purple_media_manager_unregister_element(PurpleMediaManager *manager,
 		const gchar *name);
+gboolean purple_media_manager_set_active_element(PurpleMediaManager *manager,
+		PurpleMediaElementInfo *info);
+PurpleMediaElementInfo *purple_media_manager_get_active_element(
+		PurpleMediaManager *manager, PurpleMediaElementType type);
 /*}@*/
 
 #ifdef __cplusplus
============================================================
--- pidgin/gtkmedia.c	a1609b25a9f99a90f043063e44044648080fa753
+++ pidgin/gtkmedia.c	ad8bbdc4fc206a5332fa1de867f09a0b882be959
@@ -785,34 +785,74 @@ pidgin_media_new_cb(PurpleMediaManager *
 	return TRUE;
 }
 
+static GstElement *
+create_default_video_src(void)
+{
+	GstElement *ret = NULL;
+	purple_media_video_init_src(&ret);
+	return ret;
+}
+
+static GstElement *
+create_default_video_sink(void)
+{
+	GstElement *ret = NULL;
+	purple_media_video_init_recv(&ret);
+	return ret;
+}
+
+static GstElement *
+create_default_audio_src(void)
+{
+	GstElement *ret = NULL, *level = NULL;
+	purple_media_audio_init_src(&ret, &level);
+	return ret;
+}
+
+static GstElement *
+create_default_audio_sink(void)
+{
+	GstElement *ret = NULL, *level = NULL;
+	purple_media_audio_init_recv(&ret, &level);
+	return ret;
+}
+
 static PurpleMediaElementInfo default_video_src =
 {
 	"pidgindefaultvideosrc",	/* id */
 	PURPLE_MEDIA_ELEMENT_VIDEO	/* type */
+			| PURPLE_MEDIA_ELEMENT_SRC
 			| PURPLE_MEDIA_ELEMENT_ONE_SRC
 			| PURPLE_MEDIA_ELEMENT_UNIQUE,
+	create_default_video_src,	/* create */
 };
 
 static PurpleMediaElementInfo default_video_sink =
 {
 	"pidgindefaultvideosink",	/* id */
 	PURPLE_MEDIA_ELEMENT_VIDEO	/* type */
+			| PURPLE_MEDIA_ELEMENT_SINK
 			| PURPLE_MEDIA_ELEMENT_ONE_SINK,
+	create_default_video_sink,	/* create */
 };
 
 static PurpleMediaElementInfo default_audio_src =
 {
 	"pidgindefaultaudiosrc",	/* id */
 	PURPLE_MEDIA_ELEMENT_AUDIO	/* type */
+			| PURPLE_MEDIA_ELEMENT_SRC
 			| PURPLE_MEDIA_ELEMENT_ONE_SRC
 			| PURPLE_MEDIA_ELEMENT_UNIQUE,
+	create_default_audio_src,	/* create */
 };
 
 static PurpleMediaElementInfo default_audio_sink =
 {
 	"pidgindefaultaudiosink",	/* id */
 	PURPLE_MEDIA_ELEMENT_AUDIO	/* type */
+			| PURPLE_MEDIA_ELEMENT_SINK
 			| PURPLE_MEDIA_ELEMENT_ONE_SINK,
+	create_default_audio_sink,	/* create */
 };
 
 void
@@ -823,10 +863,10 @@ pidgin_medias_init(void)
 			 G_CALLBACK(pidgin_media_new_cb), NULL);
 
 	purple_debug_info("gtkmedia", "Registering media element types\n");
-	purple_media_manager_register_element(manager, &default_video_src);
-	purple_media_manager_register_element(manager, &default_video_sink);
-	purple_media_manager_register_element(manager, &default_audio_src);
-	purple_media_manager_register_element(manager, &default_audio_sink);
+	purple_media_manager_set_active_element(manager, &default_video_src);
+	purple_media_manager_set_active_element(manager, &default_video_sink);
+	purple_media_manager_set_active_element(manager, &default_audio_src);
+	purple_media_manager_set_active_element(manager, &default_audio_sink);
 }
 
 #endif  /* USE_VV */


More information about the Commits mailing list