Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added basic-tutorial-2 #33

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions tutorials/src/bin/basic-tutorial-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
extern crate gstreamer as gst;

use gst::prelude::*;

fn main() {
// Initialize GStreamer
gst::init().unwrap();

// Create the elements
let source = gst::ElementFactory::make("videotestsrc", "source")
.expect("Could not create source element.");
let sink = gst::ElementFactory::make("autovideosink", "sink")
.expect("Could not create sink element");

// Create the empty pipeline
let pipeline = gst::Pipeline::new("test-pipeline");

// 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
let ret = pipeline.set_state(gst::State::Playing);
assert_ne!(ret, gst::StateChangeReturn::Failure,
"Unable to set the pipeline to the playing state.");

// Wait until error or EOS
let bus = pipeline.get_bus().unwrap();
while let Some(msg) = bus.timed_pop(gst::CLOCK_TIME_NONE) {
use gst::MessageView;
match msg.view() {
MessageView::Error(err) => {
eprintln!("Error received from element {}: {}",
msg.get_src().get_path_string(), err.get_error());
eprintln!("Debugging information: {:?}", err.get_debug());
},
MessageView::Eos(..) => break,
_ => (),
}
}
}