Add prelude modules to all cratest that only re-export the traits

And use those in the examples instead of blanket * imports
This commit is contained in:
Sebastian Dröge 2017-08-17 17:58:15 +03:00
parent 767bd0537e
commit f751afc0fb
19 changed files with 148 additions and 70 deletions

View file

@ -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<Pipeline, utils::ExampleError> {
fn create_pipeline() -> Result<gst::Pipeline, utils::ExampleError> {
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<Pipeline, utils::ExampleError> {
utils::link_elements(&src, &sink)?;
let appsink = sink.clone()
.dynamic_cast::<AppSink>()
.dynamic_cast::<gst_app::AppSink>()
.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::<i32>::new(1, i32::MAX)),
("rate", &gst::IntRange::<i32>::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<Pipeline, utils::ExampleError> {
let samples = if let Ok(samples) = map.as_slice().as_slice_of::<i16>() {
samples
} else {
return FlowReturn::Error;
return gst::FlowReturn::Error;
};
let sum: f64 = samples
@ -77,7 +76,7 @@ fn create_pipeline() -> Result<Pipeline, utils::ExampleError> {
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,

View file

@ -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::<AppSrc>()
.dynamic_cast::<gst_app::AppSrc>()
.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,

View file

@ -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,

View file

@ -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(..) => {

View file

@ -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: &gtk::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", &gtkglsink.to_value())
.unwrap();
@ -27,7 +26,7 @@ fn create_ui(app: &gtk::Application) {
let widget = gtkglsink.get_property("widget").unwrap();
(glsinkbin, widget.get::<gtk::Widget>().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::<gtk::Widget>().unwrap())
};
@ -49,7 +48,7 @@ fn create_ui(app: &gtk::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: &gtk::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(),

View file

@ -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::<ParseError>() {
if let Some(gst::ParseError::NoSuchElement) = err.kind::<gst::ParseError>() {
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,

View file

@ -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(),

View file

@ -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::<Bin>()
.dynamic_cast::<gst::Bin>()
.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::<i16>() {
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,

View file

@ -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::<TagList>().unwrap();
let tags = tags.get::<gst::TagList>().unwrap();
if let Some(artist) = tags.get::<tags::Artist>() {
if let Some(artist) = tags.get::<gst::tags::Artist>() {
println!(" Artist: {}", artist.get().unwrap());
}
if let Some(title) = tags.get::<tags::Title>() {
if let Some(title) = tags.get::<gst::tags::Title>() {
println!(" Title: {}", title.get().unwrap());
}
if let Some(album) = tags.get::<tags::Album>() {
if let Some(album) = tags.get::<gst::tags::Album>() {
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,

View file

@ -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)?;

View file

@ -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(),

View file

@ -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,

View file

@ -1,6 +1,6 @@
extern crate gstreamer as gst;
#[cfg(feature = "tokio")]
use gst::*;
use gst::prelude::*;
#[cfg(feature = "tokio")]
extern crate futures;

View file

@ -1,6 +1,5 @@
extern crate gstreamer as gst;
use gst::*;
use gst::prelude::*;
extern crate glib;
use std::fmt;

View file

@ -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::*;
}

View file

@ -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::*;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}