stream-manager-dbus: Add new DBus method to get preferred device id 36/212936/4 submit/tizen/20190829.100932
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 28 Aug 2019 08:27:01 +0000 (17:27 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 29 Aug 2019 08:12:50 +0000 (17:12 +0900)
  server          : org.pulseaudio.Server
  object path     : /org/pulseaudio/StreamManager
  interface       : org.pulseaudio.StreamManager

  method name     : GetStreamPreferredDevice
  method argument : [in] unsigned int for stream index
                    [out] unsigned int for input device id
                    [out] unsigned int for output device id
  return value    : string for return message
                    - success          : "STREAM_MANAGER_RETURN_OK"
                    - internal error   : "STREAM_MANAGER_RETURN_ERROR_INTERNAL"

[Version] 11.1.71
[Issue Type] Improvement

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

index 9ca471b..d71d26f 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          11.1.70
+Version:          11.1.71
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 651f95a..6f1585f 100644 (file)
@@ -31,6 +31,7 @@
 #define STREAM_MANAGER_METHOD_NAME_SET_STREAM_ROUTE_DEVICES          "SetStreamRouteDevices"
 #define STREAM_MANAGER_METHOD_NAME_SET_STREAM_ROUTE_OPTION           "SetStreamRouteOption"
 #define STREAM_MANAGER_METHOD_NAME_SET_STREAM_PREFERRED_DEVICE       "SetStreamPreferredDevice"
+#define STREAM_MANAGER_METHOD_NAME_GET_STREAM_PREFERRED_DEVICE       "GetStreamPreferredDevice"
 #define STREAM_MANAGER_METHOD_NAME_SET_VOLUME_LEVEL                  "SetVolumeLevel"
 #define STREAM_MANAGER_METHOD_NAME_GET_VOLUME_LEVEL                  "GetVolumeLevel"
 #define STREAM_MANAGER_METHOD_NAME_GET_VOLUME_MAX_LEVEL              "GetVolumeMaxLevel"
@@ -62,6 +63,7 @@ enum method_handler_index {
     METHOD_HANDLER_SET_STREAM_ROUTE_DEVICES,
     METHOD_HANDLER_SET_STREAM_ROUTE_OPTION,
     METHOD_HANDLER_SET_STREAM_PREFERRED_DEVICE,
+    METHOD_HANDLER_GET_STREAM_PREFERRED_DEVICE,
     METHOD_HANDLER_SET_VOLUME_LEVEL,
     METHOD_HANDLER_GET_VOLUME_LEVEL,
     METHOD_HANDLER_GET_VOLUME_MAX_LEVEL,
@@ -135,6 +137,12 @@ pa_dbus_interface_info stream_manager_interface_info = {
     "   <arg name=\"device_id\" direction=\"in\" type=\"u\"/>"               \
     "   <arg name=\"ret_msg\" direction=\"out\" type=\"s\"/>"                \
     "  </method>"                                                            \
+    "  <method name=\"STREAM_MANAGER_METHOD_NAME_GET_STREAM_PREFERRED_DEVICE\">" \
+    "   <arg name=\"parent_id\" direction=\"in\" type=\"u\"/>"               \
+    "   <arg name=\"in_device_id\" direction=\"out\" type=\"u\"/>"           \
+    "   <arg name=\"out_device_id\" direction=\"out\" type=\"u\"/>"          \
+    "   <arg name=\"ret_msg\" direction=\"out\" type=\"s\"/>"                \
+    "  </method>"                                                            \
     "  <method name=\"STREAM_MANAGER_METHOD_NAME_SET_VOLUME_LEVEL\">"        \
     "   <arg name=\"io_direction\" direction=\"in\" type=\"s\"/>"            \
     "   <arg name=\"type\" direction=\"in\" type=\"s\"/>"                    \
index 48ce7b4..b752363 100644 (file)
@@ -46,6 +46,7 @@ static void handle_get_stream_list(DBusConnection *conn, DBusMessage *msg, void
 static void handle_set_stream_route_devices(DBusConnection *conn, DBusMessage *msg, void *userdata);
 static void handle_set_stream_route_option(DBusConnection *conn, DBusMessage *msg, void *userdata);
 static void handle_set_stream_preferred_device(DBusConnection *conn, DBusMessage *msg, void *userdata);
+static void handle_get_stream_preferred_device(DBusConnection *conn, DBusMessage *msg, void *userdata);
 static void handle_set_volume_level(DBusConnection *conn, DBusMessage *msg, void *userdata);
 static void handle_get_volume_level(DBusConnection *conn, DBusMessage *msg, void *userdata);
 static void handle_get_volume_max_level(DBusConnection *conn, DBusMessage *msg, void *userdata);
@@ -89,6 +90,10 @@ static pa_dbus_arg_info set_stream_preferred_device_args[]  = { { "parent_id", "
                                                              { "io_direction", "s", "in" },
                                                                 { "device_id", "u", "in" },
                                                                { "ret_msg", "s", "out" } };
+static pa_dbus_arg_info get_stream_preferred_device_args[]  = { { "parent_id", "u", "in" },
+                                                            { "in_device_id", "u", "out" },
+                                                           { "out_device_id", "u", "out" },
+                                                               { "ret_msg", "s", "out" } };
 static pa_dbus_arg_info set_volume_level_args[]  = { { "io_direction", "s", "in" },
                                                              { "type", "s", "in" },
                                                             { "level", "u", "in" },
@@ -170,6 +175,7 @@ static const char* signature_args_for_in[] = {
     "uauau",    /* METHOD_HANDLER_SET_STREAM_ROUTE_DEVICES */
     "usi",      /* METHOD_HANDLER_SET_STREAM_ROUTE_OPTION */
     "usu",      /* METHOD_HANDLER_SET_STREAM_PREFERRED_DEVICE */
+    "u",        /* METHOD_HANDLER_GET_STREAM_PREFERRED_DEVICE */
     "ssu",      /* METHOD_HANDLER_SET_VOLUME_LEVEL */
     "ss",       /* METHOD_HANDLER_GET_VOLUME_LEVEL */
     "ss",       /* METHOD_HANDLER_GET_VOLUME_MAX_LEVEL */
@@ -218,6 +224,11 @@ static pa_dbus_method_handler method_handlers[METHOD_HANDLER_MAX] = {
         .arguments = set_stream_preferred_device_args,
         .n_arguments = sizeof(set_stream_preferred_device_args) / sizeof(pa_dbus_arg_info),
         .receive_cb = handle_set_stream_preferred_device },
+    [METHOD_HANDLER_GET_STREAM_PREFERRED_DEVICE] = {
+        .method_name = STREAM_MANAGER_METHOD_NAME_GET_STREAM_PREFERRED_DEVICE,
+        .arguments = get_stream_preferred_device_args,
+        .n_arguments = sizeof(get_stream_preferred_device_args) / sizeof(pa_dbus_arg_info),
+        .receive_cb = handle_get_stream_preferred_device },
     [METHOD_HANDLER_SET_VOLUME_LEVEL] = {
         .method_name = STREAM_MANAGER_METHOD_NAME_SET_VOLUME_LEVEL,
         .arguments = set_volume_level_args,
@@ -729,8 +740,13 @@ static void handle_set_stream_preferred_device(DBusConnection *conn, DBusMessage
     /* get default role of the device */
     device_role = pa_tz_device_get_role(device, NULL);
 
-    sp->preferred_device.roles[direction] = pa_safe_streq(device_role, DEVICE_ROLE_NORMAL) ? NULL : device_role;
-    sp->preferred_device.types[direction] = sp->preferred_device.roles[direction] ? device->type : NULL;
+    if (device_id == 0) {
+        sp->preferred_device.types[direction] = NULL;
+        sp->preferred_device.roles[direction] = NULL;
+    } else {
+        sp->preferred_device.types[direction] = device->type;
+        sp->preferred_device.roles[direction] = device_role;
+    }
 
     pa_log_info("preferred device role is set to [%s] of device type[%s], direction[%s]",
             sp->preferred_device.roles[direction], device->type, direction == STREAM_DIRECTION_OUT ? "out" :  "in");
@@ -753,7 +769,7 @@ static void handle_set_stream_preferred_device(DBusConnection *conn, DBusMessage
         stream_index = (direction == STREAM_DIRECTION_OUT) ?
                         PA_SINK_INPUT(stream)->index : PA_SOURCE_OUTPUT(stream)->index;
 
-        if (pa_safe_streq(device_role, DEVICE_ROLE_NORMAL))
+        if (device_id == 0)
             pa_proplist_unset(props, PA_PROP_MEDIA_ROUTE_AUTO_PREFERRED_DEVICE_ROLE);
         else
             pa_proplist_sets(props, PA_PROP_MEDIA_ROUTE_AUTO_PREFERRED_DEVICE_ROLE, device_role);
@@ -803,6 +819,73 @@ finish:
     dbus_message_unref(reply);
 }
 
+static void handle_get_stream_preferred_device(DBusConnection *conn, DBusMessage *msg, void *userdata) {
+    stream_parent *sp = NULL;
+    uint32_t sp_id = 0;
+    uint32_t in_device_id = 0;
+    uint32_t out_device_id = 0;
+    const char *pref_in_type, *pref_out_type;
+    const char *pref_in_role, *pref_out_role;
+    pa_idxset *dm_device_list;
+    pa_tz_device *dm_device;
+    dm_device_direction_t dm_direction;
+    uint32_t idx = 0;
+    ret_msg_t ret = RET_MSG_OK;
+    DBusMessage *reply = NULL;
+
+    pa_stream_manager *m = (pa_stream_manager*)userdata;
+
+    pa_assert(conn);
+    pa_assert(msg);
+    pa_assert(m);
+
+    pa_assert_se(dbus_message_get_args(msg, NULL,
+                                       DBUS_TYPE_UINT32, &sp_id,
+                                       DBUS_TYPE_INVALID));
+    pa_log_info("stream parent id[%u]", sp_id);
+
+    pa_assert_se((reply = dbus_message_new_method_return(msg)));
+
+    if (!(sp = pa_hashmap_get(m->stream_parents, (const void*)sp_id))) {
+        pa_log_error("could not find matching client for this parent_id[%u]", sp_id);
+        ret = RET_MSG_ERROR_INTERNAL;
+        goto finish;
+    }
+
+    pref_in_type = sp->preferred_device.types[STREAM_DIRECTION_IN];
+    pref_in_role = sp->preferred_device.roles[STREAM_DIRECTION_IN];
+    pref_out_type = sp->preferred_device.types[STREAM_DIRECTION_OUT];
+    pref_out_role = sp->preferred_device.roles[STREAM_DIRECTION_OUT];
+
+    /* get device ids of preferred in/out device respectively */
+    dm_device_list = pa_device_manager_get_device_list(m->dm);
+    PA_IDXSET_FOREACH(dm_device, dm_device_list, idx) {
+        dm_direction = pa_tz_device_get_direction(dm_device);
+        if (!in_device_id && dm_direction & DM_DEVICE_DIRECTION_IN) {
+            if (pa_safe_streq(pref_in_type, pa_tz_device_get_type(dm_device))) {
+                if (pa_safe_streq(pref_in_role, pa_tz_device_get_role(dm_device, pref_in_role)))
+                    in_device_id = pa_tz_device_get_id(dm_device);
+            }
+        }
+        if (!out_device_id && dm_direction & DM_DEVICE_DIRECTION_OUT) {
+            if (pa_safe_streq(pref_out_type, pa_tz_device_get_type(dm_device))) {
+                if (pa_safe_streq(pref_out_role, pa_tz_device_get_role(dm_device, pref_out_role)))
+                    out_device_id = pa_tz_device_get_id(dm_device);
+            }
+        }
+    }
+
+    pa_log_info("preferred  IN device: type[%s] role[%s] id[%u]",  pref_in_type, pref_in_role, in_device_id);
+    pa_log_info("preferred  OUT device: type[%s] role[%s] id[%u]", pref_out_type, pref_out_role, out_device_id);
+
+finish:
+    pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &in_device_id, DBUS_TYPE_INVALID));
+    pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_UINT32, &out_device_id, DBUS_TYPE_INVALID));
+    pa_assert_se(dbus_message_append_args(reply, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret], DBUS_TYPE_INVALID));
+    pa_assert_se(dbus_connection_send(conn, reply, NULL));
+    dbus_message_unref(reply);
+}
+
 static void handle_set_volume_level(DBusConnection *conn, DBusMessage *msg, void *userdata) {
     const char *direction = NULL;
     const char *type = NULL;