From bea8229a99e60310c98ff20eb1bb3c9473382c3a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Cr=C3=AAte?= Date: Thu, 15 Oct 2020 19:36:45 -0400 Subject: [PATCH] webrtcbin: Implement getting stats for a specific pad Change-Id: I6147beab9bd62a7fe7c9cb4c76a0207476e3d77e Part-of: --- ext/webrtc/gstwebrtcbin.c | 38 +++++--------------------------------- ext/webrtc/gstwebrtcbin.h | 2 -- ext/webrtc/gstwebrtcstats.c | 15 ++++++++------- ext/webrtc/gstwebrtcstats.h | 3 ++- 4 files changed, 15 insertions(+), 43 deletions(-) diff --git a/ext/webrtc/gstwebrtcbin.c b/ext/webrtc/gstwebrtcbin.c index 08227bb..3b20e6d 100644 --- a/ext/webrtc/gstwebrtcbin.c +++ b/ext/webrtc/gstwebrtcbin.c @@ -5224,16 +5224,6 @@ _on_local_ice_candidate_cb (GstWebRTCICE * ice, guint session_id, } } -/* https://www.w3.org/TR/webrtc/#dfn-stats-selection-algorithm */ -static GstStructure * -_get_stats_from_selector (GstWebRTCBin * webrtc, gpointer selector) -{ - if (selector) - GST_FIXME_OBJECT (webrtc, "Implement stats selection"); - - return gst_structure_copy (webrtc->priv->stats); -} - struct get_stats { GstPad *pad; @@ -5254,25 +5244,11 @@ _free_get_stats (struct get_stats *stats) static void _get_stats_task (GstWebRTCBin * webrtc, struct get_stats *stats) { - GstStructure *s; - gpointer selector = NULL; - - gst_webrtc_bin_update_stats (webrtc); - - if (stats->pad) { - GstWebRTCBinPad *wpad = GST_WEBRTC_BIN_PAD (stats->pad); - - if (wpad->trans) { - if (GST_PAD_DIRECTION (wpad) == GST_PAD_SRC) { - selector = wpad->trans->receiver; - } else { - selector = wpad->trans->sender; - } - } - } - - s = _get_stats_from_selector (webrtc, selector); - gst_promise_reply (stats->promise, s); + /* Our selector is the pad, + * https://www.w3.org/TR/webrtc/#dfn-stats-selection-algorithm + */ + gst_promise_reply (stats->promise, gst_webrtc_bin_create_stats (webrtc, + stats->pad)); } static void @@ -6476,10 +6452,6 @@ gst_webrtc_bin_finalize (GObject * object) gst_webrtc_session_description_free (webrtc->priv->last_generated_offer); webrtc->priv->last_generated_offer = NULL; - if (webrtc->priv->stats) - gst_structure_free (webrtc->priv->stats); - webrtc->priv->stats = NULL; - g_mutex_clear (ICE_GET_LOCK (webrtc)); g_mutex_clear (PC_GET_LOCK (webrtc)); g_cond_clear (PC_GET_COND (webrtc)); diff --git a/ext/webrtc/gstwebrtcbin.h b/ext/webrtc/gstwebrtcbin.h index 4200b1a..f3eb9f6 100644 --- a/ext/webrtc/gstwebrtcbin.h +++ b/ext/webrtc/gstwebrtcbin.h @@ -140,8 +140,6 @@ struct _GstWebRTCBinPrivate GstWebRTCSessionDescription *last_generated_offer; GstWebRTCSessionDescription *last_generated_answer; - GstStructure *stats; - gboolean tos_attached; }; diff --git a/ext/webrtc/gstwebrtcstats.c b/ext/webrtc/gstwebrtcstats.c index 6145411..0401f70 100644 --- a/ext/webrtc/gstwebrtcstats.c +++ b/ext/webrtc/gstwebrtcstats.c @@ -768,8 +768,8 @@ out: return TRUE; } -void -gst_webrtc_bin_update_stats (GstWebRTCBin * webrtc) +GstStructure * +gst_webrtc_bin_create_stats (GstWebRTCBin * webrtc, GstPad * pad) { GstStructure *s = gst_structure_new_empty ("application/x-webrtc-stats"); double ts = monotonic_time_as_double_milliseconds (); @@ -792,12 +792,13 @@ gst_webrtc_bin_update_stats (GstWebRTCBin * webrtc) gst_structure_free (pc_stats); } - gst_element_foreach_pad (GST_ELEMENT (webrtc), - (GstElementForeachPadFunc) _get_stats_from_pad, s); + if (pad) + _get_stats_from_pad (webrtc, pad, s); + else + gst_element_foreach_pad (GST_ELEMENT (webrtc), + (GstElementForeachPadFunc) _get_stats_from_pad, s); gst_structure_remove_field (s, "timestamp"); - if (webrtc->priv->stats) - gst_structure_free (webrtc->priv->stats); - webrtc->priv->stats = s; + return s; } diff --git a/ext/webrtc/gstwebrtcstats.h b/ext/webrtc/gstwebrtcstats.h index e67ba47..0573df7 100644 --- a/ext/webrtc/gstwebrtcstats.h +++ b/ext/webrtc/gstwebrtcstats.h @@ -28,7 +28,8 @@ G_BEGIN_DECLS G_GNUC_INTERNAL -void gst_webrtc_bin_update_stats (GstWebRTCBin * webrtc); +GstStructure * gst_webrtc_bin_create_stats (GstWebRTCBin * webrtc, + GstPad * pad); G_END_DECLS -- 2.7.4