webrtc stats: Add more details about codecs into the stats
authorOlivier Crête <olivier.crete@collabora.com>
Mon, 13 Dec 2021 21:56:37 +0000 (16:56 -0500)
committerOlivier Crête <olivier.crete@collabora.com>
Fri, 24 Dec 2021 04:48:17 +0000 (23:48 -0500)
This makes the output a little closer to what the upstream stats are.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1448>

subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcstats.c

index d56c17d..ed9a1aa 100644 (file)
@@ -31,6 +31,8 @@
 #include "utils.h"
 #include "webrtctransceiver.h"
 
+#include <stdlib.h>
+
 #define GST_CAT_DEFAULT gst_webrtc_stats_debug
 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
 
@@ -776,9 +778,13 @@ _get_codec_stats_from_pad (GstWebRTCBin * webrtc, GstPad * pad,
   _set_base_stats (stats, GST_WEBRTC_STATS_CODEC, ts, id);
 
   caps = gst_pad_get_current_caps (pad);
+  GST_DEBUG_OBJECT (pad, "Pad caps are: %" GST_PTR_FORMAT, caps);
   if (caps && gst_caps_is_fixed (caps)) {
     GstStructure *caps_s = gst_caps_get_structure (caps, 0);
     gint pt;
+    const gchar *encoding_name, *media, *encoding_params;
+    GstSDPMedia sdp_media = { 0 };
+    guint channels = 0;
 
     if (gst_structure_get_int (caps_s, "payload", &pt))
       gst_structure_set (stats, "payload-type", G_TYPE_UINT, pt, NULL);
@@ -789,7 +795,40 @@ _get_codec_stats_from_pad (GstWebRTCBin * webrtc, GstPad * pad,
     if (gst_structure_get_uint (caps_s, "ssrc", &ssrc))
       gst_structure_set (stats, "ssrc", G_TYPE_UINT, ssrc, NULL);
 
-    /* FIXME: codecType, mimeType, channels, sdpFmtpLine, implementation, transportId */
+    media = gst_structure_get_string (caps_s, "media");
+    encoding_name = gst_structure_get_string (caps_s, "encoding-name");
+    encoding_params = gst_structure_get_string (caps_s, "encoding-params");
+
+    if (media || encoding_name) {
+      gchar *mime_type;
+
+      mime_type = g_strdup_printf ("%s/%s", media ? media : "",
+          encoding_name ? encoding_name : "");
+      gst_structure_set (stats, "mime-type", G_TYPE_STRING, mime_type, NULL);
+      g_free (mime_type);
+    }
+
+    if (encoding_params)
+      channels = atoi (encoding_params);
+    if (channels)
+      gst_structure_set (stats, "channels", G_TYPE_UINT, channels, NULL);
+
+    if (gst_pad_get_direction (pad) == GST_PAD_SRC)
+      gst_structure_set (stats, "codec-type", G_TYPE_STRING, "decode", NULL);
+    else
+      gst_structure_set (stats, "codec-type", G_TYPE_STRING, "encode", NULL);
+
+    gst_sdp_media_init (&sdp_media);
+    if (gst_sdp_media_set_media_from_caps (caps, &sdp_media) == GST_SDP_OK) {
+      const gchar *fmtp = gst_sdp_media_get_attribute_val (&sdp_media, "fmtp");
+
+      if (fmtp) {
+        gst_structure_set (stats, "sdp-fmtp-line", G_TYPE_STRING, fmtp, NULL);
+      }
+    }
+    gst_sdp_media_uninit (&sdp_media);
+
+    /* FIXME: transportId */
   }
 
   if (caps)