winegstreamer: Introduce find_element_factories.

This commit is contained in:
Ziqing Hui 2023-10-20 10:40:30 +08:00 committed by Alexandre Julliard
parent ebc8a45968
commit eb7571c8b1
2 changed files with 45 additions and 30 deletions

View file

@ -35,7 +35,10 @@ extern NTSTATUS wg_init_gstreamer(void *args) 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 *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 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;

View file

@ -78,32 +78,50 @@ GstElement *create_element(const char *name, const char *plugin_set)
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)
{
GList *tmp, *factories = NULL;
if (!(factories = gst_element_factory_list_get_elements(type, min_rank)))
goto done;
if (element_sink_caps)
{
tmp = gst_element_factory_list_filter(factories, element_sink_caps, GST_PAD_SINK, FALSE);
gst_plugin_feature_list_free(factories);
if (!(factories = tmp))
goto done;
}
if (element_src_caps)
{
tmp = gst_element_factory_list_filter(factories, element_src_caps, GST_PAD_SRC, FALSE);
gst_plugin_feature_list_free(factories);
if (!(factories = tmp))
goto done;
}
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 = gst_element_factory_list_get_elements(type, GST_RANK_MARGINAL)))
goto done;
if (!(transforms = find_element_factories(type, GST_RANK_MARGINAL, element_sink_caps, element_src_caps)))
return NULL;
if (src_caps)
{
tmp = gst_element_factory_list_filter(transforms, src_caps, GST_PAD_SINK, FALSE);
gst_plugin_feature_list_free(transforms);
if (!(transforms = tmp))
goto done;
}
if (sink_caps)
{
tmp = gst_element_factory_list_filter(transforms, sink_caps, GST_PAD_SRC, FALSE);
gst_plugin_feature_list_free(transforms);
if (!(transforms = tmp))
goto done;
}
transforms = g_list_sort(transforms, gst_plugin_feature_rank_compare_func);
for (tmp = transforms; tmp != NULL && element == NULL; tmp = tmp->next)
{
name = gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(tmp->data));
@ -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)))
GST_WARNING("Failed to create %s element.", name);
}
gst_plugin_feature_list_free(transforms);
done:
if (element)
{
GST_DEBUG("Created %s element %p.", name, element);
}
else
{
gchar *src_str = gst_caps_to_string(src_caps), *sink_str = gst_caps_to_string(sink_caps);
GST_WARNING("Failed to create element matching caps %s / %s.", src_str, sink_str);
g_free(sink_str);
g_free(src_str);
}
GST_WARNING("Failed to create element matching caps %"GST_PTR_FORMAT" / %"GST_PTR_FORMAT".",
element_sink_caps, element_src_caps);
return element;
}