mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-26 19:41:09 +00:00
functions: Add new parse_bin_from_description_with_name utility
This is basically `parse_bin_from_description()` but additionally the returned bin has the passed name. It is sometimes convenient to name those bins so they can later be easily retrieved by name from the pipeline they belong to.
This commit is contained in:
parent
81aba1b8a2
commit
3adc3d9337
1 changed files with 37 additions and 5 deletions
|
@ -6,15 +6,35 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
use auto::functions::parse_bin_from_description;
|
||||||
use glib;
|
use glib;
|
||||||
use glib::translate::*;
|
use glib::translate::*;
|
||||||
|
use glib::Cast;
|
||||||
use gst_sys;
|
use gst_sys;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
|
use Bin;
|
||||||
use Element;
|
use Element;
|
||||||
|
use Object;
|
||||||
use ParseContext;
|
use ParseContext;
|
||||||
use ParseFlags;
|
use ParseFlags;
|
||||||
|
|
||||||
|
pub fn parse_bin_from_description_with_name(
|
||||||
|
bin_description: &str,
|
||||||
|
ghost_unlinked_pads: bool,
|
||||||
|
bin_name: &str,
|
||||||
|
) -> Result<Bin, glib::Error> {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
let bin = parse_bin_from_description(bin_description, ghost_unlinked_pads)?;
|
||||||
|
if !bin_name.is_empty() {
|
||||||
|
let obj = bin.clone().upcast::<Object>();
|
||||||
|
unsafe {
|
||||||
|
gst_sys::gst_object_set_name(obj.to_glib_none().0, bin_name.to_glib_none().0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(bin)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse_bin_from_description_full(
|
pub fn parse_bin_from_description_full(
|
||||||
bin_description: &str,
|
bin_description: &str,
|
||||||
ghost_unlinked_pads: bool,
|
ghost_unlinked_pads: bool,
|
||||||
|
@ -154,14 +174,12 @@ pub fn type_is_plugin_api(type_: glib::types::Type) -> Option<::PluginAPIFlags>
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use prelude::*;
|
||||||
|
|
||||||
#[cfg(feature = "v1_12")]
|
#[cfg(feature = "v1_12")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_calculate_linear_regression() {
|
fn test_calculate_linear_regression() {
|
||||||
// Moved the module `use` inside test function because this is the only test for now
|
|
||||||
// and it is feature-gated, so it generates a warning when the feature is not selected.
|
|
||||||
// Can be moved out of the function when other tests are added.
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
::init().unwrap();
|
::init().unwrap();
|
||||||
|
|
||||||
let values = [(0, 0), (1, 1), (2, 2), (3, 3)];
|
let values = [(0, 0), (1, 1), (2, 2), (3, 3)];
|
||||||
|
@ -174,4 +192,18 @@ mod tests {
|
||||||
calculate_linear_regression(&values, Some(&mut temp)).unwrap();
|
calculate_linear_regression(&values, Some(&mut temp)).unwrap();
|
||||||
assert_eq!((m_num, m_denom, b, xbase), (10, 10, 3, 3));
|
assert_eq!((m_num, m_denom, b, xbase), (10, 10, 3, 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_bin_from_description_with_name() {
|
||||||
|
::init().unwrap();
|
||||||
|
|
||||||
|
let bin =
|
||||||
|
parse_bin_from_description_with_name("fakesrc ! fakesink", false, "all_fake").unwrap();
|
||||||
|
let name = bin.get_name();
|
||||||
|
assert_eq!(name, "all_fake");
|
||||||
|
|
||||||
|
let bin = parse_bin_from_description_with_name("fakesrc ! fakesink", false, "").unwrap();
|
||||||
|
let name = bin.get_name();
|
||||||
|
assert_ne!(name, "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue