Apply ASSERT() to the result of g_hash_table_insert() 54/304354/1 accepted/tizen/8.0/unified/20240117.162928
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 12 Jan 2024 00:22:27 +0000 (09:22 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 16 Jan 2024 08:35:53 +0000 (08:35 +0000)
[Version] 0.4.36
[Issue Type] Refactoring

Change-Id: Ia298d0697c6cc06c2417d686ebccc1b497b0d5fa
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
(cherry picked from commit 941cdb71d03ca95508806f629ee6938488f1cc6c)

packaging/capi-media-webrtc.spec
src/webrtc_data_channel.c
src/webrtc_ini.c
src/webrtc_signaling_server.c
src/webrtc_sink.c
src/webrtc_source.c

index 06522f4363a8ffa163c95aa87103928147bbb8d0..735338160e7fa4a3938a3653aa8ff3d49e566d52 100644 (file)
@@ -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
index ba9e19db59f2ae59b9b19634980ebc7424a7a1c2..524073282b88969a7bffe33dd4be65213b821edb 100644 (file)
@@ -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);
index 49fc7fe0be3adce88716ac5203016f0cfa0bff04..2f7e61a23811b2b442ef4e984a775a2afd7bfa18 100644 (file)
@@ -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));
                }
        }
 
index 8fa123f0bfcae3190597acc4e8c4aa4bbc05e6c5..7b43462196720566ebc7816f66935df733a5d499 100644 (file)
@@ -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);
 
index 981794824542a0de5d27a02abc47116ea9dc7990..4e164e9084f366a044001e5d0909ee5c263b6ec0 100644 (file)
@@ -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;
index a6d6843bd71fb2b0d468834051cb22b96f02a0e2..d82fee5bdac5448e8d767fcd602ac45d487e126e 100644 (file)
@@ -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;