inspect: Print element clocking and uri handling capabilities

Example:

 $ gst-inspect-rs identity # For clocking capabilities
 $ gst-inspect-rs rtspsrc  # For URI handling capabilities
This commit is contained in:
Fabian Orccon 2023-06-10 20:42:39 +02:00
parent 861943d047
commit af50051806

View file

@ -26,6 +26,7 @@ const BRBLUE: Color = Color::RGB(97, 127, 166);
const PLUGIN_NAME_COLOR: Color = BRBLUE;
const ELEMENT_NAME_COLOR: Color = Color::Green;
const PROP_NAME_COLOR: Color = BRBLUE;
const PROP_VALUE_COLOR: Color = Color::Yellow;
const HEADING_COLOR: Color = Color::Yellow;
const DATA_TYPE_COLOR: Color = Color::Green;
const CHILD_LINK_COLOR: Color = Color::Purple;
@ -34,6 +35,7 @@ const STRUCT_NAME_COLOR: Color = Color::Yellow;
const CAPS_FEATURE_COLOR: Color = Color::Green;
const FIELD_VALUE_COLOR: Color = BRBLUE;
const FIELD_NAME_COLOR: Color = Color::Cyan;
const PROP_ATTR_VALUE_COLOR: Color = Color::Cyan;
fn print_element_list() {
let registry = gst::Registry::get();
@ -225,6 +227,61 @@ fn print_pad_templates_info(factory: &gst::ElementFactory) {
}
}
fn print_clocking_info(element: &gst::Element) {
let flags = element.element_flags();
let requires_clock = flags.contains(gst::ElementFlags::REQUIRE_CLOCK);
let provides_clock = flags.contains(gst::ElementFlags::PROVIDE_CLOCK);
if requires_clock || provides_clock {
let indent = " ".repeat(2);
println!();
print_property("Clocking interaction", "", 0, 0, true);
print!("{}", indent);
if requires_clock {
println!("{}", "element requires a clock");
}
if provides_clock {
println!("{}", "element provides a clock");
}
} else {
println!("Element has no clocking capabilities.");
}
}
fn print_uri_handler_info(element: &gst::Element) {
if let Some(uri_handler) = element.dynamic_cast_ref::<gst::URIHandler>() {
let indent = " ".repeat(2);
let uri_type = match uri_handler.uri_type() {
gst::URIType::Src => "source",
gst::URIType::Sink => "sink",
gst::URIType::Unknown => "unknown",
};
println!();
println!("{}", HEADING_COLOR.paint("URI handling capabilities:"));
println!("{}Element can act as {}.", indent, uri_type);
let uri_protocols = uri_handler.protocols();
if uri_protocols.is_empty() {
println!(
"{}{}",
indent,
PROP_VALUE_COLOR.paint("No supported URI protocols")
);
} else {
println!("{}Supported URI protocols:", indent);
}
for prot in uri_protocols {
let indent = indent.repeat(2);
println!("{}{}", indent, PROP_ATTR_VALUE_COLOR.paint(prot.as_str()));
}
} else {
println!("Element has no URI handling capabilities.");
}
println!();
}
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()));
@ -247,6 +304,8 @@ fn print_element_info(feature: &gst::PluginFeature) -> Result<(), String> {
print_hierarchy(element.type_());
print_interfaces(element.type_());
print_pad_templates_info(element_factory);
print_clocking_info(&element);
print_uri_handler_info(&element);
Ok(())
}