From 60146e3097c864f9db68002cbda44c95b11cc902 Mon Sep 17 00:00:00 2001 From: Jacek Tomaszewski Date: Wed, 12 Dec 2018 13:14:13 +0100 Subject: [PATCH] wasapi: Fixed corner-cases in mapping of channel mask 'channel-mask' field should not be put in caps if channel mask is 0x0 Mapping WASAPI channel mask to GST equivalent was going only over first nChannels elements of wasapi_to_gst_pos array, translating, for example, WASAPI's 0x63f to GST's 0x3f instead of 0xc3f. When 'channel-mask' is specified as NULL, it signifies that there's need to do downmix or upmix and it makes caps negotiation with audioconvert element impossible. Just omit it. Signed-off-by: Nirbheek Chauhan --- sys/wasapi/gstwasapiutil.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/sys/wasapi/gstwasapiutil.c b/sys/wasapi/gstwasapiutil.c index f2f62aa06c..2e191f496e 100644 --- a/sys/wasapi/gstwasapiutil.c +++ b/sys/wasapi/gstwasapiutil.c @@ -695,7 +695,7 @@ static guint64 gst_wasapi_util_waveformatex_to_channel_mask (WAVEFORMATEXTENSIBLE * format, GstAudioChannelPosition ** out_position) { - int ii; + int ii, ch; guint64 mask = 0; WORD nChannels = format->Format.nChannels; DWORD dwChannelMask = format->dwChannelMask; @@ -719,14 +719,19 @@ gst_wasapi_util_waveformatex_to_channel_mask (WAVEFORMATEXTENSIBLE * format, /* Map WASAPI's channel mask to Gstreamer's channel mask and positions. * If the no. of bits in the mask > nChannels, we will ignore the extra. */ - for (ii = 0; ii < nChannels; ii++) { + for (ii = 0, ch = 0; ii < G_N_ELEMENTS (wasapi_to_gst_pos) && ch < nChannels; + ii++) { if (!(dwChannelMask & wasapi_to_gst_pos[ii].wasapi_pos)) - /* Non-positional or unknown position, warn? */ + /* no match, try next */ continue; mask |= G_GUINT64_CONSTANT (1) << wasapi_to_gst_pos[ii].gst_pos; - pos[ii] = wasapi_to_gst_pos[ii].gst_pos; + pos[ch++] = wasapi_to_gst_pos[ii].gst_pos; } + /* XXX: Warn if some channel masks couldn't be mapped? */ + + GST_DEBUG ("Converted WASAPI mask 0x%x -> 0x%x", dwChannelMask, mask); + out: if (out_position) *out_position = pos; @@ -773,8 +778,12 @@ gst_wasapi_util_parse_waveformatex (WAVEFORMATEXTENSIBLE * format, gst_structure_set (s, "format", G_TYPE_STRING, afmt, "channels", G_TYPE_INT, format->Format.nChannels, - "rate", G_TYPE_INT, format->Format.nSamplesPerSec, - "channel-mask", GST_TYPE_BITMASK, channel_mask, NULL); + "rate", G_TYPE_INT, format->Format.nSamplesPerSec, NULL); + + if (channel_mask) { + gst_structure_set (s, + "channel-mask", GST_TYPE_BITMASK, channel_mask, NULL); + } } return TRUE;