stream-manager: Add periodical dump for monitoring 56/302856/8 accepted/tizen/unified/20231219.160333 accepted/tizen/unified/riscv/20231226.211719
authorSeungbae Shin <seungbae.shin@samsung.com>
Thu, 14 Dec 2023 12:22:04 +0000 (21:22 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Mon, 18 Dec 2023 07:14:54 +0000 (07:14 +0000)
currently, the following stuffs are on dump

- sink-inputs
- source-outputs
- stream duckings

[Version] 15.0.71
[Issue Type] Feature

Change-Id: I13517e0459a2cfa0556867eaa96f713587530438

packaging/pulseaudio-modules-tizen.spec
src/stream-manager-priv.h
src/stream-manager.c

index 011e84e..e93c4f6 100644 (file)
@@ -2,7 +2,7 @@
 
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          15.0.70
+Version:          15.0.71
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index b4eb25e..86a4dad 100644 (file)
@@ -260,6 +260,7 @@ struct _stream_manager {
     stream_restrictions restrictions;
     bool on_call;
     pa_time_event *time_event_for_unmute;
+    pa_time_event *time_event_for_monitoring;
     pa_hashmap *filter_infos;
 
     pa_thread_mq thread_mq;
index 34698e9..7a4afdd 100644 (file)
@@ -81,6 +81,8 @@ static const char* stream_manager_media_names_for_skip[NAME_FOR_SKIP_MAX] = {"pu
 #define MUTE_KEY    "mute_by_device_disconnection"
 #define TIMED_UNMUTE_USEC    300000
 
+#define MONITORING_INTERVAL_SEC 3 /* FIXME: make this configurable */
+
 static const char* process_command_type_str[] = {
     [PROCESS_COMMAND_PREPARE] = "PREPARE",
     [PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_STARTED] = "CHANGE_ROUTE_BY_STREAM_STARTED",
@@ -3444,6 +3446,50 @@ static void timed_unmute_cb(pa_mainloop_api *a, pa_time_event *e, const struct t
     m->time_event_for_unmute = NULL;
 }
 
+static void dump_ducking(pa_stream_manager *m) {
+    stream_ducking *sd = NULL;
+    void *state = NULL;
+    pa_client* client = NULL;
+    unsigned int iteration = 0;
+
+    if (!m->stream_duckings) {
+        pa_log_warn("No stream_duckings hashmap available....");
+        return;
+    }
+
+    if (pa_hashmap_isempty(m->stream_duckings)) {
+        pa_log_warn("No ducking to dump");
+        return;
+    }
+
+    while ((sd = pa_hashmap_iterate(m->stream_duckings, &state, NULL))) {
+        client = pa_idxset_get_by_index(m->core->clients, sd->trigger_index);
+
+        pa_log_warn(" #(%2u/%2u), client(%5d), app(%s, %s), state(%u), ducking_streams(%u, %d), target_role(%s)",
+            ++iteration, pa_hashmap_size(m->stream_duckings),
+            sd->trigger_index,
+            pa_strnull(client ? pa_proplist_gets(client->proplist, PA_PROP_APPLICATION_PROCESS_ID) : NULL),
+            pa_strnull(client ? pa_proplist_gets(client->proplist, PA_PROP_APPLICATION_PROCESS_BINARY) : NULL),
+            sd->state,
+            pa_idxset_size(sd->idx_ducking_streams), sd->ducking_stream_count,
+            pa_strnull(sd->target_role));
+    }
+}
+
+static void monitoring_cb(pa_mainloop_api *a, pa_time_event *e, const struct timeval *t, void *userdata) {
+    pa_stream_manager *m = (pa_stream_manager *)userdata;
+
+    pa_assert(m);
+
+    pa_log_info("monitoring callback invoked, event(%p)", e);
+
+    pa_core_dump_sink_inputs(m->core);
+    pa_core_dump_source_outputs(m->core);
+    dump_ducking(m);
+
+    pa_core_rttime_restart(m->core, e, pa_rtclock_now() + (MONITORING_INTERVAL_SEC * PA_USEC_PER_SEC));
+}
+
 static int active_device_filter_func(const void *i, const void *device_type) {
     pa_assert(i);
     pa_assert(device_type);
@@ -3972,6 +4018,9 @@ pa_stream_manager* pa_stream_manager_get(pa_core *c) {
 
     set_initial_active_device(m);
 
+    // FIXME: timer should be configurable by daemon.conf
+    m->time_event_for_monitoring = pa_core_rttime_new(m->core, pa_rtclock_now() + (3 * PA_USEC_PER_SEC), monitoring_cb, m);
+
     pa_shared_set(c, SHARED_STREAM_MANAGER, m);
 
     return m;
@@ -4096,6 +4145,9 @@ void pa_stream_manager_unref(pa_stream_manager *m) {
     if (m->stream_duckings)
         pa_hashmap_free(m->stream_duckings);
 
+    if (m->time_event_for_monitoring)
+        m->core->mainloop->time_free(m->time_event_for_monitoring);
+
     deinit_volumes(m);
     deinit_stream_map(m);
     deinit_ipc(m);