[PATCH 4/5] winegstreamer: Lookup and instantiate a WMA decoder element.

Rémi Bernon rbernon at codeweavers.com
Fri Feb 18 11:27:14 CST 2022


Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51931
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52391
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/winegstreamer/wg_transform.c | 66 ++++++++++++++++++++++++++++++-
 1 file changed, 65 insertions(+), 1 deletion(-)

diff --git a/dlls/winegstreamer/wg_transform.c b/dlls/winegstreamer/wg_transform.c
index 120d9fcf1a5..22d97aa1241 100644
--- a/dlls/winegstreamer/wg_transform.c
+++ b/dlls/winegstreamer/wg_transform.c
@@ -78,6 +78,50 @@ NTSTATUS wg_transform_destroy(void *args)
     return STATUS_SUCCESS;
 }
 
+static GstElement *tranform_find_element(GstElementFactoryListType type, GstCaps *src_caps, GstCaps *sink_caps)
+{
+    GstElement *element = NULL;
+    GList *tmp, *transforms;
+    gchar *name;
+
+    transforms = gst_element_factory_list_get_elements(type, GST_RANK_MARGINAL);
+    if (!transforms)
+        goto done;
+
+    tmp = gst_element_factory_list_filter(transforms, src_caps, GST_PAD_SINK, FALSE);
+    gst_plugin_feature_list_free(transforms);
+    if (!(transforms = tmp))
+        goto done;
+
+    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));
+        element = gst_element_factory_create(GST_ELEMENT_FACTORY(tmp->data), NULL);
+        if (!element)
+            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 transform matching caps %s / %s.", src_str, sink_str);
+        g_free(sink_str);
+        g_free(src_str);
+    }
+
+    return element;
+}
+
 static bool transform_append_element(struct wg_transform *transform, GstElement *element,
         GstElement **first, GstElement **last)
 {
@@ -110,12 +154,13 @@ static bool transform_append_element(struct wg_transform *transform, GstElement
 NTSTATUS wg_transform_create(void *args)
 {
     struct wg_transform_create_params *params = args;
+    GstCaps *raw_caps = NULL, *src_caps = NULL, *sink_caps = NULL;
     struct wg_format output_format = *params->output_format;
     struct wg_format input_format = *params->input_format;
     GstElement *first = NULL, *last = NULL, *element;
-    GstCaps *src_caps = NULL, *sink_caps = NULL;
     GstPadTemplate *template = NULL;
     struct wg_transform *transform;
+    const gchar *media_type;
     NTSTATUS status;
     int ret;
 
@@ -131,10 +176,27 @@ NTSTATUS wg_transform_create(void *args)
         goto done;
     if (!(sink_caps = wg_format_to_caps(&output_format)))
         goto done;
+    media_type = gst_structure_get_name(gst_caps_get_structure(sink_caps, 0));
+    if (!(raw_caps = gst_caps_new_empty_simple(media_type)))
+        goto done;
 
     if (!(transform->container = gst_bin_new("wg_transform")))
         goto done;
 
+    switch (input_format.major_type)
+    {
+    case WG_MAJOR_TYPE_WMA:
+        if (!(element = tranform_find_element(GST_ELEMENT_FACTORY_TYPE_DECODER, src_caps, raw_caps)) ||
+                !transform_append_element(transform, element, &first, &last))
+            goto done;
+        break;
+    case WG_MAJOR_TYPE_AUDIO:
+    case WG_MAJOR_TYPE_VIDEO:
+    case WG_MAJOR_TYPE_UNKNOWN:
+        GST_FIXME("Format %u not implemented!", input_format.major_type);
+        goto done;
+    }
+
     switch (output_format.major_type)
     {
     case WG_MAJOR_TYPE_AUDIO:
@@ -181,6 +243,8 @@ NTSTATUS wg_transform_create(void *args)
 done:
     if (template)
         g_object_unref(template);
+    if (raw_caps)
+        gst_caps_unref(raw_caps);
     if (sink_caps)
         gst_caps_unref(sink_caps);
     if (src_caps)
-- 
2.34.1




More information about the wine-devel mailing list