webrtc: precise-sync-recv: add media details log

This commit adds the ability to log details about the media being received by
the webrtc-precise-recv example. Among others, the log shows whether RFC7273 is
active. This uses the 'rfc7273-active' property from rtpjitterbuffer which was
introduced in GStreamer1.26.

See also: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7829

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1908>
This commit is contained in:
François Laignel 2024-11-07 10:13:13 +01:00
parent cdd2b87953
commit 50b0ad95e4

View file

@ -6,8 +6,7 @@ use gst::prelude::*;
use tracing::{debug, error, info, trace};
use url::Url;
use std::pin::Pin;
use std::sync::Arc;
use std::{ops::ControlFlow, pin::Pin, sync::Arc, thread, time::Duration};
use gst_plugin_webrtc_protocol::{
IncomingMessage as ToSignaller, OutgoingMessage as FromSignaller, PeerRole, PeerStatus,
@ -146,6 +145,8 @@ fn spawn_consumer(
signaller.connect("webrtcbin-ready", false, {
let cli_args = args.clone();
let peer_id = peer_id.clone();
let meta = meta.clone();
move |args| {
let webrtcbin = args[2].get::<gst::Element>().unwrap();
webrtcbin.set_property("latency", cli_args.rtp_latency);
@ -175,6 +176,60 @@ fn spawn_consumer(
// in the range of the RTP clock rate, i.e. 1/90000s and 1/48000s in this case
rtpbin.set_property("min-ts-offset", gst::ClockTime::MSECOND);
// Log a couple of media details
rtpbin.call_async({
let cli_args = cli_args.clone();
let peer_id = peer_id.clone();
let meta = meta.clone();
move |rtpbin| {
// Wait for actual streaming and clocks to sync
thread::sleep(Duration::from_secs(cli_args.clock_sync_timeout));
let _ = rtpbin
.downcast_ref::<gst::Bin>()
.unwrap()
.iterate_all_by_element_factory_name("rtpjitterbuffer")
.foreach(|jbuf| {
let stats = jbuf.property::<gst::Structure>("stats");
// stats.rfc7273-active is available since GStreamer 1.26
let rfc7273_active =
stats.get_optional::<bool>("rfc7273-active").ok().flatten();
let ptdemux = jbuf
.static_pad("src")
.unwrap()
.peer()
.expect("rtpptdemux linked at this point")
.parent_element()
.unwrap();
ptdemux.foreach_src_pad(|_, pad| {
if let Some(caps) = pad.current_caps() {
let s = caps.structure(0).unwrap();
let ssrc = s.get::<u32>("ssrc").unwrap();
let mid = s.get::<&str>("a-mid").unwrap();
let encoding_name = s.get::<&str>("encoding-name").unwrap();
if let Some(rfc7273_active) = rfc7273_active {
let ts_refclk =
s.get_optional::<&str>("a-ts-refclk").unwrap();
let mediaclk =
s.get_optional::<&str>("a-mediaclk").unwrap();
info!(
%peer_id, ?meta, %ssrc, %mid, %encoding_name,
%rfc7273_active, ?ts_refclk, ?mediaclk,
"media info"
);
} else {
info!(%peer_id, ?meta, %ssrc, %mid, %encoding_name, "media info");
}
}
ControlFlow::Continue(())
});
});
}
});
None
}
});
@ -290,7 +345,7 @@ fn spawn_consumer(
signaller.connect("session-ended", true, {
let bin = bin.downgrade();
move |_| {
info!(%peer_id, "Session ended");
info!(%peer_id, ?meta, "Session ended");
let Some(bin) = bin.upgrade() else {
return Some(false.into());