Import iniparser 76/246076/4
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 23 Oct 2020 04:50:20 +0000 (13:50 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 26 Oct 2020 07:00:36 +0000 (16:00 +0900)
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 <sc11.lee@samsung.com>
CMakeLists.txt
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc.c
src/webrtc_ini.c [new file with mode: 0644]
src/webrtc_private.c

index 6757b966d2fb6771f75e873603d1197859d32f59..3f3e106b570ca971efb7007e24a285350e436e48 100644 (file)
@@ -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)
index aee72ead56c888712f3ae1b557c6a288e2d58ffb..9ab77cfd0161c3c7280c85da67d83ebf108e4202 100644 (file)
@@ -24,6 +24,7 @@
 #define GST_USE_UNSTABLE_API
 #include <gst/webrtc/webrtc.h>
 #endif
+#include <iniparser.h>
 
 #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);
index d4b43c3e36b1f7236ec219dcf595f8658d2f7621..0acf6df8958422f9b792b86c5d3aaef78d2a4548 100644 (file)
@@ -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.
index df22eda2d8a549d64c2e20ce51986747016fd84a..a47d6ca50a184703e5900a9d230d96712ee3b41e 100644 (file)
@@ -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 (file)
index 0000000..15515aa
--- /dev/null
@@ -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;
+}
index e1309110e24262292c67e80a5312e8b3cb1715f5..4e5406d2577f3d1a677dbfa2e3f6640c94e9040a 100644 (file)
@@ -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;