Mercurial > pidgin
changeset 26083:0e8814c437b2
Add active elements to PurpleMediaManager. These are the elements that
will be created when media sessions require new srcs or sinks.
author | Mike Ruprecht <maiku@soc.pidgin.im> |
---|---|
date | Wed, 04 Feb 2009 09:27:27 +0000 |
parents | fc100e71de5d |
children | d6741612b1d0 |
files | libpurple/mediamanager.c libpurple/mediamanager.h pidgin/gtkmedia.c |
diffstat | 3 files changed, 135 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/mediamanager.c Tue Feb 03 23:34:53 2009 +0000 +++ b/libpurple/mediamanager.c Wed Feb 04 09:27:27 2009 +0000 @@ -40,6 +40,11 @@ { 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 @@ 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 @@ 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 */
--- a/libpurple/mediamanager.h Tue Feb 03 23:34:53 2009 +0000 +++ b/libpurple/mediamanager.h Wed Feb 04 09:27:27 2009 +0000 @@ -85,12 +85,16 @@ 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 @@ 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
--- a/pidgin/gtkmedia.c Tue Feb 03 23:34:53 2009 +0000 +++ b/pidgin/gtkmedia.c Wed Feb 04 09:27:27 2009 +0000 @@ -785,34 +785,74 @@ 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 @@ 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 */