From: Seungbae Shin Date: Thu, 10 Mar 2022 04:22:31 +0000 (+0900) Subject: Use GStrv instead of gchar** on explict NULL-terminated vector string X-Git-Tag: submit/tizen/20220311.035914^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f8f6157cd2b73bf00d8b53eba35080acc1363d5f;p=platform%2Fcore%2Fapi%2Fwebrtc.git Use GStrv instead of gchar** on explict NULL-terminated vector string use g_auto for GStrv whenever possible [Version] 0.3.66 [Issue Type] Refactoring Change-Id: I58458c31bf4ff6e384358b9eb3bf6be53d71c531 --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index b9849576..bf03fd78 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -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); diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 15fa28f9..fdd1fd37 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.65 +Version: 0.3.66 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_ini.c b/src/webrtc_ini.c index da879d98..791889d6 100644 --- a/src/webrtc_ini.c +++ b/src/webrtc_ini.c @@ -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; diff --git a/src/webrtc_private.c b/src/webrtc_private.c index 7d4e5c6c..872fecd4 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -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"); diff --git a/src/webrtc_signaling_client.c b/src/webrtc_signaling_client.c index 17f509f5..223e3aba 100644 --- a/src/webrtc_signaling_client.c +++ b/src/webrtc_signaling_client.c @@ -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 diff --git a/src/webrtc_signaling_server.c b/src/webrtc_signaling_server.c index 9f3fb994..a663ae32 100644 --- a/src/webrtc_signaling_server.c +++ b/src/webrtc_signaling_server.c @@ -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 diff --git a/src/webrtc_sink.c b/src/webrtc_sink.c index 43e6b7c4..ad1a7bfd 100644 --- a/src/webrtc_sink.c +++ b/src/webrtc_sink.c @@ -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"); diff --git a/test/webrtc_test.c b/test/webrtc_test.c index b5294722..3ba5a59a 100644 --- a/test/webrtc_test.c +++ b/test/webrtc_test.c @@ -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)