From: Sangchul Lee Date: Tue, 7 Sep 2021 10:19:56 +0000 (+0900) Subject: webrtc_ini: Add support for printing stats log periodically X-Git-Tag: submit/tizen/20210908.142042~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=893bf41fb0f1ac7699044ab1dd6390876fff4a9c;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_ini: Add support for printing stats log periodically [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 --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index ab042877..d24dc757 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -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); diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index bf25b1c6..883ab6ee 100644 --- a/packaging/capi-media-webrtc.spec +++ b/packaging/capi-media-webrtc.spec @@ -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 diff --git a/src/webrtc.c b/src/webrtc.c index 17858efd..a045a8e9 100644 --- a/src/webrtc.c +++ b/src/webrtc.c @@ -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()"); diff --git a/src/webrtc_ini.c b/src/webrtc_ini.c index 9d87dac1..2b4b5dc5 100644 --- a/src/webrtc_ini.c +++ b/src/webrtc_ini.c @@ -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) diff --git a/src/webrtc_private.c b/src/webrtc_private.c index bda78f9e..2b63884d 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -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()"); diff --git a/src/webrtc_stats.c b/src/webrtc_stats.c index 2910ddc2..45864121 100644 --- a/src/webrtc_stats.c +++ b/src/webrtc_stats.c @@ -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