webrtcbin: Support for setting kind attribute on RTCRtpStreamStats

The attribute maps the `kind` property of the associated transceiver.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3630>
This commit is contained in:
Philippe Normand 2022-12-22 21:29:39 +00:00
parent e2fe594a19
commit 72884f141c
3 changed files with 36 additions and 12 deletions

View file

@ -8746,6 +8746,7 @@ gst_webrtc_bin_class_init (GstWebRTCBinClass * klass)
* "ssrc" G_TYPE_STRING the rtp sequence src in use
* "transport-id" G_TYPE_STRING identifier for the associated RTCTransportStats for this stream
* "codec-id" G_TYPE_STRING identifier for the associated RTCCodecStats for this stream
* "kind" G_TYPE_STRING either "audio" or "video", depending on the associated transceiver (Since: 1.22)
*
* RTCReceivedStreamStats supported fields (https://w3c.github.io/webrtc-stats/#receivedrtpstats-dict*)
*

View file

@ -105,7 +105,7 @@ _gst_structure_take_structure (GstStructure * s, const char *fieldname,
static gboolean
_get_stats_from_remote_rtp_source_stats (GstWebRTCBin * webrtc,
TransportStream * stream, const GstStructure * source_stats,
guint ssrc, guint clock_rate, const gchar * codec_id,
guint ssrc, guint clock_rate, const gchar * codec_id, const gchar * kind,
const gchar * transport_id, GstStructure * s)
{
gboolean have_rb = FALSE, internal = FALSE;
@ -135,7 +135,8 @@ _get_stats_from_remote_rtp_source_stats (GstWebRTCBin * webrtc,
gst_structure_set (r_in, "ssrc", G_TYPE_UINT, ssrc, NULL);
gst_structure_set (r_in, "codec-id", G_TYPE_STRING, codec_id, NULL);
gst_structure_set (r_in, "transport-id", G_TYPE_STRING, transport_id, NULL);
/* To be added: kind */
if (kind)
gst_structure_set (r_in, "kind", G_TYPE_STRING, kind, NULL);
/* RTCReceivedRtpStreamStats */
@ -205,7 +206,8 @@ _get_stats_from_remote_rtp_source_stats (GstWebRTCBin * webrtc,
static void
_get_stats_from_rtp_source_stats (GstWebRTCBin * webrtc,
TransportStream * stream, const GstStructure * source_stats,
const gchar * codec_id, const gchar * transport_id, GstStructure * s)
const gchar * codec_id, const gchar * kind, const gchar * transport_id,
GstStructure * s)
{
guint ssrc, fir, pli, nack, jitter;
int clock_rate;
@ -230,8 +232,8 @@ _get_stats_from_rtp_source_stats (GstWebRTCBin * webrtc,
gst_structure_set (out, "ssrc", G_TYPE_UINT, ssrc, NULL);
gst_structure_set (out, "codec-id", G_TYPE_STRING, codec_id, NULL);
gst_structure_set (out, "transport-id", G_TYPE_STRING, transport_id, NULL);
/* To be added: kind */
if (kind)
gst_structure_set (out, "kind", G_TYPE_STRING, kind, NULL);
/* RTCSentRtpStreamStats */
if (gst_structure_get_uint64 (source_stats, "octets-sent", &bytes))
@ -350,8 +352,8 @@ _get_stats_from_rtp_source_stats (GstWebRTCBin * webrtc,
gst_structure_set (in, "ssrc", G_TYPE_UINT, ssrc, NULL);
gst_structure_set (in, "codec-id", G_TYPE_STRING, codec_id, NULL);
gst_structure_set (in, "transport-id", G_TYPE_STRING, transport_id, NULL);
/* To be added: kind */
if (kind)
gst_structure_set (in, "kind", G_TYPE_STRING, kind, NULL);
/* RTCReceivedRtpStreamStats */
@ -871,6 +873,7 @@ struct transport_stream_stats
TransportStream *stream;
char *transport_id;
char *codec_id;
const char *kind;
guint clock_rate;
GValueArray *source_stats;
GstStructure *s;
@ -897,12 +900,14 @@ webrtc_stats_get_from_transport (SsrcMapItem * entry,
if (gst_structure_get_uint (stats, "ssrc", &stats_ssrc) &&
entry->ssrc == stats_ssrc)
_get_stats_from_rtp_source_stats (ts_stats->webrtc, ts_stats->stream,
stats, ts_stats->codec_id, ts_stats->transport_id, ts_stats->s);
else if (gst_structure_get_uint (stats, "rb-ssrc", &stats_ssrc) &&
entry->ssrc == stats_ssrc)
stats, ts_stats->codec_id, ts_stats->kind, ts_stats->transport_id,
ts_stats->s);
else if (gst_structure_get_uint (stats, "rb-ssrc", &stats_ssrc)
&& entry->ssrc == stats_ssrc)
_get_stats_from_remote_rtp_source_stats (ts_stats->webrtc,
ts_stats->stream, stats, entry->ssrc, ts_stats->clock_rate,
ts_stats->codec_id, ts_stats->transport_id, ts_stats->s);
ts_stats->codec_id, ts_stats->kind, ts_stats->transport_id,
ts_stats->s);
}
/* we want to look at all the entries */
@ -918,6 +923,7 @@ _get_stats_from_pad (GstWebRTCBin * webrtc, GstPad * pad, GstStructure * s)
GObject *rtp_session;
GObject *gst_rtp_session;
GstStructure *rtp_stats, *twcc_stats;
GstWebRTCKind kind;
_get_codec_stats_from_pad (webrtc, pad, s, &ts_stats.codec_id, &ssrc,
&clock_rate);
@ -925,6 +931,19 @@ _get_stats_from_pad (GstWebRTCBin * webrtc, GstPad * pad, GstStructure * s)
if (!wpad->trans)
goto out;
g_object_get (wpad->trans, "kind", &kind, NULL);
switch (kind) {
case GST_WEBRTC_KIND_AUDIO:
ts_stats.kind = "audio";
break;
case GST_WEBRTC_KIND_VIDEO:
ts_stats.kind = "video";
break;
case GST_WEBRTC_KIND_UNKNOWN:
ts_stats.kind = NULL;
break;
};
ts_stats.stream = WEBRTC_TRANSCEIVER (wpad->trans)->stream;
if (!ts_stats.stream)
goto out;

View file

@ -1517,7 +1517,7 @@ validate_codec_stats (const GstStructure * s)
static void
validate_rtc_stream_stats (const GstStructure * s, const GstStructure * stats)
{
gchar *codec_id, *transport_id;
gchar *codec_id, *transport_id, *kind;
GstStructure *codec, *transport;
fail_unless (gst_structure_get (s, "codec-id", G_TYPE_STRING, &codec_id,
@ -1536,8 +1536,12 @@ validate_rtc_stream_stats (const GstStructure * s, const GstStructure * stats)
gst_structure_free (transport);
gst_structure_free (codec);
fail_unless (gst_structure_get (s, "kind", G_TYPE_STRING, &kind, NULL));
fail_unless (g_str_equal (kind, "audio") || g_str_equal (kind, "video"));
g_free (codec_id);
g_free (transport_id);
g_free (kind);
}
static void