webrtc_ini: Add new item to set source element properties 43/266643/8 accepted/tizen/unified/20211125.144720 submit/tizen/20211124.083808
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 16 Nov 2021 10:59:02 +0000 (19:59 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 24 Nov 2021 04:01:16 +0000 (13:01 +0900)
ini file example)
[source xxx]
source element properties = prop_name1=value1, prop_name2=value2

_gst_set_element_properties() is added to set property list
to an element.

[Version] 0.3.11
[Issue Type] New feature

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

index 8de568b85f22ea9cf8cb04cd43331aabb3adb954..e2e1e4b66d0b7ac5381b5f8c205df0a9641eb688 100644 (file)
@@ -298,6 +298,7 @@ typedef     struct _ini_item_general_s {
 
 typedef struct _ini_item_media_source_s {
        const char *source_element;
+       gchar **source_element_properties;
        /* video source pipeline */
        const char *v_raw_format;
        int v_width;
@@ -566,6 +567,7 @@ int _gst_init(webrtc_s *webrtc);
 int _gst_build_pipeline(webrtc_s *webrtc);
 void _gst_destroy_pipeline(webrtc_s *webrtc);
 int _gst_pipeline_set_state(webrtc_s *webrtc, GstState state);
+void _gst_set_element_properties(GstElement *element, gchar **key_value_pairs);
 int _add_media_source(webrtc_s *webrtc, int type, unsigned int *source_id);
 int _add_media_source_internal(webrtc_s *webrtc, int type, unsigned int *source_id);
 int _remove_media_source(webrtc_s *webrtc, unsigned int source_id);
index b662ac2e96be4f0a1682a1a39412f2642453fa52..0aa12413c53d6ee2915fa5a3c5ccda85bbc82c1b 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.10
+Version:    0.3.11
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 3045eee0f0eea573777037aae14db0dbc734a0b7..9d5dddacea418837599a20a0c42b13d2027a7238 100644 (file)
@@ -58,6 +58,7 @@ bool g_verbose = false;
 
 /* items for media source */
 #define INI_ITEM_SOURCE_ELEMENT            "source element"
+#define INI_ITEM_SOURCE_ELEMENT_PROPERTIES "source element properties"
 #define INI_ITEM_VIDEO_RAW_FORMAT          "video raw format"
 #define INI_ITEM_VIDEO_WIDTH               "video width"
 #define INI_ITEM_VIDEO_HEIGHT              "video height"
@@ -182,6 +183,7 @@ static void __dump_items_of_source(ini_item_media_source_s *source)
        RET_IF(source == NULL, "source is NULL");
 
        __dump_item(INI_ITEM_SOURCE_ELEMENT, INI_ITEM_TYPE_STRING, (void *)source->source_element);
+       __dump_item(INI_ITEM_SOURCE_ELEMENT_PROPERTIES, INI_ITEM_TYPE_STRINGS, (void *)source->source_element_properties);
        __dump_item(INI_ITEM_VIDEO_RAW_FORMAT, INI_ITEM_TYPE_STRING, (void *)source->v_raw_format);
        __dump_item(INI_ITEM_VIDEO_WIDTH, INI_ITEM_TYPE_INT, &source->v_width);
        __dump_item(INI_ITEM_VIDEO_HEIGHT, INI_ITEM_TYPE_INT, &source->v_height);
@@ -357,6 +359,11 @@ static void __ini_source_destroy_cb(gpointer data)
 
        RET_IF(source == NULL, "source is NULL");
 
+       if (source->source_element_properties) {
+               g_strfreev(source->source_element_properties);
+               source->source_element_properties = NULL;
+       }
+
        g_free(source);
 }
 
@@ -390,8 +397,10 @@ static void __apply_media_source_setting(webrtc_ini_s *ini, ini_item_media_sourc
        if (g_strcmp0(category, INI_CATEGORY_MEDIA_SOURCE) == 0)
                is_default = true;
 
-       if (!is_default)
+       if (!is_default) {
                source->source_element = __ini_get_string(ini->dict, category, INI_ITEM_SOURCE_ELEMENT, NULL);
+               __ini_read_list(ini->dict, category, INI_ITEM_SOURCE_ELEMENT_PROPERTIES, &source->source_element_properties);
+       }
 
        source->v_raw_format = __ini_get_string(ini->dict, category, INI_ITEM_VIDEO_RAW_FORMAT,
                        is_default ? DEFAULT_VIDEO_RAW_FORMAT : ini->media_source.v_raw_format);
index 99fad14f207d3951ad971edfab34bddda47db113..619721f4196a643a7504b4b8c74ac257a1ac3a0b 100644 (file)
@@ -1364,6 +1364,78 @@ int _gst_pipeline_set_state(webrtc_s *webrtc, GstState state)
        return WEBRTC_ERROR_NONE;
 }
 
+static void __parse_type_and_set_value(GType type, GstElement *element, gchar **key_value_pair)
+{
+       RET_IF(element == NULL, "element is NULL");
+       RET_IF(key_value_pair == NULL, "key_value_pairs is NULL");
+       RET_IF(key_value_pair[0] == NULL, "key is NULL");
+       RET_IF(key_value_pair[1] == NULL, "value is NULL");
+
+       switch (type) {
+       case G_TYPE_STRING:
+               g_object_set(G_OBJECT(element), key_value_pair[0], key_value_pair[1], NULL);
+               break;
+       case G_TYPE_INT:
+       case G_TYPE_INT64:
+       case G_TYPE_ENUM: {
+               gint64 value = g_ascii_strtoll((const gchar *)key_value_pair[1], NULL, 10);
+               g_object_set(G_OBJECT(element), key_value_pair[0], value, NULL);
+               break;
+       }
+       case G_TYPE_UINT:
+       case G_TYPE_UINT64:
+       case G_TYPE_BOOLEAN: {
+               guint64 value = g_ascii_strtoll((const gchar *)key_value_pair[1], NULL, 10);
+               g_object_set(G_OBJECT(element), key_value_pair[0], value, NULL);
+               break;
+       }
+       case G_TYPE_FLOAT:
+       case G_TYPE_DOUBLE: {
+               gdouble value = g_ascii_strtod((const gchar *)key_value_pair[1], NULL);
+               g_object_set(G_OBJECT(element), key_value_pair[0], value, NULL);
+               break;
+       }
+       default:
+               LOG_DEBUG("not supported type(0x%x) exactly, but try it with int64 type", (unsigned int)type); /* e.g.) custom enum type falls through here */
+               gint64 value = g_ascii_strtoll((const gchar *)key_value_pair[1], NULL, 10);
+               g_object_set(G_OBJECT(element), key_value_pair[0], value, NULL);
+               break;
+       }
+
+       LOG_DEBUG("element[%s] property[%s] value[type:0x%x, %s]", GST_ELEMENT_NAME(element), key_value_pair[0], (unsigned int)type, key_value_pair[1]);
+}
+
+void _gst_set_element_properties(GstElement *element, gchar **key_value_pairs)
+{
+       gchar **key_value_pair;
+       GParamSpec *param_spec;
+
+       RET_IF(element == NULL, "element is NULL");
+
+       if (!key_value_pairs)
+               return;
+
+       while (key_value_pairs && *key_value_pairs) {
+               key_value_pair = g_strsplit(*key_value_pairs++, "=", 2);
+
+               if (!g_strcmp0(key_value_pair[0], "") || !g_strcmp0(key_value_pair[1], "")) {
+                       LOG_ERROR("invalid key_value_pair, key[%s], value[%s]", key_value_pair[0], key_value_pair[1]);
+                       g_strfreev(key_value_pair);
+                       continue;
+               }
+
+               if (!(param_spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(element)), g_strstrip(key_value_pair[0])))) {
+                       LOG_ERROR("element[%s] does not have this property[%s]", GST_ELEMENT_NAME(element), key_value_pair[0]);
+                       g_strfreev(key_value_pair);
+                       continue;
+               }
+
+               __parse_type_and_set_value(param_spec->value_type, element, key_value_pair);
+
+               g_strfreev(key_value_pair);
+       }
+}
+
 static gboolean __check_id_equal_cb(gpointer key, gpointer value, gpointer user_data)
 {
        webrtc_gst_slot_s *slot = value;