From 9e0358930d05c7306fb3998c280f8aafb9f3f39d Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Fri, 6 Aug 2010 11:53:38 +0200 Subject: [PATCH] playback: Switch to gstfactorylist from core https://bugzilla.gnome.org/show_bug.cgi?id=626181 --- gst/playback/Makefile.am | 4 +- gst/playback/gstdecodebin2.c | 28 ++++- gst/playback/gstfactorylists.c | 266 ----------------------------------------- gst/playback/gstfactorylists.h | 50 -------- gst/playback/gstplaybin2.c | 48 ++++++-- gst/playback/gsturidecodebin.c | 28 ++++- 6 files changed, 81 insertions(+), 343 deletions(-) delete mode 100644 gst/playback/gstfactorylists.c delete mode 100644 gst/playback/gstfactorylists.h diff --git a/gst/playback/Makefile.am b/gst/playback/Makefile.am index b7ccac1..009229b 100644 --- a/gst/playback/Makefile.am +++ b/gst/playback/Makefile.am @@ -17,7 +17,6 @@ libgstplaybin_la_SOURCES = \ gstplaysink.c \ gstplaybasebin.c \ gstplay-enum.c \ - gstfactorylists.c \ gstinputselector.c \ gstscreenshot.c \ gststreaminfo.c \ @@ -44,7 +43,7 @@ libgstdecodebin_la_LIBADD = \ $(GST_LIBS) libgstdecodebin_la_LIBTOOLFLAGS = --tag=disable-static -libgstdecodebin2_la_SOURCES = gstdecodebin2.c gsturidecodebin.c gstfactorylists.c gstplay-enum.c +libgstdecodebin2_la_SOURCES = gstdecodebin2.c gsturidecodebin.c gstplay-enum.c nodist_libgstdecodebin2_la_SOURCES = $(built_sources) libgstdecodebin2_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) libgstdecodebin2_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) @@ -58,7 +57,6 @@ noinst_HEADERS = \ gstplaybasebin.h \ gstplaysink.h \ gststreaminfo.h \ - gstfactorylists.h \ gstinputselector.h \ gstplay-enum.h \ gstscreenshot.h \ diff --git a/gst/playback/gstdecodebin2.c b/gst/playback/gstdecodebin2.c index 61a1aaa..eab089f 100644 --- a/gst/playback/gstdecodebin2.c +++ b/gst/playback/gstdecodebin2.c @@ -90,7 +90,6 @@ #include "gstplay-marshal.h" #include "gstplay-enum.h" #include "gstplayback.h" -#include "gstfactorylists.h" #include "gstrawcaps.h" /* generic templates */ @@ -153,7 +152,7 @@ struct _GstDecodeBin GMutex *factories_lock; guint32 factories_cookie; /* Cookie from last time when factories was updated */ - GValueArray *factories; /* factories we can use for selecting elements */ + GList *factories; /* factories we can use for selecting elements */ GMutex *subtitle_lock; /* Protects changes to subtitles and encoding */ GList *subtitles; /* List of elements with subtitle-encoding, @@ -902,8 +901,10 @@ gst_decode_bin_update_factories_list (GstDecodeBin * dbin) || dbin->factories_cookie != gst_default_registry_get_feature_list_cookie ()) { if (dbin->factories) - g_value_array_free (dbin->factories); - dbin->factories = gst_factory_list_get_elements (GST_FACTORY_LIST_DECODER); + gst_plugin_feature_list_free (dbin->factories); + dbin->factories = + gst_element_factory_list_get_elements + (GST_ELEMENT_FACTORY_TYPE_DECODABLE, GST_RANK_MARGINAL); dbin->factories_cookie = gst_default_registry_get_feature_list_cookie (); } } @@ -976,7 +977,7 @@ gst_decode_bin_dispose (GObject * object) decode_bin = GST_DECODE_BIN (object); if (decode_bin->factories) - g_value_array_free (decode_bin->factories); + gst_plugin_feature_list_free (decode_bin->factories); decode_bin->factories = NULL; if (decode_bin->decode_chain) @@ -1232,6 +1233,7 @@ static GValueArray * gst_decode_bin_autoplug_factories (GstElement * element, GstPad * pad, GstCaps * caps) { + GList *list, *tmp; GValueArray *result; GstDecodeBin *dbin = GST_DECODE_BIN_CAST (element); @@ -1240,9 +1242,23 @@ gst_decode_bin_autoplug_factories (GstElement * element, GstPad * pad, /* return all compatible factories for caps */ g_mutex_lock (dbin->factories_lock); gst_decode_bin_update_factories_list (dbin); - result = gst_factory_list_filter (dbin->factories, caps); + list = + gst_element_factory_list_filter (dbin->factories, caps, GST_PAD_SINK, + FALSE); g_mutex_unlock (dbin->factories_lock); + result = g_value_array_new (g_list_length (list)); + for (tmp = list; tmp; tmp = tmp->next) { + GstElementFactory *factory = GST_ELEMENT_FACTORY_CAST (tmp->data); + GValue val = { 0, }; + + g_value_init (&val, G_TYPE_OBJECT); + g_value_set_object (&val, factory); + g_value_array_append (result, &val); + g_value_unset (&val); + } + gst_plugin_feature_list_free (list); + GST_DEBUG_OBJECT (element, "autoplug-factories returns %p", result); return result; diff --git a/gst/playback/gstfactorylists.c b/gst/playback/gstfactorylists.c deleted file mode 100644 index eb5fb4c..0000000 --- a/gst/playback/gstfactorylists.c +++ /dev/null @@ -1,266 +0,0 @@ -/* GStreamer - * Copyright (C) <2007> Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#include - -#include "gstfactorylists.h" - -typedef struct -{ - GstFactoryListType type; -} FilterData; - -/* function used to sort element features. We first sort on the rank, then - * on the element name (to get a consistent, predictable list) */ -static gint -compare_ranks (GValue * v1, GValue * v2) -{ - gint diff; - GstPluginFeature *f1, *f2; - - f1 = g_value_get_object (v1); - f2 = g_value_get_object (v2); - - diff = f2->rank - f1->rank; - if (diff != 0) - return diff; - - diff = strcmp (f2->name, f1->name); - - return diff; -} - -/* the filter function for selecting the elements we can use in - * autoplugging */ -static gboolean -decoders_filter (GstElementFactory * factory) -{ - guint rank; - const gchar *klass; - - klass = gst_element_factory_get_klass (factory); - /* only demuxers, decoders, depayloaders and parsers can play */ - if (strstr (klass, "Demux") == NULL && - strstr (klass, "Decoder") == NULL && - strstr (klass, "Depayloader") == NULL && - strstr (klass, "Parse") == NULL) { - return FALSE; - } - - /* only select elements with autoplugging rank */ - rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)); - if (rank < GST_RANK_MARGINAL) - return FALSE; - - return TRUE; -} - -/* the filter function for selecting the elements we can use in - * autoplugging */ -static gboolean -sinks_filter (GstElementFactory * factory) -{ - guint rank; - const gchar *klass; - - klass = gst_element_factory_get_klass (factory); - /* only sinks can play */ - if (strstr (klass, "Sink") == NULL) { - return FALSE; - } - - /* must be audio or video sink */ - if (strstr (klass, "Audio") == NULL && strstr (klass, "Video") == NULL) { - return FALSE; - } - - /* only select elements with autoplugging rank */ - rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)); - if (rank < GST_RANK_MARGINAL) - return FALSE; - - return TRUE; -} - -/** - * gst_factory_list_is_type: - * @factory: a #GstElementFactory - * @type: a #GstFactoryListType - * - * Check if @factory if of the given types. - * - * Returns: %TRUE if @factory is of @type. - */ -gboolean -gst_factory_list_is_type (GstElementFactory * factory, GstFactoryListType type) -{ - gboolean res = FALSE; - - if (!res && (type & GST_FACTORY_LIST_SINK)) - res = sinks_filter (factory); - if (!res && (type & GST_FACTORY_LIST_DECODER)) - res = decoders_filter (factory); - - return res; -} - -static gboolean -element_filter (GstPluginFeature * feature, FilterData * data) -{ - gboolean res; - - /* we only care about element factories */ - if (!GST_IS_ELEMENT_FACTORY (feature)) - return FALSE; - - res = - gst_factory_list_is_type (GST_ELEMENT_FACTORY_CAST (feature), data->type); - - return res; -} - -/** - * gst_factory_list_get_elements: - * @type: a #GstFactoryListType - * - * Get a sorted list of factories of @type. - * - * Returns: a #GValueArray of #GstElementFactory elements. Use - * g_value_array_free() after usage. - */ -GValueArray * -gst_factory_list_get_elements (GstFactoryListType type) -{ - GValueArray *result; - GList *walk, *list; - FilterData data; - - result = g_value_array_new (0); - - /* prepare type */ - data.type = type; - - /* get the feature list using the filter */ - list = gst_default_registry_feature_filter ((GstPluginFeatureFilter) - element_filter, FALSE, &data); - - /* convert to an array */ - for (walk = list; walk; walk = g_list_next (walk)) { - GstElementFactory *factory = GST_ELEMENT_FACTORY_CAST (walk->data); - GValue val = { 0, }; - - g_value_init (&val, G_TYPE_OBJECT); - g_value_set_object (&val, factory); - g_value_array_append (result, &val); - g_value_unset (&val); - } - gst_plugin_feature_list_free (list); - - /* sort on rank and name */ - g_value_array_sort (result, (GCompareFunc) compare_ranks); - - return result; -} - -/** - * gst_factory_list_debug: - * @array: an array of element factories - * - * Debug the element factory names in @array. - */ -void -gst_factory_list_debug (GValueArray * array) -{ -#ifndef GST_DISABLE_GST_DEBUG - gint i; - - for (i = 0; i < array->n_values; i++) { - GValue *value; - GstPluginFeature *feature; - - value = g_value_array_get_nth (array, i); - feature = g_value_get_object (value); - - GST_DEBUG ("%s", gst_plugin_feature_get_name (feature)); - } -#endif -} - -/** - * gst_factory_list_filter: - * @array: a #GValueArray to filter - * @caps: a #GstCaps - * - * Filter out all the elementfactories in @array that can handle @caps as - * input. - * - * Returns: a #GValueArray of #GstElementFactory elements. Use - * g_value_array_free() after usage. - */ -GValueArray * -gst_factory_list_filter (GValueArray * array, const GstCaps * caps) -{ - GValueArray *result; - gint i; - - result = g_value_array_new (0); - - GST_DEBUG ("finding factories"); - - /* loop over all the factories */ - for (i = 0; i < array->n_values; i++) { - GValue *value; - GstElementFactory *factory; - const GList *templates; - GList *walk; - - value = g_value_array_get_nth (array, i); - factory = g_value_get_object (value); - - /* get the templates from the element factory */ - templates = gst_element_factory_get_static_pad_templates (factory); - for (walk = (GList *) templates; walk; walk = g_list_next (walk)) { - GstStaticPadTemplate *templ = walk->data; - - /* we only care about the sink templates */ - if (templ->direction == GST_PAD_SINK) { - GstCaps *tmpl_caps; - - /* try to intersect the caps with the caps of the template */ - tmpl_caps = gst_static_caps_get (&templ->static_caps); - - /* FIXME, intersect is not the right method, we ideally want to check - * for a subset here */ - - /* check if the intersection is empty */ - if (gst_caps_can_intersect (caps, tmpl_caps)) { - /* non empty intersection, we can use this element */ - GValue resval = { 0, }; - g_value_init (&resval, G_TYPE_OBJECT); - g_value_set_object (&resval, factory); - g_value_array_append (result, &resval); - g_value_unset (&resval); - gst_caps_unref (tmpl_caps); - break; - } - gst_caps_unref (tmpl_caps); - } - } - } - return result; -} diff --git a/gst/playback/gstfactorylists.h b/gst/playback/gstfactorylists.h deleted file mode 100644 index 5d4c64c..0000000 --- a/gst/playback/gstfactorylists.h +++ /dev/null @@ -1,50 +0,0 @@ -/* GStreamer - * Copyright (C) <2007> Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - - -#ifndef __GST_FACTORY_LISTS_H__ -#define __GST_FACTORY_LISTS_H__ - -#include - -G_BEGIN_DECLS - -typedef enum { - GST_FACTORY_LIST_DECODER = (1 << 0), - GST_FACTORY_LIST_ENCODER = (1 << 1), - GST_FACTORY_LIST_SINK = (1 << 2), - GST_FACTORY_LIST_SRC = (1 << 3) -} GstFactoryListType; - -gboolean gst_factory_list_is_type (GstElementFactory *factory, GstFactoryListType type); -GValueArray * gst_factory_list_get_elements (GstFactoryListType type); - -void gst_factory_list_debug (GValueArray *array); - -GValueArray * gst_factory_list_filter (GValueArray *array, const GstCaps *caps); - -#ifndef GST_DISABLE_GST_DEBUG -#define GST_FACTORY_LIST_DEBUG(array) gst_factory_list_debug(array) -#else -#define GST_FACTORY_LIST_DEBUG(array) -#endif - -G_END_DECLS - -#endif /* __GST_FACTORY_LISTS_H__ */ diff --git a/gst/playback/gstplaybin2.c b/gst/playback/gstplaybin2.c index 7ecfec1..558b300 100644 --- a/gst/playback/gstplaybin2.c +++ b/gst/playback/gstplaybin2.c @@ -231,7 +231,6 @@ #include "gstplay-marshal.h" #include "gstplayback.h" #include "gstplaysink.h" -#include "gstfactorylists.h" #include "gstscreenshot.h" #include "gstinputselector.h" #include "gstsubtitleoverlay.h" @@ -386,7 +385,7 @@ struct _GstPlayBin GMutex *elements_lock; guint32 elements_cookie; - GValueArray *elements; /* factories we can use for selecting elements */ + GList *elements; /* factories we can use for selecting elements */ gboolean have_selector; /* set to FALSE when we fail to create an * input-selector, so that we only post a @@ -1135,14 +1134,22 @@ notify_mute_cb (GObject * selector, GParamSpec * pspec, GstPlayBin * playbin) static void gst_play_bin_update_elements_list (GstPlayBin * playbin) { + GList *res, *tmp; + if (!playbin->elements || playbin->elements_cookie != gst_default_registry_get_feature_list_cookie ()) { if (playbin->elements) - g_value_array_free (playbin->elements); + gst_plugin_feature_list_free (playbin->elements); + res = + gst_element_factory_list_get_elements + (GST_ELEMENT_FACTORY_TYPE_DECODABLE, GST_RANK_MARGINAL); + tmp = + gst_element_factory_list_get_elements + (GST_ELEMENT_FACTORY_TYPE_AUDIOVIDEO_SINKS, GST_RANK_MARGINAL); + playbin->elements = g_list_concat (res, tmp); playbin->elements = - gst_factory_list_get_elements (GST_FACTORY_LIST_DECODER | - GST_FACTORY_LIST_SINK); + g_list_sort (playbin->elements, gst_plugin_feature_rank_compare_func); playbin->elements_cookie = gst_default_registry_get_feature_list_cookie (); } } @@ -1204,7 +1211,7 @@ gst_play_bin_finalize (GObject * object) gst_object_unref (playbin->text_sink); if (playbin->elements) - g_value_array_free (playbin->elements); + gst_plugin_feature_list_free (playbin->elements); g_mutex_free (playbin->lock); g_mutex_free (playbin->dyn_lock); g_mutex_free (playbin->elements_lock); @@ -2812,6 +2819,7 @@ autoplug_factories_cb (GstElement * decodebin, GstPad * pad, GstCaps * caps, GstSourceGroup * group) { GstPlayBin *playbin; + GList *mylist, *tmp; GValueArray *result; playbin = group->playbin; @@ -2822,11 +2830,26 @@ autoplug_factories_cb (GstElement * decodebin, GstPad * pad, /* filter out the elements based on the caps. */ g_mutex_lock (playbin->elements_lock); gst_play_bin_update_elements_list (playbin); - result = gst_factory_list_filter (playbin->elements, caps); + mylist = + gst_element_factory_list_filter (playbin->elements, caps, GST_PAD_SINK, + FALSE); g_mutex_unlock (playbin->elements_lock); - GST_DEBUG_OBJECT (playbin, "found factories %p", result); - GST_FACTORY_LIST_DEBUG (result); + GST_DEBUG_OBJECT (playbin, "found factories %p", mylist); + GST_PLUGIN_FEATURE_LIST_DEBUG (mylist); + + result = g_value_array_new (g_list_length (mylist)); + + for (tmp = mylist; tmp; tmp = tmp->next) { + GstElementFactory *factory = GST_ELEMENT_FACTORY_CAST (tmp->data); + GValue val = { 0, }; + + g_value_init (&val, G_TYPE_OBJECT); + g_value_set_object (&val, factory); + g_value_array_append (result, &val); + g_value_unset (&val); + } + gst_plugin_feature_list_free (mylist); return result; } @@ -2847,8 +2870,8 @@ autoplug_continue_cb (GstElement * element, GstPad * pad, GstCaps * caps, GstPad *text_sinkpad = NULL; text_sink = - (group->playbin->text_sink) ? gst_object_ref (group-> - playbin->text_sink) : NULL; + (group->playbin->text_sink) ? gst_object_ref (group->playbin-> + text_sink) : NULL; if (text_sink) text_sinkpad = gst_element_get_static_pad (text_sink, "sink"); @@ -2904,7 +2927,8 @@ autoplug_select_cb (GstElement * decodebin, GstPad * pad, GST_PLUGIN_FEATURE_NAME (factory)); /* if it's not a sink, we just make decodebin try it */ - if (!gst_factory_list_is_type (factory, GST_FACTORY_LIST_SINK)) + if (!gst_element_factory_list_is_type (factory, + GST_ELEMENT_FACTORY_TYPE_SINK)) return GST_AUTOPLUG_SELECT_TRY; /* it's a sink, see if an instance of it actually works */ diff --git a/gst/playback/gsturidecodebin.c b/gst/playback/gsturidecodebin.c index 1df1bb6..2b63355 100644 --- a/gst/playback/gsturidecodebin.c +++ b/gst/playback/gsturidecodebin.c @@ -34,7 +34,6 @@ #include #include -#include "gstfactorylists.h" #include "gstplay-marshal.h" #include "gstplay-enum.h" #include "gstrawcaps.h" @@ -71,7 +70,7 @@ struct _GstURIDecodeBin GMutex *factories_lock; guint32 factories_cookie; - GValueArray *factories; /* factories we can use for selecting elements */ + GList *factories; /* factories we can use for selecting elements */ gchar *uri; guint connection_speed; @@ -267,8 +266,10 @@ gst_uri_decode_bin_update_factories_list (GstURIDecodeBin * dec) dec->factories_cookie != gst_default_registry_get_feature_list_cookie ()) { if (dec->factories) - g_value_array_free (dec->factories); - dec->factories = gst_factory_list_get_elements (GST_FACTORY_LIST_DECODER); + gst_plugin_feature_list_free (dec->factories); + dec->factories = + gst_element_factory_list_get_elements + (GST_ELEMENT_FACTORY_TYPE_DECODABLE, GST_RANK_MARGINAL); dec->factories_cookie = gst_default_registry_get_feature_list_cookie (); } } @@ -277,6 +278,7 @@ static GValueArray * gst_uri_decode_bin_autoplug_factories (GstElement * element, GstPad * pad, GstCaps * caps) { + GList *list, *tmp; GValueArray *result; GstURIDecodeBin *dec = GST_URI_DECODE_BIN_CAST (element); @@ -285,9 +287,23 @@ gst_uri_decode_bin_autoplug_factories (GstElement * element, GstPad * pad, /* return all compatible factories for caps */ g_mutex_lock (dec->factories_lock); gst_uri_decode_bin_update_factories_list (dec); - result = gst_factory_list_filter (dec->factories, caps); + list = + gst_element_factory_list_filter (dec->factories, caps, GST_PAD_SINK, + FALSE); g_mutex_unlock (dec->factories_lock); + result = g_value_array_new (g_list_length (list)); + for (tmp = list; tmp; tmp = tmp->next) { + GstElementFactory *factory = GST_ELEMENT_FACTORY_CAST (tmp->data); + GValue val = { 0, }; + + g_value_init (&val, G_TYPE_OBJECT); + g_value_set_object (&val, factory); + g_value_array_append (result, &val); + g_value_unset (&val); + } + gst_plugin_feature_list_free (list); + GST_DEBUG_OBJECT (element, "autoplug-factories returns %p", result); return result; @@ -557,7 +573,7 @@ gst_uri_decode_bin_finalize (GObject * obj) g_free (dec->uri); g_free (dec->encoding); if (dec->factories) - g_value_array_free (dec->factories); + gst_plugin_feature_list_free (dec->factories); if (dec->caps) gst_caps_unref (dec->caps); -- 2.7.4