2017-09-12 17:24:36 +00:00
|
|
|
extern crate gstreamer as gst;
|
|
|
|
use gst::prelude::*;
|
|
|
|
|
2017-11-12 13:53:50 +00:00
|
|
|
#[path = "../tutorials-common.rs"]
|
|
|
|
mod tutorials_common;
|
|
|
|
|
|
|
|
fn tutorial_main() {
|
2017-09-12 17:24:36 +00:00
|
|
|
// Initialize GStreamer
|
|
|
|
gst::init().unwrap();
|
|
|
|
|
|
|
|
// Create the elements
|
2019-04-15 15:17:42 +00:00
|
|
|
let source = gst::ElementFactory::make("videotestsrc", Some("source"))
|
2017-09-12 17:24:36 +00:00
|
|
|
.expect("Could not create source element.");
|
2019-04-15 15:17:42 +00:00
|
|
|
let sink = gst::ElementFactory::make("autovideosink", Some("sink"))
|
|
|
|
.expect("Could not create sink element");
|
2017-09-12 17:24:36 +00:00
|
|
|
|
|
|
|
// Create the empty pipeline
|
2019-04-15 15:17:42 +00:00
|
|
|
let pipeline = gst::Pipeline::new(Some("test-pipeline"));
|
2017-09-12 17:24:36 +00:00
|
|
|
|
|
|
|
// Build the pipeline
|
|
|
|
pipeline.add_many(&[&source, &sink]).unwrap();
|
|
|
|
source.link(&sink).expect("Elements could not be linked.");
|
|
|
|
|
|
|
|
// Modify the source's properties
|
|
|
|
source.set_property_from_str("pattern", "smpte");
|
|
|
|
|
|
|
|
// Start playing
|
2019-01-08 16:13:37 +00:00
|
|
|
pipeline
|
|
|
|
.set_state(gst::State::Playing)
|
|
|
|
.expect("Unable to set the pipeline to the `Playing` state");
|
2017-09-12 17:24:36 +00:00
|
|
|
|
|
|
|
// Wait until error or EOS
|
|
|
|
let bus = pipeline.get_bus().unwrap();
|
2018-12-27 22:06:03 +00:00
|
|
|
for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
|
2017-09-12 17:24:36 +00:00
|
|
|
use gst::MessageView;
|
|
|
|
match msg.view() {
|
|
|
|
MessageView::Error(err) => {
|
|
|
|
eprintln!(
|
2017-11-16 11:58:56 +00:00
|
|
|
"Error received from element {:?}: {}",
|
2018-01-29 14:26:01 +00:00
|
|
|
err.get_src().map(|s| s.get_path_string()),
|
2017-09-12 17:24:36 +00:00
|
|
|
err.get_error()
|
|
|
|
);
|
|
|
|
eprintln!("Debugging information: {:?}", err.get_debug());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
MessageView::Eos(..) => break,
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
pipeline
|
|
|
|
.set_state(gst::State::Null)
|
|
|
|
.expect("Unable to set the pipeline to the `Null` state");
|
2017-09-12 17:24:36 +00:00
|
|
|
}
|
2017-11-12 13:53:50 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// tutorials_common::run is only required to set up the application environment on macOS
|
|
|
|
// (but not necessary in normal Cocoa applications where this is set up automatically)
|
|
|
|
tutorials_common::run(tutorial_main);
|
|
|
|
}
|