diff --git a/examples/src/bin/appsink.rs b/examples/src/bin/appsink.rs index e4cd2b5c5..671b4f853 100644 --- a/examples/src/bin/appsink.rs +++ b/examples/src/bin/appsink.rs @@ -1,7 +1,6 @@ extern crate gstreamer as gst; -use gst::*; +use gst::prelude::*; extern crate gstreamer_app as gst_app; -use gst_app::*; extern crate gstreamer_audio as gst_audio; extern crate glib; @@ -15,7 +14,7 @@ use std::i32; pub mod utils; -fn create_pipeline() -> Result { +fn create_pipeline() -> Result { gst::init().map_err(utils::ExampleError::InitFailed)?; let pipeline = gst::Pipeline::new(None); let src = utils::create_element("audiotestsrc")?; @@ -28,28 +27,28 @@ fn create_pipeline() -> Result { utils::link_elements(&src, &sink)?; let appsink = sink.clone() - .dynamic_cast::() + .dynamic_cast::() .expect("Sink element is expected to be an appsink!"); - appsink.set_caps(&Caps::new_simple( + appsink.set_caps(&gst::Caps::new_simple( "audio/x-raw", &[ ("format", &gst_audio::AUDIO_FORMAT_S16.to_string()), ("layout", &"interleaved"), ("channels", &(1i32)), - ("rate", &IntRange::::new(1, i32::MAX)), + ("rate", &gst::IntRange::::new(1, i32::MAX)), ], )); - appsink.set_callbacks(AppSinkCallbacks::new( + appsink.set_callbacks(gst_app::AppSinkCallbacks::new( /* eos */ |_| {}, /* new_preroll */ - |_| FlowReturn::Ok, + |_| gst::FlowReturn::Ok, /* new_samples */ |appsink| { let sample = match appsink.pull_sample() { - None => return FlowReturn::Eos, + None => return gst::FlowReturn::Eos, Some(sample) => sample, }; @@ -64,7 +63,7 @@ fn create_pipeline() -> Result { let samples = if let Ok(samples) = map.as_slice().as_slice_of::() { samples } else { - return FlowReturn::Error; + return gst::FlowReturn::Error; }; let sum: f64 = samples @@ -77,7 +76,7 @@ fn create_pipeline() -> Result { let rms = (sum / (samples.len() as f64)).sqrt(); println!("rms: {}", rms); - FlowReturn::Ok + gst::FlowReturn::Ok }, )); @@ -94,6 +93,8 @@ fn main_loop() -> Result<(), utils::ExampleError> { .expect("Pipeline without bus. Shouldn't happen!"); loop { + use gst::MessageView; + let msg = match bus.timed_pop(u64::MAX) { None => break, Some(msg) => msg, diff --git a/examples/src/bin/appsrc.rs b/examples/src/bin/appsrc.rs index fc4cf5824..0f0c8f631 100644 --- a/examples/src/bin/appsrc.rs +++ b/examples/src/bin/appsrc.rs @@ -1,7 +1,6 @@ extern crate gstreamer as gst; -use gst::*; +use gst::prelude::*; extern crate gstreamer_app as gst_app; -use gst_app::*; extern crate gstreamer_video as gst_video; extern crate glib; @@ -14,7 +13,7 @@ pub mod utils; const WIDTH: usize = 320; const HEIGHT: usize = 240; -fn create_pipeline() -> Result<(Pipeline, AppSrc), utils::ExampleError> { +fn create_pipeline() -> Result<(gst::Pipeline, gst_app::AppSrc), utils::ExampleError> { gst::init().map_err(utils::ExampleError::InitFailed)?; let pipeline = gst::Pipeline::new(None); @@ -29,16 +28,16 @@ fn create_pipeline() -> Result<(Pipeline, AppSrc), utils::ExampleError> { utils::link_elements(&videoconvert, &sink)?; let appsrc = src.clone() - .dynamic_cast::() + .dynamic_cast::() .expect("Source element is expected to be an appsrc!"); let info = gst_video::VideoInfo::new(gst_video::VideoFormat::Bgrx, WIDTH as u32, HEIGHT as u32) - .fps(Fraction::new(2, 1)) + .fps(gst::Fraction::new(2, 1)) .build() .unwrap(); appsrc.set_caps(&info.to_caps().unwrap()); - appsrc.set_property_format(Format::Time); + appsrc.set_property_format(gst::Format::Time); appsrc.set_max_bytes(1); appsrc.set_property_block(true); @@ -72,7 +71,7 @@ fn main_loop() -> Result<(), utils::ExampleError> { } } - if appsrc.push_buffer(buffer) != FlowReturn::Ok { + if appsrc.push_buffer(buffer) != gst::FlowReturn::Ok { break; } } @@ -87,6 +86,8 @@ fn main_loop() -> Result<(), utils::ExampleError> { .expect("Pipeline without bus. Shouldn't happen!"); loop { + use gst::MessageView; + let msg = match bus.timed_pop(u64::MAX) { None => break, Some(msg) => msg, diff --git a/examples/src/bin/decodebin.rs b/examples/src/bin/decodebin.rs index ac7285837..d4f65e927 100644 --- a/examples/src/bin/decodebin.rs +++ b/examples/src/bin/decodebin.rs @@ -1,8 +1,7 @@ extern crate gstreamer as gst; -use gst::*; +use gst::prelude::*; extern crate glib; -use glib::*; use std::env; use std::u64; @@ -21,7 +20,8 @@ fn main() { let src = gst::ElementFactory::make("filesrc", None).unwrap(); let decodebin = gst::ElementFactory::make("decodebin", None).unwrap(); - src.set_property("location", &Value::from(uri)).unwrap(); + src.set_property("location", &glib::Value::from(uri)) + .unwrap(); pipeline.add_many(&[&src, &decodebin]).unwrap(); gst::Element::link_many(&[&src, &decodebin]).unwrap(); @@ -82,6 +82,8 @@ fn main() { let bus = pipeline.get_bus().unwrap(); loop { + use gst::MessageView; + let msg = match bus.timed_pop(u64::MAX) { None => break, Some(msg) => msg, diff --git a/examples/src/bin/events.rs b/examples/src/bin/events.rs index a39efcd05..1f4c79581 100644 --- a/examples/src/bin/events.rs +++ b/examples/src/bin/events.rs @@ -1,13 +1,12 @@ extern crate gstreamer as gst; -use gst::*; +use gst::prelude::*; extern crate glib; -use glib::*; fn main() { gst::init().unwrap(); - let main_loop = MainLoop::new(None, false); + let main_loop = glib::MainLoop::new(None, false); let pipeline = gst::parse_launch("audiotestsrc ! fakesink").unwrap(); let bus = pipeline.get_bus().unwrap(); @@ -23,7 +22,7 @@ fn main() { println!("sending eos"); - let ev = Event::new_eos().build(); + let ev = gst::Event::new_eos().build(); pipeline.send_event(ev); glib::Continue(false) @@ -32,6 +31,8 @@ fn main() { //bus.add_signal_watch(); //bus.connect_message(move |_, msg| { bus.add_watch(move |_, msg| { + use gst::MessageView; + let main_loop = &main_loop_clone; match msg.view() { MessageView::Eos(..) => { diff --git a/examples/src/bin/gtksink.rs b/examples/src/bin/gtksink.rs index 6766137f2..4023b5c77 100644 --- a/examples/src/bin/gtksink.rs +++ b/examples/src/bin/gtksink.rs @@ -1,11 +1,10 @@ extern crate gstreamer as gst; -use gst::*; +use gst::prelude::*; extern crate glib; -use glib::*; extern crate gio; -use gio::*; +use gio::prelude::*; extern crate gtk; use gtk::prelude::*; @@ -16,10 +15,10 @@ extern crate send_cell; use send_cell::SendCell; fn create_ui(app: >k::Application) { - let pipeline = Pipeline::new(None); - let src = ElementFactory::make("videotestsrc", None).unwrap(); - let (sink, widget) = if let Some(gtkglsink) = ElementFactory::make("gtkglsink", None) { - let glsinkbin = ElementFactory::make("glsinkbin", None).unwrap(); + let pipeline = gst::Pipeline::new(None); + let src = gst::ElementFactory::make("videotestsrc", None).unwrap(); + let (sink, widget) = if let Some(gtkglsink) = gst::ElementFactory::make("gtkglsink", None) { + let glsinkbin = gst::ElementFactory::make("glsinkbin", None).unwrap(); glsinkbin .set_property("sink", >kglsink.to_value()) .unwrap(); @@ -27,7 +26,7 @@ fn create_ui(app: >k::Application) { let widget = gtkglsink.get_property("widget").unwrap(); (glsinkbin, widget.get::().unwrap()) } else { - let sink = ElementFactory::make("gtksink", None).unwrap(); + let sink = gst::ElementFactory::make("gtksink", None).unwrap(); let widget = sink.get_property("widget").unwrap(); (sink, widget.get::().unwrap()) }; @@ -49,7 +48,7 @@ fn create_ui(app: >k::Application) { let pipeline_clone = pipeline.clone(); gtk::timeout_add(500, move || { let pipeline = &pipeline_clone; - let position = pipeline.query_position(Format::Time); + let position = pipeline.query_position(gst::Format::Time); if let Some(position) = position { let mut seconds = position / 1_000_000_000; @@ -86,6 +85,8 @@ fn create_ui(app: >k::Application) { let app_clone = SendCell::new(app.clone()); bus.add_watch(move |_, msg| { + use gst::MessageView; + let app = app_clone.borrow(); match msg.view() { MessageView::Eos(..) => gtk::main_quit(), diff --git a/examples/src/bin/launch.rs b/examples/src/bin/launch.rs index 4b96ea181..20febb1ea 100644 --- a/examples/src/bin/launch.rs +++ b/examples/src/bin/launch.rs @@ -1,5 +1,5 @@ extern crate gstreamer as gst; -use gst::*; +use gst::prelude::*; use std::u64; use std::env; @@ -10,12 +10,12 @@ fn main() { gst::init().unwrap(); - let mut context = ParseContext::new(); + let mut context = gst::ParseContext::new(); let pipeline = - match gst::parse_launch_full(&pipeline_str, Some(&mut context), PARSE_FLAG_NONE) { + match gst::parse_launch_full(&pipeline_str, Some(&mut context), gst::PARSE_FLAG_NONE) { Ok(pipeline) => pipeline, Err(err) => { - if let Some(ParseError::NoSuchElement) = err.kind::() { + if let Some(gst::ParseError::NoSuchElement) = err.kind::() { println!("Missing element(s): {:?}", context.get_missing_elements()); } else { println!("Failed to parse pipeline: {}", err); @@ -30,6 +30,8 @@ fn main() { assert_ne!(ret, gst::StateChangeReturn::Failure); loop { + use gst::MessageView; + let msg = match bus.timed_pop(u64::MAX) { None => break, Some(msg) => msg, diff --git a/examples/src/bin/launch_glib_main.rs b/examples/src/bin/launch_glib_main.rs index c8b8f1fb8..06db2c71e 100644 --- a/examples/src/bin/launch_glib_main.rs +++ b/examples/src/bin/launch_glib_main.rs @@ -1,8 +1,7 @@ extern crate gstreamer as gst; -use gst::*; +use gst::prelude::*; extern crate glib; -use glib::*; use std::env; @@ -11,7 +10,7 @@ fn main() { gst::init().unwrap(); - let main_loop = MainLoop::new(None, false); + let main_loop = glib::MainLoop::new(None, false); let pipeline = gst::parse_launch(&pipeline_str).unwrap(); let bus = pipeline.get_bus().unwrap(); @@ -24,6 +23,8 @@ fn main() { //bus.add_signal_watch(); //bus.connect_message(move |_, msg| { bus.add_watch(move |_, msg| { + use gst::MessageView; + let main_loop = &main_loop_clone; match msg.view() { MessageView::Eos(..) => main_loop.quit(), diff --git a/examples/src/bin/pad_probes.rs b/examples/src/bin/pad_probes.rs index 78ecd7f32..573a93b47 100644 --- a/examples/src/bin/pad_probes.rs +++ b/examples/src/bin/pad_probes.rs @@ -1,5 +1,5 @@ extern crate gstreamer as gst; -use gst::*; +use gst::prelude::*; extern crate gstreamer_audio as gst_audio; extern crate byte_slice_cast; @@ -19,19 +19,19 @@ fn main() { let src = pipeline .clone() - .dynamic_cast::() + .dynamic_cast::() .unwrap() .get_by_name("src") .unwrap(); let src_pad = src.get_static_pad("src").unwrap(); - src_pad.add_probe(PAD_PROBE_TYPE_BUFFER, |_, probe_info| { - if let Some(PadProbeData::Buffer(ref buffer)) = probe_info.data { + src_pad.add_probe(gst::PAD_PROBE_TYPE_BUFFER, |_, probe_info| { + if let Some(gst::PadProbeData::Buffer(ref buffer)) = probe_info.data { let map = buffer.map_readable().unwrap(); let samples = if let Ok(samples) = map.as_slice().as_slice_of::() { samples } else { - return PadProbeReturn::Ok; + return gst::PadProbeReturn::Ok; }; let sum: f64 = samples @@ -45,13 +45,15 @@ fn main() { println!("rms: {}", rms); } - PadProbeReturn::Ok + gst::PadProbeReturn::Ok }); let ret = pipeline.set_state(gst::State::Playing); assert_ne!(ret, gst::StateChangeReturn::Failure); loop { + use gst::MessageView; + let msg = match bus.timed_pop(u64::MAX) { None => break, Some(msg) => msg, diff --git a/examples/src/bin/playbin.rs b/examples/src/bin/playbin.rs index 8a9cb192a..4f009e30b 100644 --- a/examples/src/bin/playbin.rs +++ b/examples/src/bin/playbin.rs @@ -1,8 +1,7 @@ extern crate gstreamer as gst; -use gst::*; +use gst::prelude::*; extern crate glib; -use glib::*; use std::env; use std::u64; @@ -18,7 +17,9 @@ fn main() { }; let playbin = gst::ElementFactory::make("playbin", None).unwrap(); - playbin.set_property("uri", &Value::from(uri)).unwrap(); + playbin + .set_property("uri", &glib::Value::from(uri)) + .unwrap(); // For flags handling // let flags = playbin.get_property("flags").unwrap(); @@ -41,17 +42,17 @@ fn main() { .emit("get-audio-tags", &[&idx.to_value()]) .unwrap() .unwrap(); - let tags = tags.get::().unwrap(); + let tags = tags.get::().unwrap(); - if let Some(artist) = tags.get::() { + if let Some(artist) = tags.get::() { println!(" Artist: {}", artist.get().unwrap()); } - if let Some(title) = tags.get::() { + if let Some(title) = tags.get::() { println!(" Title: {}", title.get().unwrap()); } - if let Some(album) = tags.get::() { + if let Some(album) = tags.get::() { println!(" Album: {}", album.get().unwrap()); } @@ -65,6 +66,8 @@ fn main() { assert_ne!(ret, gst::StateChangeReturn::Failure); loop { + use gst::MessageView; + let msg = match bus.timed_pop(u64::MAX) { None => break, Some(msg) => msg, diff --git a/examples/src/bin/player.rs b/examples/src/bin/player.rs index 8e896773d..c28113cfa 100644 --- a/examples/src/bin/player.rs +++ b/examples/src/bin/player.rs @@ -1,17 +1,18 @@ extern crate gstreamer as gst; +#[cfg(feature = "gst-player")] +use gst::prelude::*; #[cfg(feature = "gst-player")] extern crate gstreamer_player as gst_player; +#[cfg(feature = "gst-player")] +use gst_player::prelude::*; extern crate glib; -#[cfg(feature = "gst-player")] -use glib::ObjectExt; use std::env; pub mod utils; - #[cfg(feature = "gst-player")] fn main_loop(uri: &str) -> Result<(), utils::ExampleError> { gst::init().map_err(utils::ExampleError::InitFailed)?; diff --git a/examples/src/bin/queries.rs b/examples/src/bin/queries.rs index 9065abdc1..43f88c7d1 100644 --- a/examples/src/bin/queries.rs +++ b/examples/src/bin/queries.rs @@ -1,8 +1,7 @@ extern crate gstreamer as gst; -use gst::*; +use gst::prelude::*; extern crate glib; -use glib::*; use std::env; @@ -11,7 +10,7 @@ fn main() { gst::init().unwrap(); - let main_loop = MainLoop::new(None, false); + let main_loop = glib::MainLoop::new(None, false); let pipeline = gst::parse_launch(&pipeline_str).unwrap(); let bus = pipeline.get_bus().unwrap(); @@ -23,12 +22,14 @@ fn main() { let pipeline_clone = pipeline.clone(); glib::timeout_add_seconds(1, move || { + use gst::QueryView; + let pipeline = &pipeline_clone; - //let pos = pipeline.query_position(Format::Time).unwrap_or(-1); - //let dur = pipeline.query_duration(Format::Time).unwrap_or(-1); + //let pos = pipeline.query_position(gst::Format::Time).unwrap_or(-1); + //let dur = pipeline.query_duration(gst::Format::Time).unwrap_or(-1); let pos = { - let mut q = Query::new_position(Format::Time); + let mut q = gst::Query::new_position(gst::Format::Time); pipeline.query(q.get_mut().unwrap()); match q.view() { QueryView::Position(ref p) => p.get().1, @@ -37,7 +38,7 @@ fn main() { }; let dur = { - let mut q = Query::new_duration(Format::Time); + let mut q = gst::Query::new_duration(gst::Format::Time); pipeline.query(q.get_mut().unwrap()); match q.view() { QueryView::Duration(ref p) => p.get().1, @@ -53,6 +54,8 @@ fn main() { //bus.add_signal_watch(); //bus.connect_message(move |_, msg| { bus.add_watch(move |_, msg| { + use gst::MessageView; + let main_loop = &main_loop_clone; match msg.view() { MessageView::Eos(..) => main_loop.quit(), diff --git a/examples/src/bin/toc.rs b/examples/src/bin/toc.rs index 0dc5281fa..ff05648a3 100644 --- a/examples/src/bin/toc.rs +++ b/examples/src/bin/toc.rs @@ -1,8 +1,7 @@ extern crate gstreamer as gst; -use gst::*; +use gst::prelude::*; extern crate glib; -use glib::*; use std::env; use std::u64; @@ -21,7 +20,8 @@ fn main() { let src = gst::ElementFactory::make("filesrc", None).unwrap(); let decodebin = gst::ElementFactory::make("decodebin", None).unwrap(); - src.set_property("location", &Value::from(uri)).unwrap(); + src.set_property("location", &glib::Value::from(uri)) + .unwrap(); pipeline.add_many(&[&src, &decodebin]).unwrap(); gst::Element::link_many(&[&src, &decodebin]).unwrap(); @@ -53,6 +53,8 @@ fn main() { let bus = pipeline.get_bus().unwrap(); loop { + use gst::MessageView; + let msg = match bus.timed_pop(u64::MAX) { None => break, Some(msg) => msg, diff --git a/examples/src/bin/tokio.rs b/examples/src/bin/tokio.rs index 15c079afa..8f8dda92a 100644 --- a/examples/src/bin/tokio.rs +++ b/examples/src/bin/tokio.rs @@ -1,6 +1,6 @@ extern crate gstreamer as gst; #[cfg(feature = "tokio")] -use gst::*; +use gst::prelude::*; #[cfg(feature = "tokio")] extern crate futures; diff --git a/examples/src/bin/utils/mod.rs b/examples/src/bin/utils/mod.rs index bde22f2df..af8391015 100644 --- a/examples/src/bin/utils/mod.rs +++ b/examples/src/bin/utils/mod.rs @@ -1,6 +1,5 @@ - extern crate gstreamer as gst; -use gst::*; +use gst::prelude::*; extern crate glib; use std::fmt; diff --git a/gstreamer-app/src/lib.rs b/gstreamer-app/src/lib.rs index d0de5a4f6..31365a0db 100644 --- a/gstreamer-app/src/lib.rs +++ b/gstreamer-app/src/lib.rs @@ -41,3 +41,12 @@ mod app_src; mod app_sink; pub use app_src::AppSrcCallbacks; pub use app_sink::AppSinkCallbacks; + +// Re-export all the traits in a prelude module, so that applications +// can always "use gst::prelude::*" without getting conflicts +pub mod prelude { + pub use glib::prelude::*; + pub use gst::prelude::*; + + pub use auto::traits::*; +} diff --git a/gstreamer-audio/src/lib.rs b/gstreamer-audio/src/lib.rs index 02ba65e83..9c56d2ce0 100644 --- a/gstreamer-audio/src/lib.rs +++ b/gstreamer-audio/src/lib.rs @@ -65,3 +65,12 @@ pub fn audio_buffer_clip( )) } } + +// Re-export all the traits in a prelude module, so that applications +// can always "use gst::prelude::*" without getting conflicts +pub mod prelude { + pub use glib::prelude::*; + pub use gst::prelude::*; + + pub use auto::traits::*; +} diff --git a/gstreamer-player/src/lib.rs b/gstreamer-player/src/lib.rs index 00c325518..b768b5290 100644 --- a/gstreamer-player/src/lib.rs +++ b/gstreamer-player/src/lib.rs @@ -46,3 +46,13 @@ mod player; mod player_video_overlay_video_renderer; pub use player_video_overlay_video_renderer::PlayerVideoOverlayVideoRendererExtManual; + +// Re-export all the traits in a prelude module, so that applications +// can always "use gst::prelude::*" without getting conflicts +pub mod prelude { + pub use glib::prelude::*; + pub use gst::prelude::*; + + pub use auto::traits::*; + pub use player_video_overlay_video_renderer::PlayerVideoOverlayVideoRendererExtManual; +} diff --git a/gstreamer-video/src/lib.rs b/gstreamer-video/src/lib.rs index 386a34404..903a026ec 100644 --- a/gstreamer-video/src/lib.rs +++ b/gstreamer-video/src/lib.rs @@ -42,3 +42,13 @@ mod video_frame; pub use video_frame::VideoFrame; mod video_overlay; pub use video_overlay::VideoOverlayExtManual; + +// Re-export all the traits in a prelude module, so that applications +// can always "use gst::prelude::*" without getting conflicts +pub mod prelude { + pub use glib::prelude::*; + pub use gst::prelude::*; + + pub use auto::traits::*; + pub use video_overlay::VideoOverlayExtManual; +} diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index cdb84f9e0..58cf44ce5 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -143,3 +143,24 @@ pub fn init() -> Result<(), glib::Error> { pub const BUFFER_OFFSET_NONE: u64 = ffi::GST_BUFFER_OFFSET_NONE; pub const CLOCK_TIME_NONE: u64 = ffi::GST_CLOCK_TIME_NONE; + +// Re-export all the traits in a prelude module, so that applications +// can always "use gst::prelude::*" without getting conflicts +pub mod prelude { + pub use glib::prelude::*; + + pub use auto::traits::*; + + pub use element::ElementExtManual; + pub use bin::BinExtManual; + pub use pad::PadExtManual; + pub use gobject::GObjectExtManualGst; + pub use child_proxy::ChildProxyExtManual; + pub use tag_setter::TagSetterExtManual; + pub use device_provider::DeviceProviderExtManual; + pub use clock::ClockExtManual; + pub use value::GstValueExt; + + pub use tags::Tag; + pub use miniobject::MiniObject; +}