webrtc_internal: Add APIs to set/get RTP packet drop probability 90/265890/7
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 1 Nov 2021 09:43:00 +0000 (18:43 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 8 Nov 2021 06:39:22 +0000 (15:39 +0900)
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 <sc11.lee@samsung.com>
include/webrtc_internal.h
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc_internal.c
src/webrtc_source.c

index 860988776a927c0e0ec1c918ec2b63eb33b72a25..7fbdc98bdaec144ae68e6d8849d53a6b235644e1 100644 (file)
@@ -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.
index 6d816374c3c34b320fb53462da02ccefbae4686e..3a4343b7bbf4c83b22a9f1f36489dafac8fc26a8 100644 (file)
@@ -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);
index 70c7168546f29d05e5e951783f2c9a6d7e4d1583..876bc2e3eb516a4c137b6c952b00613874e0d824 100644 (file)
@@ -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
index 69424587b76d7defc4a1e5dd8921f433527f7878..c4625688fc1f7ff86dbeaa96ed3d9417d7aa8ae9 100644 (file)
@@ -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
index 32f4acfd1569043d30b31739ec264e13312fff44..f95863697e4da1824cb967b7176b562ac153e8a8 100644 (file)
@@ -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