[PATCH v3 4/5] winegstreamer: Append an audioconvert and audioresample elements.

Rémi Bernon rbernon at codeweavers.com
Tue Feb 22 03:41:01 CST 2022


So that we can decode WMA to something else than the default avdec_wmav2
F32LE / non-interleaved format.

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/unix_private.h |  1 +
 dlls/winegstreamer/wg_parser.c    |  2 +-
 dlls/winegstreamer/wg_transform.c | 50 +++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/dlls/winegstreamer/unix_private.h b/dlls/winegstreamer/unix_private.h
index f9c4da2f6ea..d3f32484ee6 100644
--- a/dlls/winegstreamer/unix_private.h
+++ b/dlls/winegstreamer/unix_private.h
@@ -26,6 +26,7 @@
 #include <gst/gst.h>
 
 extern bool init_gstreamer(void) DECLSPEC_HIDDEN;
+extern GstElement *create_element(const char *name, const char *plugin_set) DECLSPEC_HIDDEN;
 
 extern void wg_format_from_caps(struct wg_format *format, const GstCaps *caps) DECLSPEC_HIDDEN;
 extern bool wg_format_compare(const struct wg_format *a, const struct wg_format *b) DECLSPEC_HIDDEN;
diff --git a/dlls/winegstreamer/wg_parser.c b/dlls/winegstreamer/wg_parser.c
index 37da2d1e1c4..d9bbc60964e 100644
--- a/dlls/winegstreamer/wg_parser.c
+++ b/dlls/winegstreamer/wg_parser.c
@@ -699,7 +699,7 @@ static gboolean sink_query_cb(GstPad *pad, GstObject *parent, GstQuery *query)
     }
 }
 
-static GstElement *create_element(const char *name, const char *plugin_set)
+GstElement *create_element(const char *name, const char *plugin_set)
 {
     GstElement *element;
 
diff --git a/dlls/winegstreamer/wg_transform.c b/dlls/winegstreamer/wg_transform.c
index a0805b9c45f..7ed35211915 100644
--- a/dlls/winegstreamer/wg_transform.c
+++ b/dlls/winegstreamer/wg_transform.c
@@ -72,11 +72,34 @@ NTSTATUS wg_transform_destroy(void *args)
     return STATUS_SUCCESS;
 }
 
+static bool transform_append_element(struct wg_transform *transform, GstElement *element,
+        GstElement **first, GstElement **last)
+{
+    gchar *name = gst_element_get_name(element);
+    bool success = false;
+
+    if (!gst_bin_add(GST_BIN(transform->container), element) ||
+            (*last && !gst_element_link(*last, element)))
+        GST_ERROR("Failed to link %s element.", name);
+    else
+    {
+        GST_DEBUG("Linked %s element %p.", name, element);
+        if (!*first)
+            *first = element;
+        *last = element;
+        success = true;
+    }
+
+    g_free(name);
+    return success;
+}
+
 NTSTATUS wg_transform_create(void *args)
 {
     struct wg_transform_create_params *params = args;
     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;
     NTSTATUS status = STATUS_UNSUCCESSFUL;
     GstPadTemplate *template = NULL;
@@ -95,6 +118,33 @@ NTSTATUS wg_transform_create(void *args)
     if (!(sink_caps = wg_format_to_caps(&output_format)))
         goto done;
 
+    switch (output_format.major_type)
+    {
+    case WG_MAJOR_TYPE_AUDIO:
+        /* The MF audio decoder transforms allow decoding to various formats as well
+         * as resampling the audio at the same time, where GStreamer decoder plugins
+         * usually only support decoding to a single format and at the original rate.
+         *
+         * The WMA decoder transform also has output samples interleaved on Windows,
+         * where GStreamer avdec_wmav2 output uses non-interleaved format.
+         *
+         * Adding an audioconvert and audioresample elements will make the required
+         * transformation to match the desired output format.
+         */
+        if (!(element = create_element("audioconvert", "base")) ||
+                !transform_append_element(transform, element, &first, &last))
+            goto done;
+        if (!(element = create_element("audioresample", "base")) ||
+                !transform_append_element(transform, element, &first, &last))
+            goto done;
+        break;
+    case WG_MAJOR_TYPE_VIDEO:
+    case WG_MAJOR_TYPE_WMA:
+    case WG_MAJOR_TYPE_UNKNOWN:
+        GST_FIXME("Format %u not implemented!", output_format.major_type);
+        goto done;
+    }
+
     if (!(template = gst_pad_template_new("src", GST_PAD_SRC, GST_PAD_ALWAYS, src_caps)))
         goto done;
     if (!(transform->my_src = gst_pad_new_from_template(template, "src")))
-- 
2.34.1




More information about the wine-devel mailing list