device-manager: Revise handle_device_connected() to pass device_type_info 47/209047/1
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 2 Jul 2019 02:57:06 +0000 (11:57 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 2 Jul 2019 02:57:39 +0000 (11:57 +0900)
Each device_type_info has hashmap of playback[capture]_devices
that have device descriptions per device role.
This patch makes it possible to load the same built-in device type
with different device role.

[Version] 11.1.55
[Issue type] Improvement

Change-Id: I14fea61488dc6d3f4289acee339380bf33c67bde
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

index 17174f8..5e301ca 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          11.1.54
+Version:          11.1.55
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 18d0c0c..88efc9a 100644 (file)
@@ -375,13 +375,13 @@ static int handle_device_status_changed(pa_device_manager *dm, const char *type,
         if (detected == DEVICE_DISCONNECTED)
             handle_device_disconnected(dm, type, system_id);
         else
-            handle_device_connected(dm, type, name, system_id, detected);
+            handle_device_connected(dm, type, name, system_id, detected, NULL);
     } else if (device_type_is_need_detect(type)) {
         device_set_detected(dm, type, name, system_id, detected);
         if (detected == DEVICE_DISCONNECTED)
             handle_device_disconnected(dm, type, system_id);
         else
-            handle_device_connected(dm, type, name, system_id, detected);
+            handle_device_connected(dm, type, name, system_id, detected, NULL);
     } else {
         pa_log_debug("No need to detect type %s", type);
     }
index b54a208..faf4b1d 100644 (file)
@@ -77,6 +77,17 @@ struct _device_manager {
     pa_database *database;
 };
 
+/* structure for represent device-types(ex. builtin-speaker) properties*/
+typedef struct _device_type_info {
+    const char *type;
+    /*
+        For save supported roles and related device-file.
+        { key:role -> value:device_string ]
+    */
+    pa_hashmap *playback_devices;
+    pa_hashmap *capture_devices;
+} device_type_info;
+
 /*
     Enums for represent values which is defined on other module.
     This is needed to identify values which are sent by dbus or vconf.
@@ -140,7 +151,7 @@ void simple_device_dump(pa_log_level_t level, const char *prefix, int id, const
 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 *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);
+void handle_device_connected(pa_device_manager *dm, const char *type, const char *name, const char *system_id, device_detected_type_t detected_type,  device_type_info *type_info);
 pa_sink* load_acm_sink(pa_device_manager *dm);
 void unload_acm_sink(pa_device_manager *dm);
 
index dbe965d..d569f98 100644 (file)
@@ -161,17 +161,6 @@ struct device_file_info {
     pa_hashmap *device_types;
 };
 
-/* structure for represent device-types(ex. builtin-speaker) properties*/
-struct device_type_info {
-    const char *type;
-    /*
-        For save supported roles and related device-file.
-        { key:role -> value:device_string ]
-    */
-    pa_hashmap *playback_devices;
-    pa_hashmap *capture_devices;
-};
-
 struct device_status_info {
     char *type;
     char *name;
@@ -284,7 +273,7 @@ static void find_device_and_set_running(pa_device_manager *dm, const char *type,
     }
 }
 
-static void type_info_free_func(struct device_type_info *type_info) {
+static void type_info_free_func(device_type_info *type_info) {
     if (!type_info)
         return;
 
@@ -607,8 +596,8 @@ static const char* device_class_get_module_name(dm_device_class_t device_class,
     }
 }
 
-static struct device_type_info* _device_manager_get_type_info(pa_idxset *type_infos, const char *type, const char *role) {
-    struct device_type_info *type_info;
+static device_type_info* _device_manager_get_type_info(pa_idxset *type_infos, const char *type, const char *role) {
+    device_type_info *type_info;
     uint32_t type_idx;
     const char *device_string;
     const char *_role;
@@ -968,7 +957,7 @@ static bool pulse_device_same_device_string(pa_object *pdevice, const char *devi
     return pa_safe_streq(_device_string, device_string);
 }
 
-static const char* device_type_info_get_device_string(struct device_type_info *type_info, bool is_playback, const char *role) {
+static const char* device_type_info_get_device_string(device_type_info *type_info, bool is_playback, const char *role) {
     const char *_role, *device_string;
     void *state;
     pa_hashmap *pcm_devices;
@@ -990,7 +979,7 @@ static const char* device_type_info_get_device_string(struct device_type_info *t
 pa_dynarray* pulse_device_get_belongs_type(pa_object *pdevice, pa_device_manager *dm) {
     pa_dynarray *ctypes;
     struct composite_type *ctype;
-    struct device_type_info *type_info;
+    device_type_info *type_info;
     const char *device_string, *role, *param;
     uint32_t type_idx;
     pa_device_type_t pdt;
@@ -1207,7 +1196,7 @@ static void _fill_new_data_basic(pa_tz_device_new_data *data, const char *type,
     pa_tz_device_new_data_set_use_internal_codec(data, use_internal_codec);
 }
 
-static int _fill_new_data_sinks(pa_tz_device_new_data *data, struct device_type_info *type_info, pa_device_manager *dm) {
+static int _fill_new_data_sinks(pa_tz_device_new_data *data, device_type_info *type_info, pa_device_manager *dm) {
     pa_sink *sink;
     const char *device_string, *role, *param;
     void *state;
@@ -1239,7 +1228,7 @@ static int _fill_new_data_sinks(pa_tz_device_new_data *data, struct device_type_
     return 0;
 }
 
-static int _fill_new_data_sources(pa_tz_device_new_data *data, struct device_type_info *type_info, pa_device_manager *dm) {
+static int _fill_new_data_sources(pa_tz_device_new_data *data, device_type_info *type_info, pa_device_manager *dm) {
     pa_source *source;
     const char *device_string, *role, *param;
     void *state;
@@ -1803,7 +1792,7 @@ static void unload_module(pa_core *c, bool is_sink, const char *device_string) {
     }
 }
 
-static int _load_type_devices(struct device_type_info *type_info, bool is_playback, pa_device_manager *dm) {
+static int _load_type_devices(device_type_info *type_info, bool is_playback, pa_device_manager *dm) {
     pa_hashmap *pcm_devices;
     pa_idxset *file_infos;
     void *state;
@@ -1895,9 +1884,8 @@ static pa_tz_device* _load_forwarding_device(pa_device_manager *dm) {
     And if correnspondent sink/sources for device_type exist, should make device and notify it.
     Use [device_type->roles] mappings in sink/source for find proper sink/source.
 */
-void handle_device_connected(pa_device_manager *dm, const char *type,
-        const char *name, const char *system_id, device_detected_type_t detected_type) {
-    struct device_type_info *type_info;
+void handle_device_connected(pa_device_manager *dm, const char *type, const char *name,
+        const char *system_id, device_detected_type_t detected_type, device_type_info *type_info) {
     pa_tz_device_new_data data;
 
     pa_assert(dm);
@@ -1907,7 +1895,8 @@ void handle_device_connected(pa_device_manager *dm, const char *type,
     pa_log_info("Device connected, type(%s) name(%s) system_id(%s) detected_type(%d)",
             type, pa_strempty(name), pa_strempty(system_id), detected_type);
 
-    type_info = _device_manager_get_type_info(dm->type_infos, type, NULL);
+    if (!type_info)
+        type_info = _device_manager_get_type_info(dm->type_infos, type, NULL);
 
     if (device_type_is_equal(type, DEVICE_TYPE_BT_SCO)) {
         pa_tz_device_new_data_init(&data, dm->device_list, dm->comm, dm->dbus_conn);
@@ -1965,7 +1954,7 @@ void handle_device_connected(pa_device_manager *dm, const char *type,
 }
 
 static int load_builtin_devices(pa_device_manager *dm) {
-    struct device_type_info *type_info;
+    device_type_info *type_info;
     uint32_t type_idx;
     device_detected_type_t detected_type = DEVICE_CONNECTED;
     const char *type;
@@ -1992,7 +1981,7 @@ static int load_builtin_devices(pa_device_manager *dm) {
             } else {
                 _load_type_devices(type_info, true, dm);
             }
-            handle_device_connected(dm, type, NULL, NULL, detected_type);
+            handle_device_connected(dm, type, NULL, NULL, detected_type, type_info);
         } else if (device_type_is_use_external_card(type) == false) {
             dm_device_direction_t direction;
             direction = device_type_get_static_direction(type);
@@ -2004,7 +1993,7 @@ static int load_builtin_devices(pa_device_manager *dm) {
                 _load_type_devices(type_info, true, dm);
             if (direction & DM_DEVICE_DIRECTION_IN)
                 _load_type_devices(type_info, false, dm);
-            handle_device_connected(dm, type, NULL, NULL, detected_type);
+            handle_device_connected(dm, type, NULL, NULL, detected_type, type_info);
         } else {
             pa_log_warn("Invalid case");
         }
@@ -2234,7 +2223,7 @@ static pa_idxset* parse_device_type_infos() {
     json_object *o, *device_array_o = NULL;
     int device_type_num = 0;
     int device_type_idx = 0;
-    struct device_type_info *type_info = NULL;
+    device_type_info *type_info = NULL;
     //pa_hashmap *type_infos = NULL;
     pa_idxset *type_infos = NULL;
 
@@ -2263,7 +2252,7 @@ static pa_idxset* parse_device_type_infos() {
                 type = json_object_get_string(device_prop_o);
                 pa_log_info("[ Device - %s ]", type);
 
-                type_info = pa_xmalloc0(sizeof(struct device_type_info));
+                type_info = pa_xmalloc0(sizeof(device_type_info));
                 type_info->type = type;
 
                 if (json_object_object_get_ex(device_o, DEVICE_TYPE_PROP_PLAYBACK_DEVICES, &device_prop_o) && json_object_is_type(device_prop_o, json_type_object)) {
@@ -2300,7 +2289,7 @@ fail:
     If not, initialize to not detected.
 */
 static void device_type_status_init(pa_device_manager *manager) {
-    struct device_type_info *type_info;
+    device_type_info *type_info;
     uint32_t type_idx;
     const char *type;
 
@@ -2351,7 +2340,7 @@ static void device_type_status_init(pa_device_manager *manager) {
 
 static pa_sink* load_sink(pa_device_manager *dm, const char *type, const char *role) {
     const char *device_string, *params;
-    struct device_type_info *type_info;
+    device_type_info *type_info;
     struct device_file_info *file_info;
     pa_tz_device *device;
     pa_sink *sink;
@@ -2412,7 +2401,7 @@ fail:
 
 static void unload_sink(pa_device_manager *dm, const char *type, const char *role) {
     const char *device_string;
-    struct device_type_info *type_info;
+    device_type_info *type_info;
 
     pa_assert(dm);
     pa_assert(dm->device_list);
@@ -2441,7 +2430,7 @@ static void unload_sink(pa_device_manager *dm, const char *type, const char *rol
 
 static pa_source* load_source(pa_device_manager *dm, const char *type, const char *role) {
     const char *device_string, *params;
-    struct device_type_info *type_info;
+    device_type_info *type_info;
     struct device_file_info *file_info;
     pa_tz_device *device;
     pa_source *source;
@@ -2503,7 +2492,7 @@ fail:
 
 static void unload_source(pa_device_manager *dm, const char *type, const char *role) {
     const char *device_string;
-    struct device_type_info *type_info;
+    device_type_info *type_info;
 
     pa_assert(dm);
     pa_assert(dm->device_list);
@@ -2652,7 +2641,7 @@ void pa_device_manager_unload_source_with_device_string(pa_device_manager *dm, c
 }
 
 const char* pa_device_manager_get_device_string(pa_device_manager *dm, bool is_playback, const char *type, const char *role) {
-    struct device_type_info *type_info;
+    device_type_info *type_info;
 
     pa_assert(dm);
     pa_assert(type);