[PATCH 1/2] winegstreamer: Support block_alignment attribute mapping.

Rémi Bernon rbernon at codeweavers.com
Wed Oct 27 10:25:03 CDT 2021


Planet Coaster adds this attribute to its media type when loading user
music in some of the supported formats, and missing it will make media
type matching only partially succeed.

This will also be useful for WMA/XMA compressed formats.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/winegstreamer/mfplat.c    | 10 ++++++++--
 dlls/winegstreamer/unixlib.h   |  1 +
 dlls/winegstreamer/wg_parser.c |  8 +++++++-
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/dlls/winegstreamer/mfplat.c b/dlls/winegstreamer/mfplat.c
index 58200dc409a..340cb92e87a 100644
--- a/dlls/winegstreamer/mfplat.c
+++ b/dlls/winegstreamer/mfplat.c
@@ -547,8 +547,8 @@ static inline UINT64 make_uint64(UINT32 high, UINT32 low)
 
 static IMFMediaType *mf_media_type_from_wg_format_audio(const struct wg_format *format)
 {
+    unsigned int i, block_alignment;
     IMFMediaType *type;
-    unsigned int i;
 
     for (i = 0; i < ARRAY_SIZE(audio_formats); ++i)
     {
@@ -564,6 +564,8 @@ static IMFMediaType *mf_media_type_from_wg_format_audio(const struct wg_format *
             IMFMediaType_SetUINT32(type, &MF_MT_AUDIO_NUM_CHANNELS, format->u.audio.channels);
             IMFMediaType_SetUINT32(type, &MF_MT_AUDIO_CHANNEL_MASK, format->u.audio.channel_mask);
             IMFMediaType_SetUINT32(type, &MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
+            block_alignment = format->u.audio.channels * audio_formats[i].depth / 8;
+            IMFMediaType_SetUINT32(type, &MF_MT_AUDIO_BLOCK_ALIGNMENT, block_alignment);
 
             return type;
         }
@@ -621,7 +623,7 @@ IMFMediaType *mf_media_type_from_wg_format(const struct wg_format *format)
 
 static void mf_media_type_to_wg_format_audio(IMFMediaType *type, struct wg_format *format)
 {
-    UINT32 rate, channels, channel_mask, depth;
+    UINT32 rate, channels, channel_mask, depth, block_alignment;
     unsigned int i;
     GUID subtype;
 
@@ -658,10 +660,14 @@ static void mf_media_type_to_wg_format_audio(IMFMediaType *type, struct wg_forma
         }
     }
 
+    if (FAILED(IMFMediaType_GetUINT32(type, &MF_MT_AUDIO_BLOCK_ALIGNMENT, &block_alignment)))
+        block_alignment = 0;
+
     format->major_type = WG_MAJOR_TYPE_AUDIO;
     format->u.audio.channels = channels;
     format->u.audio.channel_mask = channel_mask;
     format->u.audio.rate = rate;
+    format->u.audio.block_alignment = block_alignment;
 
     for (i = 0; i < ARRAY_SIZE(audio_formats); ++i)
     {
diff --git a/dlls/winegstreamer/unixlib.h b/dlls/winegstreamer/unixlib.h
index 90101893541..9a98e97e7d7 100644
--- a/dlls/winegstreamer/unixlib.h
+++ b/dlls/winegstreamer/unixlib.h
@@ -87,6 +87,7 @@ struct wg_format
             uint32_t channels;
             uint32_t channel_mask; /* In WinMM format. */
             uint32_t rate;
+            uint32_t block_alignment;
         } audio;
     } u;
 };
diff --git a/dlls/winegstreamer/wg_parser.c b/dlls/winegstreamer/wg_parser.c
index c3c9051a174..3b341dad9eb 100644
--- a/dlls/winegstreamer/wg_parser.c
+++ b/dlls/winegstreamer/wg_parser.c
@@ -411,13 +411,19 @@ static GstCaps *wg_format_to_caps_audio(const struct wg_format *format)
     GstAudioChannelPosition positions[32];
     GstAudioFormat audio_format;
     GstAudioInfo info;
+    GstCaps *caps;
 
     if ((audio_format = wg_audio_format_to_gst(format->u.audio.format)) == GST_AUDIO_FORMAT_UNKNOWN)
         return NULL;
 
     wg_channel_mask_to_gst(positions, format->u.audio.channel_mask, format->u.audio.channels);
     gst_audio_info_set_format(&info, audio_format, format->u.audio.rate, format->u.audio.channels, positions);
-    return gst_audio_info_to_caps(&info);
+    caps = gst_audio_info_to_caps(&info);
+
+    if (format->u.audio.block_alignment)
+        gst_caps_set_simple(caps, "block_align", G_TYPE_INT, format->u.audio.block_alignment, NULL);
+
+    return caps;
 }
 
 static GstVideoFormat wg_video_format_to_gst(enum wg_video_format format)
-- 
2.33.0




More information about the wine-devel mailing list