From: Sangchul Lee Date: Fri, 23 Oct 2020 04:50:20 +0000 (+0900) Subject: Import iniparser X-Git-Tag: submit/tizen/20210729.023123~199 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b8cbc6bb4178b06bc5058f251ecf369a6999b6a1;p=platform%2Fcore%2Fapi%2Fwebrtc.git Import iniparser webrtc_ini.c is added. - get ready for reading items of ini configuration file as below. [general] generate dot = dot path = gstreamer arguments = gstreamer excluded elements = [Version] 0.1.43 [Issue Type] Improvement Change-Id: Ib5a19ad4253867ff4e03d6daf6e5ada96aa54dcb Signed-off-by: Sangchul Lee --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 6757b966..3f3e106b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib") SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) -SET(dependents "dlog glib-2.0 gstreamer-1.0 gstreamer-webrtc-1.0 json-glib-1.0") +SET(dependents "dlog glib-2.0 gstreamer-1.0 gstreamer-webrtc-1.0 json-glib-1.0 iniparser") SET(pc_dependents "capi-base-common" ) INCLUDE(FindPkgConfig) diff --git a/include/webrtc_private.h b/include/webrtc_private.h index aee72ead..9ab77cfd 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -24,6 +24,7 @@ #define GST_USE_UNSTABLE_API #include #endif +#include #ifdef __cplusplus extern "C" { @@ -157,8 +158,10 @@ typedef enum { #define MLINES_IDX_VIDEO 1 typedef struct _webrtc_ini_s { + dictionary *dict; gboolean generate_dot; gchar **gst_args; + gchar **gst_excluded_elements; } webrtc_ini_s; typedef struct _webrtc_gst_slot_s { @@ -235,7 +238,10 @@ typedef struct _webrtc_signal_s { gulong signal_id; } webrtc_signal_s; -int _ini_load(webrtc_s *webrtc); +int _load_ini(webrtc_s *webrtc); +void _unload_ini(webrtc_s *webrtc); +void _ini_read_list(dictionary *dict, const char *ini_path, gchar ***list); + int _gst_init(webrtc_s *webrtc); int _gst_build_pipeline(webrtc_s *webrtc); void _gst_destroy_pipeline(webrtc_s *webrtc); diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index d4b43c3e..0acf6df8 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.1.42 +Version: 0.1.43 Release: 0 Group: Multimedia/API License: Apache-2.0 @@ -17,6 +17,7 @@ BuildRequires: pkgconfig(appcore-efl) BuildRequires: pkgconfig(elementary) BuildRequires: pkgconfig(json-glib-1.0) BuildRequires: pkgconfig(libsoup-2.4) +BuildRequires: pkgconfig(iniparser) %description A WebRTC library in Tizen Native API. diff --git a/src/webrtc.c b/src/webrtc.c index df22eda2..a47d6ca5 100644 --- a/src/webrtc.c +++ b/src/webrtc.c @@ -116,7 +116,7 @@ int webrtc_create(webrtc_h *webrtc) g_mutex_init(&_webrtc->desc_mutex); g_cond_init(&_webrtc->desc_cond); - _ini_load(_webrtc); + _load_ini(_webrtc); _gst_init(_webrtc); _gst_build_pipeline(_webrtc); _init_data_channels(_webrtc); @@ -148,6 +148,7 @@ int webrtc_destroy(webrtc_h webrtc) _destroy_data_channels(_webrtc); _gst_destroy_pipeline(_webrtc); + _unload_ini(_webrtc); g_mutex_clear(&_webrtc->desc_mutex); g_cond_clear(&_webrtc->desc_cond); diff --git a/src/webrtc_ini.c b/src/webrtc_ini.c new file mode 100644 index 00000000..15515aab --- /dev/null +++ b/src/webrtc_ini.c @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "webrtc.h" +#include "webrtc_private.h" + +#define WEBRTC_INI_PATH "/etc/multimedia/mmfw_webrtc.ini" +#define DEFAULT_GENERATE_DOT TRUE +#define DEFAULT_DOT_PATH "/tmp" + +#define INI_ITEM_GENERAL_DOT_PATH "general:dot path" +#define INI_ITEM_GENERAL_DOT_GENERATE "general:generate dot" +#define INI_ITEM_GENERAL_GST_ARGS "general:gstreamer arguments" +#define INI_ITEM_GENERAL_GST_EXCLUDED_ELEMENTS "general:gstreamer excluded elements" + +static const char* __get_delimiter(const char *ini_path) +{ + const char *delimiter = ","; + + if (g_strcmp0(ini_path, INI_ITEM_GENERAL_GST_ARGS) == 0) + delimiter = "|"; + + return delimiter; +} + +static void __ini_read_list(dictionary *dict, const char *ini_path, gchar ***list) +{ + const char *str; + gchar *strtmp = NULL; + + RET_IF(dict == NULL, "dict is NULL"); + RET_IF(ini_path == NULL, "ini_path is NULL"); + RET_IF(list == NULL, "list is NULL"); + + str = iniparser_getstring(dict, ini_path, NULL); + if (str && strlen(str) > 0) { + strtmp = g_strdup(str); + g_strstrip(strtmp); + *list = g_strsplit(strtmp, __get_delimiter(ini_path), 10); + } + + LOG_DEBUG("[%s] %s", ini_path, strtmp ? strtmp : "none"); + + g_free(strtmp); +} + +int _load_ini(webrtc_s *webrtc) +{ + const char *dot_path; + + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + + memset(&webrtc->ini, 0, sizeof(webrtc_ini_s)); + + webrtc->ini.dict = iniparser_load(WEBRTC_INI_PATH); + if (!webrtc->ini.dict) + LOG_WARNING("could not open ini[%s], use default values", WEBRTC_INI_PATH); + + webrtc->ini.generate_dot = iniparser_getboolean(webrtc->ini.dict, INI_ITEM_GENERAL_DOT_GENERATE, DEFAULT_GENERATE_DOT); + + dot_path = iniparser_getstring(webrtc->ini.dict, INI_ITEM_GENERAL_DOT_PATH, DEFAULT_DOT_PATH); + if (webrtc->ini.generate_dot) { + LOG_INFO("dot file will be stored in [%s]", dot_path); + g_setenv("GST_DEBUG_DUMP_DOT_DIR", dot_path, FALSE); + } + + __ini_read_list(webrtc->ini.dict, INI_ITEM_GENERAL_GST_ARGS, &webrtc->ini.gst_args); + + __ini_read_list(webrtc->ini.dict, INI_ITEM_GENERAL_GST_EXCLUDED_ELEMENTS, &webrtc->ini.gst_excluded_elements); + + return WEBRTC_ERROR_NONE; +} + +void _unload_ini(webrtc_s *webrtc) +{ + RET_IF(webrtc == NULL, "webrtc is NULL"); + RET_IF(webrtc->ini.dict == NULL, "ini.dict is NULL"); + + g_strfreev(webrtc->ini.gst_args); + webrtc->ini.gst_args = NULL; + + g_strfreev(webrtc->ini.gst_excluded_elements); + webrtc->ini.gst_excluded_elements = NULL; + + iniparser_freedict(webrtc->ini.dict); + LOG_DEBUG("ini instance[%p] is freed", webrtc->ini.dict); + webrtc->ini.dict = NULL; +} diff --git a/src/webrtc_private.c b/src/webrtc_private.c index e1309110..4e5406d2 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -18,8 +18,7 @@ #include "webrtc.h" #include "webrtc_private.h" -#define DEFAULT_DOT_FILE_NAME_PREFIX "webrtc" -#define DEFAULT_DOT_DIRECTORY "/tmp" +#define DEFAULT_DOT_FILE_NAME_PREFIX "webrtc" static const char* __state_str[] = { "IDLE", @@ -377,25 +376,6 @@ GstElement *_create_element_from_registry(element_info_s *elem_info) return element; } -int _ini_load(webrtc_s *webrtc) -{ - RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); - - memset(&webrtc->ini, 0, sizeof(webrtc_ini_s)); - - /* FIXME: load from ini file */ - /* set it TRUE temporarily until ini ready */ - webrtc->ini.generate_dot = TRUE; - - if (webrtc->ini.generate_dot) { - /* FIXME: get path from ini */ - LOG_INFO("dot file will be stored in [%s]", DEFAULT_DOT_DIRECTORY); - g_setenv("GST_DEBUG_DUMP_DOT_DIR", DEFAULT_DOT_DIRECTORY, FALSE); - } - - return WEBRTC_ERROR_NONE; -} - int _gst_init(webrtc_s *webrtc) { int i = 0;