From ee6b57dfaef1684f768a8bc535f932ee019f4cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Wed, 15 Dec 2021 13:25:13 +0100 Subject: [PATCH] pipeline: move render_gst to this module Remove render_gst from graphview and define it in pipeline. This will allow to isolate properly the graphmanager module. --- TODO.md | 3 ++- src/app.rs | 16 ++++++++++++-- src/graphmanager/graphview.rs | 40 ---------------------------------- src/pipeline.rs | 41 ++++++++++++++++++++++++++++++++++- 4 files changed, 56 insertions(+), 44 deletions(-) diff --git a/TODO.md b/TODO.md index 136b2e1..3b82bff 100644 --- a/TODO.md +++ b/TODO.md @@ -28,7 +28,7 @@ TODO: ## bugs -- [] crash with x11 on contextual menu +- [x] crash with x11 on contextual menu - [] check that element exists before creating it on file load. - [] open multiple times dialog (About) prevent to close it. @@ -36,3 +36,4 @@ TODO: [] remove useless code from graphview [] Move render to a specific module +[x] Move GST render to a specific module diff --git a/src/app.rs b/src/app.rs index 59cbad0..38cd4de 100644 --- a/src/app.rs +++ b/src/app.rs @@ -302,7 +302,13 @@ impl GPSApp { let graph_view = app.graphview.borrow(); let pipeline = app.pipeline.borrow(); if pipeline.state() == PipelineState::Stopped { - pipeline.create_pipeline(&graph_view.render_gst()).expect("Unable to create the pipeline"); + if let Err(err) = pipeline.create_pipeline(&pipeline.render_gst_launch(&graph_view)) { + GPSApp::show_error_dialog( + false, + format!("Unable to start a pipeline: {}", err) + .as_str(), + ); + } pipeline.set_state(PipelineState::Playing).expect("Unable to change state"); } else if pipeline.state() == PipelineState::Paused { pipeline.set_state(PipelineState::Playing).expect("Unable to change state"); @@ -320,7 +326,13 @@ impl GPSApp { let graph_view = app.graphview.borrow(); let pipeline = app.pipeline.borrow(); if pipeline.state() == PipelineState::Stopped { - pipeline.create_pipeline(&graph_view.render_gst()).expect("Unable to create the pipeline"); + if let Err(err) = pipeline.create_pipeline(&pipeline.render_gst_launch(&graph_view)) { + GPSApp::show_error_dialog( + false, + format!("Unable to start a pipeline: {}", err) + .as_str(), + ); + } pipeline.set_state(PipelineState::Paused).expect("Unable to change state"); } else if pipeline.state() == PipelineState::Paused { pipeline.set_state(PipelineState::Playing).expect("Unable to change state"); diff --git a/src/graphmanager/graphview.rs b/src/graphmanager/graphview.rs index 5475c76..27ebb68 100644 --- a/src/graphmanager/graphview.rs +++ b/src/graphmanager/graphview.rs @@ -733,36 +733,6 @@ impl GraphView { None } - // * filesrc location=obama_last_speech.mp4 ! decodebin name=bin bin. ! audioconvert ! audioresample ! autoaudiosink bin. ! autovideosink - - // Render graph methods - //TO BE MOVED - pub fn process_node(&self, node: &Node, mut description: String) -> String { - let private = imp::GraphView::from_instance(self); - let unique_name = node.unique_name(); - description.push_str(&format!("{} name={}", node.name(), unique_name)); - for (name, value) in node.properties().iter() { - description.push_str(&format!(" {}={}", name, value)); - } - println!("{}", description); - - let ports = node.all_ports(PortDirection::Output); - let n_ports = ports.len(); - for port in ports { - if let Some((_port_to, node_to)) = self.port_connected_to(port.id()) { - if n_ports > 1 { - description.push_str(&format!(" {}. ! ", unique_name)); - } else { - description.push_str(" ! "); - } - if let Some(node) = private.nodes.borrow().get(&node_to) { - description = self.process_node(node, description.clone()); - } - } - } - description - } - pub fn unselect_all(&self) { self.unselect_nodes(); self.unselect_links(); @@ -792,16 +762,6 @@ impl GraphView { self.queue_draw(); } - //TO BE MOVED - pub fn render_gst(&self) -> String { - let nodes = self.all_nodes(NodeType::Source); - let mut description = String::from(""); - for node in nodes { - description = self.process_node(&node, description.clone()); - } - description - } - pub fn render_xml(&self, filename: &str) -> anyhow::Result<(), Box> { let mut file = File::create(filename).unwrap(); let mut writer = EmitterConfig::new() diff --git a/src/pipeline.rs b/src/pipeline.rs index 13744d3..fbffacb 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -17,7 +17,7 @@ // // SPDX-License-Identifier: GPL-3.0-only use crate::app::GPSApp; -use crate::graphmanager::NodeType; +use crate::graphmanager::{GraphView, Node, NodeType, PortDirection}; use gst::prelude::*; use gstreamer as gst; use std::cell::{Cell, RefCell}; @@ -363,6 +363,45 @@ impl Pipeline { Err(_e) => false, } } + + // Render graph methods + pub fn process_node( + &self, + graphview: &GraphView, + node: &Node, + mut description: String, + ) -> String { + let unique_name = node.unique_name(); + description.push_str(&format!("{} name={}", node.name(), unique_name)); + for (name, value) in node.properties().iter() { + description.push_str(&format!(" {}={}", name, value)); + } + + let ports = node.all_ports(PortDirection::Output); + let n_ports = ports.len(); + for port in ports { + if let Some((_port_to, node_to)) = graphview.port_connected_to(port.id()) { + if n_ports > 1 { + description.push_str(&format!(" {}. ! ", unique_name)); + } else { + description.push_str(" ! "); + } + if let Some(node) = graphview.node(&node_to) { + description = self.process_node(graphview, &node, description.clone()); + } + } + } + description + } + + pub fn render_gst_launch(&self, graphview: &GraphView) -> String { + let nodes = graphview.all_nodes(NodeType::Source); + let mut description = String::from(""); + for node in nodes { + description = self.process_node(graphview, &node, description.clone()); + } + description + } } impl Drop for PipelineInner {