From 0c6cf03b2f1331bfa416b3d4dc81fc75a65566a0 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Fri, 12 Jan 2024 09:22:27 +0900 Subject: [PATCH] Apply ASSERT() to the result of g_hash_table_insert() [Version] 0.4.36 [Issue Type] Refactoring Change-Id: Ia298d0697c6cc06c2417d686ebccc1b497b0d5fa Signed-off-by: Sangchul Lee (cherry picked from commit 941cdb71d03ca95508806f629ee6938488f1cc6c) --- packaging/capi-media-webrtc.spec | 2 +- src/webrtc_data_channel.c | 7 +------ src/webrtc_ini.c | 5 +---- src/webrtc_signaling_server.c | 7 +------ src/webrtc_sink.c | 18 +++--------------- src/webrtc_source.c | 12 ++---------- 6 files changed, 9 insertions(+), 42 deletions(-) diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 06522f43..73533816 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.4.35 +Version: 0.4.36 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_data_channel.c b/src/webrtc_data_channel.c index ba9e19db..52407328 100644 --- a/src/webrtc_data_channel.c +++ b/src/webrtc_data_channel.c @@ -171,12 +171,7 @@ static webrtc_data_channel_s *__prepare_data_channel(webrtc_s *webrtc, GObject * _channel->webrtc = webrtc; _channel->channel = dc_obj; - if (!g_hash_table_insert(webrtc->data_channels, (gpointer)_channel, (gpointer)_channel)) { - LOG_ERROR("should not be reached here, _channel[%p] already exist, it'll be removed", _channel); - g_mutex_unlock(&_channel->mutex); - g_hash_table_remove(webrtc->data_channels, _channel); - return NULL; - } + ASSERT(g_hash_table_insert(webrtc->data_channels, (gpointer)_channel, (gpointer)_channel)); _connect_and_append_signal(&_channel->signals, dc_obj, "on-open", G_CALLBACK(__data_channel_on_open_cb), _channel); _connect_and_append_signal(&_channel->signals, dc_obj, "on-message-string", G_CALLBACK(__data_channel_on_message_string_cb), _channel); diff --git a/src/webrtc_ini.c b/src/webrtc_ini.c index 49fc7fe0..2f7e61a2 100644 --- a/src/webrtc_ini.c +++ b/src/webrtc_ini.c @@ -538,10 +538,7 @@ void _load_ini(webrtc_s *webrtc) if (iniparser_getsecnkeys(ini->dict, category_source_names[i]) > 0) { ini_item_media_source_s *source = g_new0(ini_item_media_source_s, 1); __apply_media_source_setting(ini, source, category_source_names[i]); - if (!g_hash_table_insert(ini->sources, g_strdup(category_source_names[i]), (gpointer)source)) { - LOG_WARNING("[%s] already exist", category_source_names[i]); - continue; - } + ASSERT(g_hash_table_insert(ini->sources, g_strdup(category_source_names[i]), (gpointer)source)); } } diff --git a/src/webrtc_signaling_server.c b/src/webrtc_signaling_server.c index 8fa123f0..7b434621 100644 --- a/src/webrtc_signaling_server.c +++ b/src/webrtc_signaling_server.c @@ -176,12 +176,7 @@ static void __handle_established(webrtc_signaling_server_s *server, struct lws * client = g_new0(webrtc_client_slot_s, 1); client->wsi = wsi; client->id = id; - if (!g_hash_table_insert(server->clients, new_peer, (gpointer)client)) { - LOG_ERROR("should not be reached here, new_peer[%s] already exist, wsi[%p] will be removed", new_peer, wsi); - g_hash_table_remove(server->clients, new_peer); - __send_message(wsi, SIGNALING_MESSAGE_REPLY_CONNECT_ERROR); - return; - } + ASSERT(g_hash_table_insert(server->clients, new_peer, (gpointer)client)); LOG_INFO("[%s] is connected", new_peer); diff --git a/src/webrtc_sink.c b/src/webrtc_sink.c index 98179482..4e164e90 100644 --- a/src/webrtc_sink.c +++ b/src/webrtc_sink.c @@ -52,11 +52,7 @@ static int __add_track_build_context(webrtc_s *webrtc, gchar *id) context = g_main_context_new(); g_main_context_push_thread_default(context); - if (!g_hash_table_insert(webrtc->track_build_contexts, id, context)) { - LOG_ERROR("should not be reached here, id[%s] already exist, it'll be removed", id); - g_hash_table_remove(webrtc->track_build_contexts, id); - return WEBRTC_ERROR_INVALID_OPERATION; - } + ASSERT(g_hash_table_insert(webrtc->track_build_contexts, id, context)); return WEBRTC_ERROR_NONE; } @@ -739,11 +735,7 @@ int _add_rendering_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio) if (__link_pads(webrtc, src_pad, sink, decodebin) != WEBRTC_ERROR_NONE) goto error_before_insert; - if (!g_hash_table_insert(webrtc->gst.sink_slots, track_name, (gpointer)sink)) { - LOG_ERROR("should not be reached here, track_name[%s] already exist, sink id[%u] will be removed", track_name, sink->id); - g_hash_table_remove(webrtc->gst.sink_slots, track_name); - return WEBRTC_ERROR_INVALID_OPERATION; - } + ASSERT(g_hash_table_insert(webrtc->gst.sink_slots, track_name, (gpointer)sink)); if (!gst_element_sync_state_with_parent(GST_ELEMENT(sink->bin))) { LOG_ERROR("failed to gst_element_sync_state_with_parent() for [%s]", GST_ELEMENT_NAME(sink->bin)); @@ -1094,11 +1086,7 @@ int _add_forwarding_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio) if (__link_pads(webrtc, src_pad, sink, depayloader) != WEBRTC_ERROR_NONE) goto error_before_insert; - if (!g_hash_table_insert(webrtc->gst.sink_slots, track_name, (gpointer)sink)) { - LOG_ERROR("should not be reached here, track_name[%s] already exist, sink id[%u] will be removed", track_name, sink->id); - g_hash_table_remove(webrtc->gst.sink_slots, track_name); - return WEBRTC_ERROR_INVALID_OPERATION; - } + ASSERT(g_hash_table_insert(webrtc->gst.sink_slots, track_name, (gpointer)sink)); sink->encoded_frame_cb = is_audio ? &(webrtc->encoded_audio_frame_cb) : &(webrtc->encoded_video_frame_cb); sink->media_types = is_audio ? MEDIA_TYPE_AUDIO : MEDIA_TYPE_VIDEO; diff --git a/src/webrtc_source.c b/src/webrtc_source.c index a6d6843b..d82fee5b 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -632,11 +632,7 @@ static int __add_media_source(webrtc_s *webrtc, int type, unsigned int *source_i /* The gst_element_get_request_pad() of webrtcbin will trigger the transceiver callback. To update the mline value of * new transceiver object to the source structure in the callback, hash table inserting should be preceded. */ - if (!g_hash_table_insert(webrtc->gst.source_slots, bin_name, (gpointer)source)) { - LOG_ERROR("should not be reached here, bin_name[%s] already exist, source id[%u] will be removed", bin_name, source->id); - g_hash_table_remove(webrtc->gst.source_slots, bin_name); - return WEBRTC_ERROR_INVALID_OPERATION; - } + ASSERT(g_hash_table_insert(webrtc->gst.source_slots, bin_name, (gpointer)source)); *source_id = source->id; webrtc->gst.sources[*source_id - 1] = source; @@ -666,11 +662,7 @@ static int __add_null_source(webrtc_s *webrtc, unsigned int *source_id) /* The gst_element_get_request_pad() of webrtcbin will trigger the transceiver callback. To update the mline value of * new transceiver object to the source structure in the callback, hash table inserting should be preceded. */ - if (!g_hash_table_insert(webrtc->gst.source_slots, name, (gpointer)source)) { - LOG_ERROR("should not be reached here, name[%s] already exist, source id[%u] will be removed", name, source->id); - g_hash_table_remove(webrtc->gst.source_slots, name); - return WEBRTC_ERROR_INVALID_OPERATION; - } + ASSERT(g_hash_table_insert(webrtc->gst.source_slots, name, (gpointer)source)); *source_id = source->id; webrtc->gst.sources[*source_id - 1] = source; -- 2.34.1