From: Sangchul Lee Date: Fri, 8 Apr 2022 04:18:32 +0000 (+0900) Subject: webrtc_data_channel: Add sub-function to prepare data channel X-Git-Tag: submit/tizen/20220415.001132~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c80d380731741bcb4278435f3250be2d20577109;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_data_channel: Add sub-function to prepare data channel [Version] 0.3.81 [Issue Type] Refactoring Change-Id: Idae4533ee3b790e43daaa60a26999364bdbe791f Signed-off-by: Sangchul Lee --- diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index a0c833b8..156f6ce9 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.80 +Version: 0.3.81 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_data_channel.c b/src/webrtc_data_channel.c index d0f18531..7a21a148 100644 --- a/src/webrtc_data_channel.c +++ b/src/webrtc_data_channel.c @@ -135,6 +135,30 @@ static void __data_channel_on_buffered_amount_low_cb(GObject *data_channel, gpoi } //LCOV_EXCL_STOP +static webrtc_data_channel_s *__prepare_data_channel(GObject *dc_obj) +{ + webrtc_data_channel_s *_channel; + + RET_VAL_IF(dc_obj == NULL, NULL, "dc_obj is NULL"); + + _channel = g_new0(webrtc_data_channel_s, 1); + g_mutex_init(&_channel->mutex); + g_mutex_lock(&_channel->mutex); + + _channel->channel = dc_obj; + + _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); + _connect_and_append_signal(&_channel->signals, dc_obj, "on-message-data", G_CALLBACK(__data_channel_on_message_data_cb), _channel); + _connect_and_append_signal(&_channel->signals, dc_obj, "on-error", G_CALLBACK(__data_channel_on_error_cb), _channel); + _connect_and_append_signal(&_channel->signals, dc_obj, "on-close", G_CALLBACK(__data_channel_on_close_cb), _channel); + _connect_and_append_signal(&_channel->signals, dc_obj, "on-buffered-amount-low", G_CALLBACK(__data_channel_on_buffered_amount_low_cb), _channel); + + g_mutex_unlock(&_channel->mutex); + + return _channel; +} + void _webrtcbin_on_data_channel_cb(GstElement *webrtcbin, GObject *data_channel, gpointer user_data) { webrtc_s *webrtc = (webrtc_s *)user_data; @@ -142,11 +166,8 @@ void _webrtcbin_on_data_channel_cb(GstElement *webrtcbin, GObject *data_channel, RET_IF(webrtc == NULL, "webrtc is NULL"); - channel = g_new0(webrtc_data_channel_s, 1); - g_mutex_init(&channel->mutex); - g_mutex_lock(&channel->mutex); - - channel->channel = gst_object_ref(data_channel); + if (!(channel = __prepare_data_channel(gst_object_ref(data_channel)))) + return; LOG_INFO("channel[%p, %p, %s] user_data[%p]", channel, data_channel, GST_OBJECT_NAME(data_channel), user_data); @@ -157,14 +178,6 @@ void _webrtcbin_on_data_channel_cb(GstElement *webrtcbin, GObject *data_channel, return; } - _connect_and_append_signal(&channel->signals, channel->channel, "on-open", G_CALLBACK(__data_channel_on_open_cb), channel); - _connect_and_append_signal(&channel->signals, channel->channel, "on-message-string", G_CALLBACK(__data_channel_on_message_string_cb), channel); - _connect_and_append_signal(&channel->signals, channel->channel, "on-message-data", G_CALLBACK(__data_channel_on_message_data_cb), channel); - _connect_and_append_signal(&channel->signals, channel->channel, "on-error", G_CALLBACK(__data_channel_on_error_cb), channel); - _connect_and_append_signal(&channel->signals, channel->channel, "on-close", G_CALLBACK(__data_channel_on_close_cb), channel); - - g_mutex_unlock(&channel->mutex); - g_mutex_lock(&webrtc->mutex); if (webrtc->state == WEBRTC_STATE_NEGOTIATING) _post_state_cb_in_idle(webrtc, WEBRTC_STATE_PLAYING); @@ -193,25 +206,13 @@ int _create_data_channel(webrtc_s *webrtc, const char *label, bundle *options, w return WEBRTC_ERROR_INVALID_OPERATION; } - _channel = g_new0(webrtc_data_channel_s, 1); - g_mutex_init(&_channel->mutex); - g_mutex_lock(&_channel->mutex); - - _channel->channel = data_channel; + if (!(_channel = __prepare_data_channel(data_channel))) + return WEBRTC_ERROR_INVALID_OPERATION; 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); - _connect_and_append_signal(&_channel->signals, data_channel, "on-message-data", G_CALLBACK(__data_channel_on_message_data_cb), _channel); - _connect_and_append_signal(&_channel->signals, data_channel, "on-error", G_CALLBACK(__data_channel_on_error_cb), _channel); - _connect_and_append_signal(&_channel->signals, data_channel, "on-close", G_CALLBACK(__data_channel_on_close_cb), _channel); - _connect_and_append_signal(&_channel->signals, data_channel, "on-buffered-amount-low", G_CALLBACK(__data_channel_on_buffered_amount_low_cb), _channel); - *channel = _channel; - g_mutex_unlock(&_channel->mutex); - return WEBRTC_ERROR_NONE; }