device-manager: Add 'role' parameter to device_list_get_device() 14/207914/3
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 14 Jun 2019 03:15:59 +0000 (12:15 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 14 Jun 2019 07:21:16 +0000 (16:21 +0900)
With new role parameter is specified, it returns a device considering
the role. For this, pa_tz_device_get_role() is added to tizen-device.c.

It is revised not to judge whether a device type is for multi-devices
by predefined device types. So, device_type_is_avail_multi_device() is
removed from tizen-device-def.c.

[Version] 11.1.49
[Issue type] Improvement

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

index efabe149c80ee2b215a2314f51d11d471e4136ee..d873447d3ad278c958b385c35780532995d7ffe2 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          11.1.48
+Version:          11.1.49
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 08cb2e80f76b73b4761519a093ce47274faba34c..f0650558f9ebfa63f543cdc2a33df67fdc8863cd 100644 (file)
@@ -336,7 +336,7 @@ static int handle_device_disconnected(pa_device_manager *dm, const char *type, c
     pa_log_info("Device type(%s) system_id(%s) disconnected",
             type, pa_strempty(system_id));
 
-    device = device_list_get_device(dm, type, system_id);
+    device = device_list_get_device(dm, type, NULL, system_id);
     if (!device) {
         pa_log_error("Disconnection detected but no device for that");
         return -1;
@@ -515,7 +515,7 @@ static DBusHandlerResult dbus_filter_device_detect_handler(DBusConnection *c, DB
             } else if (pa_safe_streq(property_name, "Playing")) {
                 pa_tz_device *device;
                 pa_log_info("SCO Playing : %d", value);
-                if ((device = device_list_get_device(dm, DEVICE_TYPE_BT_SCO, NULL)) != NULL) {
+                if ((device = device_list_get_device(dm, DEVICE_TYPE_BT_SCO, NULL, NULL)) != NULL) {
                     device->sco_opened = value;
                     if (value) {
                         /* update BT band/nrec information */
@@ -879,7 +879,7 @@ static void handle_get_bt_a2dp_status(DBusConnection *conn, DBusMessage *msg, vo
     pa_assert_se((reply = dbus_message_new_method_return(msg)));
 
     /* FIXME : Give system_id for multi device */
-    if ((device = device_list_get_device(dm, DEVICE_TYPE_BT_A2DP, NULL)) != NULL) {
+    if ((device = device_list_get_device(dm, DEVICE_TYPE_BT_A2DP, NULL, NULL)) != NULL) {
         is_bt_on = true;
         bt_name = pa_tz_device_get_name(device);
     }
index 5b8c4f797a16e41eb898e781d2040c4d89bd4cc0..4d491a1c7dcae40ef90f5c5a4d9347632b7f6186 100644 (file)
@@ -138,7 +138,7 @@ typedef enum {
 const char* build_key_from_proplist(pa_proplist *p);
 void simple_device_dump(pa_log_level_t level, const char *prefix, int id, const char *type, const char *name, int direction, int state);
 void device_set_detected(pa_device_manager *dm, const char *type, const char *name, const char *system_id, device_detected_type_t detected_type);
-pa_tz_device *device_list_get_device(pa_device_manager *dm, const char *type, const char *system_id);
+pa_tz_device *device_list_get_device(pa_device_manager *dm, const char *type, const char *role, const char *system_id);
 pa_tz_device *device_list_get_device_by_id(pa_device_manager *dm, uint32_t id);
 void handle_device_connected(pa_device_manager *dm, const char *type, const char *name, const char *system_id, device_detected_type_t detected_type);
 
index 98f24ba2997009ee37838ffeec1b0cd28248b76c..9fa9e325d46851a97d445dcdaa6ecbfd6a1d6dcb 100644 (file)
@@ -115,9 +115,6 @@ static const char* const valid_alsa_device_modargs[] = {
     NULL
 };
 
-#define BT_CVSD_CODEC_ID 1 // narrow-band
-#define BT_MSBC_CODEC_ID 2 // wide-band
-
 typedef enum dm_device_class_type {
     DM_DEVICE_CLASS_NONE,
     DM_DEVICE_CLASS_ALSA,
@@ -654,19 +651,12 @@ static struct device_status_info* _get_device_status(pa_device_manager *manager,
 
     PA_IDXSET_FOREACH(status_info, manager->device_status, status_idx) {
         if (device_type_is_equal(status_info->type, type)) {
-            if (device_type_is_avail_multi_device(type)) {
-                /* if system_id is null, just compare type */
-                if (system_id == NULL)
-                    return status_info;
-                else if (status_info->system_id == NULL)
-                    continue;
-                else if (pa_safe_streq(status_info->system_id, system_id))
+            if (system_id) {
+                if (pa_safe_streq(status_info->system_id, system_id))
                     return status_info;
-                else
-                    continue;
-            } else {
-                return status_info;
+                continue;
             }
+            return status_info;
         }
     }
 
@@ -744,31 +734,31 @@ void device_set_detected(pa_device_manager *manager, const char *type,
     }
 }
 
-pa_tz_device* device_list_get_device(pa_device_manager *manager, const char *type, const char *system_id) {
+pa_tz_device* device_list_get_device(pa_device_manager *manager, const char *type, const char *role, const char *system_id) {
     pa_tz_device *device;
     uint32_t idx;
-    char *_type, *_system_id;
 
     pa_assert(manager);
     pa_assert(manager->device_list);
     pa_assert(type);
 
     PA_IDXSET_FOREACH(device, manager->device_list, idx) {
-        _type = pa_tz_device_get_type(device);
-        _system_id = pa_tz_device_get_system_id(device);
-        if (pa_safe_streq(_type, type)) {
-            if (device_type_is_avail_multi_device(type)) {
-                if (system_id == NULL)
+        if (pa_safe_streq(pa_tz_device_get_type(device), type)) {
+            /* 1. check system_id first */
+            if (system_id) {
+                if (pa_safe_streq(pa_tz_device_get_system_id(device), system_id))
                     return device;
-                else if (_system_id == NULL)
+                else
                     continue;
-                else if (pa_safe_streq(_system_id, system_id))
+            }
+            /* 2. check role */
+            if (role) {
+                if (pa_tz_device_get_role(device, role))
                     return device;
                 else
                     continue;
-            } else {
-                return device;
             }
+            return device;
         }
     }
 
@@ -1104,7 +1094,7 @@ static void pulse_device_set_use_internal_codec(pa_object *pdevice, bool use_int
     }
 }
 
-/* Get system_id of physical device, if external device */
+/* Get system_id of physical device, it should be a unique id */
 static const char* pulse_device_get_system_id(pa_object *pdevice) {
     pa_proplist *prop;
 
@@ -1244,7 +1234,7 @@ static pa_sink* _device_manager_set_default_sink(pa_device_manager *dm,  const c
         return NULL;
     }
 
-    if (!(device = device_list_get_device(dm, type, NULL))) {
+    if (!(device = device_list_get_device(dm, type, NULL, NULL))) {
         pa_log_warn("cannot get device item for %s", type);
         return NULL;
     }
@@ -1267,7 +1257,7 @@ static pa_source* _device_manager_set_default_source(pa_device_manager *dm,  con
         return NULL;
     }
 
-    if (!(device = device_list_get_device(dm, type, NULL))) {
+    if (!(device = device_list_get_device(dm, type, NULL, NULL))) {
         pa_log_warn("cannot get device item for %s", type);
         return NULL;
     }
@@ -1363,7 +1353,7 @@ static void handle_usb_pulse_device(pa_object *pdevice, bool is_loaded, pa_devic
         pa_tz_device_new(&data);
         pa_tz_device_new_data_done(&data);
     } else {
-        if (!(device = device_list_get_device(dm, DEVICE_TYPE_USB_AUDIO, system_id)))
+        if (!(device = device_list_get_device(dm, DEVICE_TYPE_USB_AUDIO, NULL, system_id)))
             pa_log_warn("Can't get usb device for %s", system_id);
         else
             pa_tz_device_free(device);
@@ -1405,7 +1395,7 @@ static void handle_bt_pulse_device(pa_object *pdevice, bool is_loaded, pa_device
         pa_tz_device_new_data_done(&data);
     } else {
 
-        if (!(device = device_list_get_device(dm, DEVICE_TYPE_BT_A2DP, system_id)))
+        if (!(device = device_list_get_device(dm, DEVICE_TYPE_BT_A2DP, NULL, system_id)))
             pa_log_warn("Can't get bt device for %s", system_id);
         else
             pa_tz_device_free(device);
@@ -1437,7 +1427,7 @@ static void handle_raop_pulse_device(pa_object *pdevice, bool is_loaded, pa_devi
         pa_tz_device_new(&data);
         pa_tz_device_new_data_done(&data);
     } else {
-        if (!(device = device_list_get_device(dm, DEVICE_TYPE_RAOP, system_id)))
+        if (!(device = device_list_get_device(dm, DEVICE_TYPE_RAOP, NULL, system_id)))
             pa_log_warn("Can't get RAOP device for %s", system_id);
         else
             pa_tz_device_free(device);
@@ -1467,7 +1457,7 @@ static void handle_internal_pulse_device(pa_object *pdevice, bool is_loaded, pa_
         for (int i = 0; i < pa_dynarray_size(ctypes); i++) {
             ctype = pa_dynarray_get(ctypes, i);
             pa_log_info("Found belongs type %s %s", ctype->type, ctype->role);
-            if ((device = device_list_get_device(dm, ctype->type, NULL))) {
+            if ((device = device_list_get_device(dm, ctype->type, NULL, NULL))) {
                 pa_log_info("Add this pulse_device to device(%u)", pa_tz_device_get_id(device));
                 if (direction == DM_DEVICE_DIRECTION_OUT)
                     pa_tz_device_add_sink(device, ctype->role, PA_SINK(pdevice));
@@ -1482,7 +1472,7 @@ static void handle_internal_pulse_device(pa_object *pdevice, bool is_loaded, pa_
         for (int i = 0; i < pa_dynarray_size(ctypes); i++) {
             ctype = pa_dynarray_get(ctypes, i);
             pa_log_info("Found belongs type %s %s", ctype->type, ctype->role);
-            if ((device = device_list_get_device(dm, ctype->type, NULL))) {
+            if ((device = device_list_get_device(dm, ctype->type, NULL, NULL))) {
                 pa_log_info("Remove this pulse_device from device(%u)", pa_tz_device_get_id(device));
                 if (direction == DM_DEVICE_DIRECTION_OUT)
                     pa_tz_device_remove_sink(device, PA_SINK(pdevice));
@@ -1794,12 +1784,12 @@ static pa_tz_device* _load_forwarding_device(pa_device_manager *dm) {
 
     pa_log_info("Load forwarding device");
 
-    if ((forwarding_device = device_list_get_device(dm, DEVICE_TYPE_FORWARDING, NULL))) {
+    if ((forwarding_device = device_list_get_device(dm, DEVICE_TYPE_FORWARDING, NULL, NULL))) {
         pa_log_info("Forwarding device already exists");
         return forwarding_device;
     }
 
-    if ((spk_device = device_list_get_device(dm, DEVICE_TYPE_SPEAKER, NULL)) == NULL) {
+    if ((spk_device = device_list_get_device(dm, DEVICE_TYPE_SPEAKER, NULL, NULL)) == NULL) {
         pa_log_error("Get speaker device failed");
         return NULL;
     }
@@ -2244,6 +2234,7 @@ static void device_type_status_init(pa_device_manager *manager) {
 
     PA_IDXSET_FOREACH(type_info, manager->type_infos, type_idx) {
         type = type_info->type;
+
         if (device_type_is_equal(type, DEVICE_TYPE_AUDIO_JACK)) {
             int earjack_status = 0;
             if (vconf_get_int(VCONFKEY_SYSMAN_EARJACK, &earjack_status) < 0) {
@@ -2258,10 +2249,13 @@ static void device_type_status_init(pa_device_manager *manager) {
                 device_set_detected(manager, type, NULL, NULL, DEVICE_DISCONNECTED);
             else
                 pa_log_warn("Unknown earjack status : %d", earjack_status);
+
         } else if (device_type_is_equal(type, DEVICE_TYPE_BT_SCO)) {
                 device_set_detected(manager, type, NULL, NULL, DEVICE_DISCONNECTED);
+
         } else if (device_type_is_equal(type, DEVICE_TYPE_HDMI)) {
                 device_set_detected(manager, type, NULL, NULL, DEVICE_DISCONNECTED);
+
         } else if (device_type_is_equal(type, DEVICE_TYPE_FORWARDING)) {
             int miracast_wfd_status = 0;
             if (vconf_get_bool(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, &miracast_wfd_status) < 0) {
@@ -2270,6 +2264,7 @@ static void device_type_status_init(pa_device_manager *manager) {
             }
             if (miracast_wfd_status == FORWARDING_CONNECTED)
                 device_set_detected(manager, type, NULL, NULL, DEVICE_CONNECTED);
+
         } else {
             device_set_detected(manager, type, NULL, NULL, DEVICE_CONNECTED);
         }
@@ -2468,7 +2463,7 @@ pa_idxset* pa_device_manager_get_device_list(pa_device_manager *dm) {
 pa_tz_device* pa_device_manager_get_device(pa_device_manager *dm, const char *type) {
     pa_assert(dm);
 
-    return device_list_get_device(dm, type, NULL);
+    return device_list_get_device(dm, type, NULL, NULL);
 }
 
 pa_tz_device* pa_device_manager_get_device_by_id(pa_device_manager *dm, uint32_t id) {
@@ -2496,7 +2491,7 @@ pa_tz_device* pa_device_manager_load_forwarding(pa_device_manager *dm) {
 void pa_device_manager_unload_forwarding(pa_device_manager *dm) {
     pa_tz_device *forwarding_device;
 
-    forwarding_device = device_list_get_device(dm, DEVICE_TYPE_FORWARDING, NULL);
+    forwarding_device = device_list_get_device(dm, DEVICE_TYPE_FORWARDING, NULL, NULL);
     if (forwarding_device)
         pa_tz_device_free(forwarding_device);
     else
index 22f661225b75213868058af24801ffb7b47524a0..e423af4b94094f7085a37ea70e67ebc0e041a3da 100644 (file)
@@ -74,19 +74,6 @@ bool device_type_is_use_external_card(const char *device_type) {
         return false;
 }
 
-bool device_type_is_avail_multi_device(const char *device_type) {
-    if (pa_safe_streq(device_type, DEVICE_TYPE_BT_A2DP))
-        return true;
-    else if (pa_safe_streq(device_type, DEVICE_TYPE_BT_SCO))
-        return true;
-    else if (pa_safe_streq(device_type, DEVICE_TYPE_USB_AUDIO))
-        return true;
-    else if (pa_safe_streq(device_type, DEVICE_TYPE_RAOP))
-        return true;
-    else
-        return false;
-}
-
 bool device_type_is_need_detect(const char *type) {
     if (pa_safe_streq(type, DEVICE_TYPE_AUDIO_JACK))
         return true;
index d1bd862cbd1a4961cbccce715951ffcf07571c15..a64b34e71a75350ced2fdc29dc6ee44b4e4ab715 100644 (file)
@@ -45,7 +45,6 @@ bool device_type_is_builtin(const char *device_type);
 bool device_type_is_use_external_card(const char *device_type);
 bool device_type_is_valid(const char *device_type);
 bool device_type_is_valid_direction(const char *device_type, dm_device_direction_t direction);
-bool device_type_is_avail_multi_device(const char *device_type);
 bool device_type_is_need_detect(const char *type);
 dm_device_direction_t device_type_get_static_direction(const char *type);
 const char* device_direction_to_string(dm_device_direction_t direction);
index 81f3401a9afad308135f499bddd5d7b7a0d0f66b..d561d00519ad2bb43cd3fed377ed13ac968f6d0f 100644 (file)
@@ -669,6 +669,44 @@ char* pa_tz_device_get_type(pa_tz_device *device) {
     return device->type;
 }
 
+char* pa_tz_device_get_role(pa_tz_device *device, const char *preferred_role) {
+    char *role;
+    pa_sink *sink;
+    pa_source *source;
+    void *state;
+
+    pa_assert(device);
+
+    if (device->playback_devices) {
+        PA_HASHMAP_FOREACH_KV(role, sink, device->playback_devices, state) {
+            if (preferred_role) {
+                if (pa_safe_streq(role, preferred_role))
+                    return role;
+                else
+                    continue;
+            }
+            return role;
+        }
+    }
+
+    if (device->capture_devices) {
+        PA_HASHMAP_FOREACH_KV(role, source, device->capture_devices, state) {
+            if (preferred_role) {
+                if (pa_safe_streq(role, preferred_role))
+                    return role;
+                else
+                    continue;
+            }
+            return role;
+        }
+    }
+
+    pa_log_error("Failed to get a role from the device[type:%s, id:%u, name:%s] with preferred_role[%s]",
+            device->type, device->id, device->name, preferred_role);
+
+    return NULL;
+}
+
 char* pa_tz_device_get_name(pa_tz_device *device) {
     pa_assert(device);
 
index b0235d2ad123e06f282ddc69f7af6f341ba845c9..916a819ee991ebf88375db1bc8451653bb554c51 100644 (file)
@@ -144,6 +144,7 @@ void pa_tz_device_set_running_and_notify(pa_tz_device *device, bool running);
 bool pa_tz_device_is_running(pa_tz_device *device);
 uint32_t pa_tz_device_get_id(pa_tz_device *device);
 char* pa_tz_device_get_type(pa_tz_device *device);
+char* pa_tz_device_get_role(pa_tz_device *device, const char *preferred_role);
 char* pa_tz_device_get_name(pa_tz_device *device);
 char* pa_tz_device_get_system_id(pa_tz_device *device);
 dm_device_direction_t pa_tz_device_get_direction(pa_tz_device *device);