From fc8046b9bdd1b2b6e09398c7573c8e17330010f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 3 Jul 2017 18:08:43 +0300 Subject: [PATCH] Implement simple example application and clean up API --- Cargo.lock | 8 ++++++++ Cargo.toml | 1 + Gir_Gst.toml | 10 ++++++++++ examples/Cargo.toml | 11 +++++++++++ examples/src/launch.rs | 31 +++++++++++++++++++++++++++++++ gstreamer/src/auto/object.rs | 8 ++++---- gstreamer/src/lib.rs | 3 ++- 7 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 examples/Cargo.toml create mode 100644 examples/src/launch.rs diff --git a/Cargo.lock b/Cargo.lock index 55a4b7918..7b3b73b08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,6 +15,14 @@ name = "bitflags" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "examples" +version = "0.1.0" +dependencies = [ + "glib 0.1.3 (git+https://github.com/gtk-rs/glib)", + "gstreamer 0.1.0", +] + [[package]] name = "glib" version = "0.1.3" diff --git a/Cargo.toml b/Cargo.toml index 1de409863..8eee8f672 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,4 +2,5 @@ members = [ "gstreamer", + "examples", ] diff --git a/Gir_Gst.toml b/Gir_Gst.toml index ef8b811f3..60846381b 100644 --- a/Gir_Gst.toml +++ b/Gir_Gst.toml @@ -156,6 +156,16 @@ status = "generate" [object.function.return] bool_return_is_error = "Failed to set object name" + [[object.function]] + name = "get_name" + [object.function.return] + nullable = false + + [[object.function]] + name = "get_path_string" + [object.function.return] + nullable = false + [[object.function]] name = "set_parent" [object.function.return] diff --git a/examples/Cargo.toml b/examples/Cargo.toml new file mode 100644 index 000000000..8f64d184d --- /dev/null +++ b/examples/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "examples" +version = "0.1.0" +authors = ["Sebastian Dröge "] + +[dependencies] +glib = { version = "0.1.3", git = "https://github.com/gtk-rs/glib" } +gstreamer = { path = "../gstreamer" } + +[[bin]] +name = "launch" diff --git a/examples/src/launch.rs b/examples/src/launch.rs new file mode 100644 index 000000000..9ec146fc9 --- /dev/null +++ b/examples/src/launch.rs @@ -0,0 +1,31 @@ +extern crate gstreamer as gst; +use gst::*; + +use std::u64; + +fn main() { + gst::init().unwrap(); + + let pipeline = gst::parse_launch("audiotestsrc ! autoaudiosink").unwrap(); + let bus = pipeline.get_bus().unwrap(); + + let ret = pipeline.set_state(gst::State::Playing); + assert_ne!(ret, gst::StateChangeReturn::Failure); + + loop { + let msg = match bus.timed_pop(u64::MAX) { + None => break, + Some(msg) => msg, + }; + + match msg.view() { + MessageView::Eos(_) => break, + MessageView::Error(err) => { + println!("Error from {}: {} ({:?})", msg.get_src().get_path_string(), + err.get_error(), err.get_debug()); + break; + }, + _ => (), + } + } +} diff --git a/gstreamer/src/auto/object.rs b/gstreamer/src/auto/object.rs index e898f8cb2..3ba77cc13 100644 --- a/gstreamer/src/auto/object.rs +++ b/gstreamer/src/auto/object.rs @@ -50,11 +50,11 @@ pub trait ObjectExt { //fn get_g_value_array(&self, property_name: &str, timestamp: ClockTime, interval: ClockTime, values: /*Ignored*/&[&glib::Value]) -> bool; - fn get_name(&self) -> Option; + fn get_name(&self) -> String; fn get_parent(&self) -> Option; - fn get_path_string(&self) -> Option; + fn get_path_string(&self) -> String; //fn get_value(&self, property_name: &str, timestamp: ClockTime) -> /*Ignored*/Option; @@ -117,7 +117,7 @@ impl> ObjectExt for O { // unsafe { TODO: call ffi::gst_object_get_g_value_array() } //} - fn get_name(&self) -> Option { + fn get_name(&self) -> String { unsafe { from_glib_full(ffi::gst_object_get_name(self.to_glib_none().0)) } @@ -129,7 +129,7 @@ impl> ObjectExt for O { } } - fn get_path_string(&self) -> Option { + fn get_path_string(&self) -> String { unsafe { from_glib_full(ffi::gst_object_get_path_string(self.to_glib_none().0)) } diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index 560d246f2..dc328e4f5 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -29,14 +29,15 @@ pub use glib::{ Value, }; -pub use auto::*; mod auto; +pub use auto::*; pub use auto::functions::{parse_launch, parse_bin_from_description}; pub mod miniobject; pub use miniobject::GstRc; pub mod message; pub use message::Message; +pub use message::MessageView; use std::ptr;