mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-12-23 08:36:31 +00:00
Simplify player example a bit
This commit is contained in:
parent
d654252e65
commit
4276cb6228
1 changed files with 7 additions and 20 deletions
|
@ -4,12 +4,9 @@ extern crate gstreamer as gst;
|
||||||
extern crate gstreamer_player as gst_player;
|
extern crate gstreamer_player as gst_player;
|
||||||
|
|
||||||
extern crate glib;
|
extern crate glib;
|
||||||
|
#[cfg(feature = "gst-player")]
|
||||||
#[allow(unused_imports)]
|
|
||||||
use glib::ObjectExt;
|
use glib::ObjectExt;
|
||||||
|
|
||||||
extern crate send_cell;
|
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
@ -27,9 +24,7 @@ fn main_loop(uri: &str) -> Result<(), utils::ExampleError> {
|
||||||
.set_property("uri", &glib::Value::from(uri))
|
.set_property("uri", &glib::Value::from(uri))
|
||||||
.expect("Can't set uri property");
|
.expect("Can't set uri property");
|
||||||
|
|
||||||
let result = std::cell::RefCell::new(Some(Ok(())));
|
let error = std::sync::Arc::new(std::sync::Mutex::new(Ok(())));
|
||||||
let error = std::sync::Arc::new(std::sync::Mutex::new(send_cell::SendCell::new(result)));
|
|
||||||
let error_clone = error.clone();
|
|
||||||
|
|
||||||
let player_clone = player.clone();
|
let player_clone = player.clone();
|
||||||
let main_loop_clone = main_loop.clone();
|
let main_loop_clone = main_loop.clone();
|
||||||
|
@ -42,19 +37,18 @@ fn main_loop(uri: &str) -> Result<(), utils::ExampleError> {
|
||||||
|
|
||||||
let player_clone = player.clone();
|
let player_clone = player.clone();
|
||||||
let main_loop_clone = main_loop.clone();
|
let main_loop_clone = main_loop.clone();
|
||||||
|
let error_clone = error.clone();
|
||||||
player.connect_error(move |_, err| {
|
player.connect_error(move |_, err| {
|
||||||
let main_loop = &main_loop_clone;
|
let main_loop = &main_loop_clone;
|
||||||
let player = &player_clone;
|
let player = &player_clone;
|
||||||
|
|
||||||
let error = std::sync::Arc::clone(&error_clone);
|
let error = std::sync::Arc::clone(&error_clone);
|
||||||
let guard = error.lock().unwrap();
|
let mut guard = error.lock().unwrap();
|
||||||
let cell = &*guard;
|
*guard = Err(utils::ExampleError::ElementError(
|
||||||
let refcell = cell.get();
|
|
||||||
*refcell.borrow_mut() = Some(Err(utils::ExampleError::ElementError(
|
|
||||||
"player".to_owned(),
|
"player".to_owned(),
|
||||||
err.clone(),
|
err.clone(),
|
||||||
"".to_owned(),
|
"".to_owned(),
|
||||||
)));
|
));
|
||||||
|
|
||||||
player.stop();
|
player.stop();
|
||||||
main_loop.quit();
|
main_loop.quit();
|
||||||
|
@ -64,15 +58,8 @@ fn main_loop(uri: &str) -> Result<(), utils::ExampleError> {
|
||||||
main_loop.run();
|
main_loop.run();
|
||||||
|
|
||||||
let guard = error.as_ref().lock().unwrap();
|
let guard = error.as_ref().lock().unwrap();
|
||||||
let cell = &*guard;
|
|
||||||
let refcell = cell.get();
|
|
||||||
let result = refcell.borrow();
|
|
||||||
|
|
||||||
if let Some(ref e) = *result {
|
guard.clone()
|
||||||
return e.clone();
|
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "gst-player"))]
|
#[cfg(not(feature = "gst-player"))]
|
||||||
|
|
Loading…
Reference in a new issue