Add support for notifying stream connection information to the policy implementation 55/255455/3
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 18 Mar 2021 12:19:13 +0000 (21:19 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 18 Mar 2021 22:41:29 +0000 (07:41 +0900)
[Version] 13.0.54
[Issue Type] New feature

Change-Id: I63ebdd3e62a40d54b04e0ac83f1654015e6095cb
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/pulseaudio-modules-tizen.spec
src/communicator.h
src/module-tizenaudio-policy.c
src/stream-manager.c
src/stream-manager.h

index 6c7bd8bd5c4221da3be413ea52618bafc2ea3612..6478812264d0d28fee978071d9b772d9d33e450b 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          13.0.53
+Version:          13.0.54
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 6dd40fcc5bede165af5009a657a58434b90fe78c..f41ef588a64ba99fbf9bcbea86eb5004da86e1c1 100644 (file)
@@ -27,6 +27,7 @@
 typedef enum pa_communicator_hook {
     PA_COMMUNICATOR_HOOK_SELECT_INIT_SINK_OR_SOURCE, /* It is fired when a stream is created and needs to be set to sink or source */
     PA_COMMUNICATOR_HOOK_CHANGE_ROUTE,               /* It is fired when routing using internal codec should be processed */
+    PA_COMMUNICATOR_HOOK_STREAM_CONNECTION_CHANGED,  /* It is fired when a stream is connected or disconnected */
     PA_COMMUNICATOR_HOOK_DEVICE_CONNECTION_CHANGED,  /* It is fired when a device is connected or disconnected */
     PA_COMMUNICATOR_HOOK_DEVICE_STATE_CHANGED,       /* It is fired when a device's state is changed, it will be replaced by RUNNING_CHANGED */
     PA_COMMUNICATOR_HOOK_DEVICE_RUNNING_CHANGED,     /* It is fired when a device's running state is changed */
index 09759e33fc193a2f561a535b93c790dd1780a7b5..6aa27786a82715e59d12a50152391d5440b07a9f 100644 (file)
@@ -158,6 +158,7 @@ struct userdata {
         pa_communicator *comm;
         pa_hook_slot *comm_hook_select_proper_sink_or_source_slot;
         pa_hook_slot *comm_hook_change_route_slot;
+        pa_hook_slot *comm_hook_stream_connection_changed_slot;
         pa_hook_slot *comm_hook_device_connection_changed_slot;
         pa_hook_slot *comm_hook_update_info_slot;
     } communicator;
@@ -1675,6 +1676,18 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_
     return PA_HOOK_OK;
 }
 
+static pa_hook_result_t stream_connection_changed_hook_cb(pa_core *c, pa_stream_manager_hook_data_for_stream *data, struct userdata *u) {
+    pa_assert(c);
+    pa_assert(data);
+    pa_assert(u);
+
+    pa_log_info("[STREAM][%s] stream(%p, type:%d, role:%s, parent_id:%s)",
+                data->is_connected ? "connected" : "disconnected",
+                data->stream, data->stream_type, data->stream_role, data->parent_id);
+
+    return PA_HOOK_OK;
+}
+
 static pa_hook_result_t update_info_hook_cb(pa_core *c, pa_stream_manager_hook_data_for_update_info *data, struct userdata *u) {
     pa_assert(c);
     pa_assert(data);
@@ -1821,6 +1834,9 @@ int pa__init(pa_module *m)
         u->communicator.comm_hook_change_route_slot = pa_hook_connect(
                 pa_communicator_hook(u->communicator.comm, PA_COMMUNICATOR_HOOK_CHANGE_ROUTE),
                 PA_HOOK_EARLY, (pa_hook_cb_t)route_change_hook_cb, u);
+        u->communicator.comm_hook_stream_connection_changed_slot = pa_hook_connect(
+                pa_communicator_hook(u->communicator.comm, PA_COMMUNICATOR_HOOK_STREAM_CONNECTION_CHANGED),
+                PA_HOOK_EARLY, (pa_hook_cb_t)stream_connection_changed_hook_cb, u);
         u->communicator.comm_hook_device_connection_changed_slot = pa_hook_connect(
                 pa_communicator_hook(u->communicator.comm, PA_COMMUNICATOR_HOOK_DEVICE_CONNECTION_CHANGED),
                 PA_HOOK_EARLY, (pa_hook_cb_t)device_connection_changed_hook_cb, u);
index 8ff7ddec8a81b89cac29977535c9c73cd550ee67..8232c1ac3a738266b8121fef78a51bc0ae8039cf 100644 (file)
@@ -1793,6 +1793,25 @@ static ret_msg_t prepare_and_invoke_hook_to_change_route(pa_stream_manager *m, n
     return ret;
 }
 
+static ret_msg_t prepare_and_invoke_hook_to_inform_stream_connection(pa_stream_manager *m, bool is_connected,
+                                                        stream_type_t type, void *s) {
+    pa_stream_manager_hook_data_for_stream hook_call_stream_data;
+
+    pa_assert(m);
+    pa_assert(s);
+
+    hook_call_stream_data.stream = s;
+    hook_call_stream_data.stream_type = type;
+    hook_call_stream_data.stream_role = pa_proplist_gets(GET_STREAM_PROPLIST(s, type), PA_PROP_MEDIA_ROLE);
+    hook_call_stream_data.parent_id = pa_proplist_gets(GET_STREAM_PROPLIST(s, type), PA_PROP_MEDIA_PARENT_ID);
+    hook_call_stream_data.is_connected = is_connected;
+
+    if (pa_hook_fire(pa_communicator_hook(m->comm.comm, PA_COMMUNICATOR_HOOK_STREAM_CONNECTION_CHANGED), &hook_call_stream_data))
+        return RET_MSG_ERROR_INTERNAL;
+
+    return RET_MSG_OK;
+}
+
 ret_msg_t do_notify(pa_stream_manager *m, notify_command_type_t command, stream_type_t type, bool is_new_data, void *user_data) {
     hal_stream_connection_info stream_conn_info;
     hal_route_option route_option;
@@ -1838,14 +1857,17 @@ ret_msg_t do_notify(pa_stream_manager *m, notify_command_type_t command, stream_
         pa_assert(user_data);
         memset(&stream_conn_info, 0, sizeof(hal_stream_connection_info));
         s = user_data;
-        if (s) {
-            stream_conn_info.role = pa_proplist_gets(GET_STREAM_PROPLIST(s, type), PA_PROP_MEDIA_ROLE);
-            stream_conn_info.direction = (type == STREAM_SINK_INPUT) ? DIRECTION_OUT : DIRECTION_IN;
-            stream_conn_info.idx = GET_STREAM_INDEX(s, type);
-            stream_conn_info.is_connected = (command == NOTIFY_COMMAND_INFORM_STREAM_CONNECTED) ? true : false;
-            if (pa_hal_interface_notify_stream_connection_changed(m->hal, &stream_conn_info))
-                ret = RET_MSG_ERROR_INTERNAL;
-        }
+
+        ret = prepare_and_invoke_hook_to_inform_stream_connection(m, command == NOTIFY_COMMAND_INFORM_STREAM_CONNECTED, type, s);
+        if (ret != RET_MSG_OK)
+            pa_log_error("failed to prepare_and_invoke_hook_to_inform_stream_connection()");
+        stream_conn_info.role = pa_proplist_gets(GET_STREAM_PROPLIST(s, type), PA_PROP_MEDIA_ROLE);
+        stream_conn_info.direction = (type == STREAM_SINK_INPUT) ? DIRECTION_OUT : DIRECTION_IN;
+        stream_conn_info.idx = GET_STREAM_INDEX(s, type);
+        stream_conn_info.is_connected = (command == NOTIFY_COMMAND_INFORM_STREAM_CONNECTED);
+        if (pa_hal_interface_notify_stream_connection_changed(m->hal, &stream_conn_info))
+            ret = RET_MSG_ERROR_INTERNAL;
+
         break;
     }
     }
index 1aae92cad729be8e19abb9b54ffce81ca9dfe70e..ffb9d345d47d9ef6131e5713f8042e8aa7dbd715 100644 (file)
@@ -146,6 +146,14 @@ typedef struct _hook_call_data_for_route {
     bool origins_from_new_data;
 } pa_stream_manager_hook_data_for_route;
 
+typedef struct _hook_call_data_for_stream {
+    void *stream;
+    const char *stream_role;
+    const char *parent_id;
+    stream_type_t stream_type;
+    bool is_connected;
+} pa_stream_manager_hook_data_for_stream;
+
 typedef struct _hook_call_data_for_update_info {
     const char *stream_role;
     const char *name;