changeset 26081:521366dfd8db

Implement functions to register and unregister media elements for use in allowing plugins and GUIs to alter the pipeline.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Tue, 03 Feb 2009 22:37:24 +0000
parents 88f183f7dfc7
children fc100e71de5d
files libpurple/mediamanager.c libpurple/mediamanager.h pidgin/gtkmedia.c
diffstat 3 files changed, 96 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/mediamanager.c	Tue Feb 03 21:37:27 2009 +0000
+++ b/libpurple/mediamanager.c	Tue Feb 03 22:37:24 2009 +0000
@@ -39,6 +39,7 @@
 struct _PurpleMediaManagerPrivate
 {
 	GList *medias;
+	GList *elements;
 };
 
 #define PURPLE_MEDIA_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_MEDIA_MANAGER, PurpleMediaManagerPrivate))
@@ -123,6 +124,8 @@
 			g_list_delete_link(priv->medias, priv->medias)) {
 		g_object_unref(priv->medias->data);
 	}
+	for (; priv->elements; priv->elements =
+			g_list_delete_link(priv->elements, priv->elements));
 	parent_class->finalize(media);
 }
 
@@ -225,4 +228,56 @@
 	return ret;
 }
 
+PurpleMediaElementInfo *
+purple_media_manager_get_element_info(PurpleMediaManager *manager,
+		const gchar *id)
+{
+	GList *iter;
+
+	g_return_val_if_fail(PURPLE_IS_MEDIA_MANAGER(manager), NULL);
+
+	iter = manager->priv->elements;
+
+	for (; iter; iter = g_list_next(iter)) {
+		PurpleMediaElementInfo *info = iter->data;
+		if (!strcmp(info->id, id))
+			return info;
+	}
+
+	return NULL;
+}
+
+gboolean
+purple_media_manager_register_element(PurpleMediaManager *manager,
+		PurpleMediaElementInfo *info)
+{
+	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)
+		return FALSE;
+
+	manager->priv->elements =
+			g_list_prepend(manager->priv->elements, info);
+	return TRUE;
+}
+
+gboolean
+purple_media_manager_unregister_element(PurpleMediaManager *manager,
+		const gchar *id)
+{
+	PurpleMediaElementInfo *info;
+
+	g_return_val_if_fail(PURPLE_IS_MEDIA_MANAGER(manager), FALSE);
+
+	info = purple_media_manager_get_element_info(manager, id);
+
+	if (info == NULL)
+		return FALSE;
+
+	manager->priv->elements = g_list_remove(
+			manager->priv->elements, info);
+	return TRUE;
+}
+
 #endif  /* USE_VV */
--- a/libpurple/mediamanager.h	Tue Feb 03 21:37:27 2009 +0000
+++ b/libpurple/mediamanager.h	Tue Feb 03 22:37:24 2009 +0000
@@ -50,6 +50,8 @@
 typedef struct _PurpleMediaManagerClass PurpleMediaManagerClass;
 /** @copydoc _PurpleMediaManagerPrivate */
 typedef struct _PurpleMediaManagerPrivate PurpleMediaManagerPrivate;
+/** @copydoc _PurpleMediaElementInfo */
+typedef struct _PurpleMediaElementInfo PurpleMediaElementInfo;
 
 /** The media manager class. */
 struct _PurpleMediaManagerClass
@@ -64,6 +66,11 @@
 	PurpleMediaManagerPrivate *priv; /**< Private data for the manager. */
 };
 
+struct _PurpleMediaElementInfo
+{
+	const gchar *id;
+};
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -131,6 +138,12 @@
 GstElement *purple_media_manager_get_element(PurpleMediaManager *manager,
 		PurpleMediaSessionType type);
 
+PurpleMediaElementInfo *purple_media_manager_get_element_info(
+		PurpleMediaManager *manager, const gchar *name);
+gboolean purple_media_manager_register_element(PurpleMediaManager *manager,
+		PurpleMediaElementInfo *info);
+gboolean purple_media_manager_unregister_element(PurpleMediaManager *manager,
+		const gchar *name);
 /*}@*/
 
 #ifdef __cplusplus
--- a/pidgin/gtkmedia.c	Tue Feb 03 21:37:27 2009 +0000
+++ b/pidgin/gtkmedia.c	Tue Feb 03 22:37:24 2009 +0000
@@ -785,11 +785,38 @@
 	return TRUE;
 }
 
+static PurpleMediaElementInfo default_video_src =
+{
+	"pidgindefaultvideosrc",	/* id */
+};
+
+static PurpleMediaElementInfo default_video_sink =
+{
+	"pidgindefaultvideosink",	/* id */
+};
+
+static PurpleMediaElementInfo default_audio_src =
+{
+	"pidgindefaultaudiosrc",	/* id */
+};
+
+static PurpleMediaElementInfo default_audio_sink =
+{
+	"pidgindefaultaudiosink",	/* id */
+};
+
 void
 pidgin_medias_init(void)
 {
-	g_signal_connect(G_OBJECT(purple_media_manager_get()), "init-media",
+	PurpleMediaManager *manager = purple_media_manager_get();
+	g_signal_connect(G_OBJECT(manager), "init-media",
 			 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);
 }
 
 #endif  /* USE_VV */