diff --git a/Cargo.lock b/Cargo.lock index cddc797..7b4f8d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -505,6 +505,7 @@ name = "gst_pipeline_studio" version = "0.1.0" dependencies = [ "anyhow", + "fragile", "futures-channel", "futures-executor", "gettext-rs", diff --git a/Cargo.toml b/Cargo.toml index 5c192f6..ebeb8f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ serde = "1.0" serde_any = "0.5" simplelog = "0.11.2" futures-channel = "0.3" +fragile = "1.0.0" [dev-dependencies] futures-executor = "0.3" diff --git a/src/app.rs b/src/app.rs index 608025a..12cfb50 100644 --- a/src/app.rs +++ b/src/app.rs @@ -50,7 +50,7 @@ pub struct GPSAppInner { pub window: gtk::ApplicationWindow, pub graphview: RefCell, pub builder: Builder, - pub pipeline: RefCell, + pub player: RefCell, pub plugin_list_initialized: OnceCell, pub signal_handlers: RefCell>, } @@ -106,17 +106,17 @@ impl GPSApp { window.set_application(Some(application)); window.set_title(Some("GStreamer Pipeline Studio")); - let pipeline = GPS::Pipeline::new().expect("Unable to initialize GStreamer subsystem"); + let player = GPS::Player::new().expect("Unable to initialize GStreamer subsystem"); let app = GPSApp(Rc::new(GPSAppInner { window, graphview: RefCell::new(GM::GraphView::new()), builder, - pipeline: RefCell::new(pipeline), + player: RefCell::new(player), plugin_list_initialized: OnceCell::new(), signal_handlers: RefCell::new(HashMap::new()), })); let app_weak = app.downgrade(); - app.pipeline.borrow().set_app(app_weak); + app.player.borrow().set_app(app_weak); app.graphview.borrow_mut().set_id(0); let settings = Settings::load_settings(); @@ -189,10 +189,10 @@ impl GPSApp { .expect("Couldn't get status_bar"); let slider_update_signal_id = slider.connect_value_changed(move |slider| { let app = upgrade_weak!(app_weak); - let pipeline = app.pipeline.borrow(); + let player = app.player.borrow(); let value = slider.value() as u64; GPS_TRACE!("Seeking to {} s", value); - if pipeline.set_position(value).is_err() { + if player.set_position(value).is_err() { GPS_ERROR!("Seeking to {} failed", value); } }); @@ -200,7 +200,7 @@ impl GPSApp { let timeout_id = glib::timeout_add_local(std::time::Duration::from_millis(500), move || { let app = upgrade_weak!(app_weak, glib::Continue(false)); - let pipeline = app.pipeline.borrow(); + let player = app.player.borrow(); let label: gtk::Label = app .builder @@ -210,15 +210,15 @@ impl GPSApp { .builder .object("scale-position") .expect("Couldn't get status_bar"); - let position = pipeline.position(); - let duration = pipeline.duration(); + let position = player.position(); + let duration = player.duration(); slider.set_range(0.0, duration as f64 / 1000_f64); slider.block_signal(&slider_update_signal_id); slider.set_value(position as f64 / 1000_f64); slider.unblock_signal(&slider_update_signal_id); - // Query the current playing position from the underlying pipeline. - let position_desc = pipeline.position_description(); + // Query the current playing position from the underlying player. + let position_desc = player.position_description(); // Display the playing position in the gui. label.set_text(&position_desc); // Tell the callback to continue calling this closure. @@ -538,7 +538,7 @@ impl GPSApp { let app = upgrade_weak!(app_weak); let graph_view = app.graphview.borrow(); let _ = app - .pipeline + .player .borrow() .start_pipeline(&graph_view, GPS::PipelineState::Playing); }); @@ -548,7 +548,7 @@ impl GPSApp { let app = upgrade_weak!(app_weak); let graph_view = app.graphview.borrow(); let _ = app - .pipeline + .player .borrow() .start_pipeline(&graph_view, GPS::PipelineState::Paused); }); @@ -556,8 +556,8 @@ impl GPSApp { let app_weak = self.downgrade(); self.connect_button_action("button-stop", move |_| { let app = upgrade_weak!(app_weak); - let pipeline = app.pipeline.borrow(); - let _ = pipeline.set_state(GPS::PipelineState::Stopped); + let player = app.player.borrow(); + let _ = player.set_state(GPS::PipelineState::Stopped); }); let app_weak = self.downgrade(); @@ -647,8 +647,8 @@ impl GPSApp { app.connect_app_menu_action("graph.check", move |_,_| { let app = upgrade_weak!(app_weak); - let render_parse_launch = app.pipeline.borrow().render_gst_launch(&app.graphview.borrow()); - if app.pipeline.borrow().create_pipeline(&render_parse_launch).is_ok() { + let render_parse_launch = app.player.borrow().render_gst_launch(&app.graphview.borrow()); + if app.player.borrow().create_pipeline(&render_parse_launch).is_ok() { GPSUI::message::display_message_dialog(&render_parse_launch,gtk::MessageType::Info, |_| {}); } else { GPSUI::message::display_error_dialog(false, &format!("Unable to render:\n\n{}", render_parse_launch)); diff --git a/src/gps/mod.rs b/src/gps/mod.rs index 8fc5585..cdb7150 100644 --- a/src/gps/mod.rs +++ b/src/gps/mod.rs @@ -1,7 +1,7 @@ mod element; mod pad; -mod pipeline; +mod player; pub use element::ElementInfo; pub use pad::PadInfo; -pub use pipeline::{Pipeline, PipelineState}; +pub use player::{PipelineState, Player}; diff --git a/src/gps/pipeline.rs b/src/gps/player.rs similarity index 94% rename from src/gps/pipeline.rs rename to src/gps/player.rs index e076b1b..0b6b838 100644 --- a/src/gps/pipeline.rs +++ b/src/gps/player.rs @@ -1,4 +1,4 @@ -// pipeline.rs +// player.rs // // Copyright 2021 Stéphane Cerveau // @@ -49,39 +49,41 @@ impl fmt::Display for PipelineState { } #[derive(Debug, Clone)] -pub struct Pipeline(Rc); +pub struct Player(Rc); // Deref into the contained struct to make usage a bit more ergonomic -impl ops::Deref for Pipeline { - type Target = PipelineInner; +impl ops::Deref for Player { + type Target = PlayerInner; - fn deref(&self) -> &PipelineInner { + fn deref(&self) -> &PlayerInner { &*self.0 } } #[derive(Debug, Clone)] -pub struct PipelineWeak(Weak); +pub struct PlayerWeak(Weak); -impl PipelineWeak { - pub fn upgrade(&self) -> Option { - self.0.upgrade().map(Pipeline) +impl PlayerWeak { + pub fn upgrade(&self) -> Option { + self.0.upgrade().map(Player) } } #[derive(Debug)] -pub struct PipelineInner { +pub struct PlayerInner { app: RefCell>, pipeline: RefCell>, current_state: Cell, + n_video_sink: Cell, } -impl Pipeline { +impl Player { pub fn new() -> anyhow::Result { - let pipeline = Pipeline(Rc::new(PipelineInner { + let pipeline = Player(Rc::new(PlayerInner { app: RefCell::new(None), pipeline: RefCell::new(None), current_state: Cell::new(PipelineState::Stopped), + n_video_sink: Cell::new(0), })); #[cfg(feature = "gtk4-plugin")] { @@ -120,6 +122,7 @@ impl Pipeline { "Unable to create a pipeline from the given parse launch {" )); } + Ok(pipeline.unwrap()) } @@ -185,7 +188,7 @@ impl Pipeline { .borrow() .as_ref() .expect("App should be available") - .set_app_state(Pipeline::state_to_app_state(new_state)); + .set_app_state(Player::state_to_app_state(new_state)); } Ok(new_state) } @@ -243,8 +246,8 @@ impl Pipeline { } } - pub fn downgrade(&self) -> PipelineWeak { - PipelineWeak(Rc::downgrade(&self.0)) + pub fn downgrade(&self) -> PlayerWeak { + PlayerWeak(Rc::downgrade(&self.0)) } fn on_pipeline_message(&self, msg: &gst::MessageRef) { @@ -335,7 +338,7 @@ impl Pipeline { } } -impl Drop for PipelineInner { +impl Drop for PlayerInner { fn drop(&mut self) { // TODO: If a recording is currently running we would like to finish that first // before quitting the pipeline and shutting down the pipeline. diff --git a/src/meson.build b/src/meson.build index 8c63db6..72e75dd 100644 --- a/src/meson.build +++ b/src/meson.build @@ -17,7 +17,7 @@ run_command( ) rust_sources = files( - 'gps/pipeline.rs', + 'gps/player.rs', 'gps/element.rs', 'gps/pad.rs', 'gps/mod.rs',