webrtcbin: Implement getting stats for a specific pad

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1766>
This commit is contained in:
Olivier Crête 2020-10-15 19:36:45 -04:00 committed by GStreamer Merge Bot
parent 23ea950351
commit 1c1661b54f
4 changed files with 15 additions and 43 deletions

View file

@ -5219,16 +5219,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;
@ -5249,25 +5239,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
@ -6461,10 +6437,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));

View file

@ -140,8 +140,6 @@ struct _GstWebRTCBinPrivate
GstWebRTCSessionDescription *last_generated_offer;
GstWebRTCSessionDescription *last_generated_answer;
GstStructure *stats;
gboolean tos_attached;
};

View file

@ -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);
}
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;
}

View file

@ -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