From 7c5705a18bc87964637cafb00906ed339d311d73 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Fri, 17 Dec 2021 15:03:57 +0900 Subject: [PATCH] webrtcbin: Add drop-probability-receiver property If netsim property is enabled, this property can be set to simulate loss of being received RTP packets. Change-Id: I4f229d41f40e649bdefffd48827f6f7172401741 Signed-off-by: Sangchul Lee --- ext/webrtc/gstwebrtcbin.c | 54 +++++++++++++++++++++++++++++++-------- ext/webrtc/gstwebrtcbin.h | 1 + 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/ext/webrtc/gstwebrtcbin.c b/ext/webrtc/gstwebrtcbin.c index bd1a134dc..10626ffb7 100644 --- a/ext/webrtc/gstwebrtcbin.c +++ b/ext/webrtc/gstwebrtcbin.c @@ -396,7 +396,8 @@ enum #else PROP_LATENCY, PROP_NETSIM, - PROP_DROP_PROBABILITY_SENDER + PROP_DROP_PROBABILITY_SENDER, + PROP_DROP_PROBABILITY_RECEIVER #endif }; @@ -3840,11 +3841,19 @@ out: #ifdef TIZEN_FEATURE_IMPORT_NETSIM static void _insert_netsim_element_between (GstWebRTCBin * webrtc, GstElement * srcbin, - const gchar * srcpadname, GstElement * sinkbin, const gchar * sinkpadname) + const gchar * srcpadname, GstElement * sinkbin, const gchar * sinkpadname, + uint32_t idx) { - GstElement *netsim = gst_element_factory_make ("netsim", NULL); + gboolean send = !g_strcmp0 (sinkpadname, "rtp_sink"); + gchar *netsim_name = g_strdup_printf ("netsim_%s_%u", + send ? "send" : "recv", idx); + GstElement *netsim = gst_element_factory_make ("netsim", netsim_name); + g_free (netsim_name); + gst_bin_add (GST_BIN (webrtc), netsim); - g_object_set (netsim, "drop-probability", webrtc->priv->drop_probability_sender, NULL); + g_object_set (netsim, "drop-probability", + send ? webrtc->priv->drop_probability_sender : + webrtc->priv->drop_probability_receiver, NULL); gst_element_sync_state_with_parent (netsim); if (!gst_element_link_pads (srcbin, srcpadname, netsim, "sink")) @@ -3918,7 +3927,7 @@ _connect_input_stream (GstWebRTCBin * webrtc, GstWebRTCBinPad * pad) #ifdef TIZEN_FEATURE_IMPORT_NETSIM if (webrtc->priv->netsim) { _insert_netsim_element_between (webrtc, GST_ELEMENT (webrtc->rtpbin), pad_name, - GST_ELEMENT (trans->stream->send_bin), "rtp_sink"); + GST_ELEMENT (trans->stream->send_bin), "rtp_sink", pad->mlineindex); } else { #endif if (!gst_element_link_pads (GST_ELEMENT (webrtc->rtpbin), pad_name, @@ -3973,9 +3982,18 @@ _connect_output_stream (GstWebRTCBin * webrtc, session_id, stream); pad_name = g_strdup_printf ("recv_rtp_sink_%u", session_id); +#ifdef TIZEN_FEATURE_IMPORT_NETSIM + if (webrtc->priv->netsim) { + _insert_netsim_element_between (webrtc, GST_ELEMENT (stream->receive_bin), + "rtp_src", GST_ELEMENT (webrtc->rtpbin), pad_name, session_id); + } else { +#endif if (!gst_element_link_pads (GST_ELEMENT (stream->receive_bin), "rtp_src", GST_ELEMENT (webrtc->rtpbin), pad_name)) g_warn_if_reached (); +#ifdef TIZEN_FEATURE_IMPORT_NETSIM + } +#endif g_free (pad_name); gst_element_sync_state_with_parent (GST_ELEMENT (stream->receive_bin)); @@ -4612,7 +4630,7 @@ _connect_rtpfunnel (GstWebRTCBin * webrtc, guint session_id) #ifdef TIZEN_FEATURE_IMPORT_NETSIM if (webrtc->priv->netsim) { _insert_netsim_element_between (webrtc, GST_ELEMENT (webrtc->rtpbin), pad_name, - GST_ELEMENT (stream->send_bin), "rtp_sink"); + GST_ELEMENT (stream->send_bin), "rtp_sink", session_id); } else { #endif if (!gst_element_link_pads (GST_ELEMENT (webrtc->rtpbin), pad_name, @@ -6421,7 +6439,7 @@ _update_rtpstorage_latency (GstWebRTCBin * webrtc) #ifdef TIZEN_FEATURE_IMPORT_NETSIM static void -_update_drop_probability (GstWebRTCBin * webrtc, gfloat probability) +_update_drop_probability (GstWebRTCBin * webrtc, gfloat probability, gboolean sender) { GValue value = G_VALUE_INIT; GstElement *element; @@ -6430,7 +6448,7 @@ _update_drop_probability (GstWebRTCBin * webrtc, gfloat probability) while (gst_iterator_next (bin_iterator, &value) == GST_ITERATOR_OK) { element = GST_ELEMENT (g_value_get_object (&value)); - if (g_strrstr (GST_ELEMENT_NAME (element), "netsim")) + if (g_strrstr (GST_ELEMENT_NAME (element), sender ? "netsim_send" : "netsim_recv")) g_object_set (element, "drop-probability", probability, NULL); g_value_reset (&value); } @@ -6477,11 +6495,17 @@ gst_webrtc_bin_set_property (GObject * object, guint prop_id, case PROP_NETSIM: webrtc->priv->netsim = g_value_get_boolean (value); _update_drop_probability (webrtc, webrtc->priv->netsim ? - webrtc->priv->drop_probability_sender : 0.0); + webrtc->priv->drop_probability_sender : 0.0, TRUE); + _update_drop_probability (webrtc, webrtc->priv->netsim ? + webrtc->priv->drop_probability_receiver : 0.0, FALSE); break; case PROP_DROP_PROBABILITY_SENDER: webrtc->priv->drop_probability_sender = g_value_get_float (value); - _update_drop_probability (webrtc, webrtc->priv->drop_probability_sender); + _update_drop_probability (webrtc, webrtc->priv->drop_probability_sender, TRUE); + break; + case PROP_DROP_PROBABILITY_RECEIVER: + webrtc->priv->drop_probability_receiver = g_value_get_float (value); + _update_drop_probability (webrtc, webrtc->priv->drop_probability_receiver, FALSE); break; #endif default: @@ -6565,6 +6589,9 @@ gst_webrtc_bin_get_property (GObject * object, guint prop_id, case PROP_DROP_PROBABILITY_SENDER: g_value_set_float (value, webrtc->priv->drop_probability_sender); break; + case PROP_DROP_PROBABILITY_RECEIVER: + g_value_set_float (value, webrtc->priv->drop_probability_receiver); + break; #endif default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -6859,6 +6886,13 @@ gst_webrtc_bin_class_init (GstWebRTCBinClass * klass) 0.0, 1.0, 0.0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (gobject_class, + PROP_DROP_PROBABILITY_RECEIVER, + g_param_spec_float ("drop-probability-receiver", "Drop Probability for receiver", + "The Probability a received RTP buffer is dropped", + 0.0, 1.0, 0.0, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); + #endif /** * GstWebRTCBin::create-offer: diff --git a/ext/webrtc/gstwebrtcbin.h b/ext/webrtc/gstwebrtcbin.h index ea5ab1782..6995000ef 100644 --- a/ext/webrtc/gstwebrtcbin.h +++ b/ext/webrtc/gstwebrtcbin.h @@ -147,6 +147,7 @@ struct _GstWebRTCBinPrivate #ifdef TIZEN_FEATURE_IMPORT_NETSIM gboolean netsim; gfloat drop_probability_sender; + gfloat drop_probability_receiver; #endif }; -- 2.34.1