Mercurial > pidgin.yaz
changeset 26011:e8b8c6b14196
Simplified purple_media_get_devices.
author | Mike Ruprecht <maiku@soc.pidgin.im> |
---|---|
date | Mon, 01 Sep 2008 03:18:26 +0000 |
parents | 3b4b9795f987 |
children | ef161c8f14df |
files | libpurple/media.c libpurple/media.h pidgin/gtkprefs.c |
diffstat | 3 files changed, 26 insertions(+), 50 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/media.c Mon Sep 01 01:58:42 2008 +0000 +++ b/libpurple/media.c Mon Sep 01 03:18:26 2008 +0000 @@ -756,18 +756,20 @@ } GList* -purple_media_get_devices(GstElement *element) +purple_media_get_devices(const gchar *plugin) { GObjectClass *klass; GstPropertyProbe *probe; const GParamSpec *pspec; - + GstElement *element = gst_element_factory_make(plugin, NULL); + GstElementFactory *factory; const gchar *longname = NULL; + GList *ret = NULL; - GstElementFactory *factory = - gst_element_get_factory(element); + if (element == NULL) + return NULL; - GList *ret = NULL; + factory = gst_element_get_factory(element); longname = gst_element_factory_get_longname(factory); klass = G_OBJECT_GET_CLASS(element); @@ -800,6 +802,8 @@ ret = g_list_append(ret, g_value_dup_string(device)); + g_object_set(G_OBJECT(element), "device", + g_value_get_string(device), NULL); g_object_get(G_OBJECT(element), "device-name", &name, NULL); purple_debug_info("media", "Found source '%s' (%s) - device '%s' (%s)\n", longname, GST_PLUGIN_FEATURE (factory)->name, @@ -818,6 +822,7 @@ } } + gst_object_unref(element); return ret; }
--- a/libpurple/media.h Mon Sep 01 01:58:42 2008 +0000 +++ b/libpurple/media.h Mon Sep 01 03:18:26 2008 +0000 @@ -287,11 +287,11 @@ /** * Enumerates a list of devices. * - * @param element The plugin from which to enumerate devices. + * @param plugin The name of the GStreamer plugin from which to enumerate devices. * * @return The list of enumerated devices. */ -GList *purple_media_get_devices(GstElement *element); +GList *purple_media_get_devices(const gchar *plugin); /** * Gets the device the plugin is currently set to.
--- a/pidgin/gtkprefs.c Mon Sep 01 01:58:42 2008 +0000 +++ b/pidgin/gtkprefs.c Mon Sep 01 03:18:26 2008 +0000 @@ -2024,18 +2024,24 @@ /* get a GList of pairs name / device */ static GList * -get_device_items(const GstElement *element, - const GList *devices) +get_device_items(const gchar *plugin) { GList *ret = NULL; - - for(; devices ; devices = devices->next) { + GList *devices = purple_media_get_devices(plugin); + GstElement *element = gst_element_factory_make(plugin, NULL); + + if (element == NULL) + return NULL; + + for(; devices ; devices = g_list_delete_link(devices, devices)) { gchar *name; + g_object_set(G_OBJECT(element), "device", devices->data, NULL); g_object_get(G_OBJECT(element), "device-name", &name, NULL); ret = g_list_append(ret, name); - ret = g_list_append(ret, g_strdup(devices->data)); + ret = g_list_append(ret, devices->data); } + gst_object_unref(element); return ret; } @@ -2122,20 +2128,9 @@ GtkWidget *preview_button = NULL; const char *plugin = value; const char *device = purple_prefs_get_string("/purple/media/video/device"); - GstElement *video = gst_element_factory_make(plugin, NULL); - GList *video_items = NULL; + GList *video_items = get_device_items(plugin); GList *list; - if (video != NULL) { - GList *video_devices = purple_media_get_devices(video); - video_items = get_device_items(video, video_devices); - for(; video_devices; video_devices = g_list_delete_link( - video_devices, video_devices)) { - g_free(video_devices->data); - } - gst_object_unref(video); - } - if (video_items == NULL) { video_items = g_list_prepend(video_items, g_strdup("")); video_items = g_list_prepend(video_items, g_strdup("Default")); @@ -2229,32 +2224,8 @@ GtkSizeGroup *sg, *sg2; const char *plugin = purple_prefs_get_string("/purple/media/video/plugin"); const char *device = purple_prefs_get_string("/purple/media/video/device"); - - GstElement *video = gst_element_factory_make(plugin, NULL); - GstElement *audio = gst_element_factory_make("alsasrc", NULL); - - GList *video_items = NULL; - GList *audio_items = NULL; - - if (video != NULL) { - GList *video_devices = purple_media_get_devices(video); - video_items = get_device_items(video, video_devices); - for(; video_devices; video_devices = g_list_delete_link( - video_devices, video_devices)) { - g_free(video_devices->data); - } - gst_object_unref(video); - } - - if (audio != NULL) { - GList *audio_devices = purple_media_get_devices(audio); - audio_items = get_device_items(audio, audio_devices); - for(; audio_devices; audio_devices = g_list_delete_link( - audio_devices, audio_devices)) { - g_free(audio_devices->data); - } - gst_object_unref(audio); - } + GList *video_items = get_device_items(plugin); + GList *audio_items = get_device_items("alsasrc"); if (video_items == NULL) { video_items = g_list_prepend(video_items, "");