From: Sangchul Lee Date: Fri, 17 Dec 2021 02:43:11 +0000 (+0900) Subject: webrtc_internal: Add APIs to set/get RTP packet drop probability X-Git-Tag: submit/tizen/20211229.072812~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a588dd08588e22f383509a23fbe5919b5b8b52e3;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_internal: Add APIs to set/get RTP packet drop probability Functions below are added. - webrtc_set_rtp_packet_drop_probability() - webrtc_get_rtp_packet_drop_probability() RTP packets can be dropped before sending or after being received with this new function. [Version] 0.3.27 [Issue Type] New feature Change-Id: I8d2ca412bb272d750e40d39332d999e3b0cc0085 Signed-off-by: Sangchul Lee --- diff --git a/include/webrtc_internal.h b/include/webrtc_internal.h index 2f6c153a..30f71d34 100644 --- a/include/webrtc_internal.h +++ b/include/webrtc_internal.h @@ -234,6 +234,39 @@ int webrtc_media_source_set_rtp_packet_drop_probability(webrtc_h webrtc, unsigne */ int webrtc_media_source_get_rtp_packet_drop_probability(webrtc_h webrtc, unsigned int source_id, float *probability); +/** + * @internal + * @brief Sets the probability of RTP packet dropping. + * @since_tizen 7.0 + * @param[in] webrtc WebRTC handle + * @param[in] sender Sender or receiver + * @param[in] probability The probability to be dropped (from @c 0 to @c 1.0 = 100%) + * @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_OPERATION Invalid operation + * @see webrtc_get_rtp_packet_drop_probability() + */ +int webrtc_set_rtp_packet_drop_probability(webrtc_h webrtc, bool sender, float probability); + +/** + * @internal + * @brief Gets the probability of RTP packet dropping. + * @since_tizen 7.0 + * @remarks The default value is 0. + * @param[in] webrtc WebRTC handle + * @param[in] sender Sender or receiver + * @param[out] probability The probability to be dropped (from @c 0 to @c 1.0 = 100%) + * @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_OPERATION Invalid operation + * @see webrtc_set_rtp_packet_drop_probability() + */ +int webrtc_get_rtp_packet_drop_probability(webrtc_h webrtc, bool sender, float *probability); + /** * @internal * @brief Creates a signaling server for private network. diff --git a/include/webrtc_private.h b/include/webrtc_private.h index ada0e61a..6e9a9b44 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -706,6 +706,9 @@ gchar * _get_media_type_from_pad(GstPad *pad); bool _is_supported_media_type(const char *media_type); bool _is_audio_media_type(const char *media_type); +int _set_packet_drop_probability(webrtc_s *webrtc, bool sender, float probability); +int _get_packet_drop_probability(webrtc_s *webrtc, bool sender, float *probability); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index b6dca198..9fae1d77 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.26 +Version: 0.3.27 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_internal.c b/src/webrtc_internal.c index 37ed3553..de574cdc 100644 --- a/src/webrtc_internal.c +++ b/src/webrtc_internal.c @@ -140,4 +140,31 @@ int webrtc_media_source_get_rtp_packet_drop_probability(webrtc_h webrtc, unsigne return _get_rtp_packet_drop_probability(webrtc, source_id, probability); } + +int webrtc_set_rtp_packet_drop_probability(webrtc_h webrtc, bool sender, float probability) +{ + webrtc_s *_webrtc = (webrtc_s*)webrtc; + g_autoptr(GMutexLocker) locker = NULL; + + RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(probability > 1.0, WEBRTC_ERROR_INVALID_PARAMETER, "probability > 1.0"); + RET_VAL_IF(probability < 0, WEBRTC_ERROR_INVALID_PARAMETER, "probability < 0"); + + locker = g_mutex_locker_new(&_webrtc->mutex); + + return _set_packet_drop_probability(webrtc, sender, probability); +} + +int webrtc_get_rtp_packet_drop_probability(webrtc_h webrtc, bool sender, float *probability) +{ + webrtc_s *_webrtc = (webrtc_s*)webrtc; + g_autoptr(GMutexLocker) locker = NULL; + + RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(probability == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "probability is NULL"); + + locker = g_mutex_locker_new(&_webrtc->mutex); + + return _get_packet_drop_probability(webrtc, sender, probability); +} //LCOV_EXCL_STOP \ No newline at end of file diff --git a/src/webrtc_private.c b/src/webrtc_private.c index 921f782b..8df8e295 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -1449,7 +1449,11 @@ int _gst_build_pipeline(webrtc_s *webrtc) } g_free(webrtcbin_name); - g_object_set(G_OBJECT(webrtc->gst.webrtcbin), "bundle-policy", 3, NULL); /* 3 for max-bundle */ + g_object_set(G_OBJECT(webrtc->gst.webrtcbin), + "bundle-policy", 3, /* 3 for max-bundle */ + "latency", webrtc->ini.general.jitterbuffer_latency, + "netsim", webrtc->ini.general.network_simulator, + NULL); if (webrtc->ini.general.stun_server) { webrtc->stun_server_url = g_strdup(webrtc->ini.general.stun_server); @@ -1457,8 +1461,6 @@ int _gst_build_pipeline(webrtc_s *webrtc) LOG_INFO("stun_server[%s]", webrtc->stun_server_url); } - g_object_set(G_OBJECT(webrtc->gst.webrtcbin), "latency", webrtc->ini.general.jitterbuffer_latency, NULL); - _connect_and_append_signal(&webrtc->signals, (GObject *)webrtc->gst.webrtcbin, "on-negotiation-needed", G_CALLBACK(__webrtcbin_on_negotiation_needed_cb), webrtc); _connect_and_append_signal(&webrtc->signals, (GObject *)webrtc->gst.webrtcbin, "on-ice-candidate", G_CALLBACK(__webrtcbin_on_ice_candidate_cb), webrtc); _connect_and_append_signal(&webrtc->signals, (GObject *)webrtc->gst.webrtcbin, "notify::connection-state", G_CALLBACK(__webrtcbin_peer_connection_state_cb), webrtc); @@ -2081,3 +2083,34 @@ int _apply_stream_info(GstElement *element, const char *stream_type, int stream_ return WEBRTC_ERROR_NONE; } + +int _set_packet_drop_probability(webrtc_s *webrtc, bool sender, float probability) +{ + const char *prop_name = sender ? "drop-probability-sender" : "drop-probability-receiver"; + + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(probability > 1.0, WEBRTC_ERROR_INVALID_PARAMETER, "probability > 1.0"); + RET_VAL_IF(probability < 0, WEBRTC_ERROR_INVALID_PARAMETER, "probability < 0"); + RET_VAL_IF(webrtc->ini.general.network_simulator == false, WEBRTC_ERROR_INVALID_OPERATION, "network simulator is disabled, please check the ini"); + + g_object_set(G_OBJECT(webrtc->gst.webrtcbin), prop_name, probability, NULL); + + LOG_INFO("webrtc[%p] set [%s] to [%f]", webrtc, prop_name, probability); + + return WEBRTC_ERROR_NONE; +} + +int _get_packet_drop_probability(webrtc_s *webrtc, bool sender, float *probability) +{ + const char *prop_name = sender ? "drop-probability-sender" : "drop-probability-receiver"; + + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(probability == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "probability is NULL"); + RET_VAL_IF(webrtc->ini.general.network_simulator == false, WEBRTC_ERROR_INVALID_OPERATION, "network simulator is disabled, please check the ini"); + + g_object_get(G_OBJECT(webrtc->gst.webrtcbin), prop_name, probability, NULL); + + LOG_INFO("webrtc[%p] [%s] is [%f]", webrtc, prop_name, *probability); + + return WEBRTC_ERROR_NONE; +} \ No newline at end of file