From: Sangchul Lee Date: Mon, 23 Nov 2020 06:07:37 +0000 (+0900) Subject: Add webrtc_get_stun_server() API X-Git-Tag: submit/tizen/20210729.023123~181 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F63%2F248163%2F1;p=platform%2Fcore%2Fapi%2Fwebrtc.git Add webrtc_get_stun_server() API [Version] 0.1.61 [Issue Type] API Change-Id: I57f394e91b4708b34cea637a31f6c0536efbece5 Signed-off-by: Sangchul Lee --- diff --git a/include/webrtc.h b/include/webrtc.h index a528383a..df4ecfa2 100644 --- a/include/webrtc.h +++ b/include/webrtc.h @@ -489,6 +489,19 @@ int webrtc_set_transceiver_direction(webrtc_h webrtc, unsigned int source_id, we */ int webrtc_set_stun_server(webrtc_h webrtc, const char *stun_server); +/** + * @brief Gets the STUN server URL. + * @since_tizen 6.5 + * @remarks The @a stun_server should be released using free(). + * @param[in] webrtc WebRTC handle + * @param[out] stun_server The STUN server URL + * @return @c 0 on success, + * otherwise a negative error value + * @retval #WEBRTC_ERROR_NONE Successful + * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter + */ +int webrtc_get_stun_server(webrtc_h webrtc, char **stun_server); + /** * @brief Sets a negotiation needed callback function to be invoked when a change has occurred which requires session negotiation. * @since_tizen 6.5 diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 7c2fe7a3..0630923f 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.60 +Version: 0.1.61 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc.c b/src/webrtc.c index 668eadc0..ad090854 100644 --- a/src/webrtc.c +++ b/src/webrtc.c @@ -330,6 +330,27 @@ int webrtc_set_stun_server(webrtc_h webrtc, const char *stun_server) return WEBRTC_ERROR_NONE; } +int webrtc_get_stun_server(webrtc_h webrtc, char **stun_server) +{ + webrtc_s *_webrtc = (webrtc_s*)webrtc; + + RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(stun_server == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "stun_server is NULL"); + + g_mutex_lock(&_webrtc->mutex); + + if (_webrtc->stun_server_url == NULL) + *stun_server = NULL; + else + *stun_server = strdup(_webrtc->stun_server_url); + + LOG_INFO("stun_server[%s]", *stun_server); + + g_mutex_unlock(&_webrtc->mutex); + + return WEBRTC_ERROR_NONE; +} + int webrtc_set_negotiation_needed_cb(webrtc_h webrtc, webrtc_negotiation_needed_cb callback, void *user_data) { webrtc_s *_webrtc = (webrtc_s*)webrtc; diff --git a/test/webrtc_test.c b/test/webrtc_test.c index 01224b7f..bcbc28cd 100644 --- a/test/webrtc_test.c +++ b/test/webrtc_test.c @@ -108,7 +108,6 @@ static GList *g_ice_candidates; static SoupWebsocketConnection *g_ws_conn; static gint32 g_local_peer_id; static gchar g_signaling_server[MAX_STRING_LEN]; -static gchar g_stun_server[MAX_STRING_LEN]; static gchar g_proxy[MAX_STRING_LEN]; static int g_server_status = SERVER_STATUS_DISCONNECTED; static int g_menu_state = CURRENT_STATUS_MAINMENU; @@ -499,15 +498,25 @@ static void _webrtc_set_stun_server(char *uri) if (!uri) return; - ret = __copy_string_arr(g_stun_server, uri); - if (ret != 0) - return; - - ret = webrtc_set_stun_server(g_webrtc, g_stun_server); + webrtc_set_stun_server(g_webrtc, uri); if (ret != WEBRTC_ERROR_NONE) - g_print("failed to webrtc_set_stun_server(), uri[%s]\n", g_stun_server); + g_print("failed to webrtc_set_stun_server(), uri[%s], ret[0x%x]\n", uri, ret); else - g_print("webrtc_set_stun_server() success, uri[%s]\n", g_stun_server); + g_print("webrtc_set_stun_server() success, uri[%s]\n", uri); +} + +static void _webrtc_get_stun_server(void) +{ + int ret = WEBRTC_ERROR_NONE; + char *stun_server; + + ret = webrtc_get_stun_server(g_webrtc, &stun_server); + if (ret != WEBRTC_ERROR_NONE) { + g_print("failed to webrtc_get_stun_server(), ret[0x%x]\n", ret); + } else { + g_print("STUN server[%s]", stun_server); + free(stun_server); + } } static void __data_channel_open_cb(webrtc_data_channel_h channel, void *user_data) @@ -1259,6 +1268,9 @@ void _interpret_main_menu(char *cmd) } else if (strncmp(cmd, "st", 2) == 0) { g_menu_state = CURRENT_STATUS_SET_STUN_SERVER; + } else if (strncmp(cmd, "gt", 2) == 0) { + _webrtc_get_stun_server(); + } else if (strncmp(cmd, "ss", 2) == 0) { g_menu_state = CURRENT_STATUS_SETTING_SIGNALING_SERVER; @@ -1290,7 +1302,7 @@ void display_handle_status() { int ret = WEBRTC_ERROR_NONE; webrtc_state_e state; - int len_stun_server = strlen(g_stun_server); + char *stun_server; if (g_webrtc == NULL) return; @@ -1299,9 +1311,15 @@ void display_handle_status() if (ret != WEBRTC_ERROR_NONE) return; + ret = webrtc_get_stun_server(g_webrtc, &stun_server); + if (ret != WEBRTC_ERROR_NONE) + return; + g_print(" state[%s]", g_webrtc_state_str[state]); - if (len_stun_server > 0) - g_print(" STUN server[%s]", g_stun_server); /* FIXME: get from API */ + if (strlen(stun_server) > 0) + g_print(" STUN server[%s]", stun_server); + + free(stun_server); g_print("\n-----------------------------------------------------------------------------------------\n"); } @@ -1358,7 +1376,8 @@ void display_sub_basic() g_print("sz. Set data channel callback\t"); g_print("uz. Unset data channel callback\n"); g_print("------------------------------------- Negotiation ---------------------------------------\n"); - g_print("st. Set STUN server\n"); + g_print("st. Set STUN server\t"); + g_print("gt. Get STUN server\n"); g_print("co. Create offer\t"); g_print("ca. Create answer\n"); g_print("sl. Set local description\t");