device-manager: Add Dbus interfaces to set/get avoid-resampling feature 17/183717/2
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 10 Jul 2018 08:24:19 +0000 (17:24 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 11 Jul 2018 05:19:34 +0000 (14:19 +0900)
Methods are added as below
 - SetAvoidResampling
    : arg#1 (in)  int32 for device_id
      arg#2 (in)  boolean for enable/disable
 - GetAvoidResampling
    : arg#1 (in)  int32 for device_id
      arg#2 (out) boolean for enabled/disabled

Those APIs are only for usb output device.
Note that the functionality of setting '0' with SetSampleRate method
is totally moved to this SetAvoidResampling method.

[Version] 11.1.16
[Issue Type] New feature

Change-Id: I0f90b1b277349f86b1017b30203260caa3b83243
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/pulseaudio-modules-tizen.spec
src/device-manager.c

index a431c55..af044a5 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          11.1.15
+Version:          11.1.16
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 1f2c416..49fa516 100644 (file)
     "   <arg name=\"device_id\" direction=\"in\" type=\"i\"/>\n"                            \
     "   <arg name=\"stream_role\" direction=\"out\" type=\"s\"/>\n"                         \
     "  </method>\n"                                                                         \
+    "  <method name=\"SetAvoidResampling\">\n"                                              \
+    "   <arg name=\"device_id\" direction=\"in\" type=\"i\"/>\n"                            \
+    "   <arg name=\"avoid_resampling\" direction=\"in\" type=\"b\"/>\n"                     \
+    "  </method>\n"                                                                         \
+    "  <method name=\"GetAvoidResampling\">\n"                                              \
+    "   <arg name=\"device_id\" direction=\"in\" type=\"i\"/>\n"                            \
+    "   <arg name=\"avoid_resampling\" direction=\"out\" type=\"b\"/>\n"                    \
+    "  </method>\n"                                                                         \
     "  <method name=\"DumpDeviceList\">\n"                                                  \
     "  </method>\n"                                                                         \
     "  <method name=\"TestStatusChange\">\n"                                                \
@@ -446,6 +454,8 @@ static void handle_set_sample_rate(DBusConnection *conn, DBusMessage *msg, void
 static void handle_get_sample_rate(DBusConnection *conn, DBusMessage *msg, void *userdata);
 static void handle_set_specific_stream_only(DBusConnection *conn, DBusMessage *msg, void *userdata);
 static void handle_get_specified_stream(DBusConnection *conn, DBusMessage *msg, void *userdata);
+static void handle_set_avoid_resampling(DBusConnection *conn, DBusMessage *msg, void *userdata);
+static void handle_get_avoid_resampling(DBusConnection *conn, DBusMessage *msg, void *userdata);
 static void handle_load_sink(DBusConnection *conn, DBusMessage *msg, void *userdata);
 static void handle_unload_sink(DBusConnection *conn, DBusMessage *msg, void *userdata);
 static void handle_unload_sink_with_device_string(DBusConnection *conn, DBusMessage *msg, void *userdata);
@@ -472,6 +482,8 @@ enum method_handler_index {
     METHOD_HANDLER_GET_SAMPLE_RATE,
     METHOD_HANDLER_SET_SPECIFIC_STREAM_ONLY,
     METHOD_HANDLER_GET_SPECIFIED_STREAM,
+    METHOD_HANDLER_SET_AVOID_RESAMPLING,
+    METHOD_HANDLER_GET_AVOID_RESAMPLING,
     METHOD_HANDLER_DUMP_DEVICE_LIST,
     METHOD_HANDLER_STATUS_TEST,
     METHOD_HANDLER_MAX
@@ -526,6 +538,12 @@ static pa_dbus_method_handler method_handlers[METHOD_HANDLER_MAX] = {
     [METHOD_HANDLER_GET_SPECIFIED_STREAM] = {
         .method_name = "GetSpecifiedStream",
         .receive_cb = handle_get_specified_stream },
+    [METHOD_HANDLER_SET_AVOID_RESAMPLING] = {
+        .method_name = "SetAvoidResampling",
+        .receive_cb = handle_set_avoid_resampling },
+    [METHOD_HANDLER_GET_AVOID_RESAMPLING] = {
+        .method_name = "GetAvoidResampling",
+        .receive_cb = handle_get_avoid_resampling },
     [METHOD_HANDLER_DUMP_DEVICE_LIST] = {
         .method_name = "DumpDeviceList",
         .receive_cb = handle_dump_device_list },
@@ -3603,25 +3621,6 @@ static void handle_set_sample_rate(DBusConnection *conn, DBusMessage *msg, void
         return;
     }
 
-    /* use stream original sample rate if possible */
-    if (sample_rate == 0) {
-        sink->avoid_resampling = true;
-        PA_IDXSET_FOREACH(si, sink->inputs, idx) {
-            if (pa_sink_reconfigure(sink, &si->sample_spec, pa_sink_input_is_passthrough(si)) == -1) {
-                pa_log_error("failed to reconfigure");
-                pa_dbus_send_error(conn, msg, DBUS_ERROR_FAILED, "%s", "org.tizen.multimedia.audio.Internal");
-                sink->avoid_resampling = sink->origin_avoid_resampling;
-                return;
-            }
-        }
-        sink->selected_sample_rate = 0;
-
-        pa_log_info("Set sample rate to avoid resampling for the device(%u) successfully", device_id);
-        pa_assert_se(dbus_connection_send(conn, reply, NULL));
-        dbus_message_unref(reply);
-        return;
-    }
-
     /* use a supported sample rate selected by user */
     if (!is_supported_sample_rate(sink->supported_sample_rates, sample_rate)) {
         pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", "org.tizen.multimedia.audio.InvalidArgument");
@@ -3639,7 +3638,6 @@ static void handle_set_sample_rate(DBusConnection *conn, DBusMessage *msg, void
         }
         break;
     }
-    sink->avoid_resampling = sink->origin_avoid_resampling;
 
     pa_log_info("Set sample rate(%u) of the device(id:%d) successfully", sample_rate, device_id);
     pa_assert_se(dbus_connection_send(conn, reply, NULL));
@@ -3769,6 +3767,111 @@ static void handle_get_specified_stream(DBusConnection *conn, DBusMessage *msg,
     dbus_message_unref(reply);
 }
 
+static void handle_set_avoid_resampling(DBusConnection *conn, DBusMessage *msg, void *userdata) {
+    pa_device_manager *dm;
+    DBusMessage *reply = NULL;
+    dbus_int32_t device_id;
+    dbus_bool_t avoid_resampling;
+    pa_tz_device *device;
+    pa_sink *sink;
+    pa_sink_input *si;
+    uint32_t idx;
+
+    pa_assert(conn);
+    pa_assert(msg);
+    pa_assert(userdata);
+
+    pa_assert_se((reply = dbus_message_new_method_return(msg)));
+    dm = (pa_device_manager *)userdata;
+    pa_assert_se(dbus_message_get_args(msg, NULL,
+                                       DBUS_TYPE_INT32, &device_id,
+                                       DBUS_TYPE_BOOLEAN, &avoid_resampling,
+                                       DBUS_TYPE_INVALID));
+
+    pa_log_info("Set the device(id:%d) avoid-resampling(%d)", device_id, avoid_resampling);
+
+    if (!(device = _device_list_get_device_by_id(dm, device_id))) {
+        pa_log_error("could not find any device with id:%d", device_id);
+        pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", "org.tizen.multimedia.audio.InvalidArgument");
+        return;
+    }
+    if (!is_usb_output_device(device)) {
+        pa_dbus_send_error(conn, msg, DBUS_ERROR_NOT_SUPPORTED, "%s", "org.tizen.multimedia.audio.PolicyInternal");
+        return;
+    }
+    if (!(sink = pa_tz_device_get_sink(device, DEVICE_ROLE_NORMAL))) {
+        pa_log_error("could not get sink for normal role");
+        pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", "org.tizen.multimedia.audio.InvalidArgument");
+        return;
+    }
+    if (sink->avoid_resampling == avoid_resampling) {
+        pa_log_info("already set to %d", avoid_resampling);
+        pa_assert_se(dbus_connection_send(conn, reply, NULL));
+        dbus_message_unref(reply);
+        return;
+    }
+
+    sink->avoid_resampling = avoid_resampling;
+    PA_IDXSET_FOREACH(si, sink->inputs, idx) {
+        if (pa_sink_reconfigure(sink, &si->sample_spec, pa_sink_input_is_passthrough(si)) == -1) {
+            pa_log_error("failed to reconfigure");
+            pa_dbus_send_error(conn, msg, DBUS_ERROR_FAILED, "%s", "org.tizen.multimedia.audio.Internal");
+            sink->avoid_resampling = sink->origin_avoid_resampling;
+            return;
+        }
+    }
+    pa_log_info("Set avoid-resampling(%d) to the device(id:%d)", avoid_resampling, device_id);
+
+    pa_assert_se(dbus_connection_send(conn, reply, NULL));
+    dbus_message_unref(reply);
+}
+
+static void handle_get_avoid_resampling(DBusConnection *conn, DBusMessage *msg, void *userdata) {
+    pa_device_manager *dm;
+    DBusMessage *reply = NULL;
+    dbus_int32_t device_id;
+    dbus_bool_t avoid_resampling;
+    pa_tz_device *device;
+    pa_sink *sink;
+
+    pa_assert(conn);
+    pa_assert(msg);
+    pa_assert(userdata);
+
+    dm = (pa_device_manager *)userdata;
+
+    pa_assert_se((reply = dbus_message_new_method_return(msg)));
+
+    pa_assert_se(dbus_message_get_args(msg, NULL,
+                                       DBUS_TYPE_INT32, &device_id,
+                                       DBUS_TYPE_INVALID));
+
+    pa_log_info("Get avoid-resampling of the device(id:%d)", device_id);
+
+    if (!(device = _device_list_get_device_by_id(dm, device_id))) {
+        pa_log_error("could not find any device with id:%d", device_id);
+        pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", "org.tizen.multimedia.audio.InvalidArgument");
+        return;
+    }
+    if (!is_usb_output_device(device)) {
+        pa_dbus_send_error(conn, msg, DBUS_ERROR_NOT_SUPPORTED, "%s", "org.tizen.multimedia.audio.PolicyInternal");
+        return;
+    }
+    if (!(sink = pa_tz_device_get_sink(device, DEVICE_ROLE_NORMAL))) {
+        pa_log_error("could not get sink for normal role");
+        pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "%s", "org.tizen.multimedia.audio.InvalidArgument");
+        return;
+    }
+
+    avoid_resampling = sink->avoid_resampling;
+    pa_log_info("got avoid-resampling(%d) of the device(id:%d)", avoid_resampling, device_id);
+
+    pa_assert_se((reply = dbus_message_new_method_return(msg)));
+    pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &avoid_resampling, DBUS_TYPE_INVALID));
+    pa_assert_se(dbus_connection_send(conn, reply, NULL));
+    dbus_message_unref(reply);
+}
+
 static void handle_test_device_status_change(DBusConnection *conn, DBusMessage *msg, void *userdata) {
     pa_device_manager *dm = (pa_device_manager *)userdata;
     char *type;