From: Sangchul Lee Date: Mon, 1 Nov 2021 09:43:00 +0000 (+0900) Subject: webrtc_internal: Add APIs to set/get RTP packet drop probability X-Git-Tag: submit/tizen/20211109.062149~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F90%2F265890%2F7;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_internal: Add APIs to set/get RTP packet drop probability Functions below are added. - webrtc_media_source_set_rtp_packet_drop_probability() - webrtc_media_source_get_rtp_packet_drop_probability() [Version] 0.3.2 [Issue Type] API Change-Id: I0dfbc2e39705c2d47485807bc0cc1c8ba1850d58 Signed-off-by: Sangchul Lee --- diff --git a/include/webrtc_internal.h b/include/webrtc_internal.h index 86098877..7fbdc98b 100644 --- a/include/webrtc_internal.h +++ b/include/webrtc_internal.h @@ -253,6 +253,41 @@ int webrtc_screen_source_set_crop(webrtc_h webrtc, unsigned int source_id, int x */ int webrtc_screen_source_unset_crop(webrtc_h webrtc, unsigned int source_id); +/** + * @internal + * @brief Sets the probability of RTP packet dropping. + * @since_tizen 7.0 + * @param[in] webrtc WebRTC handle + * @param[in] source_id The file source id + * @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 + * @pre Add screen source to @a webrtc to get @a source_id by calling webrtc_add_media_source(). + * @see webrtc_media_source_get_rtp_packet_drop_probability() + */ +int webrtc_media_source_set_rtp_packet_drop_probability(webrtc_h webrtc, unsigned int source_id, 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] source_id The file source id + * @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 + * @pre Add screen source to @a webrtc to get @a source_id by calling webrtc_add_media_source(). + * @see webrtc_media_source_set_rtp_packet_drop_probability() + */ +int webrtc_media_source_get_rtp_packet_drop_probability(webrtc_h webrtc, unsigned int source_id, float *probability); + /** * @internal * @brief Creates a signaling server for private network. diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 6d816374..3a4343b7 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -586,6 +586,8 @@ int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int int _unset_screen_source_crop(webrtc_s *webrtc, unsigned int source_id); bool _check_if_path_is_set_to_file_sources(webrtc_s *webrtc); int _push_media_packet(webrtc_s *webrtc, unsigned int source_id, media_packet_h packet); +int _set_rtp_packet_drop_probability(webrtc_s *webrtc, unsigned int source_id, float probability); +int _get_rtp_packet_drop_probability(webrtc_s *webrtc, unsigned int source_id, float *probability); void _invoke_state_changed_cb(webrtc_s *webrtc, webrtc_state_e old, webrtc_state_e new); void _post_state_cb_in_idle(webrtc_s *webrtc, webrtc_state_e new_state); void _post_error_cb_in_idle(webrtc_s *webrtc, webrtc_error_e error); diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 70c71685..876bc2e3 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.1 +Version: 0.3.2 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_internal.c b/src/webrtc_internal.c index 69424587..c4625688 100644 --- a/src/webrtc_internal.c +++ b/src/webrtc_internal.c @@ -154,4 +154,33 @@ int webrtc_screen_source_unset_crop(webrtc_h webrtc, unsigned int source_id) return _unset_screen_source_crop(_webrtc, source_id); } + +int webrtc_media_source_set_rtp_packet_drop_probability(webrtc_h webrtc, unsigned int source_id, 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(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0"); + 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_rtp_packet_drop_probability(webrtc, source_id, probability); +} + +int webrtc_media_source_get_rtp_packet_drop_probability(webrtc_h webrtc, unsigned int source_id, 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(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0"); + RET_VAL_IF(probability == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "probability is NULL"); + + locker = g_mutex_locker_new(&_webrtc->mutex); + + return _get_rtp_packet_drop_probability(webrtc, source_id, probability); +} //LCOV_EXCL_STOP \ No newline at end of file diff --git a/src/webrtc_source.c b/src/webrtc_source.c index 32f4acfd..f9586369 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -4261,7 +4261,7 @@ int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0"); - RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "could not find source"); + RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_SCREEN, WEBRTC_ERROR_INVALID_PARAMETER, "source type is not screen"); RET_VAL_IF(w == 0, WEBRTC_ERROR_INVALID_PARAMETER, "w is 0"); RET_VAL_IF(h == 0, WEBRTC_ERROR_INVALID_PARAMETER, "h is 0"); @@ -4320,7 +4320,7 @@ int _unset_screen_source_crop(webrtc_s *webrtc, unsigned int source_id) RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0"); - RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "could not find source"); + RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_SCREEN, WEBRTC_ERROR_INVALID_PARAMETER, "source type is not screen"); screen_source = gst_bin_get_by_name(source->bin, DEFAULT_NAME_SCREENSRC); @@ -4368,12 +4368,11 @@ int _gst_filesrc_pipeline_set_state(webrtc_s *webrtc, GstState state) int _set_filesrc_looping(webrtc_s *webrtc, unsigned int source_id, bool looping) { - webrtc_gst_slot_s *source = NULL; + webrtc_gst_slot_s *source; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0"); - - RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "could not find source"); + RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_FILE, WEBRTC_ERROR_INVALID_PARAMETER, "invalid source type [%d]", source->type); source->filesrc_loop = looping; @@ -4385,13 +4384,12 @@ int _set_filesrc_looping(webrtc_s *webrtc, unsigned int source_id, bool looping) int _get_filesrc_looping(webrtc_s * webrtc, unsigned int source_id, bool *looping) { - webrtc_gst_slot_s *source = NULL; + webrtc_gst_slot_s *source; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0"); RET_VAL_IF(looping == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "looping is NULL"); - - RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "could not find source"); + RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_FILE, WEBRTC_ERROR_INVALID_PARAMETER, "invalid source type [%d]", source->type); *looping = source->filesrc_loop; @@ -4400,4 +4398,79 @@ int _get_filesrc_looping(webrtc_s * webrtc, unsigned int source_id, bool *loopin return WEBRTC_ERROR_NONE; } + +int _set_rtp_packet_drop_probability(webrtc_s *webrtc, unsigned int source_id, float probability) +{ + webrtc_gst_slot_s *source; + GstElement *netsim; + GstBin *bin; + + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0"); + 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((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); + RET_VAL_IF(webrtc->ini.general.network_simulator == false, WEBRTC_ERROR_INVALID_OPERATION, "network simulator is disabled, please check the ini"); + bin = (source->type == WEBRTC_MEDIA_SOURCE_TYPE_FILE) ? GST_BIN(source->filesrc_pipeline) : GST_BIN(source->bin); + RET_VAL_IF(bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); + + if (source->type == WEBRTC_MEDIA_SOURCE_TYPE_FILE) { + int count = 0; + if ((netsim = gst_bin_get_by_name(bin, DEFAULT_NAME_AUDIO_NETWORK_SIMULATOR))) { + g_object_set(G_OBJECT(netsim), "drop-probability", probability, NULL); + LOG_INFO("webrtc[%p] source_id[%u] probability[%f] applies to [%s]", webrtc, source_id, probability, GST_ELEMENT_NAME(netsim)); + count++; + } + if ((netsim = gst_bin_get_by_name(bin, DEFAULT_NAME_VIDEO_NETWORK_SIMULATOR))) { + g_object_set(G_OBJECT(netsim), "drop-probability", probability, NULL); + LOG_INFO("webrtc[%p] source_id[%u] probability[%f] applies to [%s]", webrtc, source_id, probability, GST_ELEMENT_NAME(netsim)); + count++; + } + RET_VAL_IF(count == 0, WEBRTC_ERROR_INVALID_OPERATION, "could not find any element for network simulator"); + return WEBRTC_ERROR_NONE; + } + + if (!(netsim = __find_element_in_bin(bin, DEFAULT_ELEMENT_NETWORK_SIMULATOR))) { + LOG_ERROR("could not find any element for network simulator"); + return WEBRTC_ERROR_INVALID_OPERATION; + } + g_object_set(G_OBJECT(netsim), "drop-probability", probability, NULL); + + LOG_INFO("webrtc[%p] source_id[%u] probability[%f] applies to [%s]", webrtc, source_id, probability, GST_ELEMENT_NAME(netsim)); + + return WEBRTC_ERROR_NONE; +} + +int _get_rtp_packet_drop_probability(webrtc_s *webrtc, unsigned int source_id, float *probability) +{ + webrtc_gst_slot_s *source; + GstElement *netsim; + GstBin *bin; + + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0"); + RET_VAL_IF(probability == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "probability is NULL"); + RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); + RET_VAL_IF(webrtc->ini.general.network_simulator == false, WEBRTC_ERROR_INVALID_OPERATION, "network simulator is disabled, please check the ini"); + bin = (source->type == WEBRTC_MEDIA_SOURCE_TYPE_FILE) ? GST_BIN(source->filesrc_pipeline) : GST_BIN(source->bin); + RET_VAL_IF(bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); + + if (source->type == WEBRTC_MEDIA_SOURCE_TYPE_FILE) { + if (!(netsim = gst_bin_get_by_name(bin, DEFAULT_NAME_AUDIO_NETWORK_SIMULATOR)) && + !(netsim = gst_bin_get_by_name(bin, DEFAULT_NAME_VIDEO_NETWORK_SIMULATOR))) { + LOG_ERROR("could not find any element for network simulator"); + return WEBRTC_ERROR_INVALID_OPERATION; + } + } else { + if (!(netsim = __find_element_in_bin(bin, DEFAULT_ELEMENT_NETWORK_SIMULATOR))) { + LOG_ERROR("could not find any element for network simulator"); + return WEBRTC_ERROR_INVALID_OPERATION; + } + } + + g_object_get(G_OBJECT(netsim), "drop-probability", (gfloat *)probability, NULL); + LOG_INFO("webrtc[%p] source_id[%u] probability[%f]", webrtc, source_id, *probability); + + return WEBRTC_ERROR_NONE; +} //LCOV_EXCL_STOP