diff --git a/Cargo.lock b/Cargo.lock index 2fbf29f..876728a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -344,6 +344,7 @@ dependencies = [ "gtk4", "log", "once_cell", + "x11", "xml-rs", ] @@ -826,6 +827,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "x11" +version = "2.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dd0565fa8bfba8c5efe02725b14dff114c866724eff2cfd44d76cea74bcd87a" +dependencies = [ + "libc", + "pkg-config", +] + [[package]] name = "xml-rs" version = "0.8.4" diff --git a/Cargo.toml b/Cargo.toml index 09d3a7b..393eb22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,3 +13,4 @@ gstreamer = "0.17" log = "0.4.11" once_cell = "1.7.2" xml-rs = "0.8.4" +x11 = { version = "2.18", features = ["xlib"] } diff --git a/src/common.rs b/src/common.rs new file mode 100644 index 0000000..b9ddee7 --- /dev/null +++ b/src/common.rs @@ -0,0 +1,32 @@ +// common.rs +// +// Copyright 2021 Stéphane Cerveau +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// SPDX-License-Identifier: GPL-3.0-only + +use anyhow::Result; +use gstreamer as gst; + +pub const APPLICATION_NAME: &str = "org.freedesktop.gst-pipeline-studio"; + +pub fn init() -> Result<()> { + unsafe { + x11::xlib::XInitThreads(); + } + gst::init()?; + gtk::init()?; + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index dcdf771..e4fa405 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,20 +20,19 @@ #[macro_use] mod macros; mod app; +mod common; mod graphmanager; mod pipeline; mod pluginlist; - use gtk::prelude::*; use crate::app::GPSApp; +use crate::common::init; + fn main() { // gio::resources_register_include!("compiled.gresource").unwrap(); - - let application = gtk::Application::new( - Some("com.github.gtk-rs.examples.menu_bar"), - Default::default(), - ); + init().expect("Unable to init app"); + let application = gtk::Application::new(Some(common::APPLICATION_NAME), Default::default()); application.connect_startup(|application| { GPSApp::on_startup(application); }); diff --git a/src/pipeline.rs b/src/pipeline.rs index 42fcdc8..90ef7c7 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -79,16 +79,13 @@ impl PipelineWeak { #[derive(Debug)] pub struct PipelineInner { - initialized: bool, pipeline: RefCell>, current_state: Cell, } impl Pipeline { pub fn new() -> Result> { - gst::init()?; let pipeline = Pipeline(Rc::new(PipelineInner { - initialized: true, pipeline: RefCell::new(None), current_state: Cell::new(PipelineState::Stopped), }));