Commit eb7571c8 authored by Ziqing Hui's avatar Ziqing Hui Committed by Alexandre Julliard

winegstreamer: Introduce find_element_factories.

parent ebc8a459
...@@ -35,7 +35,10 @@ extern NTSTATUS wg_init_gstreamer(void *args) DECLSPEC_HIDDEN; ...@@ -35,7 +35,10 @@ extern NTSTATUS wg_init_gstreamer(void *args) DECLSPEC_HIDDEN;
extern GstStreamType stream_type_from_caps(GstCaps *caps) DECLSPEC_HIDDEN; extern GstStreamType stream_type_from_caps(GstCaps *caps) DECLSPEC_HIDDEN;
extern GstElement *create_element(const char *name, const char *plugin_set) DECLSPEC_HIDDEN; extern GstElement *create_element(const char *name, const char *plugin_set) DECLSPEC_HIDDEN;
extern GstElement *find_element(GstElementFactoryListType type, GstCaps *src_caps, GstCaps *sink_caps) DECLSPEC_HIDDEN; extern GList *find_element_factories(GstElementFactoryListType type, GstRank min_rank,
GstCaps *element_sink_caps, GstCaps *element_src_caps) DECLSPEC_HIDDEN;
extern GstElement *find_element(GstElementFactoryListType type,
GstCaps *element_sink_caps, GstCaps *element_src_caps) DECLSPEC_HIDDEN;
extern bool append_element(GstElement *container, GstElement *element, GstElement **first, GstElement **last) DECLSPEC_HIDDEN; extern bool append_element(GstElement *container, GstElement *element, GstElement **first, GstElement **last) DECLSPEC_HIDDEN;
extern bool link_src_to_sink(GstPad *src_pad, GstPad *sink_pad) DECLSPEC_HIDDEN; extern bool link_src_to_sink(GstPad *src_pad, GstPad *sink_pad) DECLSPEC_HIDDEN;
extern bool link_src_to_element(GstPad *src_pad, GstElement *element) DECLSPEC_HIDDEN; extern bool link_src_to_element(GstPad *src_pad, GstElement *element) DECLSPEC_HIDDEN;
......
...@@ -78,32 +78,50 @@ GstElement *create_element(const char *name, const char *plugin_set) ...@@ -78,32 +78,50 @@ GstElement *create_element(const char *name, const char *plugin_set)
return element; return element;
} }
GstElement *find_element(GstElementFactoryListType type, GstCaps *src_caps, GstCaps *sink_caps) GList *find_element_factories(GstElementFactoryListType type, GstRank min_rank,
GstCaps *element_sink_caps, GstCaps *element_src_caps)
{ {
GstElement *element = NULL; GList *tmp, *factories = NULL;
GList *tmp, *transforms;
const gchar *name;
if (!(transforms = gst_element_factory_list_get_elements(type, GST_RANK_MARGINAL))) if (!(factories = gst_element_factory_list_get_elements(type, min_rank)))
goto done; goto done;
if (src_caps) if (element_sink_caps)
{ {
tmp = gst_element_factory_list_filter(transforms, src_caps, GST_PAD_SINK, FALSE); tmp = gst_element_factory_list_filter(factories, element_sink_caps, GST_PAD_SINK, FALSE);
gst_plugin_feature_list_free(transforms); gst_plugin_feature_list_free(factories);
if (!(transforms = tmp)) if (!(factories = tmp))
goto done; goto done;
} }
if (sink_caps) if (element_src_caps)
{ {
tmp = gst_element_factory_list_filter(transforms, sink_caps, GST_PAD_SRC, FALSE); tmp = gst_element_factory_list_filter(factories, element_src_caps, GST_PAD_SRC, FALSE);
gst_plugin_feature_list_free(transforms); gst_plugin_feature_list_free(factories);
if (!(transforms = tmp)) if (!(factories = tmp))
goto done; goto done;
} }
transforms = g_list_sort(transforms, gst_plugin_feature_rank_compare_func); factories = g_list_sort(factories, gst_plugin_feature_rank_compare_func);
done:
if (!factories)
GST_WARNING("Failed to find any element factory matching "
"type %"G_GUINT64_FORMAT"x, caps %"GST_PTR_FORMAT" / %"GST_PTR_FORMAT".",
type, element_sink_caps, element_src_caps);
return factories;
}
GstElement *find_element(GstElementFactoryListType type, GstCaps *element_sink_caps, GstCaps *element_src_caps)
{
GstElement *element = NULL;
GList *tmp, *transforms;
const gchar *name;
if (!(transforms = find_element_factories(type, GST_RANK_MARGINAL, element_sink_caps, element_src_caps)))
return NULL;
for (tmp = transforms; tmp != NULL && element == NULL; tmp = tmp->next) for (tmp = transforms; tmp != NULL && element == NULL; tmp = tmp->next)
{ {
name = gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(tmp->data)); name = gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(tmp->data));
...@@ -120,20 +138,14 @@ GstElement *find_element(GstElementFactoryListType type, GstCaps *src_caps, GstC ...@@ -120,20 +138,14 @@ GstElement *find_element(GstElementFactoryListType type, GstCaps *src_caps, GstC
if (!(element = gst_element_factory_create(GST_ELEMENT_FACTORY(tmp->data), NULL))) if (!(element = gst_element_factory_create(GST_ELEMENT_FACTORY(tmp->data), NULL)))
GST_WARNING("Failed to create %s element.", name); GST_WARNING("Failed to create %s element.", name);
} }
gst_plugin_feature_list_free(transforms); gst_plugin_feature_list_free(transforms);
done:
if (element) if (element)
{
GST_DEBUG("Created %s element %p.", name, element); GST_DEBUG("Created %s element %p.", name, element);
}
else else
{ GST_WARNING("Failed to create element matching caps %"GST_PTR_FORMAT" / %"GST_PTR_FORMAT".",
gchar *src_str = gst_caps_to_string(src_caps), *sink_str = gst_caps_to_string(sink_caps); element_sink_caps, element_src_caps);
GST_WARNING("Failed to create element matching caps %s / %s.", src_str, sink_str);
g_free(sink_str);
g_free(src_str);
}
return element; return element;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment