From: hj kim Date: Thu, 1 Apr 2021 07:59:27 +0000 (+0900) Subject: webrtc: Add new API webrtc_data_channel_get_label() X-Git-Tag: submit/tizen/20210729.023123~102 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=981b61b44987110d46f1cdff1e12afbbda12061e;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc: Add new API webrtc_data_channel_get_label() [Version] 0.1.139 [Issue Type] API Change-Id: I02e845b4a53ba1e6c1c5c789eb368966a545037a --- diff --git a/include/webrtc.h b/include/webrtc.h index b2a9837b..91598205 100644 --- a/include/webrtc.h +++ b/include/webrtc.h @@ -1150,6 +1150,21 @@ int webrtc_data_channel_send_string(webrtc_data_channel_h channel, const char *s */ int webrtc_data_channel_send_bytes(webrtc_data_channel_h channel, const char *data, unsigned int size); +/** + * @brief Gets the channel label. + * @since_tizen 6.5 + * @remarks The @a label should be released using free(). + * @param[in] channel Data channel handle + * @param[out] label The channel label + * @return @c 0 on success, + * otherwise a negative error value + * @retval #WEBRTC_ERROR_NONE Successful + * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WEBRTC_ERROR_INVALID_OPERATION Invalid operation + * @see webrtc_create_data_channel() + */ +int webrtc_data_channel_get_label(webrtc_data_channel_h channel, char **label); + /** * @brief Gets data pointer and its size. * @since_tizen 6.5 diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 8a923f2a..c3614d6d 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.1.138 +Version: 0.1.139 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc.c b/src/webrtc.c index f2f6d9f1..bf5c0c69 100644 --- a/src/webrtc.c +++ b/src/webrtc.c @@ -1114,6 +1114,27 @@ int webrtc_data_channel_send_bytes(webrtc_data_channel_h channel, const char *da return ret; } +int webrtc_data_channel_get_label(webrtc_data_channel_h channel, char **label) +{ + webrtc_data_channel_s *_channel = (webrtc_data_channel_s*)channel; + gchar *_label; + + RET_VAL_IF(_channel == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "channel is NULL"); + RET_VAL_IF(label == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "label is NULL"); + RET_VAL_IF(_channel->channel == NULL, WEBRTC_ERROR_INVALID_OPERATION, "data_channel is NULL"); + + g_object_get(_channel->channel, "label", &_label, NULL); + RET_VAL_IF(_label == NULL, WEBRTC_ERROR_INVALID_OPERATION, "label is NULL"); + + *label = strdup(_label); + + LOG_INFO("label[%s]", *label); + + g_free(_label); + + return WEBRTC_ERROR_NONE; +} + int webrtc_get_data(webrtc_bytes_data_h bytes, const char **data, unsigned int *size) { webrtc_bytes_data_s *_bytes = (webrtc_bytes_data_s*)bytes; diff --git a/src/webrtc_data_channel.c b/src/webrtc_data_channel.c index 0abfaafa..708545dc 100644 --- a/src/webrtc_data_channel.c +++ b/src/webrtc_data_channel.c @@ -172,7 +172,7 @@ int _create_data_channel(webrtc_s *webrtc, const char *label, bundle *options, w return WEBRTC_ERROR_INVALID_OPERATION; } - LOG_INFO("data channel[%s] is created", GST_OBJECT_NAME(data_channel)); + LOG_INFO("data channel[%s] label[%s] is created", GST_OBJECT_NAME(data_channel), label); _channel = g_new0(webrtc_data_channel_s, 1); g_mutex_init(&_channel->mutex); diff --git a/test/webrtc_test.c b/test/webrtc_test.c index 8f3623ea..9d01bc73 100644 --- a/test/webrtc_test.c +++ b/test/webrtc_test.c @@ -817,11 +817,29 @@ static void _webrtc_get_stun_server(int index) } } +static char * __get_channel_label(webrtc_data_channel_h channel) +{ + int ret = WEBRTC_ERROR_NONE; + char *label = NULL; + + if (!channel) + return NULL; + + ret = webrtc_data_channel_get_label(channel, &label); + if (ret != WEBRTC_ERROR_NONE) + g_print("failed to webrtc_data_channel_get_label(), ret[0x%x]\n", ret); + + return label; +} static void __data_channel_open_cb(webrtc_data_channel_h channel, void *user_data) { connection_s *conn = (connection_s*)user_data; + char *label = __get_channel_label(channel); + + g_print("__data_channel_open_cb() is called, channel[%p], conn[%p] label[%s]\n", channel, conn, label); - g_print("__data_channel_open_cb() is called, channel[%p], conn[%p]\n", channel, conn); + if (label) + free(label); } static void __file_dump(const gchar *file_name, void *src_buffer, int size) @@ -860,8 +878,12 @@ end: static void __data_channel_message_cb(webrtc_data_channel_h channel, webrtc_data_channel_type_e type, void *message, void *user_data) { connection_s *conn = (connection_s*)user_data; + char *label = __get_channel_label(channel); - g_print("__data_channel_message_cb() is called, channel[%p], type[%d], conn[%p]", channel, type, conn); + g_print("__data_channel_message_cb() is called, channel[%p], type[%d], conn[%p], label[%s] ", channel, type, conn, label); + + if (label) + free(label); if (conn == NULL) { g_printerr("conn is NULL\n"); @@ -929,21 +951,30 @@ static void __data_channel_message_cb(webrtc_data_channel_h channel, webrtc_data static void __data_channel_error_cb(webrtc_data_channel_h channel, webrtc_error_e error, void *user_data) { connection_s *conn = (connection_s*)user_data; + char *label = __get_channel_label(channel); + + g_print("__data_channel_error_cb() is called, channel[%p], conn[%p] label[%s]\n", channel, conn, label); - g_print("__data_channel_error_cb() is called, channel[%p], conn[%p]\n", channel, conn); + if (label) + free(label); } static void __data_channel_close_cb(webrtc_data_channel_h channel, void *user_data) { connection_s *conn = (connection_s*)user_data; + char *label = __get_channel_label(channel); - g_print("__data_channel_close_cb() is called, channel[%p], conn[%p]\n", channel, conn); + g_print("__data_channel_close_cb() is called, channel[%p], conn[%p] label[%s]\n", channel, conn, label); + + if (label) + free(label); } static void __data_channel_cb(webrtc_h webrtc, webrtc_data_channel_h channel, void *user_data) { int i; connection_s *conn = (connection_s*)user_data; + char *label = NULL; if (conn == NULL) { g_printerr("conn is NULL\n"); @@ -952,13 +983,18 @@ static void __data_channel_cb(webrtc_h webrtc, webrtc_data_channel_h channel, vo for (i = 0; i < MAX_CHANNEL_LEN; i++) { if (conn->recv_channels[i] == NULL) { - g_print("__data_channel_cb() is called for conn[%p], append all the callbacks.\n", conn); + label = __get_channel_label(channel); + g_print("__data_channel_cb() is called for conn[%p], label[%s] append all the callbacks.\n", conn, label); conn->recv_channels[i] = channel; webrtc_data_channel_set_open_cb(channel, __data_channel_open_cb, (void *)conn); webrtc_data_channel_set_message_cb(channel, __data_channel_message_cb, (void *)conn); webrtc_data_channel_set_error_cb(channel, __data_channel_error_cb, (void *)conn); webrtc_data_channel_set_close_cb(channel, __data_channel_close_cb, (void *)conn); + + if (label) + free(label); + return; } } @@ -1471,6 +1507,7 @@ static void _webrtc_create_data_channel(int index) g_print("webrtc_create_data_channel() success, channel[%p], index[%d]\n", g_conns[index].channels[g_conns[index].channel_index], g_conns[index].channel_index); webrtc_data_channel_set_open_cb(g_conns[index].channels[g_conns[index].channel_index], __data_channel_open_cb, &g_conns[index]); + webrtc_data_channel_set_message_cb(g_conns[index].channels[g_conns[index].channel_index], __data_channel_message_cb, &g_conns[index]); webrtc_data_channel_set_error_cb(g_conns[index].channels[g_conns[index].channel_index], __data_channel_error_cb, &g_conns[index]); webrtc_data_channel_set_close_cb(g_conns[index].channels[g_conns[index].channel_index], __data_channel_close_cb, &g_conns[index]); g_conns[index].channel_index++;