Use GStrv instead of gchar** on explict NULL-terminated vector string 31/272131/4 accepted/tizen/unified/20220311.132040 submit/tizen/20220311.035914
authorSeungbae Shin <seungbae.shin@samsung.com>
Thu, 10 Mar 2022 04:22:31 +0000 (13:22 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Thu, 10 Mar 2022 11:06:21 +0000 (20:06 +0900)
use g_auto for GStrv whenever possible

[Version] 0.3.66
[Issue Type] Refactoring

Change-Id: I58458c31bf4ff6e384358b9eb3bf6be53d71c531

include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc_ini.c
src/webrtc_private.c
src/webrtc_signaling_client.c
src/webrtc_signaling_server.c
src/webrtc_sink.c
test/webrtc_test.c

index b9849576db6ea689d800508f5b4c6d79772d50f6..bf03fd7813481cc87cc413a807b7b4de93d5b380 100644 (file)
@@ -293,8 +293,8 @@ typedef     struct _ini_item_general_s {
        bool verbose_log;
        bool nice_verbose;
        bool network_simulator;
-       gchar **gst_args;
-       gchar **gst_excluded_elements;
+       GStrv gst_args;
+       GStrv gst_excluded_elements;
        const char *stun_server;
        int jitterbuffer_latency;
        int bundle_policy;
@@ -302,7 +302,7 @@ typedef     struct _ini_item_general_s {
 
 typedef struct _ini_item_media_source_s {
        const char *source_element;
-       gchar **source_element_properties;
+       GStrv source_element_properties;
        /* video source pipeline */
        const char *v_raw_format;
        int v_width;
@@ -330,8 +330,8 @@ typedef struct _ini_item_media_source_s {
 typedef struct _ini_item_rendering_sink_s {
        const char *a_sink_element;
        const char *v_sink_element;
-       gchar **a_hw_decoder_elements;
-       gchar **v_hw_decoder_elements;
+       GStrv a_hw_decoder_elements;
+       GStrv v_hw_decoder_elements;
        bool v_overlay_resource_required;
 } ini_item_rendering_sink_s;
 
@@ -562,7 +562,7 @@ typedef struct _element_info_s {
        const gchar *klass_name;
        GstCaps *src_caps;
        GstCaps *sink_caps;
-       gchar **excluded_elements;
+       GStrv excluded_elements;
 } element_info_s;
 
 typedef struct _webrtc_signal_s {
@@ -609,7 +609,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);
+void _gst_set_element_properties(GstElement *element, GStrv 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 15fa28f9ee5865bd5afafc581213759d73b32d7b..fdd1fd375bf38023acaa368d44ae78811a64c4a1 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.65
+Version:    0.3.66
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index da879d986d2d6deb231f783f7c72a45d6428b769..791889d6e9e64681a2c0500dd85e0918581337e1 100644 (file)
@@ -278,7 +278,7 @@ static const char* __get_delimiter(const char *ini_path)
        return delimiter;
 }
 
-static void __ini_read_list(dictionary *dict, const char *category, const char *item, gchar ***list)
+static void __ini_read_list(dictionary *dict, const char *category, const char *item, GStrv *list)
 {
        const char *str;
        gchar *path;
index 7d4e5c6c2ceffb56fd3d063d6bac8682b5f1c99d..872fecd407e0d5c85d7723c3ab9902e99a99655e 100644 (file)
@@ -234,7 +234,8 @@ static GstSDPMessage* __webrtcbin_get_description(GstElement *webrtcbin, bool is
 
 static int __parse_attribute_value(const gchar *value, int *pt, gchar **attr_param)
 {
-       gchar **values;
+       g_auto(GStrv) values = NULL;
+       gint64 _pt;
 
        RET_VAL_IF(value == NULL, -1, "value is NULL");
        RET_VAL_IF(pt == NULL && attr_param == NULL, -1, "pt and attr_param is NULL");
@@ -242,29 +243,27 @@ static int __parse_attribute_value(const gchar *value, int *pt, gchar **attr_par
        values = g_strsplit(value, " ", 2);
        if (g_strv_length(values) != 2) {
                LOG_ERROR("empty attribute parameter, value[%s]", value);
-               g_strfreev(values);
                return -1;
        }
 
        if (pt) {
-               if (!g_strcmp0(values[0], "0")) {
+               if (g_str_equal(values[0], "0")) {
                        *pt = 0;
                } else {
-                       *pt = g_ascii_strtoll((const gchar *)values[0], NULL, 10);
+                       _pt = g_ascii_strtoll((const gchar *)values[0], NULL, 10);
                        /* g_ascii_strtoll() returns 0 on failure */
-                       if (*pt == 0) {
+                       if (_pt == 0) {
                                LOG_ERROR("invalid value[%s] for pt", values[0]);
-                               g_strfreev(values);
                                return -1;
                        }
+
+                       *pt = (int)_pt;
                }
        }
 
        if (attr_param)
                *attr_param = g_strdup(values[1]);
 
-       g_strfreev(values);
-
        return 0;
 }
 
@@ -845,7 +844,7 @@ static gboolean __element_filter(GstPluginFeature *feature, gpointer data)
        gchar *factory_name;
        GstElementFactory *factory = NULL;
        const gchar *factory_klass = NULL;
-       gchar **str_arr;
+       GStrv str_arr;
 
        if (!GST_IS_ELEMENT_FACTORY(feature))
                return FALSE;
@@ -936,7 +935,7 @@ int _gst_init(webrtc_s *webrtc)
        char **argv = NULL;
        GError *err = NULL;
        gboolean gst_ret;
-       gchar **gst_args;
+       GStrv gst_args;
 
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
 
@@ -1694,7 +1693,7 @@ 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)
+static void __parse_type_and_set_value(GType type, GstElement *element, GStrv key_value_pair)
 {
        RET_IF(element == NULL, "element is NULL");
        RET_IF(key_value_pair == NULL, "key_value_pairs is NULL");
@@ -1735,9 +1734,9 @@ static void __parse_type_and_set_value(GType type, GstElement *element, gchar **
        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)
+void _gst_set_element_properties(GstElement *element, GStrv key_value_pairs)
 {
-       gchar **key_value_pair;
+       GStrv key_value_pair;
        GParamSpec *param_spec;
 
        RET_IF(element == NULL, "element is NULL");
index 17f509f57d95b0dcb29c63484f37898d269e7a98..223e3abaca0881d54e1afe7ef8236b77e19e2015 100644 (file)
@@ -21,7 +21,7 @@
 //LCOV_EXCL_START
 static int __parse_message(gchar *message, webrtc_signaling_message_type_e *type, gchar **content)
 {
-       gchar **contents;
+       g_auto(GStrv) contents = NULL;
 
        RET_VAL_IF(message == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "message is NULL");
        RET_VAL_IF(type == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "type is NULL");
@@ -43,7 +43,6 @@ static int __parse_message(gchar *message, webrtc_signaling_message_type_e *type
        contents = g_strsplit(message, " ", 2);
        if (g_strv_length(contents) != 2) {
                LOG_ERROR("invalid message[%s]", message);
-               g_strfreev(contents);
                return WEBRTC_ERROR_INVALID_OPERATION;
        }
 
@@ -51,8 +50,6 @@ static int __parse_message(gchar *message, webrtc_signaling_message_type_e *type
 
        LOG_INFO("[%s] type[%d] content[%s]", contents[0], *type, *content);
 
-       g_strfreev(contents);
-
        return WEBRTC_ERROR_NONE;
 }
 
@@ -305,4 +302,4 @@ int webrtc_signaling_get_id(webrtc_signaling_client_h client, int *id)
 
        return WEBRTC_ERROR_NONE;
 }
-//LCOV_EXCL_STOP
\ No newline at end of file
+//LCOV_EXCL_STOP
index 9f3fb994293180952c0634a428229b4023792c34..a663ae32180e596bdb1e510fd179040fd9e9c4bd 100644 (file)
@@ -99,7 +99,7 @@ static gchar *__make_new_peer_key(webrtc_signaling_server_s *server, int *id)
        return peer;
 }
 
-static received_message_type_e __parse_message(const gchar *message, gchar ***contents)
+static received_message_type_e __parse_message(const gchar *message, GStrv *contents)
 {
        received_message_type_e type = RECEIVED_MESSAGE_TYPE_UNKNOWN;
 
@@ -302,7 +302,7 @@ static int __ws_cb(struct lws *wsi, enum lws_callback_reasons reason, void *user
                webrtc_signaling_server_s *server = (webrtc_signaling_server_s *)lws_context_user(lws_get_context(wsi));
                received_message_type_e type;
                gchar *message = g_strndup((const gchar *)in, (gsize)len);
-               gchar **contents = NULL;
+               g_auto(GStrv) contents = NULL;
 
                LOG_INFO("RECEIVE:\n%s", message);
 
@@ -325,8 +325,6 @@ static int __ws_cb(struct lws *wsi, enum lws_callback_reasons reason, void *user
                }
 
                g_free(message);
-               if (contents)
-                       g_strfreev(contents);
                break;
        }
        case LWS_CALLBACK_CLOSED: {
@@ -504,4 +502,4 @@ int webrtc_signaling_server_destroy(webrtc_signaling_server_h server)
 
        return WEBRTC_ERROR_NONE;
 }
-//LCOV_EXCL_STOP
\ No newline at end of file
+//LCOV_EXCL_STOP
index 43e6b7c424d56cdc1fb878072e7cce276fc9ecdb..ad1a7bfd00fd2a5a54ef8087fe9e69fab121025b 100644 (file)
@@ -299,17 +299,14 @@ static int __build_audiosink(webrtc_s *webrtc, GstElement *decodebin, GstPad *sr
 
 static unsigned int __get_id_from_name(const gchar *name)
 {
-       gchar **tokens = NULL;
-       gint64 id;
+       g_auto(GStrv) tokens = NULL;
 
        RET_VAL_IF(name == NULL, 0, "name is NULL");
 
        tokens = g_strsplit(name, "_", 2);
-       id = g_ascii_strtoll(tokens[1], NULL, 10);
+       RET_VAL_IF(g_strv_length(tokens) < 2, 0, "invalid name %s", name);
 
-       g_strfreev(tokens);
-
-       return (unsigned int)id;
+       return (unsigned int)g_ascii_strtoll(tokens[1], NULL, 10);
 }
 
 static void __invoke_track_added_cb(webrtc_s *webrtc, const gchar *name, bool is_audio, bool build_track_context)
@@ -443,7 +440,7 @@ int _decodebin_autoplug_select_cb(GstElement *decodebin, GstPad *pad, GstCaps *c
        gchar *factory_name;
        const gchar *klass;
        webrtc_s *webrtc = (webrtc_s *)user_data;
-       gchar **str_arr;
+       GStrv str_arr;
 
        RET_VAL_IF(webrtc == NULL, GST_AUTOPLUG_SELECT_SKIP, "webrtc is NULL, skip it");
 
index b5294722365a5ee4013159b47c329269ae90e665..3ba5a59ab20e6d6affa4f6ee1935fb76b025421c 100644 (file)
@@ -1611,7 +1611,7 @@ static void __data_channel_message_cb(webrtc_data_channel_h channel, webrtc_data
        RET_IF(!conn, "conn is NULL");
 
        if (type == WEBRTC_DATA_CHANNEL_TYPE_STRING) {
-               gchar **str_arr = NULL;
+               g_auto(GStrv) str_arr = NULL;
 
                g_print("string message[%s]\n", (char *)message);
 
@@ -1636,10 +1636,6 @@ static void __data_channel_message_cb(webrtc_data_channel_h channel, webrtc_data
                } else {
                        __render_text_message_in_idle(conn, message);
                }
-
-               if (str_arr)
-                       g_strfreev(str_arr);
-
        } else if (type == WEBRTC_DATA_CHANNEL_TYPE_BYTES) {
                webrtc_bytes_data_h *data = message;
                const char *data_p;
@@ -3928,7 +3924,7 @@ static void __auto_configure_handle_room_message(gchar *peer_id, gchar *message)
 
 static void __handle_room_related_message(const gchar *text)
 {
-       gchar **tokens = NULL;
+       g_auto(GStrv) tokens = NULL;
        guint len;
        guint i;
 
@@ -3974,9 +3970,6 @@ static void __handle_room_related_message(const gchar *text)
                g_print("\n[from SERVER > %s]\n", text);
                g_signaling_server.server_status = SERVER_STATUS_ERROR_FOUND;
        }
-
-       if (tokens)
-               g_strfreev(tokens);
 }
 
 static void __websocket_message_cb(SoupWebsocketConnection *ws_conn, SoupWebsocketDataType type, GBytes *message, gpointer user_data)