Module: wine Branch: master Commit: eb7571c8b1c40784b50fe75eb1110ec3b0d3c1b8 URL: https://gitlab.winehq.org/wine/wine/-/commit/eb7571c8b1c40784b50fe75eb1110ec...
Author: Ziqing Hui zhui@codeweavers.com Date: Fri Oct 20 10:40:30 2023 +0800
winegstreamer: Introduce find_element_factories.
---
dlls/winegstreamer/unix_private.h | 5 +++- dlls/winegstreamer/unixlib.c | 58 +++++++++++++++++++++++---------------- 2 files changed, 39 insertions(+), 24 deletions(-)
diff --git a/dlls/winegstreamer/unix_private.h b/dlls/winegstreamer/unix_private.h index eefd3cdb259..ea9803e6003 100644 --- a/dlls/winegstreamer/unix_private.h +++ b/dlls/winegstreamer/unix_private.h @@ -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; diff --git a/dlls/winegstreamer/unixlib.c b/dlls/winegstreamer/unixlib.c index d0d50b34004..ad92ff230f8 100644 --- a/dlls/winegstreamer/unixlib.c +++ b/dlls/winegstreamer/unixlib.c @@ -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) { - GstElement *element = NULL; - GList *tmp, *transforms; - const gchar *name; + GList *tmp, *factories = NULL;
- 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;
- if (src_caps) + if (element_sink_caps) { - tmp = gst_element_factory_list_filter(transforms, src_caps, GST_PAD_SINK, FALSE); - gst_plugin_feature_list_free(transforms); - if (!(transforms = tmp)) + 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 (sink_caps) + if (element_src_caps) { - tmp = gst_element_factory_list_filter(transforms, sink_caps, GST_PAD_SRC, FALSE); - gst_plugin_feature_list_free(transforms); - if (!(transforms = tmp)) + 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; }
- 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) { 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; }