main: add a common init method

Rename the application to gst-pipeline-studio and
add an init method to initialize
gstreamer and x11
This commit is contained in:
Stéphane Cerveau 2021-12-07 12:11:28 +01:00
parent 6397ebff74
commit bc7f4424ca
5 changed files with 49 additions and 9 deletions

11
Cargo.lock generated
View file

@ -344,6 +344,7 @@ dependencies = [
"gtk4", "gtk4",
"log", "log",
"once_cell", "once_cell",
"x11",
"xml-rs", "xml-rs",
] ]
@ -826,6 +827,16 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 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]] [[package]]
name = "xml-rs" name = "xml-rs"
version = "0.8.4" version = "0.8.4"

View file

@ -13,3 +13,4 @@ gstreamer = "0.17"
log = "0.4.11" log = "0.4.11"
once_cell = "1.7.2" once_cell = "1.7.2"
xml-rs = "0.8.4" xml-rs = "0.8.4"
x11 = { version = "2.18", features = ["xlib"] }

32
src/common.rs Normal file
View file

@ -0,0 +1,32 @@
// common.rs
//
// Copyright 2021 Stéphane Cerveau <scerveau@collabora.com>
//
// 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 <http://www.gnu.org/licenses/>.
//
// 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(())
}

View file

@ -20,20 +20,19 @@
#[macro_use] #[macro_use]
mod macros; mod macros;
mod app; mod app;
mod common;
mod graphmanager; mod graphmanager;
mod pipeline; mod pipeline;
mod pluginlist; mod pluginlist;
use gtk::prelude::*; use gtk::prelude::*;
use crate::app::GPSApp; use crate::app::GPSApp;
use crate::common::init;
fn main() { fn main() {
// gio::resources_register_include!("compiled.gresource").unwrap(); // gio::resources_register_include!("compiled.gresource").unwrap();
init().expect("Unable to init app");
let application = gtk::Application::new( let application = gtk::Application::new(Some(common::APPLICATION_NAME), Default::default());
Some("com.github.gtk-rs.examples.menu_bar"),
Default::default(),
);
application.connect_startup(|application| { application.connect_startup(|application| {
GPSApp::on_startup(application); GPSApp::on_startup(application);
}); });

View file

@ -79,16 +79,13 @@ impl PipelineWeak {
#[derive(Debug)] #[derive(Debug)]
pub struct PipelineInner { pub struct PipelineInner {
initialized: bool,
pipeline: RefCell<Option<gst::Pipeline>>, pipeline: RefCell<Option<gst::Pipeline>>,
current_state: Cell<PipelineState>, current_state: Cell<PipelineState>,
} }
impl Pipeline { impl Pipeline {
pub fn new() -> Result<Self, Box<dyn error::Error>> { pub fn new() -> Result<Self, Box<dyn error::Error>> {
gst::init()?;
let pipeline = Pipeline(Rc::new(PipelineInner { let pipeline = Pipeline(Rc::new(PipelineInner {
initialized: true,
pipeline: RefCell::new(None), pipeline: RefCell::new(None),
current_state: Cell::new(PipelineState::Stopped), current_state: Cell::new(PipelineState::Stopped),
})); }));