webrtc_data_channel: Close data channel before destroying the handle 54/265254/1
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 13 Oct 2021 07:43:09 +0000 (16:43 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 13 Oct 2021 08:06:51 +0000 (17:06 +0900)
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 <sc11.lee@samsung.com>
packaging/capi-media-webrtc.spec
src/webrtc_data_channel.c
test/webrtc_test.c

index 0d139a200ff5aa32793001876fdfed013b0b2f94..168b9af9e64565e7ff436f994d0375b753c0043f 100644 (file)
@@ -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
index 13da56f67f6d6ea32c34110027e14af204ff0e14..472f809801f62513917607e6a6db71e595ee386b 100644 (file)
@@ -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);
index fc245c794e13adab1cbbcd3e02104bbb95ff2d92..f406582cbb9d656b0cf0bf2d193994945eb2e9a7 100644 (file)
@@ -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)