From: Sangchul Lee Date: Wed, 13 Jul 2022 00:36:43 +0000 (+0900) Subject: webrtc_private: Refactor _add_elements_to_bin() X-Git-Tag: submit/tizen/20220714.015855~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=63780a21fdb1b5539c688929cb91ad2c4440379c;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_private: Refactor _add_elements_to_bin() g_autoptr() is used for temporary list. Some comments are removed with renaming callback function. Error handling logic is separated with goto statement. [Version] 0.3.154 [Issue Type] Refactoring Change-Id: Ie2bfc61a0cda63502e925652fbdf3db1e8d39874 Signed-off-by: Sangchul Lee --- diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 3a2d30b7..2eeec1d8 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.153 +Version: 0.3.154 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_private.c b/src/webrtc_private.c index 93848b38..2ff1e0a7 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -1726,7 +1726,7 @@ bool _sync_elements_state_with_parent(GList *element_list) return true; } -static void __foreach_unref_object_cb(gpointer data, gpointer user_data) +static void __foreach_unref_rest_of_elements_cb(gpointer data, gpointer user_data) { GstElement *element = GST_ELEMENT_CAST(data); @@ -1738,28 +1738,27 @@ bool _add_elements_to_bin(GstBin *bin, GList *element_list) { GstElement *element; GList *list; - GList *added_list = NULL; + g_autoptr(GList) added_list = NULL; RET_VAL_IF(bin == NULL, false, "bin is NULL"); RET_VAL_IF(element_list == NULL, false, "element_list is NULL"); - for (list = element_list; list; list = list->next) { + for (list = element_list; list; list = g_list_next(list)) { element = GST_ELEMENT_CAST(list->data); - if (!gst_bin_add(bin, element)) { - LOG_ERROR("failed to gst_bin_add(), bin[%s], element[%s]", GST_ELEMENT_NAME(bin), GST_ELEMENT_NAME(element)); - _remove_elements_from_bin(bin, added_list); - SAFE_G_LIST_FREE(added_list); - g_list_foreach(list, __foreach_unref_object_cb, NULL); /* rest of elements on the list should be unreferenced */ - return false; - } + if (!gst_bin_add(bin, element)) + goto error; APPEND_ELEMENT(added_list, element); } LOG_DEBUG("%d elements are added to bin[%s]", g_list_length(added_list), GST_ELEMENT_NAME(bin)); - SAFE_G_LIST_FREE(added_list); - return true; + +error: + LOG_ERROR("failed to gst_bin_add(), bin[%s], element[%s]", GST_ELEMENT_NAME(bin), GST_ELEMENT_NAME(element)); + _remove_elements_from_bin(bin, added_list); + g_list_foreach(list, __foreach_unref_rest_of_elements_cb, NULL); + return false; } bool _link_elements(GList *element_list)