webrtcbin: Implement getting stats for a specific pad
authorOlivier CrĂȘte <olivier.crete@collabora.com>
Thu, 15 Oct 2020 23:36:45 +0000 (19:36 -0400)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 18 Aug 2021 06:39:58 +0000 (06:39 +0000)
Change-Id: I6147beab9bd62a7fe7c9cb4c76a0207476e3d77e
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1766>

ext/webrtc/gstwebrtcbin.c
ext/webrtc/gstwebrtcbin.h
ext/webrtc/gstwebrtcstats.c
ext/webrtc/gstwebrtcstats.h

index 08227bb..3b20e6d 100644 (file)
@@ -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));
index 4200b1a..f3eb9f6 100644 (file)
@@ -140,8 +140,6 @@ struct _GstWebRTCBinPrivate
   GstWebRTCSessionDescription *last_generated_offer;
   GstWebRTCSessionDescription *last_generated_answer;
 
-  GstStructure *stats;
-
   gboolean tos_attached;
 };
 
index 6145411..0401f70 100644 (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);
   }
 
-  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;
 }
index e67ba47..0573df7 100644 (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