2017-08-17 15:07:48 +00:00
|
|
|
#[cfg(feature = "gtksink")]
|
2017-07-31 11:09:59 +00:00
|
|
|
extern crate gstreamer as gst;
|
2017-08-17 15:07:48 +00:00
|
|
|
#[cfg(feature = "gtksink")]
|
2017-08-17 14:58:15 +00:00
|
|
|
use gst::prelude::*;
|
2017-07-31 11:09:59 +00:00
|
|
|
|
2017-08-17 15:07:48 +00:00
|
|
|
#[cfg(feature = "gtksink")]
|
2017-07-31 11:09:59 +00:00
|
|
|
extern crate glib;
|
|
|
|
|
2017-08-17 15:07:48 +00:00
|
|
|
#[cfg(feature = "gtksink")]
|
2017-08-04 14:41:21 +00:00
|
|
|
extern crate gio;
|
2017-08-17 15:07:48 +00:00
|
|
|
#[cfg(feature = "gtksink")]
|
2017-08-17 14:58:15 +00:00
|
|
|
use gio::prelude::*;
|
2017-08-04 14:41:21 +00:00
|
|
|
|
2017-08-17 15:07:48 +00:00
|
|
|
#[cfg(feature = "gtksink")]
|
2017-07-31 11:09:59 +00:00
|
|
|
extern crate gtk;
|
2017-08-17 15:07:48 +00:00
|
|
|
#[cfg(feature = "gtksink")]
|
2017-07-31 11:09:59 +00:00
|
|
|
use gtk::prelude::*;
|
|
|
|
|
2017-08-17 15:07:48 +00:00
|
|
|
#[cfg(feature = "gtksink")]
|
2017-08-04 14:41:21 +00:00
|
|
|
use std::env;
|
|
|
|
|
2017-08-17 15:07:48 +00:00
|
|
|
#[cfg(feature = "gtksink")]
|
2017-08-04 19:57:12 +00:00
|
|
|
extern crate send_cell;
|
2017-08-17 15:07:48 +00:00
|
|
|
#[cfg(feature = "gtksink")]
|
2017-08-04 19:57:12 +00:00
|
|
|
use send_cell::SendCell;
|
|
|
|
|
2017-08-17 15:07:48 +00:00
|
|
|
#[cfg(feature = "gtksink")]
|
2017-08-04 14:41:21 +00:00
|
|
|
fn create_ui(app: >k::Application) {
|
2017-08-17 14:58:15 +00:00
|
|
|
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();
|
2017-07-31 11:16:42 +00:00
|
|
|
glsinkbin
|
|
|
|
.set_property("sink", >kglsink.to_value())
|
|
|
|
.unwrap();
|
2017-07-31 11:09:59 +00:00
|
|
|
|
|
|
|
let widget = gtkglsink.get_property("widget").unwrap();
|
|
|
|
(glsinkbin, widget.get::<gtk::Widget>().unwrap())
|
|
|
|
} else {
|
2017-08-17 14:58:15 +00:00
|
|
|
let sink = gst::ElementFactory::make("gtksink", None).unwrap();
|
2017-07-31 11:09:59 +00:00
|
|
|
let widget = sink.get_property("widget").unwrap();
|
|
|
|
(sink, widget.get::<gtk::Widget>().unwrap())
|
|
|
|
};
|
|
|
|
|
|
|
|
pipeline.add_many(&[&src, &sink]).unwrap();
|
|
|
|
src.link(&sink).unwrap();
|
|
|
|
|
2017-08-07 11:18:24 +00:00
|
|
|
let window = gtk::Window::new(gtk::WindowType::Toplevel);
|
2017-07-31 11:09:59 +00:00
|
|
|
window.set_default_size(320, 240);
|
|
|
|
let vbox = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
|
|
|
vbox.pack_start(&widget, true, true, 0);
|
|
|
|
let label = gtk::Label::new("Position: 00:00:00");
|
|
|
|
vbox.pack_start(&label, true, true, 5);
|
|
|
|
window.add(&vbox);
|
|
|
|
window.show_all();
|
|
|
|
|
2017-08-04 14:41:21 +00:00
|
|
|
app.add_window(&window);
|
|
|
|
|
2017-07-31 11:09:59 +00:00
|
|
|
let pipeline_clone = pipeline.clone();
|
|
|
|
gtk::timeout_add(500, move || {
|
|
|
|
let pipeline = &pipeline_clone;
|
2017-12-09 16:20:21 +00:00
|
|
|
let position = pipeline
|
|
|
|
.query_position::<gst::ClockTime>()
|
2017-12-20 19:46:58 +00:00
|
|
|
.unwrap_or_else(|| 0.into());
|
2017-11-11 10:21:55 +00:00
|
|
|
label.set_text(&format!("Position: {:.0}", position));
|
2017-07-31 11:09:59 +00:00
|
|
|
|
|
|
|
glib::Continue(true)
|
|
|
|
});
|
|
|
|
|
2017-08-04 14:41:21 +00:00
|
|
|
let app_clone = app.clone();
|
|
|
|
window.connect_delete_event(move |_, _| {
|
|
|
|
let app = &app_clone;
|
|
|
|
app.quit();
|
2017-07-31 11:09:59 +00:00
|
|
|
Inhibit(false)
|
|
|
|
});
|
|
|
|
|
|
|
|
let bus = pipeline.get_bus().unwrap();
|
|
|
|
|
|
|
|
let ret = pipeline.set_state(gst::State::Playing);
|
|
|
|
assert_ne!(ret, gst::StateChangeReturn::Failure);
|
|
|
|
|
2017-08-04 14:41:21 +00:00
|
|
|
let app_clone = SendCell::new(app.clone());
|
2017-07-31 11:09:59 +00:00
|
|
|
bus.add_watch(move |_, msg| {
|
2017-08-17 14:58:15 +00:00
|
|
|
use gst::MessageView;
|
|
|
|
|
2017-08-04 16:56:13 +00:00
|
|
|
let app = app_clone.borrow();
|
2017-07-31 11:09:59 +00:00
|
|
|
match msg.view() {
|
|
|
|
MessageView::Eos(..) => gtk::main_quit(),
|
|
|
|
MessageView::Error(err) => {
|
|
|
|
println!(
|
2017-11-16 11:58:56 +00:00
|
|
|
"Error from {:?}: {} ({:?})",
|
|
|
|
msg.get_src().map(|s| s.get_path_string()),
|
2017-07-31 11:09:59 +00:00
|
|
|
err.get_error(),
|
|
|
|
err.get_debug()
|
|
|
|
);
|
2017-08-04 16:56:13 +00:00
|
|
|
app.quit();
|
2017-07-31 11:09:59 +00:00
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
};
|
|
|
|
|
|
|
|
glib::Continue(true)
|
|
|
|
});
|
|
|
|
|
2017-08-04 14:41:21 +00:00
|
|
|
let pipeline_clone = pipeline.clone();
|
|
|
|
app.connect_shutdown(move |_| {
|
|
|
|
let pipeline = &pipeline_clone;
|
|
|
|
let ret = pipeline.set_state(gst::State::Null);
|
|
|
|
assert_ne!(ret, gst::StateChangeReturn::Failure);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-17 15:07:48 +00:00
|
|
|
#[cfg(feature = "gtksink")]
|
2017-08-04 14:41:21 +00:00
|
|
|
fn main() {
|
|
|
|
gst::init().unwrap();
|
|
|
|
gtk::init().unwrap();
|
|
|
|
|
2017-10-01 14:18:16 +00:00
|
|
|
let app = gtk::Application::new(None, gio::ApplicationFlags::FLAGS_NONE).unwrap();
|
2017-07-31 11:09:59 +00:00
|
|
|
|
2017-08-04 14:41:21 +00:00
|
|
|
app.connect_activate(create_ui);
|
|
|
|
let args = env::args().collect::<Vec<_>>();
|
2017-09-26 07:41:03 +00:00
|
|
|
app.run(&args);
|
2017-07-31 11:09:59 +00:00
|
|
|
}
|
2017-08-17 15:07:48 +00:00
|
|
|
|
|
|
|
#[cfg(not(feature = "gtksink"))]
|
|
|
|
fn main() {
|
|
|
|
println!("Please compile with --feature gtksink");
|
|
|
|
}
|