diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..3b15ae3 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "{REPO_NAME_LOWER}" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +gst = { package = "gstreamer", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features = ["v1_20"] } +gst-video = { package = "gstreamer-video", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } +gst-audio = { package = "gstreamer-audio", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } +gst-app = { package = "gstreamer-app", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } +anyhow = "1" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..9b87c6d --- /dev/null +++ b/src/main.rs @@ -0,0 +1,58 @@ +use anyhow::Result; +use gst::prelude::*; +use gst::glib; +use gst::glib::once_cell::sync::Lazy; + +static CAT: Lazy = Lazy::new(|| { + gst::DebugCategory::new( + "main", + gst::DebugColorFlags::empty(), + Some("Main function"), + ) +}); + +fn main() -> Result<()> { + gst::init()?; + + let pipeline = gst::parse_launch(r#" + + videotestsrc ! videoconvert ! timeoverlay shaded-background=true ! gtksink + + "#,)?.downcast::().unwrap(); + + let context = glib::MainContext::default(); + let main_loop = glib::MainLoop::new(Some(&context), false); + + pipeline.set_state(gst::State::Playing)?; + + let bus = pipeline.bus().unwrap(); + bus.add_watch({ + let main_loop = main_loop.clone(); + move |_, msg| { + use gst::MessageView; + let main_loop = &main_loop; + match msg.view() { + MessageView::Eos(..) => main_loop.quit(), + MessageView::Error(err) => { + gst::error!(CAT, obj: &err.src().unwrap(), + "Error from {:?}: {} ({:?})", + err.src().map(|s| s.path_string()), + err.error(), + err.debug() + ); + main_loop.quit(); + } + _ => (), + }; + glib::Continue(true) + } + }) + .expect("Failed to add bus watch"); + + main_loop.run(); + + pipeline.set_state(gst::State::Null)?; + bus.remove_watch().unwrap(); + + Ok(()) +}