osxaudio: Avoid making a duplicate structure in caps for mono/stereo case
authorArun Raghavan <arun@centricular.com>
Tue, 7 Apr 2015 10:10:14 +0000 (15:40 +0530)
committerArun Raghavan <git@arunraghavan.net>
Tue, 14 Jul 2015 12:19:50 +0000 (17:49 +0530)
For 1ch or 2ch devices, we just need to set the caps to allow both
options since CoreAudio will up/downmix appropriately.

Also fixes the condition for the 2ch case to be exact, rather than at
least 2 channels since the downmix will not take place in the >stereo
case.

sys/osxaudio/gstosxcoreaudio.c

index 10fcd9c..60983a8 100644 (file)
@@ -542,6 +542,10 @@ gst_core_audio_get_channel_layout (GstCoreAudio * core_audio, gboolean outer)
   return layout;
 }
 
+#define STEREO_CHANNEL_MASK \
+  (GST_AUDIO_CHANNEL_POSITION_MASK (FRONT_LEFT) | \
+   GST_AUDIO_CHANNEL_POSITION_MASK (FRONT_RIGHT))
+
 GstCaps *
 gst_core_audio_probe_caps (GstCoreAudio * core_audio, GstCaps * in_caps)
 {
@@ -617,43 +621,27 @@ gst_core_audio_probe_caps (GstCoreAudio * core_audio, GstCaps * in_caps)
         gst_structure_remove_field (out_s, "channel-mask");
       }
 
-      gst_caps_append_structure (caps, out_s);
-
       /* Special cases for upmixing and downmixing.
        * Other than that, the AUs don't upmix or downmix multi-channel audio,
        * e.g. if you push 5.1-surround audio to a stereo configuration,
        * the left and right channels will be played accordingly,
        * and the rest will be dropped. */
 
-      if (channels >= 2 &&
-          (channel_mask & GST_AUDIO_CHANNEL_POSITION_MASK (FRONT_LEFT)) &&
-          (channel_mask & GST_AUDIO_CHANNEL_POSITION_MASK (FRONT_RIGHT))) {
+      if (channels == 1 || (channels == 2 &&
+              (channel_mask == 0 || channel_mask == STEREO_CHANNEL_MASK))) {
 
         /* If have stereo channels, then also offer mono since CoreAudio
-         * upmixes it */
-
-        out_s = gst_structure_copy (out_s);
-
-        gst_structure_set (out_s, "channels", G_TYPE_INT, 1, NULL);
-        /* Mono has no channel-mask */
-        gst_structure_remove_field (out_s, "channel-mask");
-
-        gst_caps_append_structure (caps, out_s);
+         * upmixes it. If mono, then also offer stereo since CoreAudio
+         * downmixes to it */
 
-      } else if (channels == 1 && channel_mask == 0) {
+        gst_structure_set (out_s, "channels", GST_TYPE_INT_RANGE, 1, 2, NULL);
 
-        /* If mono, then also offer stereo since CoreAudio downmixes to it */
-
-        out_s = gst_structure_copy (out_s);
-
-        gst_structure_set (out_s,
-            "channels", G_TYPE_INT, 1,
-            "channel-mask", GST_TYPE_BITMASK,
-            GST_AUDIO_CHANNEL_POSITION_MASK (FRONT_LEFT) |
-            GST_AUDIO_CHANNEL_POSITION_MASK (FRONT_RIGHT), NULL);
-
-        gst_caps_append_structure (caps, out_s);
+        if (channels == 1)
+          gst_structure_set (out_s, "channel-mask", GST_TYPE_BITMASK,
+              STEREO_CHANNEL_MASK, NULL);
       }
+
+      gst_caps_append_structure (caps, out_s);
     }
   }