Add API to set/get ICE transport policy 04/261204/4
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 13 Jul 2021 07:55:27 +0000 (16:55 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 16 Jul 2021 01:51:44 +0000 (10:51 +0900)
Enums are added as below.
 - WEBRTC_ICE_TRANSPORT_POLICY_ALL
 - WEBRTC_ICE_TRANSPORT_POLICY_RELAY

Functions are added as below
 - webrtc_set_ice_transport_policy()
 - webrtc_get_ice_transport_policy()

[Version] 0.2.47
[Issue Type] API

Change-Id: I4d882d48038dc77fb2be848ae45d228de7a907c8
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 a4ca636b4d20ec6c9018dda449a293b29a42c460..a06613e15bd65e35d41c6d409a6e035a53fd1965 100644 (file)
@@ -120,6 +120,15 @@ typedef enum {
        WEBRTC_ICE_CONNECTION_STATE_CLOSED,        /**<  Closed */
 } webrtc_ice_connection_state_e;
 
+/**
+ * @brief Enumeration for WebRTC ICE transport policy.
+ * @since_tizen 6.5
+ */
+typedef enum {
+       WEBRTC_ICE_TRANSPORT_POLICY_ALL,           /**<  All */
+       WEBRTC_ICE_TRANSPORT_POLICY_RELAY,         /**<  Relay */
+} webrtc_ice_transport_policy_e;
+
 /**
  * @brief Enumeration for WebRTC media type.
  * @since_tizen 6.5
@@ -1108,7 +1117,7 @@ int webrtc_unset_encoded_video_frame_cb(webrtc_h webrtc);
  *          #WEBRTC_MEDIA_SOURCE_TYPE_MIC\n
  *          #WEBRTC_MEDIA_SOURCE_TYPE_FILE
  * @since_tizen 6.5
- * @remarks The following sound stream types can be used for the @a stream_info:\n
+ * @remarks The following sound stream types can be used for the @a stream_info :\n
  *          #SOUND_STREAM_TYPE_MEDIA\n
  *          #SOUND_STREAM_TYPE_VOIP\n
  *          #SOUND_STREAM_TYPE_MEDIA_EXTERNAL_ONLY
@@ -1213,6 +1222,37 @@ int webrtc_add_turn_server(webrtc_h webrtc, const char *turn_server);
  */
 int webrtc_foreach_turn_server(webrtc_h webrtc, webrtc_turn_server_cb callback, void *user_data);
 
+/**
+ * @brief Sets a ICE transport policy that represents which candidates the ICE Agent is allowed to use.
+ * @since_tizen 6.5
+ * @remarks The @a policy enum corresponds with the RTCIceTransportPolicy enum described in https://www.w3.org/TR/webrtc/#rtcicetransportpolicy-enum.\n
+ * @param[in] webrtc       WebRTC handle
+ * @param[in] policy       The ICE transport policy
+ * @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_get_ice_transport_policy()
+ */
+int webrtc_set_ice_transport_policy(webrtc_h webrtc, webrtc_ice_transport_policy_e policy);
+
+/**
+ * @brief Gets the ICE transport policy.
+ * @since_tizen 6.5
+ * @remarks The @a policy enum corresponds with the RTCIceTransportPolicy enum described in https://www.w3.org/TR/webrtc/#rtcicetransportpolicy-enum.\n
+ *          The default value is #WEBRTC_ICE_TRANSPORT_POLICY_ALL.
+ * @param[in] webrtc       WebRTC handle
+ * @param[out] policy      The ICE transport policy
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #WEBRTC_ERROR_NONE    Successful
+ * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see webrtc_set_ice_transport_policy()
+ */
+int webrtc_get_ice_transport_policy(webrtc_h webrtc, webrtc_ice_transport_policy_e *policy);
+
 /**
  * @brief Sets a callback function to be invoked when the WebRTC peer connection state is changed.
  * @since_tizen 6.5
index b6a1fd06fdcdfd4057c89c13a2fbd3762b2d89d5..3366c80ff407155d9fb625b2b8debc977dd7f234 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.2.46
+Version:    0.2.47
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 672b486a23ce3cb2ca58ff0be153f3e612cb6827..c85aaf2e99b0d4dee18b3f2f6165a08ae321ac5e 100644 (file)
@@ -866,6 +866,47 @@ int webrtc_foreach_turn_server(webrtc_h webrtc, webrtc_turn_server_cb callback,
        return WEBRTC_ERROR_NONE;
 }
 
+int webrtc_set_ice_transport_policy(webrtc_h webrtc, webrtc_ice_transport_policy_e policy)
+{
+       webrtc_s *_webrtc = (webrtc_s*)webrtc;
+
+       RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+       RET_VAL_IF(policy > WEBRTC_ICE_TRANSPORT_POLICY_RELAY, WEBRTC_ERROR_INVALID_PARAMETER, "invalid policy(%d)", policy);
+
+       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_object_set(G_OBJECT(_webrtc->gst.webrtcbin), "ice-transport-policy", (GstWebRTCICETransportPolicy)policy, NULL);
+
+       LOG_INFO("policy[%s]", (policy == WEBRTC_ICE_TRANSPORT_POLICY_ALL) ? "all" : "relay");
+
+       g_mutex_unlock(&_webrtc->mutex);
+
+       return WEBRTC_ERROR_NONE;
+}
+
+int webrtc_get_ice_transport_policy(webrtc_h webrtc, webrtc_ice_transport_policy_e *policy)
+{
+       webrtc_s *_webrtc = (webrtc_s*)webrtc;
+       GstWebRTCICETransportPolicy _policy;
+
+       RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+       RET_VAL_IF(policy == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "policy is NULL");
+
+       g_mutex_lock(&_webrtc->mutex);
+
+       g_object_get(G_OBJECT(_webrtc->gst.webrtcbin), "ice-transport-policy", &_policy, NULL);
+
+       *policy = (webrtc_ice_transport_policy_e)_policy;
+
+       LOG_INFO("policy[%s]", (*policy == WEBRTC_ICE_TRANSPORT_POLICY_ALL) ? "all" : "relay");
+
+       g_mutex_unlock(&_webrtc->mutex);
+
+       return WEBRTC_ERROR_NONE;
+}
+
 int webrtc_set_peer_connection_state_change_cb(webrtc_h webrtc, webrtc_peer_connection_state_change_cb callback, void *user_data)
 {
        webrtc_s *_webrtc = (webrtc_s*)webrtc;
index 36e7f02116ae720b876951ec49062cb6a5691be6..c8e3b78c9614af2445820f82e4eeb640d621dac2 100644 (file)
@@ -79,6 +79,7 @@ enum {
        CURRENT_STATUS_DATA_CHANNEL_SEND_FILE,
        CURRENT_STATUS_SET_STUN_SERVER,
        CURRENT_STATUS_ADD_TURN_SERVER,
+       CURRENT_STATUS_SET_ICE_TRANSPORT_POLICY,
        CURRENT_STATUS_SET_LOCAL_DESCRIPTION,
        CURRENT_STATUS_SET_REMOTE_DESCRIPTION,
        CURRENT_STATUS_SETTING_SIGNALING_SERVER,
@@ -1044,6 +1045,27 @@ static void _webrtc_get_turn_servers(int index)
        g_print("webrtc_foreach_turn_server() success\n");
 }
 
+static void _webrtc_set_ice_transport_policy(int index, int policy)
+{
+       int ret = 0;
+
+       ret = webrtc_set_ice_transport_policy(g_conns[index].webrtc, policy);
+       RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret);
+
+       g_print("webrtc_set_ice_transport_policy() success\n");
+}
+
+static void _webrtc_get_ice_transport_policy(int index)
+{
+       int ret = 0;
+       webrtc_ice_transport_policy_e policy;
+
+       ret = webrtc_get_ice_transport_policy(g_conns[index].webrtc, &policy);
+       RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret);
+
+       g_print("webrtc_get_ice_transport_policy() success, policy[%d]\n", policy);
+}
+
 static char * __get_channel_label(webrtc_data_channel_h channel)
 {
        int ret = WEBRTC_ERROR_NONE;
@@ -3266,6 +3288,12 @@ void _interpret_main_menu(char *cmd)
                } else if (strncmp(cmd, "gan", 3) == 0) {
                        _webrtc_get_all_negotiation_states(g_conn_index);
 
+               } else if (strncmp(cmd, "stp", 3) == 0) {
+                       g_conns[g_conn_index].menu_state = CURRENT_STATUS_SET_ICE_TRANSPORT_POLICY;
+
+               } else if (strncmp(cmd, "gtp", 3) == 0) {
+                       _webrtc_get_ice_transport_policy(g_conn_index);
+
                } else if (strncmp(cmd, "ssc", 3) == 0) {
                        g_conns[g_conn_index].menu_state = CURRENT_STATUS_CREATE_PRIVATE_SIGNALING_SERVER;
 
@@ -3403,6 +3431,8 @@ void display_sub_basic()
        g_print("gt. Get STUN server\n");
        g_print("su. Add TURN server\t");
        g_print("gu. Get TURN servers\n");
+       g_print("stp. Set ICE transport policy\t");
+       g_print("gtp. Get ICE transport policy\n");
        g_print("co. Create offer\t");
        g_print("ca. Create answer\n");
        g_print("sl. Set local description\t");
@@ -3523,6 +3553,9 @@ static void displaymenu()
        } 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_ICE_TRANSPORT_POLICY) {
+               g_print("*** input ICE transport policy.(0:all, 1:relay)\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");
 
@@ -3793,6 +3826,12 @@ static void interpret(char *cmd)
                reset_menu_state();
                break;
        }
+       case CURRENT_STATUS_SET_ICE_TRANSPORT_POLICY: {
+               value = atoi(cmd);
+               _webrtc_set_ice_transport_policy(g_conn_index, value);
+               reset_menu_state();
+               break;
+       }
        case CURRENT_STATUS_SET_LOCAL_DESCRIPTION: {
                value = atoi(cmd);
                if (value == 1)