alsa: properly convert position-less channels from ALSA
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Mon, 21 Mar 2016 15:34:37 +0000 (16:34 +0100)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Tue, 12 Apr 2016 18:48:30 +0000 (14:48 -0400)
The only way for ALSA to expose a position-less multi channels is to
return an array full of SND_CHMAP_MONO. Converting this to a
GST_AUDIO_CHANNEL_POSITION_MONO array would be invalid as
GST_AUDIO_CHANNEL_POSITION_MONO is meant to be used only with one
channel.

Fix this by using GST_AUDIO_CHANNEL_POSITION_NONE which is meant to be
used for position-less channels.

https://bugzilla.gnome.org/show_bug.cgi?id=763799

ext/alsa/gstalsa.c

index b9bb291..a44e6e1 100644 (file)
@@ -750,6 +750,7 @@ alsa_chmap_to_channel_positions (const snd_pcm_chmap_t * chmap,
     GstAudioChannelPosition * pos)
 {
   int c;
+  gboolean all_mono = TRUE;
 
   for (c = 0; c < chmap->channels; c++) {
     if (chmap->pos[c] > SND_CHMAP_LAST)
@@ -758,7 +759,22 @@ alsa_chmap_to_channel_positions (const snd_pcm_chmap_t * chmap,
     if (!pos[c])
       return FALSE;
     pos[c]--;
+
+    if (pos[c] != GST_AUDIO_CHANNEL_POSITION_MONO)
+      all_mono = FALSE;
+  }
+
+  if (all_mono && chmap->channels > 1) {
+    /* GST_AUDIO_CHANNEL_POSITION_MONO can only be used with 1 channel and
+     * GST_AUDIO_CHANNEL_POSITION_NONE is meant to be used for position-less
+     * multi channels.
+     * Converting as ALSA can only express such configuration by using an array
+     * full of SND_CHMAP_MONO.
+     */
+    for (c = 0; c < chmap->channels; c++)
+      pos[c] = GST_AUDIO_CHANNEL_POSITION_NONE;
   }
+
   return TRUE;
 }