Add API to set/get bundle policy 09/262509/7
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 12 Aug 2021 08:37:30 +0000 (17:37 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 21 Jan 2022 02:01:11 +0000 (11:01 +0900)
Enums are added as below.
 - WEBRTC_BUNDLE_POLICY_NONE
 - WEBRTC_BUNDLE_POLICY_MAX_BUNDLE

Functions are added as below.
 - webrtc_set_bundle_policy()
 - webrtc_get_bundle_policy()

[Version] 0.3.45
[Issue Type] API

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

index 120e62c705f3131ad5bde141c7c13b434c6cbaf3..28827d40deeb14df0ebde570feb9903d55139f90 100644 (file)
@@ -125,6 +125,16 @@ typedef enum {
        WEBRTC_ICE_CONNECTION_STATE_CLOSED,        /**<  Closed */
 } webrtc_ice_connection_state_e;
 
+/**
+ * @brief Enumeration for WebRTC bundle policy.
+ * @since_tizen 7.0
+ * @remarks It corresponds with the RTCIceTransportPolicy enum described in https://www.w3.org/TR/webrtc/#rtcbundlepolicy-enum.
+ */
+typedef enum {
+       WEBRTC_BUNDLE_POLICY_NONE,                 /**<  None */
+       WEBRTC_BUNDLE_POLICY_MAX_BUNDLE,           /**<  Max-bundle */
+} webrtc_bundle_policy_e;
+
 /**
  * @brief Enumeration for WebRTC ICE transport policy.
  * @since_tizen 6.5
@@ -1503,6 +1513,35 @@ 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 bundle policy.
+ * @since_tizen 7.0
+ * @param[in] webrtc       WebRTC handle
+ * @param[in] policy       The bundle 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_bundle_policy()
+ */
+int webrtc_set_bundle_policy(webrtc_h webrtc, webrtc_bundle_policy_e policy);
+
+/**
+ * @brief Gets the bundle policy.
+ * @since_tizen 7.0
+ * @remarks The default value is #WEBRTC_BUNDLE_POLICY_MAX_BUNDLE.
+ * @param[in] webrtc       WebRTC handle
+ * @param[out] policy      The bundle 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_bundle_policy()
+ */
+int webrtc_get_bundle_policy(webrtc_h webrtc, webrtc_bundle_policy_e *policy);
+
 /**
  * @brief Sets a ICE transport policy that represents which candidates the ICE Agent is allowed to use.
  * @since_tizen 6.5
index ab8919e077997c25cd9fb66d8cecd9e4a5ce5d41..575f63ce2bcc1a95a34dfaad8181cb0dae2efe78 100644 (file)
@@ -441,6 +441,8 @@ typedef struct _webrtc_s {
        webrtc_gst_s gst;
        unsigned int payload_types;
 
+       webrtc_bundle_policy_e bundle_policy;
+
        gchar *stun_server_url;
        GList *turn_server_urls;
 
index 4040df431da4123f4089b57bafc008e44b38da71..af6b2af109724de2305e7ce5e56588a5cea649f6 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.44
+Version:    0.3.45
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 556d5b191322086c3486697d257c81f69978cfef..6984922f3a09bcc6e0e0fde91d38353dbbb37f9b 100644 (file)
 #define _WEBRTC_PRIVILEGE_CAMERA      "http://tizen.org/privilege/camera"
 #define _WEBRTC_PRIVILEGE_RECORDER    "http://tizen.org/privilege/recorder"
 
+typedef struct {
+       const char *str;
+       GstWebRTCBundlePolicy gst_policy;
+} bundle_policy_s;
+
+static bundle_policy_s __bundle_policies[] = {
+       [WEBRTC_BUNDLE_POLICY_NONE] = { "NONE", GST_WEBRTC_BUNDLE_POLICY_NONE },
+       [WEBRTC_BUNDLE_POLICY_MAX_BUNDLE] = { "MAX-BUNDLE", GST_WEBRTC_BUNDLE_POLICY_MAX_BUNDLE },
+};
+
 int webrtc_set_error_cb(webrtc_h webrtc, webrtc_error_cb callback, void *user_data)
 {
        webrtc_s *_webrtc = (webrtc_s*)webrtc;
@@ -1050,6 +1060,45 @@ int webrtc_foreach_turn_server(webrtc_h webrtc, webrtc_turn_server_cb callback,
        return WEBRTC_ERROR_NONE;
 }
 
+int webrtc_set_bundle_policy(webrtc_h webrtc, webrtc_bundle_policy_e policy)
+{
+       g_autoptr(GMutexLocker) locker = NULL;
+       webrtc_s *_webrtc = (webrtc_s*)webrtc;
+
+       RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+       RET_VAL_IF(policy > WEBRTC_BUNDLE_POLICY_MAX_BUNDLE, WEBRTC_ERROR_INVALID_PARAMETER, "invalid policy(%d)", policy);
+
+       locker = g_mutex_locker_new(&_webrtc->mutex);
+
+       RET_VAL_IF(_webrtc->state != WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should be IDLE");
+
+       g_object_set(G_OBJECT(_webrtc->gst.webrtcbin), "bundle-policy", __bundle_policies[policy].gst_policy, NULL);
+
+       _webrtc->bundle_policy = policy;
+
+       LOG_INFO("webrtc[%p] policy[%s]", webrtc, __bundle_policies[policy].str);
+
+       return WEBRTC_ERROR_NONE;
+}
+
+int webrtc_get_bundle_policy(webrtc_h webrtc, webrtc_bundle_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 == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "policy is NULL");
+
+       g_mutex_lock(&_webrtc->mutex);
+
+       *policy = _webrtc->bundle_policy;
+
+       LOG_INFO("webrtc[%p] policy[%d]", webrtc, _webrtc->bundle_policy);
+
+       g_mutex_unlock(&_webrtc->mutex);
+
+       return WEBRTC_ERROR_NONE;
+}
+
 int webrtc_set_ice_transport_policy(webrtc_h webrtc, webrtc_ice_transport_policy_e policy)
 {
        g_autoptr(GMutexLocker) locker = NULL;
index e12632c0d50976a4ca111b6b75d1486c7d0d2e04..3461f70812a0aeb95f78ce138ee464e50fa97823 100644 (file)
@@ -80,6 +80,18 @@ static ice_connection_state_info_s __ice_connection_state_info[] = {
        [GST_WEBRTC_ICE_CONNECTION_STATE_CLOSED] = { "CLOSED", WEBRTC_ICE_CONNECTION_STATE_CLOSED },
 };
 
+typedef struct {
+       const char *str;
+       int policy;
+} bundle_policy_info_s;
+
+static bundle_policy_info_s _bundle_policy_info[] = {
+       [GST_WEBRTC_BUNDLE_POLICY_NONE] = { "NONE", WEBRTC_BUNDLE_POLICY_NONE },
+       [GST_WEBRTC_BUNDLE_POLICY_BALANCED] = { "BALANCED", -1 }, /* NOT SUPPORTED */
+       [GST_WEBRTC_BUNDLE_POLICY_MAX_COMPAT] = { "MAX-COMPAT", -1 }, /* NOT SUPPORTED */
+       [GST_WEBRTC_BUNDLE_POLICY_MAX_BUNDLE] = { "MAX-BUNDLE", WEBRTC_BUNDLE_POLICY_MAX_BUNDLE },
+};
+
 //LCOV_EXCL_START
 static const char *__get_error_string(webrtc_error_e error)
 {
@@ -1499,12 +1511,19 @@ int _gst_build_pipeline(webrtc_s *webrtc)
        }
        g_free(webrtcbin_name);
 
+       if (_bundle_policy_info[webrtc->ini.general.bundle_policy].policy == -1) {
+               LOG_ERROR("bundle policy[%s] is not supported yet", _bundle_policy_info[webrtc->ini.general.bundle_policy].str);
+               goto error;
+       }
+
        g_object_set(G_OBJECT(webrtc->gst.webrtcbin),
                "bundle-policy", webrtc->ini.general.bundle_policy,
                "latency", webrtc->ini.general.jitterbuffer_latency,
                "netsim", webrtc->ini.general.network_simulator,
                NULL);
 
+       webrtc->bundle_policy = _bundle_policy_info[webrtc->ini.general.bundle_policy].policy;
+
        if (webrtc->ini.general.stun_server) {
                webrtc->stun_server_url = g_strdup(webrtc->ini.general.stun_server);
                g_object_set(G_OBJECT(webrtc->gst.webrtcbin), "stun-server", webrtc->stun_server_url, NULL);