device-manager: Add Dbus interfaces to specify stream role to usb device 10/178910/4
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 11 May 2018 07:58:32 +0000 (16:58 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 1 Jun 2018 08:38:39 +0000 (17:38 +0900)
Methods are added as below
 - SetSpecificStreamOnly
    : arg#1 (in)  int32 for device_id
      arg#2 (in)  string for stream_role
 - GetSpecifiedStream
    : arg#1 (in)  int32 for device_id
      arg#2 (out) string for stream_role

This information will be used in policy logic to determine which
stream is available for the usb device according to the value.

pa_tz_device_get_specified_stream_role() is also added in tizen-device.c

[Version] 11.1.8
[Issue Type] New feature

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

index 99bb142..2a6b12e 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          11.1.7
+Version:          11.1.8
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 275c439..34f9743 100644 (file)
@@ -50,6 +50,7 @@
 
 #include "communicator.h"
 #include "hal-interface.h"
+#include "stream-manager.h"
 #include "device-manager.h"
 
 #define SHARED_DEVICE_MANAGER "tizen-device-manager"
     "   <arg name=\"device_id\" direction=\"in\" type=\"i\"/>\n"                            \
     "   <arg name=\"sample_rate\" direction=\"out\" type=\"u\"/>\n"                         \
     "  </method>\n"                                                                         \
+    "  <method name=\"SetSpecificStreamOnly\">\n"                                           \
+    "   <arg name=\"device_id\" direction=\"in\" type=\"i\"/>\n"                            \
+    "   <arg name=\"stream_role\" direction=\"in\" type=\"s\"/>\n"                          \
+    "  </method>\n"                                                                         \
+    "  <method name=\"GetSpecifiedStream\">\n"                                              \
+    "   <arg name=\"device_id\" direction=\"in\" type=\"i\"/>\n"                            \
+    "   <arg name=\"stream_role\" direction=\"out\" type=\"s\"/>\n"                         \
+    "  </method>\n"                                                                         \
     "  <method name=\"DumpDeviceList\">\n"                                                  \
     "  </method>\n"                                                                         \
     "  <method name=\"TestStatusChange\">\n"                                                \
@@ -420,6 +429,8 @@ static void handle_get_bt_a2dp_status(DBusConnection *conn, DBusMessage *msg, vo
 static void handle_get_supported_sample_rates(DBusConnection *conn, DBusMessage *msg, void *userdata);
 static void handle_set_sample_rate(DBusConnection *conn, DBusMessage *msg, void *userdata);
 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_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);
@@ -441,6 +452,8 @@ enum method_handler_index {
     METHOD_HANDLER_GET_SUPPORTED_SAMPLE_RATES,
     METHOD_HANDLER_SET_SAMPLE_RATE,
     METHOD_HANDLER_GET_SAMPLE_RATE,
+    METHOD_HANDLER_SET_SPECIFIC_STREAM_ONLY,
+    METHOD_HANDLER_GET_SPECIFIED_STREAM,
     METHOD_HANDLER_DUMP_DEVICE_LIST,
     METHOD_HANDLER_STATUS_TEST,
     METHOD_HANDLER_MAX
@@ -480,6 +493,12 @@ static pa_dbus_method_handler method_handlers[METHOD_HANDLER_MAX] = {
     [METHOD_HANDLER_GET_SAMPLE_RATE] = {
         .method_name = "GetSampleRate",
         .receive_cb = handle_get_sample_rate },
+    [METHOD_HANDLER_SET_SPECIFIC_STREAM_ONLY] = {
+        .method_name = "SetSpecificStreamOnly",
+        .receive_cb = handle_set_specific_stream_only },
+    [METHOD_HANDLER_GET_SPECIFIED_STREAM] = {
+        .method_name = "GetSpecifiedStream",
+        .receive_cb = handle_get_specified_stream },
     [METHOD_HANDLER_DUMP_DEVICE_LIST] = {
         .method_name = "DumpDeviceList",
         .receive_cb = handle_dump_device_list },
@@ -3453,6 +3472,82 @@ static void handle_get_sample_rate(DBusConnection *conn, DBusMessage *msg, void
     dbus_message_unref(reply);
 }
 
+static void handle_set_specific_stream_only(DBusConnection *conn, DBusMessage *msg, void *userdata) {
+    pa_device_manager *dm;
+    DBusMessage *reply = NULL;
+    dbus_int32_t device_id;
+    char *stream_role;
+    pa_tz_device *device;
+
+    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_STRING, &stream_role,
+                                       DBUS_TYPE_INVALID));
+
+    pa_log_info("Set the device(id:%d) only for the stream role(%s)", device_id, stream_role);
+
+    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;
+    }
+
+    device->specified_stream_role = stream_role;
+
+    pa_assert_se(dbus_connection_send(conn, reply, NULL));
+    dbus_message_unref(reply);
+}
+
+static void handle_get_specified_stream(DBusConnection *conn, DBusMessage *msg, void *userdata) {
+    pa_device_manager *dm;
+    DBusMessage *reply = NULL;
+    dbus_int32_t device_id;
+    char *specified_stream_role;
+    pa_tz_device *device;
+
+    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 specified stream role for 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;
+    }
+
+    specified_stream_role = device->specified_stream_role;
+
+    pa_log_info("stream role(%s) is specified for the device(id:%d)", device->specified_stream_role, device_id);
+    pa_assert_se((reply = dbus_message_new_method_return(msg)));
+    pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &specified_stream_role, 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;
index 2204430..ebafc2d 100644 (file)
@@ -143,6 +143,7 @@ static char* _device_get_info_str(pa_tz_device *device) {
     if (device_type_is_equal(device->type, DEVICE_TYPE_USB_AUDIO)) {
         pa_strbuf_printf(buf, "  Vendor ID    : %04x\n", device->vendor_id);
         pa_strbuf_printf(buf, "  Product ID   : %04x\n", device->product_id);
+        pa_strbuf_printf(buf, "  Specified Stream role : %s\n", device->specified_stream_role);
     }
     if (device_type_is_equal(device->type, DEVICE_TYPE_BT_SCO))
         pa_strbuf_printf(buf, "    SCO opened   : %s\n", pa_yes_no(device->sco_opened));
@@ -473,6 +474,7 @@ pa_tz_device* pa_tz_device_new(pa_tz_device_new_data *data) {
     device->use_internal_codec = data->use_internal_codec;
     device->sco_opened = false;
     device->is_running = false;
+    device->specified_stream_role = "none";
 
     if (device_type_is_use_external_card(device->type)) {
         if ((sink = device_get_sink(device, DEVICE_ROLE_NORMAL)))
@@ -690,6 +692,15 @@ int pa_tz_device_get_product_id(pa_tz_device *device) {
     return device->product_id;
 }
 
+char* pa_tz_device_get_specified_stream_role(pa_tz_device *device) {
+    pa_assert(device);
+
+    if (pa_streq("none", device->specified_stream_role))
+        return NULL;
+
+    return device->specified_stream_role;
+}
+
 dm_device_direction_t pa_tz_device_get_direction(pa_tz_device *device) {
     pa_assert(device);
 
index 8a440ac..b0235d2 100644 (file)
@@ -44,6 +44,8 @@ struct pa_tz_device {
      * It will be replaced by is_running variable */
     dm_device_state_t state;
 
+    char *specified_stream_role;
+
     /* If it is changed, will notify via callback */
     bool is_running;
 
@@ -160,6 +162,7 @@ int pa_tz_device_sco_get_status(pa_tz_device *device, dm_device_bt_sco_status_t
 /* Only for USB device */
 int pa_tz_device_get_vendor_id(pa_tz_device *device);
 int pa_tz_device_get_product_id(pa_tz_device *device);
+char* pa_tz_device_get_specified_stream_role(pa_tz_device *device);
 
 void pa_intset_free(pa_intset *s);
 int pa_intset_first(pa_intset *s, int *val);