Add webrtc_get_stun_server() API 63/248163/1
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 23 Nov 2020 06:07:37 +0000 (15:07 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 23 Nov 2020 06:07:37 +0000 (15:07 +0900)
[Version] 0.1.61
[Issue Type] API

Change-Id: I57f394e91b4708b34cea637a31f6c0536efbece5
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/webrtc.h
packaging/capi-media-webrtc.spec
src/webrtc.c
test/webrtc_test.c

index a528383a5febe18aa29e5fbe53783277bff9faa8..df4ecfa2fed0044ef3b7cff0388fdfc8929997a1 100644 (file)
@@ -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
index 7c2fe7a38cb623fcad45e00a4fceae20eb099fe2..0630923fc991e769b9826437ff4f16024bf29d04 100644 (file)
@@ -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
index 668eadc07fec28ae692a8c1f0d2fa08ba44d2ae1..ad0908548eb055e95e82ae47a5f4a7e40c7e607a 100644 (file)
@@ -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;
index 01224b7fe823aeb74fb7f6cabf89ef9c3bf86e7a..bcbc28cd657f7a351f7dabfa71fd3414f98527d5 100644 (file)
@@ -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");