webrtc_ini: Add support for printing stats log periodically 48/263648/4
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 7 Sep 2021 10:19:56 +0000 (19:19 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 8 Sep 2021 01:23:54 +0000 (10:23 +0900)
[general]
stats log period = 0

It is added to print statistics log periodically to check current
situation of data transmission without any user input.
In case of 0 sec, it does not print any stats logs.

[Version] 0.2.95
[Issue Type] Log

Change-Id: Ibc0b418d7c6544f995b5d78822d8df241c064f7c
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc.c
src/webrtc_ini.c
src/webrtc_private.c
src/webrtc_stats.c

index ab042877fa774d2e433886ea79141696efb18fbd..d24dc757f4499d51784fe6e79f80f569e9465be1 100644 (file)
@@ -270,6 +270,7 @@ typedef struct _webrtc_resource_s {
 typedef        struct _ini_item_general_s {
        bool generate_dot;
        const char *dot_path;
+       int stats_log_period;
        bool verbose_log;
        bool nice_verbose;
        gchar **gst_args;
@@ -385,6 +386,7 @@ typedef struct _webrtc_negotiation_states_s {
 
 typedef struct _webrtc_s {
        webrtc_ini_s ini;
+       guint stats_timer_src;
 
        GMutex mutex;
        GMutex desc_mutex;
@@ -634,6 +636,8 @@ int _data_channel_send_string(webrtc_data_channel_s *channel, const char *string
 int _data_channel_send_bytes(webrtc_data_channel_s *channel, const char *data, unsigned int size);
 
 void _webrtcbin_get_stats(webrtc_s *webrtc);
+void _set_stats_timer(webrtc_s *webrtc);
+void _unset_stats_timer(webrtc_s *webrtc);
 
 typedef int (*_websocket_cb)(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len);
 webrtc_websocket_s *_alloc_websocket(const int port, const char *ssl_cert_path, const char *ssl_private_key_path, const char *ssl_ca_path, _websocket_cb callback, void *user_data);
index bf25b1c6fe660ae90c903f8e6e0b85a80fe17176..883ab6eefd21246a1a00d02c46a6076617104e40 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.2.94
+Version:    0.2.95
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 17858efd2efa77c7479ea3909d04b7d75b0e096d..a045a8e9ad5a9cc34c836f1e8b34d3d6c1d538f6 100644 (file)
@@ -122,6 +122,8 @@ int webrtc_destroy(webrtc_h webrtc)
 
        locker = g_mutex_locker_new(&_webrtc->mutex);
 
+       _unset_stats_timer(_webrtc);
+
        ret = _gst_pipeline_set_state(_webrtc, GST_STATE_NULL);
        RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _gst_pipeline_set_state()");
 
index 9d87dac1b67db0a07e3a254b45115d8fe66c44f9..2b4b5dc5b9b92234c7a7424b19735e19f775262c 100644 (file)
@@ -22,6 +22,7 @@ bool g_verbose = false;
 #define WEBRTC_INI_PATH                   SYSCONFDIR"/multimedia/mmfw_webrtc.ini"
 #define DEFAULT_GENERATE_DOT              true
 #define DEFAULT_DOT_PATH                  "/tmp"
+#define DEFAULT_STATS_LOG_PERIOD          0  /* sec */
 #define DEFAULT_VERBOSE_LOG               false
 #define DEFAULT_NICE_VERBOSE              false
 #define DEFAULT_JITTERBUFFER_LATENCY      200  /* ms */
@@ -45,6 +46,7 @@ bool g_verbose = false;
 /* items for general */
 #define INI_ITEM_DOT_PATH                 "dot path"
 #define INI_ITEM_DOT_GENERATE             "generate dot"
+#define INI_ITEM_STATS_LOG_PERIOD         "stats log period"
 #define INI_ITEM_VERBOSE_LOG              "verbose log"
 #define INI_ITEM_NICE_VERBOSE             "nice verbose"
 #define INI_ITEM_GST_ARGS                 "gstreamer arguments"
@@ -210,6 +212,7 @@ static void __dump_ini(webrtc_ini_s *ini)
        LOG_INFO("[%s]", INI_CATEGORY_GENERAL);
        __dump_item(INI_ITEM_DOT_GENERATE, INI_ITEM_TYPE_BOOL, &ini->general.generate_dot);
        __dump_item(INI_ITEM_DOT_PATH, INI_ITEM_TYPE_STRING, (void *)ini->general.dot_path);
+       __dump_item(INI_ITEM_STATS_LOG_PERIOD, INI_ITEM_TYPE_INT, &ini->general.stats_log_period);
        __dump_item(INI_ITEM_VERBOSE_LOG, INI_ITEM_TYPE_BOOL, &ini->general.verbose_log);
        __dump_item(INI_ITEM_NICE_VERBOSE, INI_ITEM_TYPE_BOOL, &ini->general.nice_verbose);
        __dump_item(INI_ITEM_GST_ARGS, INI_ITEM_TYPE_STRINGS, ini->general.gst_args);
@@ -442,6 +445,7 @@ int _load_ini(webrtc_s *webrtc)
                LOG_INFO("dot file will be stored in [%s]", ini->general.dot_path);
                g_setenv("GST_DEBUG_DUMP_DOT_DIR", ini->general.dot_path, FALSE);
        }
+       ini->general.stats_log_period = __ini_get_int(ini->dict, INI_CATEGORY_GENERAL, INI_ITEM_STATS_LOG_PERIOD, DEFAULT_STATS_LOG_PERIOD);
        ini->general.verbose_log = g_verbose = __ini_get_boolean(ini->dict, INI_CATEGORY_GENERAL, INI_ITEM_VERBOSE_LOG, DEFAULT_VERBOSE_LOG);
        ini->general.nice_verbose = __ini_get_boolean(ini->dict, INI_CATEGORY_GENERAL, INI_ITEM_NICE_VERBOSE, DEFAULT_NICE_VERBOSE);
        if (ini->general.nice_verbose)
index bda78f9ed1db0023602404f887f3cb09c21e560e..2b63884d032e8ee3d17529128525e0f23752a927 100644 (file)
@@ -229,6 +229,9 @@ void _invoke_state_changed_cb(webrtc_s *webrtc, webrtc_state_e old, webrtc_state
                LOG_DEBUG("<<< end of the callback");
        }
 
+       if (new == WEBRTC_STATE_PLAYING)
+               _set_stats_timer(webrtc);
+
        GENERATE_DOT(webrtc, "STATE_%s", __state_str[webrtc->state]);
 }
 
@@ -1704,6 +1707,8 @@ int _webrtc_stop(webrtc_s *webrtc)
 
        RET_VAL_IF(webrtc->state == WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should not be IDLE");
 
+       _unset_stats_timer(webrtc);
+
        ret = _gst_pipeline_set_state(webrtc, GST_STATE_NULL);
        RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _gst_pipeline_set_state()");
 
index 2910ddc227a0ba1750cdd61d23c63ed9d0203d35..45864121408275696a8551fbe8c510abf0d56424 100644 (file)
@@ -546,3 +546,42 @@ void _webrtcbin_get_stats(webrtc_s *webrtc)
 
        gst_promise_unref(promise);
 }
+
+static gboolean __get_stats_periodically(gpointer user_data)
+{
+       webrtc_s *webrtc = (webrtc_s*)user_data;
+
+       if (webrtc->state == WEBRTC_STATE_PLAYING)
+               _webrtcbin_get_stats(webrtc);
+
+       return G_SOURCE_CONTINUE;
+}
+
+void _set_stats_timer(webrtc_s *webrtc)
+{
+       RET_IF(webrtc == NULL, "webrtc is NULL");
+
+       if (webrtc->ini.general.stats_log_period <= 0) {
+               LOG_DEBUG("ini.general.stats_log_period[%d], skip printing stats", webrtc->ini.general.stats_log_period);
+               return;
+       }
+
+       if (webrtc->stats_timer_src != 0)
+               return;
+
+       webrtc->stats_timer_src = g_timeout_add_seconds(webrtc->ini.general.stats_log_period, __get_stats_periodically, webrtc);
+       LOG_DEBUG("new stats_timer_src[%u]", webrtc->stats_timer_src);
+}
+
+void _unset_stats_timer(webrtc_s *webrtc)
+{
+       RET_IF(webrtc == NULL, "webrtc is NULL");
+
+       if (webrtc->stats_timer_src == 0)
+               return;
+
+       g_source_remove(webrtc->stats_timer_src);
+
+       LOG_DEBUG("remove stats_timer_src[%u]", webrtc->stats_timer_src);
+       webrtc->stats_timer_src = 0;
+}
\ No newline at end of file