webrtc_internal: Add APIs to set/get RTP packet drop probability 97/268197/5
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 17 Dec 2021 02:43:11 +0000 (11:43 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 23 Dec 2021 03:25:50 +0000 (12:25 +0900)
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 <sc11.lee@samsung.com>
include/webrtc_internal.h
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc_internal.c
src/webrtc_private.c

index 2f6c153aba7b0d7c34d7bb4a60b7251d453f9c3c..30f71d347768d8815e7772842698cacba258137c 100644 (file)
@@ -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.
index ada0e61a5afa7ff90f60aeeddda010f86cf3ae74..6e9a9b4490763c3e87c391e6718755f4c7a90956 100644 (file)
@@ -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 */
index b6dca19805c479330bafd9353bd16402790a1c4f..9fae1d77d6877815b07d7cd08ee62ac3099a0041 100644 (file)
@@ -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
index 37ed3553ca46961966ea53b617115999e1625875..de574cdcda576862a10812bfc6359aec346d76a7 100644 (file)
@@ -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
index 921f782baff06ead33937955ee8fc3a32631c656..8df8e29585f200735a779599cedbb0525f7c9d31 100644 (file)
@@ -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