Merge branch 'upstream/1.16' into tizen_gst_1.16.2
[platform/upstream/gst-plugins-good.git] / ext / pulse / pulseutil.c
index 662fb05..6f00f75 100644 (file)
@@ -455,7 +455,7 @@ gst_pulse_format_info_to_caps (pa_format_info * format)
       if (pa_format_info_get_prop_string (format,
               PA_PROP_FORMAT_SAMPLE_FORMAT, &tmp)) {
         /* No specific sample format means any sample format */
-        ret = gst_caps_from_string (_PULSE_CAPS_PCM);
+        ret = gst_pulse_fix_pcm_caps (gst_caps_from_string (_PULSE_CAPS_PCM));
         goto out;
 
       } else if (ss.format == PA_SAMPLE_ALAW) {
@@ -472,7 +472,7 @@ gst_pulse_format_info_to_caps (pa_format_info * format)
         ret = gst_caps_from_string (_PULSE_CAPS_LINEAR);
 
         if (sformat)
-          gst_caps_set_simple (ret, "format", G_TYPE_STRING, NULL);
+          gst_caps_set_simple (ret, "format", G_TYPE_STRING, sformat, NULL);
       }
 
       pa_xfree (tmp);
@@ -561,4 +561,47 @@ finish:
 
   return;
 }
-#endif
\ No newline at end of file
+#endif
+
+GstCaps *
+gst_pulse_fix_pcm_caps (GstCaps * incaps)
+{
+  GstCaps *outcaps;
+  int i;
+
+  outcaps = gst_caps_make_writable (incaps);
+
+  for (i = 0; i < gst_caps_get_size (outcaps); i++) {
+    GstStructure *st = gst_caps_get_structure (outcaps, i);
+    const gchar *format = gst_structure_get_name (st);
+    const GValue *value;
+    GValue new_value = G_VALUE_INIT;
+    gint min, max, step;
+
+    if (!(g_str_equal (format, "audio/x-raw") ||
+            g_str_equal (format, "audio/x-alaw") ||
+            g_str_equal (format, "audio/x-mulaw")))
+      continue;
+
+    value = gst_structure_get_value (st, "rate");
+
+    if (!GST_VALUE_HOLDS_INT_RANGE (value))
+      continue;
+
+    min = gst_value_get_int_range_min (value);
+    max = gst_value_get_int_range_max (value);
+    step = gst_value_get_int_range_step (value);
+
+    if (min > PA_RATE_MAX)
+      min = PA_RATE_MAX;
+    if (max > PA_RATE_MAX)
+      max = PA_RATE_MAX;
+
+    g_value_init (&new_value, GST_TYPE_INT_RANGE);
+    gst_value_set_int_range_step (&new_value, min, max, step);
+
+    gst_structure_take_value (st, "rate", &new_value);
+  }
+
+  return outcaps;
+}