From 859f9367968b02afe1d1085fa1281c051a9128c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Wed, 17 Nov 2021 16:15:16 +0100 Subject: [PATCH] GPS: add GStreamer support Can now get the GStreamer element's list from the registry. --- Cargo.lock | 310 ++++++++++++++++++++++++++++++++++++++++------ Cargo.toml | 1 + src/main.rs | 2 +- src/mainwindow.rs | 3 + src/pipeline.rs | 77 ++++++++++++ 5 files changed, 353 insertions(+), 40 deletions(-) create mode 100644 src/pipeline.rs diff --git a/Cargo.lock b/Cargo.lock index 6868766..aefeec5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,7 +16,7 @@ checksum = "a83b21d2aa75e464db56225e1bda2dd5993311ba1095acaa8fa03d1ae67026ba" dependencies = [ "atk-sys", "bitflags", - "glib", + "glib 0.14.8", "libc", ] @@ -26,10 +26,10 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "badcf670157c84bb8b1cf6b5f70b650fed78da2033c9eed84c4e49b11cbe83ea" dependencies = [ - "glib-sys", - "gobject-sys", + "glib-sys 0.14.0", + "gobject-sys 0.14.0", "libc", - "system-deps", + "system-deps 3.2.0", ] [[package]] @@ -52,7 +52,7 @@ checksum = "9164355c892b026d6257e696dde5f3cb39beb3718297f0f161b562fe2ee3ab86" dependencies = [ "bitflags", "cairo-sys-rs", - "glib", + "glib 0.14.8", "libc", "thiserror", ] @@ -63,9 +63,9 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7c9c3928781e8a017ece15eace05230f04b647457d170d2d9641c94a444ff80" dependencies = [ - "glib-sys", + "glib-sys 0.14.0", "libc", - "system-deps", + "system-deps 3.2.0", ] [[package]] @@ -77,6 +77,12 @@ dependencies = [ "smallvec", ] +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "either" version = "1.6.1" @@ -125,6 +131,19 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" +[[package]] +name = "futures-macro" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18e4a4b95cea4b4ccbcf1c5675ca7c4ee4e9e75eb79944d07defde18068f79bb" +dependencies = [ + "autocfg", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "futures-task" version = "0.3.17" @@ -139,9 +158,12 @@ checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" dependencies = [ "autocfg", "futures-core", + "futures-macro", "futures-task", "pin-project-lite", "pin-utils", + "proc-macro-hack", + "proc-macro-nested", "slab", ] @@ -156,7 +178,7 @@ dependencies = [ "gdk-pixbuf", "gdk-sys", "gio", - "glib", + "glib 0.14.8", "libc", "pango", ] @@ -169,7 +191,7 @@ checksum = "534192cb8f01daeb8fab2c8d4baa8f9aae5b7a39130525779f5c2608e235b10f" dependencies = [ "gdk-pixbuf-sys", "gio", - "glib", + "glib 0.14.8", "libc", ] @@ -180,10 +202,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f097c0704201fbc8f69c1762dc58c6947c8bb188b8ed0bc7e65259f1894fe590" dependencies = [ "gio-sys", - "glib-sys", - "gobject-sys", + "glib-sys 0.14.0", + "gobject-sys 0.14.0", "libc", - "system-deps", + "system-deps 3.2.0", ] [[package]] @@ -195,12 +217,12 @@ dependencies = [ "cairo-sys-rs", "gdk-pixbuf-sys", "gio-sys", - "glib-sys", - "gobject-sys", + "glib-sys 0.14.0", + "gobject-sys 0.14.0", "libc", "pango-sys", "pkg-config", - "system-deps", + "system-deps 3.2.0", ] [[package]] @@ -214,7 +236,7 @@ dependencies = [ "futures-core", "futures-io", "gio-sys", - "glib", + "glib 0.14.8", "libc", "once_cell", "thiserror", @@ -226,13 +248,32 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0a41df66e57fcc287c4bcf74fc26b884f31901ea9792ec75607289b456f48fa" dependencies = [ - "glib-sys", - "gobject-sys", + "glib-sys 0.14.0", + "gobject-sys 0.14.0", "libc", - "system-deps", + "system-deps 3.2.0", "winapi", ] +[[package]] +name = "glib" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c685013b7515e668f1b57a165b009d4d28cb139a8a989bbd699c10dad29d0c5" +dependencies = [ + "bitflags", + "futures-channel", + "futures-core", + "futures-executor", + "futures-task", + "futures-util", + "glib-macros 0.10.1", + "glib-sys 0.10.1", + "gobject-sys 0.10.0", + "libc", + "once_cell", +] + [[package]] name = "glib" version = "0.14.8" @@ -244,14 +285,30 @@ dependencies = [ "futures-core", "futures-executor", "futures-task", - "glib-macros", - "glib-sys", - "gobject-sys", + "glib-macros 0.14.1", + "glib-sys 0.14.0", + "gobject-sys 0.14.0", "libc", "once_cell", "smallvec", ] +[[package]] +name = "glib-macros" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41486a26d1366a8032b160b59065a59fb528530a46a49f627e7048fb8c064039" +dependencies = [ + "anyhow", + "heck", + "itertools 0.9.0", + "proc-macro-crate 0.1.5", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "glib-macros" version = "0.14.1" @@ -260,13 +317,23 @@ checksum = "2aad66361f66796bfc73f530c51ef123970eb895ffba991a234fcf7bea89e518" dependencies = [ "anyhow", "heck", - "proc-macro-crate", + "proc-macro-crate 1.1.0", "proc-macro-error", "proc-macro2", "quote", "syn", ] +[[package]] +name = "glib-sys" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7e9b997a66e9a23d073f2b1abb4dbfc3925e0b8952f67efd8d9b6e168e4cdc1" +dependencies = [ + "libc", + "system-deps 1.3.2", +] + [[package]] name = "glib-sys" version = "0.14.0" @@ -274,7 +341,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c1d60554a212445e2a858e42a0e48cece1bd57b311a19a9468f70376cf554ae" dependencies = [ "libc", - "system-deps", + "system-deps 3.2.0", +] + +[[package]] +name = "gobject-sys" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "952133b60c318a62bf82ee75b93acc7e84028a093e06b9e27981c2b6fe68218c" +dependencies = [ + "glib-sys 0.10.1", + "libc", + "system-deps 1.3.2", ] [[package]] @@ -283,9 +361,9 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa92cae29759dae34ab5921d73fff5ad54b3d794ab842c117e36cafc7994c3f5" dependencies = [ - "glib-sys", + "glib-sys 0.14.0", "libc", - "system-deps", + "system-deps 3.2.0", ] [[package]] @@ -293,9 +371,46 @@ name = "gst_pipeline_studio" version = "0.1.0" dependencies = [ "anyhow", + "gstreamer", "gtk", ] +[[package]] +name = "gstreamer" +version = "0.16.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ff5d0f7ff308ae37e6eb47b6ded17785bdea06e438a708cd09e0288c1862f33" +dependencies = [ + "bitflags", + "cfg-if", + "futures-channel", + "futures-core", + "futures-util", + "glib 0.10.3", + "glib-sys 0.10.1", + "gobject-sys 0.10.0", + "gstreamer-sys", + "libc", + "muldiv", + "num-rational", + "once_cell", + "paste", + "pretty-hex", + "thiserror", +] + +[[package]] +name = "gstreamer-sys" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc1f154082d01af5718c5f8a8eb4f565a4ea5586ad8833a8fc2c2aa6844b601d" +dependencies = [ + "glib-sys 0.10.1", + "gobject-sys 0.10.0", + "libc", + "system-deps 1.3.2", +] + [[package]] name = "gtk" version = "0.14.3" @@ -310,7 +425,7 @@ dependencies = [ "gdk", "gdk-pixbuf", "gio", - "glib", + "glib 0.14.8", "gtk-sys", "gtk3-macros", "libc", @@ -330,11 +445,11 @@ dependencies = [ "gdk-pixbuf-sys", "gdk-sys", "gio-sys", - "glib-sys", - "gobject-sys", + "glib-sys 0.14.0", + "gobject-sys 0.14.0", "libc", "pango-sys", - "system-deps", + "system-deps 3.2.0", ] [[package]] @@ -345,7 +460,7 @@ checksum = "21de1da96dc117443fb03c2e270b2d34b7de98d0a79a19bbb689476173745b79" dependencies = [ "anyhow", "heck", - "proc-macro-crate", + "proc-macro-crate 1.1.0", "proc-macro-error", "proc-macro2", "quote", @@ -361,6 +476,15 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "itertools" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.10.1" @@ -385,6 +509,42 @@ dependencies = [ "autocfg", ] +[[package]] +name = "muldiv" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0419348c027fa7be448d2ae7ea0e4e04c2334c31dc4e74ab29f00a2a7ca69204" + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + [[package]] name = "once_cell" version = "1.8.0" @@ -398,7 +558,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "546fd59801e5ca735af82839007edd226fe7d3bb06433ec48072be4439c28581" dependencies = [ "bitflags", - "glib", + "glib 0.14.8", "libc", "once_cell", "pango-sys", @@ -410,12 +570,18 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2367099ca5e761546ba1d501955079f097caa186bb53ce0f718dca99ac1942fe" dependencies = [ - "glib-sys", - "gobject-sys", + "glib-sys 0.14.0", + "gobject-sys 0.14.0", "libc", - "system-deps", + "system-deps 3.2.0", ] +[[package]] +name = "paste" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0744126afe1a6dd7f394cb50a716dbe086cb06e255e53d8d0185d82828358fb5" + [[package]] name = "pest" version = "2.1.3" @@ -443,6 +609,21 @@ version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c9b1041b4387893b91ee6746cddfc28516aff326a3519fb2adf820932c5e6cb" +[[package]] +name = "pretty-hex" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5c99d529f0d30937f6f4b8a86d988047327bb88d04d2c4afc356de74722131" + +[[package]] +name = "proc-macro-crate" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" +dependencies = [ + "toml", +] + [[package]] name = "proc-macro-crate" version = "1.1.0" @@ -477,6 +658,18 @@ dependencies = [ "version_check", ] +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "proc-macro-nested" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" + [[package]] name = "proc-macro2" version = "1.0.30" @@ -540,12 +733,30 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" +[[package]] +name = "strum" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57bd81eb48f4c437cadc685403cad539345bf703d78e63707418431cecd4522b" + [[package]] name = "strum" version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aaf86bbcfd1fa9670b7a129f64fc0c9fcbbfe4f1bc4210e9e98fe71ffc12cde2" +[[package]] +name = "strum_macros" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87c85aa3f8ea653bfd3ddf25f7ee357ee4d204731f6aa9ad04002306f6e2774c" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "strum_macros" version = "0.21.1" @@ -569,6 +780,21 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "system-deps" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3ecc17269a19353b3558b313bba738b25d82993e30d62a18406a24aba4649b" +dependencies = [ + "heck", + "pkg-config", + "strum 0.18.0", + "strum_macros 0.18.0", + "thiserror", + "toml", + "version-compare 0.0.10", +] + [[package]] name = "system-deps" version = "3.2.0" @@ -578,13 +804,13 @@ dependencies = [ "anyhow", "cfg-expr", "heck", - "itertools", + "itertools 0.10.1", "pkg-config", - "strum", - "strum_macros", + "strum 0.21.0", + "strum_macros 0.21.1", "thiserror", "toml", - "version-compare", + "version-compare 0.0.11", ] [[package]] @@ -634,6 +860,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +[[package]] +name = "version-compare" +version = "0.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d63556a25bae6ea31b52e640d7c41d1ab27faba4ccb600013837a3d0b3994ca1" + [[package]] name = "version-compare" version = "0.0.11" diff --git a/Cargo.toml b/Cargo.toml index 23d532c..7ce9952 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,4 @@ edition = "2018" [dependencies] gtk = "0.14.3" anyhow = "1" +gstreamer = "0.16" diff --git a/src/main.rs b/src/main.rs index 9066ff9..46e98ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ // // SPDX-License-Identifier: GPL-3.0-only mod mainwindow; - +mod pipeline; use gtk::prelude::*; fn main() { diff --git a/src/mainwindow.rs b/src/mainwindow.rs index da53b9f..7dd3571 100644 --- a/src/mainwindow.rs +++ b/src/mainwindow.rs @@ -8,6 +8,7 @@ use gtk::{ use std::cell::RefCell; use std::rc::Rc; +use crate::pipeline::Pipeline; #[derive(Debug, Clone, Default)] struct Element { name: String, @@ -72,6 +73,8 @@ pub fn build_ui(application: >k::Application) { .expect("Couldn't get window"); add_button.connect_clicked(glib::clone!(@weak window => move |_| { // entry.set_text("Clicked!"); + let pipeline = Pipeline::new(); + Pipeline::get_elements_list().expect("cocuou"); add_dialog.connect_response(|dialog, _| dialog.close()); add_dialog.show_all(); })); diff --git a/src/pipeline.rs b/src/pipeline.rs new file mode 100644 index 0000000..daaa67d --- /dev/null +++ b/src/pipeline.rs @@ -0,0 +1,77 @@ +// pipeline.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 gst::prelude::*; +use gstreamer as gst; +use std::error; + +#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)] +pub struct ElementInfo { + pub name: Option, + plugin_name: Option, + rank: i32, +} + +impl Default for ElementInfo { + fn default() -> ElementInfo { + ElementInfo { + name: None, + plugin_name: None, + rank: -1, + } + } +} + +pub struct Pipeline { + initialized: bool, +} + +impl Default for Pipeline { + fn default() -> Pipeline { + Pipeline { initialized: false } + } +} + +impl Pipeline { + pub fn new() -> Result> { + gst::init()?; + Ok(Self { initialized: true }) + } + + pub fn elements_list() -> Result, Box> { + let registry = gst::Registry::get(); + let mut elements: Vec = Vec::new(); + let plugins = gst::Registry::get_plugin_list(®istry); + for plugin in plugins { + let plugin_name = gst::Plugin::get_plugin_name(&plugin); + let features = gst::Registry::get_feature_list_by_plugin(®istry, &plugin_name); + for feature in features { + let mut element = ElementInfo::default(); + if let Ok(factory) = feature.downcast::() { + let feature = factory.upcast::(); + + element.name = Some(gst::PluginFeature::get_name(&feature).as_str().to_owned()); + element.plugin_name = + Some(gst::Plugin::get_plugin_name(&plugin).as_str().to_owned()); + elements.push(element); + } + } + } + Ok(elements) + } +}