Functions are added as below.
- webrtc_add_turn_server()
- webrtc_foreach_turn_server()
Callback prototype
- typedef bool (*webrtc_turn_server_cb)(
const char *turn_server, void *user_data);
[Version] 0.1.147
[Issue Type] API
Change-Id: Iadfd91db135167556b801ef9dab3a455ca0d3e1f
*/
typedef void (*webrtc_media_packet_source_buffer_state_changed_cb)(unsigned int source_id, webrtc_media_packet_source_buffer_state_e state, void *user_data);
+/**
+ * @brief Called iteratively to inform all the TURN server URLs.
+ * @since_tizen 6.5
+ * @param[in] turn_server The TURN server URL
+ * @param[in] user_data The user data passed from the callback registration function
+ * @return @c true to continue with the next iteration of the loop,
+ * otherwise @c false to break out of the loop
+ * @see webrtc_foreach_turn_server()
+ */
+typedef bool (*webrtc_turn_server_cb)(const char *turn_server, void *user_data);
+
/**
* @brief Called when the WebRTC needs session negotiation.
* @since_tizen 6.5
*/
int webrtc_get_stun_server(webrtc_h webrtc, char **stun_server);
+/**
+ * @brief Add a TURN server URL.
+ * @since_tizen 6.5
+ * @param[in] webrtc WebRTC handle
+ * @param[in] turn_server The TURN server URL of the form turn(s)://username:password@host:port
+ * @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_STATE Invalid state
+ * @pre @a webrtc state must be set to #WEBRTC_STATE_IDLE.
+ * @see webrtc_foreach_turn_server()
+ */
+int webrtc_add_turn_server(webrtc_h webrtc, const char *turn_server);
+
+/**
+ * @brief Retrieves all the TURN server URLs.
+ * @since_tizen 6.5
+ * @param[in] webrtc WebRTC handle
+ * @param[in] callback Callback function pointer
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #WEBRTC_ERROR_NONE Successful
+ * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see webrtc_turn_servers_cb()
+ * @see webrtc_add_turn_server()
+ */
+int webrtc_foreach_turn_server(webrtc_h webrtc, webrtc_turn_server_cb callback, void *user_data);
+
/**
* @brief Sets a negotiation needed callback function to be invoked when a change has occurred which requires session negotiation.
* @since_tizen 6.5
webrtc_gst_s gst;
gchar *stun_server_url;
+ GList *turn_server_urls;
+
gchar *desc_offer;
gchar *desc_answer;
Name: capi-media-webrtc
Summary: A WebRTC library in Tizen Native API
-Version: 0.1.146
+Version: 0.1.147
Release: 0
Group: Multimedia/API
License: Apache-2.0
return WEBRTC_ERROR_NONE;
}
+int webrtc_add_turn_server(webrtc_h webrtc, const char *turn_server)
+{
+ gboolean ret = FALSE;
+ webrtc_s *_webrtc = (webrtc_s*)webrtc;
+
+ RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+ RET_VAL_IF(turn_server == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "turn_server is NULL");
+
+ g_mutex_lock(&_webrtc->mutex);
+
+ RET_VAL_WITH_UNLOCK_IF(_webrtc->state != WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, &_webrtc->mutex, "the state should be IDLE");
+
+ g_signal_emit_by_name (G_OBJECT(_webrtc->gst.webrtcbin), "add-turn-server", turn_server, &ret);
+ RET_VAL_WITH_UNLOCK_IF(!ret, WEBRTC_ERROR_INVALID_PARAMETER, &_webrtc->mutex, "invalid turn server url (%s)", turn_server);
+
+ _webrtc->turn_server_urls = g_list_append(_webrtc->turn_server_urls, g_strdup(turn_server));
+
+ LOG_INFO("turn_server[%s]", turn_server);
+
+ g_mutex_unlock(&_webrtc->mutex);
+
+ return WEBRTC_ERROR_NONE;
+}
+
+int webrtc_foreach_turn_server(webrtc_h webrtc, webrtc_turn_server_cb callback, void *user_data)
+{
+ webrtc_s *_webrtc = (webrtc_s*)webrtc;
+ int idx = 0;
+
+ RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+ RET_VAL_IF(callback == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "callback is NULL");
+
+ g_mutex_lock(&_webrtc->mutex);
+
+ for (idx = 0; idx < (int)g_list_length(_webrtc->turn_server_urls); idx++) {
+ if (!callback((const char *)g_list_nth(_webrtc->turn_server_urls, idx)->data, user_data)) {
+ LOG_INFO("stop foreach callback");
+ break;
+ }
+ }
+
+ LOG_INFO("callback[%p] user_data[%p]", callback, user_data);
+
+ 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;
g_bytes_unref(bytes);
return WEBRTC_ERROR_NONE;
-}
\ No newline at end of file
+}
g_free(webrtc->stun_server_url);
webrtc->stun_server_url = NULL;
}
+ if (webrtc->turn_server_urls) {
+ g_list_free_full(webrtc->turn_server_urls, g_free);
+ webrtc->turn_server_urls = NULL;
+ }
if (webrtc->desc_offer) {
g_free(webrtc->desc_offer);
webrtc->desc_offer = NULL;
CURRENT_STATUS_DATA_CHANNEL_SEND_STRING_AS_BYTES,
CURRENT_STATUS_DATA_CHANNEL_SEND_FILE,
CURRENT_STATUS_SET_STUN_SERVER,
+ CURRENT_STATUS_ADD_TURN_SERVER,
CURRENT_STATUS_SET_LOCAL_DESCRIPTION,
CURRENT_STATUS_SET_REMOTE_DESCRIPTION,
CURRENT_STATUS_SETTING_SIGNALING_SERVER,
}
}
+static void _webrtc_add_turn_server(int index, char *uri)
+{
+ int ret = 0;
+
+ if (!uri)
+ return;
+
+ ret = webrtc_add_turn_server(g_conns[index].webrtc, uri);
+ if (ret != WEBRTC_ERROR_NONE)
+ g_print("failed to webrtc_add_turn_server(), uri[%s], ret[0x%x]\n", uri, ret);
+ else
+ g_print("webrtc_add_turn_server() success, uri[%s]\n", uri);
+}
+
+static bool __foreach_turn_server(const char *turn_server, gpointer user_data)
+{
+ g_print("- turn server %s\n", turn_server);
+ return true;
+}
+
+static void _webrtc_get_turn_servers(int index)
+{
+ int ret = 0;
+
+ ret = webrtc_foreach_turn_server(g_conns[index].webrtc, __foreach_turn_server, NULL);
+ if (ret != WEBRTC_ERROR_NONE)
+ g_print("failed to webrtc_foreach_turn_server() ret[0x%x]\n", ret);
+ else
+ g_print("webrtc_foreach_turn_server() success\n");
+}
+
static char * __get_channel_label(webrtc_data_channel_h channel)
{
int ret = WEBRTC_ERROR_NONE;
return label;
}
+
static void __data_channel_open_cb(webrtc_data_channel_h channel, void *user_data)
{
connection_s *conn = (connection_s*)user_data;
} else if (strncmp(cmd, "gt", 2) == 0) {
_webrtc_get_stun_server(g_conn_index);
+ } else if (strncmp(cmd, "su", 2) == 0) {
+ g_conns[g_conn_index].menu_state = CURRENT_STATUS_ADD_TURN_SERVER;
+
+ } else if (strncmp(cmd, "gu", 2) == 0) {
+ _webrtc_get_turn_servers(g_conn_index);
+
} else if (strncmp(cmd, "ss", 2) == 0) {
g_conns[g_conn_index].menu_state = CURRENT_STATUS_SETTING_SIGNALING_SERVER;
if (ret != WEBRTC_ERROR_NONE)
return;
+ ret = webrtc_foreach_turn_server(g_conns[index].webrtc, __foreach_turn_server, NULL);
+ if (ret != WEBRTC_ERROR_NONE)
+ return;
+
g_print(" webrtc[%p]", g_conns[index].webrtc);
g_print(" state[%s]", g_webrtc_state_str[state]);
if (stun_server) {
g_print("------------------------------------- Negotiation ---------------------------------------\n");
g_print("st. Set STUN server\t");
g_print("gt. Get STUN server\n");
+ g_print("su. Add TURN server\t");
+ g_print("gu. Get TURN servers\n");
g_print("co. Create offer\t");
g_print("ca. Create answer\n");
g_print("sl. Set local description\t");
} else if (g_conns[g_conn_index].menu_state == CURRENT_STATUS_SET_STUN_SERVER) {
g_print("*** input STUN server address.\n");
+ } else if (g_conns[g_conn_index].menu_state == CURRENT_STATUS_ADD_TURN_SERVER) {
+ g_print("*** input TURN server address.\n");
+
} else if (g_conns[g_conn_index].menu_state == CURRENT_STATUS_SET_LOCAL_DESCRIPTION) {
g_print("*** input type of local description.(1:offer, 2:answer)\n");
reset_menu_state();
break;
}
+ case CURRENT_STATUS_ADD_TURN_SERVER: {
+ _webrtc_add_turn_server(g_conn_index, cmd);
+ reset_menu_state();
+ break;
+ }
case CURRENT_STATUS_SET_LOCAL_DESCRIPTION: {
value = atoi(cmd);
if (value == 1)