From ab2f780fb43d6bba7f0b1cbf14b1367bcdae5d9b Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Thu, 16 Dec 2021 20:31:57 +0900 Subject: [PATCH] webrtcbin: Add netsim and drop-probability-sender properties These properties are added to simulate loss of sending RTP packets. Change-Id: Ia633a32a902d6322189d1b0c033a3a15bdbc4e9d Signed-off-by: Sangchul Lee --- ext/webrtc/gstwebrtcbin.c | 97 ++++++++++++++++++++++++++++++++++++++++++ ext/webrtc/gstwebrtcbin.h | 4 ++ packaging/gst-plugins-bad.spec | 1 + 3 files changed, 102 insertions(+) diff --git a/ext/webrtc/gstwebrtcbin.c b/ext/webrtc/gstwebrtcbin.c index b2dafec..bd1a134 100644 --- a/ext/webrtc/gstwebrtcbin.c +++ b/ext/webrtc/gstwebrtcbin.c @@ -391,7 +391,13 @@ enum PROP_BUNDLE_POLICY, PROP_ICE_TRANSPORT_POLICY, PROP_ICE_AGENT, +#ifndef TIZEN_FEATURE_IMPORT_NETSIM PROP_LATENCY +#else + PROP_LATENCY, + PROP_NETSIM, + PROP_DROP_PROBABILITY_SENDER +#endif }; static guint gst_webrtc_bin_signals[LAST_SIGNAL] = { 0 }; @@ -3831,6 +3837,24 @@ out: return ret; } +#ifdef TIZEN_FEATURE_IMPORT_NETSIM +static void +_insert_netsim_element_between (GstWebRTCBin * webrtc, GstElement * srcbin, + const gchar * srcpadname, GstElement * sinkbin, const gchar * sinkpadname) +{ + GstElement *netsim = gst_element_factory_make ("netsim", NULL); + gst_bin_add (GST_BIN (webrtc), netsim); + g_object_set (netsim, "drop-probability", webrtc->priv->drop_probability_sender, NULL); + gst_element_sync_state_with_parent (netsim); + + if (!gst_element_link_pads (srcbin, srcpadname, netsim, "sink")) + g_warn_if_reached (); + + if (!gst_element_link_pads (netsim, "src", sinkbin, sinkpadname)) + g_warn_if_reached (); +} + +#endif static GstPad * _connect_input_stream (GstWebRTCBin * webrtc, GstWebRTCBinPad * pad) { @@ -3891,9 +3915,18 @@ _connect_input_stream (GstWebRTCBin * webrtc, GstWebRTCBinPad * pad) gst_object_unref (rtp_sink); pad_name = g_strdup_printf ("send_rtp_src_%u", pad->mlineindex); +#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"); + } else { +#endif if (!gst_element_link_pads (GST_ELEMENT (webrtc->rtpbin), pad_name, GST_ELEMENT (trans->stream->send_bin), "rtp_sink")) g_warn_if_reached (); +#ifdef TIZEN_FEATURE_IMPORT_NETSIM + } +#endif g_free (pad_name); } else { gchar *pad_name = g_strdup_printf ("sink_%u", pad->mlineindex); @@ -4576,9 +4609,18 @@ _connect_rtpfunnel (GstWebRTCBin * webrtc, guint session_id) gst_object_unref (rtp_sink); pad_name = g_strdup_printf ("send_rtp_src_%d", 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"); + } else { +#endif if (!gst_element_link_pads (GST_ELEMENT (webrtc->rtpbin), pad_name, GST_ELEMENT (stream->send_bin), "rtp_sink")) g_warn_if_reached (); +#ifdef TIZEN_FEATURE_IMPORT_NETSIM + } +#endif g_free (pad_name); done: @@ -6377,6 +6419,27 @@ _update_rtpstorage_latency (GstWebRTCBin * webrtc) } } +#ifdef TIZEN_FEATURE_IMPORT_NETSIM +static void +_update_drop_probability (GstWebRTCBin * webrtc, gfloat probability) +{ + GValue value = G_VALUE_INIT; + GstElement *element; + GstIterator *bin_iterator = gst_bin_iterate_sorted (GST_BIN (webrtc)); + g_assert (bin_iterator); + + 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")) + g_object_set (element, "drop-probability", probability, NULL); + g_value_reset (&value); + } + + g_value_unset (&value); + gst_iterator_free (bin_iterator); +} + +#endif static void gst_webrtc_bin_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) @@ -6410,6 +6473,17 @@ gst_webrtc_bin_set_property (GObject * object, guint prop_id, webrtc->priv->jb_latency = g_value_get_uint (value); _update_rtpstorage_latency (webrtc); break; +#ifdef TIZEN_FEATURE_IMPORT_NETSIM + 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); + 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); + break; +#endif default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -6484,6 +6558,14 @@ gst_webrtc_bin_get_property (GObject * object, guint prop_id, case PROP_LATENCY: g_value_set_uint (value, webrtc->priv->jb_latency); break; +#ifdef TIZEN_FEATURE_IMPORT_NETSIM + case PROP_NETSIM: + g_value_set_boolean (value, webrtc->priv->netsim); + break; + case PROP_DROP_PROBABILITY_SENDER: + g_value_set_float (value, webrtc->priv->drop_probability_sender); + break; +#endif default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -6763,6 +6845,21 @@ gst_webrtc_bin_class_init (GstWebRTCBinClass * klass) "Default duration to buffer in the jitterbuffers (in ms)", 0, G_MAXUINT, 200, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); +#ifdef TIZEN_FEATURE_IMPORT_NETSIM + g_object_class_install_property (gobject_class, + PROP_NETSIM, + g_param_spec_boolean ("netsim", "Use network simulator", + "Use network simulator for packet loss", + FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (gobject_class, + PROP_DROP_PROBABILITY_SENDER, + g_param_spec_float ("drop-probability-sender", "Drop Probability for sender", + "The Probability a sending RTP buffer is dropped", + 0.0, 1.0, 0.0, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); + +#endif /** * GstWebRTCBin::create-offer: * @object: the #webrtcbin diff --git a/ext/webrtc/gstwebrtcbin.h b/ext/webrtc/gstwebrtcbin.h index 7886700..ea5ab17 100644 --- a/ext/webrtc/gstwebrtcbin.h +++ b/ext/webrtc/gstwebrtcbin.h @@ -144,6 +144,10 @@ struct _GstWebRTCBinPrivate GstWebRTCSessionDescription *last_generated_answer; gboolean tos_attached; +#ifdef TIZEN_FEATURE_IMPORT_NETSIM + gboolean netsim; + gfloat drop_probability_sender; +#endif }; typedef void (*GstWebRTCBinFunc) (GstWebRTCBin * webrtc, gpointer data); diff --git a/packaging/gst-plugins-bad.spec b/packaging/gst-plugins-bad.spec index 55187f6..32def80 100644 --- a/packaging/gst-plugins-bad.spec +++ b/packaging/gst-plugins-bad.spec @@ -97,6 +97,7 @@ export CFLAGS+=" -Wall -g -fPIC\ -DTIZEN_FEATURE_HLSDEMUX_DISCONT\ -DTIZEN_FEATURE_UPSTREAM\ -DTIZEN_FEATURE_GST_UPSTREAM_AVOID_BUILD_BREAK\ + -DTIZEN_FEATURE_IMPORT_NETSIM\ -D__TIZEN__\ -fstack-protector-strong\ -Wl,-z,relro\ -- 2.7.4