mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-05-31 22:58:33 +00:00
inspect: Print element pad templates
This commit is contained in:
parent
0d23096ebf
commit
861943d047
|
@ -29,6 +29,11 @@ const PROP_NAME_COLOR: Color = BRBLUE;
|
|||
const HEADING_COLOR: Color = Color::Yellow;
|
||||
const DATA_TYPE_COLOR: Color = Color::Green;
|
||||
const CHILD_LINK_COLOR: Color = Color::Purple;
|
||||
const CAPS_TYPE_COLOR: Color = Color::Yellow;
|
||||
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;
|
||||
|
||||
fn print_element_list() {
|
||||
let registry = gst::Registry::get();
|
||||
|
@ -52,45 +57,51 @@ fn print_element_list() {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_property(name: &str, value: &str) {
|
||||
let formatted_name = format!("{:<25}", name);
|
||||
println!(" {}{}", PROP_NAME_COLOR.paint(formatted_name), value);
|
||||
fn print_property(name: &str, value: &str, width: usize, indent: usize, colon: bool) {
|
||||
let formatted_name = PROP_NAME_COLOR.paint(format!("{:<width$}", name));
|
||||
let indent_str = " ".repeat(indent);
|
||||
let colon_str = if colon { ": " } else { "" };
|
||||
println!("{}{}{}{}", indent_str, formatted_name, colon_str, value);
|
||||
}
|
||||
|
||||
fn print_property_details(name: &str, value: &str) {
|
||||
print_property(name, value, 25, 2, false);
|
||||
}
|
||||
|
||||
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());
|
||||
print_property_details("Rank", &format!("{} ({})", rank, i32::from(rank)));
|
||||
print_property_details("Long name", factory.longname());
|
||||
print_property_details("Klass", factory.klass());
|
||||
print_property_details("Description", factory.description());
|
||||
print_property_details("Author", factory.author());
|
||||
println!();
|
||||
}
|
||||
|
||||
fn print_plugin_info(plugin: &gst::Plugin) {
|
||||
println!("{}", HEADING_COLOR.paint("Plugin details:"));
|
||||
print_property("Name", plugin.plugin_name().as_str());
|
||||
print_property("Description", plugin.description().as_str());
|
||||
print_property(
|
||||
print_property_details("Name", &plugin.plugin_name());
|
||||
print_property_details("Description", &plugin.description());
|
||||
print_property_details(
|
||||
"Filename",
|
||||
&plugin.filename().map_or("(null)".to_string(), |f| {
|
||||
f.into_os_string().into_string().unwrap()
|
||||
}),
|
||||
); // FIXME: unwrap?
|
||||
print_property("Version", plugin.version().as_str());
|
||||
print_property("License", plugin.license().as_str());
|
||||
print_property("Source module", plugin.source().as_str());
|
||||
print_property_details("Version", &plugin.version());
|
||||
print_property_details("License", &plugin.license());
|
||||
print_property_details("Source module", &plugin.source());
|
||||
if let Some(mut release_date) = plugin.release_date_string() {
|
||||
// Convert YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC)
|
||||
release_date = release_date
|
||||
.replacen('T', " ", 1)
|
||||
.replacen('Z', " (UTC)", 1)
|
||||
.into();
|
||||
print_property("Source release date", &release_date);
|
||||
print_property_details("Source release date", &release_date);
|
||||
}
|
||||
print_property("Binary package", plugin.package().as_str());
|
||||
print_property("Origin URL", plugin.origin().as_str());
|
||||
print_property_details("Binary package", &plugin.package());
|
||||
print_property_details("Origin URL", &plugin.origin());
|
||||
println!();
|
||||
}
|
||||
|
||||
|
@ -133,6 +144,87 @@ fn print_interfaces(type_: gst::glib::Type) {
|
|||
println!();
|
||||
}
|
||||
|
||||
fn print_caps(caps: &gst::Caps) {
|
||||
let indent = " ".repeat(6);
|
||||
|
||||
if caps.is_any() {
|
||||
println!("{}{}", indent, CAPS_TYPE_COLOR.paint("ANY"));
|
||||
return;
|
||||
}
|
||||
if caps.is_empty() {
|
||||
println!("{}{}", indent, CAPS_TYPE_COLOR.paint("EMPTY"));
|
||||
return;
|
||||
}
|
||||
|
||||
for (structure, feature) in caps.iter_with_features() {
|
||||
if !feature.is_equal(&gst::CAPS_FEATURES_MEMORY_SYSTEM_MEMORY) {
|
||||
println!(
|
||||
"{}{}({})",
|
||||
indent,
|
||||
STRUCT_NAME_COLOR.paint(structure.name().as_str()),
|
||||
CAPS_FEATURE_COLOR.paint(feature.to_string()),
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
"{}{}",
|
||||
indent,
|
||||
STRUCT_NAME_COLOR.paint(structure.name().as_str())
|
||||
);
|
||||
};
|
||||
for (field, value) in structure {
|
||||
let width = 23;
|
||||
if let Ok(val) = value.serialize() {
|
||||
println!(
|
||||
"{}: {}",
|
||||
FIELD_NAME_COLOR.paint(format!("{:>width$}", field.as_str())),
|
||||
FIELD_VALUE_COLOR.paint(val.as_str())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn print_pad_templates_info(factory: &gst::ElementFactory) {
|
||||
let n_pads = factory.num_pad_templates();
|
||||
let indent = 2;
|
||||
|
||||
println!("{}:", HEADING_COLOR.paint("Pad Templates"));
|
||||
if n_pads == 0 {
|
||||
println!(" none");
|
||||
return;
|
||||
}
|
||||
|
||||
let mut pad_templates = factory.static_pad_templates();
|
||||
pad_templates.sort_by(|t1, t2| t1.name_template().cmp(t2.name_template()));
|
||||
|
||||
for pad_tmpl in pad_templates {
|
||||
let availability = match pad_tmpl.presence() {
|
||||
gst::PadPresence::Always => "Always",
|
||||
gst::PadPresence::Sometimes => "Sometimes",
|
||||
gst::PadPresence::Request => "On request",
|
||||
};
|
||||
|
||||
print_property(
|
||||
&format!(
|
||||
"{} template",
|
||||
match pad_tmpl.direction() {
|
||||
gst::PadDirection::Src => "SOURCE",
|
||||
gst::PadDirection::Sink => "SINK",
|
||||
gst::PadDirection::Unknown => "UNKNOWN",
|
||||
}
|
||||
),
|
||||
&format!("'{}'", pad_tmpl.name_template()),
|
||||
0,
|
||||
indent,
|
||||
true,
|
||||
);
|
||||
print_property("Availability", availability, 0, indent * 2, true);
|
||||
print_property("Capabilities", "", 0, indent * 2, true);
|
||||
print_caps(&pad_tmpl.caps());
|
||||
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()));
|
||||
|
@ -154,6 +246,7 @@ fn print_element_info(feature: &gst::PluginFeature) -> Result<(), String> {
|
|||
|
||||
print_hierarchy(element.type_());
|
||||
print_interfaces(element.type_());
|
||||
print_pad_templates_info(element_factory);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue