From: Sangchul Lee Date: Tue, 16 Nov 2021 10:59:02 +0000 (+0900) Subject: webrtc_ini: Add new item to set source element properties X-Git-Tag: submit/tizen/20211124.083808^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=77de238b65af7747cb5fda6b1d77e1333b7d4ac1;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_ini: Add new item to set source element properties 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 --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 8de568b8..e2e1e4b6 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -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); diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index b662ac2e..0aa12413 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.3.10 +Version: 0.3.11 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_ini.c b/src/webrtc_ini.c index 3045eee0..9d5dddac 100644 --- a/src/webrtc_ini.c +++ b/src/webrtc_ini.c @@ -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); diff --git a/src/webrtc_private.c b/src/webrtc_private.c index 99fad14f..619721f4 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -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;