From: Sangchul Lee Date: Thu, 12 Aug 2021 08:37:30 +0000 (+0900) Subject: Add API to set/get bundle policy X-Git-Tag: submit/tizen/20220127.110501~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=726e334ee0c9c65a36ffbf8aa9c26e1fbb66cda9;p=platform%2Fcore%2Fapi%2Fwebrtc.git Add API to set/get bundle policy 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 --- diff --git a/include/webrtc.h b/include/webrtc.h index 120e62c7..28827d40 100644 --- a/include/webrtc.h +++ b/include/webrtc.h @@ -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 diff --git a/include/webrtc_private.h b/include/webrtc_private.h index ab8919e0..575f63ce 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -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; diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 4040df43..af6b2af1 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.3.44 +Version: 0.3.45 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc.c b/src/webrtc.c index 556d5b19..6984922f 100644 --- a/src/webrtc.c +++ b/src/webrtc.c @@ -27,6 +27,16 @@ #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; diff --git a/src/webrtc_private.c b/src/webrtc_private.c index e12632c0..3461f708 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -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);