webrtc_private: Refactor _add_elements_to_bin() 50/277750/3
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 13 Jul 2022 00:36:43 +0000 (09:36 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 13 Jul 2022 03:32:38 +0000 (03:32 +0000)
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 <sc11.lee@samsung.com>
packaging/capi-media-webrtc.spec
src/webrtc_private.c

index 3a2d30b7df66c9a369289515655eac12b74179b8..2eeec1d843f1f07d73ca938eb4b5c39a8618cac5 100644 (file)
@@ -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
index 93848b38d8eb3ef915c2a7b02457fde2c47e243b..2ff1e0a7ba4ef398e604a553dbaa44444a9ae9ad 100644 (file)
@@ -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)