? gstalsasink.patch
Index: gstalsasink.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/ext/alsa/gstalsasink.c,v
retrieving revision 1.67
diff -u -u -r1.67 gstalsasink.c
--- gstalsasink.c	8 Apr 2006 16:21:15 -0000	1.67
+++ gstalsasink.c	18 Apr 2006 17:51:25 -0000
@@ -386,8 +386,20 @@
   GstAlsaSink *sink = GST_ALSA_SINK (bsink);
   GstCaps *tmpl_caps;
   GstCaps *caps = NULL;
+  GstStructure *s;
   guint min, max;
-  gint i, err, min_channels, max_channels;
+  gint i, err, width;
+  gint min_channels, max_channels;
+  guint bits = 0;
+  static const int audio_fmts[] = {
+    SND_PCM_FORMAT_U8, SND_PCM_FORMAT_S8,
+    SND_PCM_FORMAT_S16, SND_PCM_FORMAT_U16,
+    /*SND_PCM_FORMAT_S24, SND_PCM_FORMAT_U24,*/
+    SND_PCM_FORMAT_S32, SND_PCM_FORMAT_U32
+  };
+  static const guint audio_bits[] = {
+    8,8,16,16,32,32
+  };
 
   if (sink->handle == NULL) {
     GST_DEBUG_OBJECT (sink, "device not open, using template caps");
@@ -432,10 +444,18 @@
 
   GST_LOG_OBJECT (sink, "Min. channels = %d (%d)", min_channels, min);
   GST_LOG_OBJECT (sink, "Max. channels = %d (%d)", max_channels, max);
-
+  
   snd_pcm_format_mask_alloca (&mask);
   snd_pcm_hw_params_get_format_mask (hw_params, mask);
-
+  for (i = 0; i < 6; i++) {
+    if (snd_pcm_format_mask_test (mask, audio_fmts[i])) {
+      bits |= audio_bits[i];
+    }
+  }
+  GST_LOG_OBJECT (sink, "Bits = 0x%08x", bits);
+  
+  /* fill caps according to capabilities gathered above */
+  
   element_class = GST_ELEMENT_GET_CLASS (sink);
   pad_template = gst_element_class_get_pad_template (element_class, "sink");
 
@@ -446,8 +466,15 @@
   caps = gst_caps_new_empty ();
 
   for (i = 0; i < gst_caps_get_size (tmpl_caps); ++i) {
-    caps_add_channel_configuration (caps,
-        gst_caps_get_structure (tmpl_caps, i), min_channels, max_channels);
+    s = gst_caps_get_structure (tmpl_caps, i);
+    gst_structure_get_int (s, "width", &width);
+    /* TODO: filter signed/unsigned */
+    if (bits & width) {
+      caps_add_channel_configuration (caps, s , min_channels, max_channels);
+    }
+    else {
+      GST_LOG_OBJECT (sink, "width = %d unsupported", width);
+    }
   }
 
   sink->cached_caps = gst_caps_ref (caps);
@@ -679,9 +706,8 @@
 {
   switch (spec->type) {
     case GST_BUFTYPE_LINEAR:
-      GST_DEBUG_OBJECT (alsa,
-          "Linear format : depth=%d, width=%d, sign=%d, bigend=%d", spec->depth,
-          spec->width, spec->sign, spec->bigend);
+      GST_DEBUG_OBJECT (alsa, "Linear format : depth=%d, width=%d, sign=%d, bigend=%d",
+        spec->depth, spec->width, spec->sign, spec->bigend);
 
       alsa->format = snd_pcm_build_linear_format (spec->depth, spec->width,
           spec->sign ? 0 : 1, spec->bigend ? 1 : 0);
