From: Sangchul Lee Date: Wed, 13 Oct 2021 07:43:09 +0000 (+0900) Subject: webrtc_data_channel: Close data channel before destroying the handle X-Git-Tag: submit/tizen/20211020.012736~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=07e511651340406945c7660a9e29692bc9782514;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_data_channel: Close data channel before destroying the handle It'll trigger the close callback on the data channel. [Version] 0.2.123 [Issue Type] Improvement Change-Id: I578a70a3677652addd5aa9896bdf7323ee67988a Signed-off-by: Sangchul Lee --- diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 0d139a20..168b9af9 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.2.122 +Version: 0.2.123 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_data_channel.c b/src/webrtc_data_channel.c index 13da56f6..472f8098 100644 --- a/src/webrtc_data_channel.c +++ b/src/webrtc_data_channel.c @@ -131,7 +131,7 @@ void _webrtcbin_on_data_channel_cb(GstElement *webrtcbin, GObject *data_channel, channel->channel = data_channel; - LOG_DEBUG("channel[%p, %s] user_data[%p]", channel, GST_OBJECT_NAME(data_channel), user_data); + LOG_INFO("channel[%p, %p, %s] user_data[%p]", channel, data_channel, GST_OBJECT_NAME(data_channel), user_data); 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); @@ -182,7 +182,7 @@ int _create_data_channel(webrtc_s *webrtc, const char *label, bundle *options, w _channel->channel = data_channel; - LOG_INFO("channel[%p, label:%s] is created", _channel, label); + LOG_INFO("channel[%p, %p, label:%s] is created", _channel, data_channel, label); _connect_and_append_signal(&_channel->signals, data_channel, "on-open", G_CALLBACK(__data_channel_on_open_cb), _channel); _connect_and_append_signal(&_channel->signals, data_channel, "on-message-string", G_CALLBACK(__data_channel_on_message_string_cb), _channel); @@ -199,19 +199,22 @@ int _create_data_channel(webrtc_s *webrtc, const char *label, bundle *options, w int _destroy_data_channel(webrtc_data_channel_s *channel) { + GstWebRTCDataChannelState state; + RET_VAL_IF(channel == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "channel is NULL"); g_mutex_lock(&channel->mutex); - channel->open_cb.callback = NULL; - channel->message_cb.callback = NULL; - channel->error_cb.callback = NULL; - channel->close_cb.callback = NULL; + g_object_get(channel->channel, "ready-state", &state, NULL); + if (state == GST_WEBRTC_DATA_CHANNEL_STATE_OPEN) { + LOG_DEBUG("request to close channel[%p, %p]", channel, channel->channel); + g_signal_emit_by_name(channel->channel, "close"); + } g_list_free_full(channel->signals, _disconnect_signal); channel->signals = NULL; - LOG_INFO("channel[%p] is destroyed", channel); + LOG_INFO("channel[%p, %p] is destroyed", channel, channel->channel); g_mutex_unlock(&channel->mutex); g_mutex_clear(&channel->mutex); diff --git a/test/webrtc_test.c b/test/webrtc_test.c index fc245c79..f406582c 100644 --- a/test/webrtc_test.c +++ b/test/webrtc_test.c @@ -2185,11 +2185,23 @@ static void _webrtc_destroy_data_channel(int index) if (ret != WEBRTC_ERROR_NONE) { g_print("failed to _webrtc_destroy_data_channel(), index[%d]\n", i); } else { - g_print("_webrtc_destroy_data_channel() success, index[%d]\n", i); + g_print("_webrtc_destroy_data_channel() success, send channel index[%d]\n", i); g_conns[index].channels[i] = NULL; } } g_conns[index].channel_index = 0; + + for (i = 0; i < MAX_CHANNEL_LEN; i++) { + if (g_conns[index].recv_channels[i] == NULL) + continue; + ret = webrtc_destroy_data_channel(g_conns[index].recv_channels[i]); + if (ret != WEBRTC_ERROR_NONE) { + g_print("failed to _webrtc_destroy_data_channel(), index[%d]\n", i); + } else { + g_print("_webrtc_destroy_data_channel() success, receive channel index[%d]\n", i); + g_conns[index].recv_channels[i] = NULL; + } + } } static void _webrtc_data_channel_get_label(int index)