Sync time code

This commit is contained in:
Rafael Caricio 2024-05-24 21:16:43 +02:00
parent 413a6baa8c
commit a8c1615a09
3 changed files with 24 additions and 3 deletions

1
Cargo.lock generated
View file

@ -493,6 +493,7 @@ dependencies = [
"gstreamer-gl", "gstreamer-gl",
"gstreamer-gl-egl", "gstreamer-gl-egl",
"gstreamer-gl-x11", "gstreamer-gl-x11",
"gstreamer-net",
"gstreamer-pbutils", "gstreamer-pbutils",
"gstreamer-play", "gstreamer-play",
"gstreamer-player", "gstreamer-player",

View file

@ -43,6 +43,7 @@ winit = { version = "0.29", optional = true, default-features = false, features
atomic_refcell = "0.1" atomic_refcell = "0.1"
data-encoding = "2.0" data-encoding = "2.0"
once_cell = "1" once_cell = "1"
gst-net = { workspace = true }
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
windows = { version = "0.56", features=["Win32_Graphics_Direct3D11", windows = { version = "0.56", features=["Win32_Graphics_Direct3D11",

View file

@ -52,7 +52,14 @@ unsafe impl Send for LayoutWrapper {}
fn create_pipeline() -> Result<gst::Pipeline, Error> { fn create_pipeline() -> Result<gst::Pipeline, Error> {
gst::init()?; gst::init()?;
// Create the NTP clock and wait for synchronization.
let clock = gst_net::NtpClock::new(None, "pool.ntp.org", 123, gst::ClockTime::ZERO);
println!("Syncing to NTP clock");
clock.wait_for_sync(gst::ClockTime::from_seconds(5))?;
println!("Synced to NTP clock");
let pipeline = gst::Pipeline::default(); let pipeline = gst::Pipeline::default();
pipeline.set_clock(Some(&clock))?;
// The videotestsrc supports multiple test patterns. In this example, we will use the // The videotestsrc supports multiple test patterns. In this example, we will use the
// pattern with a white ball moving around the video's center point. // pattern with a white ball moving around the video's center point.
@ -68,17 +75,29 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
let caps = gst_video::VideoCapsBuilder::new() let caps = gst_video::VideoCapsBuilder::new()
.width(800) .width(800)
.height(800) .height(800)
.framerate((15, 1).into())
.build(); .build();
let capsfilter = gst::ElementFactory::make("capsfilter") let capsfilter = gst::ElementFactory::make("capsfilter")
.property("caps", &caps) .property("caps", &caps)
.build()?; .build()?;
let videoconvert = gst::ElementFactory::make("videoconvert").build()?; let videoconvert = gst::ElementFactory::make("videoconvert").build()?;
let timestamper = gst::ElementFactory::make("timecodestamper").build()?;
timestamper.set_property_from_str("set", "always");
timestamper.set_property_from_str("source", "rtc");
let timeoverlay = gst::ElementFactory::make("timeoverlay").build()?;
timeoverlay.set_property("font-desc", "Sans Bold 26");
timeoverlay.set_property_from_str("time-mode", "time-code");
timeoverlay.set_property_from_str("halignment", "center");
timeoverlay.set_property_from_str("valignment", "bottom");
timeoverlay.set_property("color", 4200427042u32);
let videoconvert2 = gst::ElementFactory::make("videoconvert").build()?;
let sink = gst::ElementFactory::make("autovideosink").build()?; let sink = gst::ElementFactory::make("autovideosink").build()?;
pipeline.add_many([&src, &overlay, &capsfilter, &videoconvert, &sink])?; pipeline.add_many([&src, &overlay, &capsfilter, &videoconvert, &timestamper, &timeoverlay, &videoconvert2, &sink])?;
gst::Element::link_many([&src, &overlay, &capsfilter, &videoconvert, &sink])?; gst::Element::link_many([&src, &overlay, &capsfilter, &videoconvert, &timestamper, &timeoverlay, &videoconvert2, &sink])?;
// The PangoFontMap represents the set of fonts available for a particular rendering system. // The PangoFontMap represents the set of fonts available for a particular rendering system.
let fontmap = pangocairo::FontMap::new(); let fontmap = pangocairo::FontMap::new();