Merge branch 'upstream/1.16' into tizen_gst_1.16.2
[platform/upstream/gst-plugins-good.git] / ext / pulse / pulseutil.c
index 83aa4b6..6f00f75 100644 (file)
@@ -358,6 +358,11 @@ make_proplist_item (GQuark field_id, const GValue * value, gpointer user_data)
     case G_TYPE_STRING:
       pa_proplist_sets (p, prop_id, g_value_get_string (value));
       break;
+#ifdef __TIZEN__
+    case G_TYPE_INT:
+      pa_proplist_setf (p, prop_id, "%d", g_value_get_int (value));
+      break;
+#endif
     default:
       GST_WARNING ("unmapped property type %s", G_VALUE_TYPE_NAME (value));
       break;
@@ -450,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) {
@@ -467,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);
@@ -507,3 +512,96 @@ gst_pulse_format_info_to_caps (pa_format_info * format)
 out:
   return ret;
 }
+
+#ifdef __TIZEN__
+#include <gio/gio.h>
+#define PA_BUS_NAME                                    "org.pulseaudio.Server"
+#define PA_STREAM_MANAGER_OBJECT_PATH                  "/org/pulseaudio/StreamManager"
+#define PA_STREAM_MANAGER_INTERFACE                    "org.pulseaudio.StreamManager"
+#define PA_STREAM_MANAGER_METHOD_NAME_SET_VOLUME_RATIO          "SetVolumeRatio"
+void
+gst_pulse_set_volume_ratio (uint32_t stream_index, const char *direction, double ratio)
+{
+  GDBusConnection *conn = NULL;
+  GError *err = NULL;
+  GVariant *result = NULL;
+  const gchar *dbus_ret = NULL;
+
+  conn = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &err);
+  if (!conn || err) {
+      GST_ERROR ("g_bus_get_sync() error (%s)", err ? err->message : NULL);
+    if (err)
+      g_error_free (err);
+    return;
+  }
+
+  result = g_dbus_connection_call_sync (conn,
+        PA_BUS_NAME,
+        PA_STREAM_MANAGER_OBJECT_PATH,
+        PA_STREAM_MANAGER_INTERFACE,
+        PA_STREAM_MANAGER_METHOD_NAME_SET_VOLUME_RATIO,
+        g_variant_new("(sud)", direction, stream_index, ratio),
+        G_VARIANT_TYPE("(s)"),
+        G_DBUS_CALL_FLAGS_NONE,
+        1000,
+        NULL,
+        &err);
+  if (!result || err) {
+    GST_ERROR ("g_dbus_connection_call_sync() for SET_VOLUME_RATIO error (%s)", err ? err->message : NULL);
+    if (err)
+      g_error_free (err);
+    goto finish;
+  }
+  g_variant_get (result, "(&s)", &dbus_ret);
+  GST_DEBUG ("SET_VOLUME_RATIO returns value(%s) for stream index(%u), ratio(%f)", dbus_ret, stream_index, ratio);
+
+finish:
+  g_variant_unref(result);
+  g_object_unref(conn);
+
+  return;
+}
+#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;
+}