inspect: Print factory details of an element

Example:

 $ gst-inspect-rs videotestsrc
This commit is contained in:
Fabian Orccon 2023-06-04 13:59:51 +02:00
parent 92bdf9a63c
commit a5c799cf34
2 changed files with 64 additions and 4 deletions

View file

@ -35,6 +35,7 @@ derive_more = "0.99.5"
futures = "0.3" futures = "0.3"
byte-slice-cast = "1" byte-slice-cast = "1"
cairo-rs = { git = "https://github.com/gtk-rs/gtk-rs-core", features=["use_glib"], optional = true } cairo-rs = { git = "https://github.com/gtk-rs/gtk-rs-core", features=["use_glib"], optional = true }
clap = { version = "4.3.0", features = ["derive"] }
pango = { git = "https://github.com/gtk-rs/gtk-rs-core", optional = true } pango = { git = "https://github.com/gtk-rs/gtk-rs-core", optional = true }
pangocairo = { git = "https://github.com/gtk-rs/gtk-rs-core", optional = true } pangocairo = { git = "https://github.com/gtk-rs/gtk-rs-core", optional = true }
glutin = { version = "0.29", optional = true } glutin = { version = "0.29", optional = true }

View file

@ -19,11 +19,14 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
use ansi_term::Color; use ansi_term::Color;
use clap::{Arg, Command};
use gst::prelude::*; use gst::prelude::*;
const BRBLUE: Color = Color::RGB(97, 127, 166); const BRBLUE: Color = Color::RGB(97, 127, 166);
const PLUGIN_NAME_COLOR: Color = BRBLUE; const PLUGIN_NAME_COLOR: Color = BRBLUE;
const ELEMENT_NAME_COLOR: Color = Color::Green; const ELEMENT_NAME_COLOR: Color = Color::Green;
const PROP_NAME_COLOR: Color = BRBLUE;
const HEADING_COLOR: Color = Color::Yellow;
fn print_element_list() { fn print_element_list() {
let registry = gst::Registry::get(); let registry = gst::Registry::get();
@ -47,8 +50,64 @@ fn print_element_list() {
} }
} }
fn main() { fn print_property(name: &str, value: &str) {
gst::init().unwrap(); let formatted_name = format!("{:<25}", name);
println!(" {}{}", PROP_NAME_COLOR.paint(formatted_name), value);
print_element_list(); }
fn print_factory_details_info(factory: &gst::ElementFactory) {
let rank = factory.rank();
println!("{}", HEADING_COLOR.paint("Factory details:"));
print_property("Rank", &format!("{} ({})", rank, i32::from(rank)));
print_property("Long name", factory.longname());
print_property("Klass", factory.klass());
print_property("Description", factory.description());
print_property("Author", factory.author());
}
fn print_element_info(feature: &gst::PluginFeature) -> Result<(), String> {
let Ok(factory) = feature.load() else {
return Err(format!("element factory '{}' couldn't be loaded", feature.name()));
};
let element_factory = factory.downcast_ref::<gst::ElementFactory>().unwrap();
let Ok(element) = element_factory.create_with_name(None) else {
return Err(format!(
"couldn't construct element '{}' for some reason",
feature.name()
));
};
print_factory_details_info(element_factory);
Ok(())
}
fn print_feature_info(feature_name: &str) -> Result<(), String> {
let registry = gst::Registry::get();
let feature = registry.find_feature(feature_name, gst::ElementFactory::static_type());
let Some(feature) = feature else {
return Err(format!("No such element or plugin '{}'", feature_name));
};
print_element_info(&feature)
}
fn main() {
let matches = Command::new("prog")
.arg(Arg::new("ELEMENT-NAME | PLUGIN-NAME"))
.get_matches();
let mut st: i32 = 0;
gst::init().unwrap();
if let Some(fname) = matches.get_one::<String>("ELEMENT-NAME | PLUGIN-NAME") {
if let Err(e) = print_feature_info(fname) {
println!("{}", e);
st = -1;
}
} else {
print_element_list();
}
std::process::exit(st);
} }