2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2017-07-10 21:02:08 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::caps_features::*;
|
|
|
|
use crate::structure::*;
|
2017-07-10 21:02:08 +00:00
|
|
|
use std::fmt;
|
2020-01-10 05:50:27 +00:00
|
|
|
use std::marker::PhantomData;
|
2018-09-28 09:00:08 +00:00
|
|
|
use std::ptr;
|
2017-07-13 11:57:02 +00:00
|
|
|
use std::str;
|
2017-07-10 21:02:08 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::CapsIntersectMode;
|
2017-07-24 23:03:18 +00:00
|
|
|
|
2019-10-04 06:11:30 +00:00
|
|
|
use glib::translate::{from_glib, from_glib_full, FromGlibPtrFull, ToGlib, ToGlibPtr};
|
2017-11-15 17:18:58 +00:00
|
|
|
use glib::value::ToSendValue;
|
2019-03-19 07:58:20 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
mini_object_wrapper!(Caps, CapsRef, ffi::GstCaps, || { ffi::gst_caps_get_type() });
|
2017-07-10 21:02:08 +00:00
|
|
|
|
2018-09-28 15:11:46 +00:00
|
|
|
impl Caps {
|
2020-01-10 05:50:27 +00:00
|
|
|
pub fn builder(name: &str) -> Builder<NoFeature> {
|
2017-11-11 12:14:49 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
Builder::new(name)
|
|
|
|
}
|
|
|
|
|
2020-01-10 05:50:27 +00:00
|
|
|
pub fn builder_full() -> BuilderFull<SomeFeatures> {
|
2020-01-08 07:11:33 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
BuilderFull::new()
|
|
|
|
}
|
|
|
|
|
2020-01-10 05:50:27 +00:00
|
|
|
pub fn builder_full_with_features(features: CapsFeatures) -> BuilderFull<SomeFeatures> {
|
2020-01-08 07:11:33 +00:00
|
|
|
assert_initialized_main_thread!();
|
2020-06-11 08:53:35 +00:00
|
|
|
BuilderFull::with_features(features)
|
2020-01-08 07:11:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-10 05:50:27 +00:00
|
|
|
pub fn builder_full_with_any_features() -> BuilderFull<AnyFeatures> {
|
2020-01-08 07:11:33 +00:00
|
|
|
assert_initialized_main_thread!();
|
2020-06-11 08:53:35 +00:00
|
|
|
BuilderFull::with_any_features()
|
2020-01-08 07:11:33 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 21:31:53 +00:00
|
|
|
pub fn new_empty() -> Self {
|
|
|
|
assert_initialized_main_thread!();
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_caps_new_empty()) }
|
2017-07-10 21:02:08 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 21:31:53 +00:00
|
|
|
pub fn new_any() -> Self {
|
|
|
|
assert_initialized_main_thread!();
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_caps_new_any()) }
|
2017-07-10 21:02:08 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 06:09:34 +00:00
|
|
|
pub fn new_simple(name: &str, values: &[(&str, &dyn ToSendValue)]) -> Self {
|
2017-07-10 21:31:53 +00:00
|
|
|
assert_initialized_main_thread!();
|
2017-10-11 12:32:03 +00:00
|
|
|
let mut caps = Caps::new_empty();
|
2017-07-10 21:02:08 +00:00
|
|
|
|
2017-07-10 21:31:53 +00:00
|
|
|
let structure = Structure::new(name, values);
|
|
|
|
caps.get_mut().unwrap().append_structure(structure);
|
2017-07-10 21:02:08 +00:00
|
|
|
|
|
|
|
caps
|
|
|
|
}
|
|
|
|
|
2020-04-20 10:30:05 +00:00
|
|
|
#[allow(clippy::should_implement_trait)]
|
|
|
|
pub fn from_iter<'a, I>(iter: I) -> Self
|
|
|
|
where
|
|
|
|
I: IntoIterator<Item = &'a StructureRef>,
|
|
|
|
{
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
let mut caps = Caps::new_empty();
|
|
|
|
|
|
|
|
iter.into_iter()
|
|
|
|
.for_each(|s| caps.get_mut().unwrap().append_structure(s.to_owned()));
|
|
|
|
|
|
|
|
caps
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_iter_with_features<'a, 'b, I>(iter: I) -> Self
|
|
|
|
where
|
|
|
|
I: IntoIterator<Item = (&'a StructureRef, &'b CapsFeaturesRef)>,
|
|
|
|
{
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
let mut caps = Caps::new_empty();
|
|
|
|
|
|
|
|
iter.into_iter().for_each(|(s, f)| {
|
|
|
|
caps.get_mut()
|
|
|
|
.unwrap()
|
|
|
|
.append_structure_full(s.to_owned(), Some(f.to_owned()))
|
|
|
|
});
|
|
|
|
|
|
|
|
caps
|
|
|
|
}
|
|
|
|
|
2020-03-06 22:31:30 +00:00
|
|
|
pub fn fixate(&mut self) {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2020-03-06 22:31:30 +00:00
|
|
|
unsafe {
|
2020-03-09 11:02:20 +00:00
|
|
|
// See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/388
|
|
|
|
assert!(!self.is_any());
|
|
|
|
let ptr = if self.is_empty() {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_caps_new_empty()
|
2020-03-09 11:02:20 +00:00
|
|
|
} else {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_caps_fixate(self.as_mut_ptr())
|
2020-03-09 11:02:20 +00:00
|
|
|
};
|
2020-03-06 22:31:30 +00:00
|
|
|
self.replace_ptr(ptr);
|
|
|
|
}
|
2017-07-24 23:03:18 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 22:31:30 +00:00
|
|
|
pub fn merge(&mut self, other: Self) {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2020-03-06 22:31:30 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr = ffi::gst_caps_merge(self.as_mut_ptr(), other.into_ptr());
|
2020-03-06 22:31:30 +00:00
|
|
|
self.replace_ptr(ptr);
|
|
|
|
}
|
2017-07-24 23:03:18 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 22:31:30 +00:00
|
|
|
pub fn merge_structure(&mut self, structure: Structure) {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-07-24 23:03:18 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr = ffi::gst_caps_merge_structure(self.as_mut_ptr(), structure.into_ptr());
|
2020-03-06 22:31:30 +00:00
|
|
|
self.replace_ptr(ptr);
|
2018-09-28 09:00:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-06 22:31:30 +00:00
|
|
|
pub fn merge_structure_full(&mut self, structure: Structure, features: Option<CapsFeatures>) {
|
2018-09-28 09:00:08 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr = ffi::gst_caps_merge_structure_full(
|
2020-03-06 22:31:30 +00:00
|
|
|
self.as_mut_ptr(),
|
2018-09-28 09:00:08 +00:00
|
|
|
structure.into_ptr(),
|
|
|
|
features.map(|f| f.into_ptr()).unwrap_or(ptr::null_mut()),
|
2020-03-06 22:31:30 +00:00
|
|
|
);
|
|
|
|
self.replace_ptr(ptr);
|
2017-07-24 23:03:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-06 22:31:30 +00:00
|
|
|
pub fn normalize(&mut self) {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2020-03-06 22:31:30 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr = ffi::gst_caps_normalize(self.as_mut_ptr());
|
2020-03-06 22:31:30 +00:00
|
|
|
self.replace_ptr(ptr);
|
|
|
|
}
|
2017-07-24 23:03:18 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 22:31:30 +00:00
|
|
|
pub fn simplify(&mut self) {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2020-03-06 22:31:30 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr = ffi::gst_caps_simplify(self.as_mut_ptr());
|
2020-03-06 22:31:30 +00:00
|
|
|
self.replace_ptr(ptr);
|
|
|
|
}
|
2017-07-24 23:03:18 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 22:31:30 +00:00
|
|
|
pub fn truncate(&mut self) {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2020-03-06 22:31:30 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr = ffi::gst_caps_truncate(self.as_mut_ptr());
|
2020-03-06 22:31:30 +00:00
|
|
|
self.replace_ptr(ptr);
|
|
|
|
}
|
2017-07-24 23:03:18 +00:00
|
|
|
}
|
2017-07-10 21:31:53 +00:00
|
|
|
}
|
2017-07-10 21:02:08 +00:00
|
|
|
|
2017-07-13 11:57:02 +00:00
|
|
|
impl str::FromStr for Caps {
|
2019-12-17 19:00:42 +00:00
|
|
|
type Err = glib::BoolError;
|
2017-07-13 11:57:02 +00:00
|
|
|
|
2020-11-28 11:34:36 +00:00
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
2019-10-04 06:11:30 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
Option::<_>::from_glib_full(ffi::gst_caps_from_string(s.to_glib_none().0))
|
2020-12-17 22:38:06 +00:00
|
|
|
.ok_or_else(|| glib::bool_error!("Failed to parse caps from string"))
|
2019-10-04 06:11:30 +00:00
|
|
|
}
|
2017-07-13 11:57:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-10 21:31:53 +00:00
|
|
|
impl CapsRef {
|
2019-06-06 06:09:34 +00:00
|
|
|
pub fn set_simple(&mut self, values: &[(&str, &dyn ToSendValue)]) {
|
2017-08-02 16:40:31 +00:00
|
|
|
for &(name, value) in values {
|
2017-07-27 22:36:44 +00:00
|
|
|
let value = value.to_value();
|
|
|
|
|
2017-07-10 21:02:08 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_caps_set_value(
|
2017-07-10 21:33:24 +00:00
|
|
|
self.as_mut_ptr(),
|
|
|
|
name.to_glib_none().0,
|
|
|
|
value.to_glib_none().0,
|
|
|
|
);
|
2017-07-10 21:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_structure(&self, idx: u32) -> Option<&StructureRef> {
|
2018-07-06 08:36:00 +00:00
|
|
|
if idx >= self.get_size() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2017-07-10 21:02:08 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let structure = ffi::gst_caps_get_structure(self.as_ptr(), idx);
|
2017-07-10 21:02:08 +00:00
|
|
|
if structure.is_null() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2018-09-28 09:00:08 +00:00
|
|
|
Some(StructureRef::from_glib_borrow(structure))
|
2017-07-10 21:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 16:40:31 +00:00
|
|
|
pub fn get_mut_structure(&mut self, idx: u32) -> Option<&mut StructureRef> {
|
2018-07-06 08:36:00 +00:00
|
|
|
if idx >= self.get_size() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2017-07-10 21:02:08 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let structure = ffi::gst_caps_get_structure(self.as_ptr(), idx);
|
2017-07-10 21:02:08 +00:00
|
|
|
if structure.is_null() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2018-09-28 09:00:08 +00:00
|
|
|
Some(StructureRef::from_glib_borrow_mut(structure))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_features(&self, idx: u32) -> Option<&CapsFeaturesRef> {
|
|
|
|
if idx >= self.get_size() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let features = ffi::gst_caps_get_features(self.as_ptr(), idx);
|
2018-09-28 09:00:08 +00:00
|
|
|
Some(CapsFeaturesRef::from_glib_borrow(features))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_mut_features(&mut self, idx: u32) -> Option<&mut CapsFeaturesRef> {
|
|
|
|
if idx >= self.get_size() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let features = ffi::gst_caps_get_features(self.as_ptr(), idx);
|
2018-09-28 09:00:08 +00:00
|
|
|
Some(CapsFeaturesRef::from_glib_borrow_mut(features))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_features(&mut self, idx: u32, features: Option<CapsFeatures>) {
|
|
|
|
assert!(idx < self.get_size());
|
|
|
|
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_caps_set_features(
|
2018-09-28 09:00:08 +00:00
|
|
|
self.as_mut_ptr(),
|
|
|
|
idx,
|
|
|
|
features.map(|f| f.into_ptr()).unwrap_or(ptr::null_mut()),
|
|
|
|
)
|
2017-07-10 21:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
|
2019-04-23 16:53:10 +00:00
|
|
|
pub fn set_features_simple(&mut self, features: Option<CapsFeatures>) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_caps_set_features_simple(
|
2019-04-23 16:53:10 +00:00
|
|
|
self.as_mut_ptr(),
|
|
|
|
features.map(|f| f.into_ptr()).unwrap_or(ptr::null_mut()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-10 21:02:08 +00:00
|
|
|
pub fn get_size(&self) -> u32 {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { ffi::gst_caps_get_size(self.as_ptr()) }
|
2017-07-10 21:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn iter(&self) -> Iter {
|
|
|
|
Iter::new(self)
|
|
|
|
}
|
|
|
|
|
2017-07-24 22:33:14 +00:00
|
|
|
pub fn iter_mut(&mut self) -> IterMut {
|
|
|
|
IterMut::new(self)
|
|
|
|
}
|
2017-07-10 21:02:08 +00:00
|
|
|
|
2018-09-28 09:00:08 +00:00
|
|
|
pub fn iter_with_features(&self) -> IterFeatures {
|
|
|
|
IterFeatures::new(self)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn iter_with_features_mut(&mut self) -> IterFeaturesMut {
|
|
|
|
IterFeaturesMut::new(self)
|
|
|
|
}
|
|
|
|
|
2017-07-24 23:03:18 +00:00
|
|
|
pub fn append_structure(&mut self, structure: Structure) {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { ffi::gst_caps_append_structure(self.as_mut_ptr(), structure.into_ptr()) }
|
2017-07-24 23:03:18 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 09:00:08 +00:00
|
|
|
pub fn append_structure_full(&mut self, structure: Structure, features: Option<CapsFeatures>) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_caps_append_structure_full(
|
2018-09-28 09:00:08 +00:00
|
|
|
self.as_mut_ptr(),
|
|
|
|
structure.into_ptr(),
|
|
|
|
features.map(|f| f.into_ptr()).unwrap_or(ptr::null_mut()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-24 23:03:18 +00:00
|
|
|
pub fn remove_structure(&mut self, idx: u32) {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { ffi::gst_caps_remove_structure(self.as_mut_ptr(), idx) }
|
2017-07-24 23:03:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn append(&mut self, other: Caps) {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { ffi::gst_caps_append(self.as_mut_ptr(), other.into_ptr()) }
|
2017-07-24 23:03:18 +00:00
|
|
|
}
|
|
|
|
|
2018-07-06 15:58:54 +00:00
|
|
|
pub fn can_intersect(&self, other: &Self) -> bool {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_caps_can_intersect(self.as_ptr(), other.as_ptr())) }
|
2017-07-24 23:03:18 +00:00
|
|
|
}
|
|
|
|
|
2018-07-06 15:58:54 +00:00
|
|
|
pub fn intersect(&self, other: &Self) -> Caps {
|
2017-07-24 23:03:18 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib_full(ffi::gst_caps_intersect(
|
2017-07-24 23:03:18 +00:00
|
|
|
self.as_mut_ptr(),
|
|
|
|
other.as_mut_ptr(),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-06 15:58:54 +00:00
|
|
|
pub fn intersect_with_mode(&self, other: &Self, mode: CapsIntersectMode) -> Caps {
|
2017-07-24 23:03:18 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib_full(ffi::gst_caps_intersect_full(
|
2017-07-24 23:03:18 +00:00
|
|
|
self.as_mut_ptr(),
|
|
|
|
other.as_mut_ptr(),
|
|
|
|
mode.to_glib(),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-06 15:58:54 +00:00
|
|
|
pub fn is_always_compatible(&self, other: &Self) -> bool {
|
2017-07-24 23:03:18 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_caps_is_always_compatible(
|
2017-07-24 23:03:18 +00:00
|
|
|
self.as_ptr(),
|
|
|
|
other.as_ptr(),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_any(&self) -> bool {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_caps_is_any(self.as_ptr())) }
|
2017-07-24 23:03:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_empty(&self) -> bool {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_caps_is_empty(self.as_ptr())) }
|
2017-07-24 23:03:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_fixed(&self) -> bool {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_caps_is_fixed(self.as_ptr())) }
|
2017-07-24 23:03:18 +00:00
|
|
|
}
|
|
|
|
|
2018-07-06 15:58:54 +00:00
|
|
|
pub fn is_equal_fixed(&self, other: &Self) -> bool {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_caps_is_equal_fixed(self.as_ptr(), other.as_ptr())) }
|
2017-07-24 23:03:18 +00:00
|
|
|
}
|
|
|
|
|
2018-07-06 15:58:54 +00:00
|
|
|
pub fn is_strictly_equal(&self, other: &Self) -> bool {
|
2017-07-24 23:03:18 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_caps_is_strictly_equal(
|
2017-07-24 23:03:18 +00:00
|
|
|
self.as_ptr(),
|
|
|
|
other.as_ptr(),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-06 15:58:54 +00:00
|
|
|
pub fn is_subset(&self, superset: &Self) -> bool {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_caps_is_subset(self.as_ptr(), superset.as_ptr())) }
|
2017-07-24 23:03:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_subset_structure(&self, structure: &StructureRef) -> bool {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_caps_is_subset_structure(
|
2017-07-24 23:03:18 +00:00
|
|
|
self.as_ptr(),
|
|
|
|
structure.as_ptr(),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 15:56:55 +00:00
|
|
|
|
2018-09-28 09:00:08 +00:00
|
|
|
pub fn is_subset_structure_full(
|
|
|
|
&self,
|
|
|
|
structure: &StructureRef,
|
|
|
|
features: Option<&CapsFeaturesRef>,
|
|
|
|
) -> bool {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_caps_is_subset_structure_full(
|
2018-09-28 09:00:08 +00:00
|
|
|
self.as_ptr(),
|
|
|
|
structure.as_ptr(),
|
|
|
|
features.map(|f| f.as_ptr()).unwrap_or(ptr::null()),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-06 15:56:55 +00:00
|
|
|
pub fn subtract(&self, other: &Self) -> Caps {
|
|
|
|
skip_assert_initialized!();
|
2018-07-27 10:36:40 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib_full(ffi::gst_caps_subtract(
|
2018-07-27 10:36:40 +00:00
|
|
|
self.as_mut_ptr(),
|
|
|
|
other.as_mut_ptr(),
|
|
|
|
))
|
|
|
|
}
|
2018-07-06 15:56:55 +00:00
|
|
|
}
|
2017-07-10 21:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! define_iter(
|
2018-09-28 09:00:08 +00:00
|
|
|
($name:ident, $typ:ty, $styp:ty, $get_item:expr) => {
|
2019-01-22 15:43:29 +00:00
|
|
|
#[derive(Debug)]
|
2017-08-30 11:39:09 +00:00
|
|
|
pub struct $name<'a> {
|
|
|
|
caps: $typ,
|
|
|
|
idx: u32,
|
|
|
|
n_structures: u32,
|
|
|
|
}
|
2017-07-10 21:02:08 +00:00
|
|
|
|
2017-08-30 11:39:09 +00:00
|
|
|
impl<'a> $name<'a> {
|
|
|
|
fn new(caps: $typ) -> $name<'a> {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
let n_structures = caps.get_size();
|
2017-07-10 21:02:08 +00:00
|
|
|
|
2017-08-30 11:39:09 +00:00
|
|
|
$name {
|
2020-06-21 15:27:39 +00:00
|
|
|
caps,
|
2017-08-30 11:39:09 +00:00
|
|
|
idx: 0,
|
2020-06-21 15:27:39 +00:00
|
|
|
n_structures,
|
2017-08-30 11:39:09 +00:00
|
|
|
}
|
2017-07-10 21:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-30 11:39:09 +00:00
|
|
|
impl<'a> Iterator for $name<'a> {
|
|
|
|
type Item = $styp;
|
2017-07-10 21:02:08 +00:00
|
|
|
|
2017-08-30 11:39:09 +00:00
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
if self.idx >= self.n_structures {
|
2017-07-24 22:33:14 +00:00
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2017-08-30 11:39:09 +00:00
|
|
|
unsafe {
|
2018-10-11 08:30:12 +00:00
|
|
|
let item = $get_item(self.caps, self.idx)?;
|
2017-08-30 11:39:09 +00:00
|
|
|
self.idx += 1;
|
2018-10-11 08:30:12 +00:00
|
|
|
Some(item)
|
2017-08-30 11:39:09 +00:00
|
|
|
}
|
2017-07-10 21:02:08 +00:00
|
|
|
}
|
|
|
|
|
2017-08-30 11:39:09 +00:00
|
|
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
|
|
if self.idx == self.n_structures {
|
|
|
|
return (0, Some(0));
|
|
|
|
}
|
2017-07-10 21:02:08 +00:00
|
|
|
|
2017-08-30 11:39:09 +00:00
|
|
|
let remaining = (self.n_structures - self.idx) as usize;
|
2017-07-10 21:02:08 +00:00
|
|
|
|
2017-08-30 11:39:09 +00:00
|
|
|
(remaining, Some(remaining))
|
2017-07-10 21:02:08 +00:00
|
|
|
}
|
2017-08-30 11:39:09 +00:00
|
|
|
}
|
2017-07-10 21:02:08 +00:00
|
|
|
|
2017-08-30 11:39:09 +00:00
|
|
|
impl<'a> DoubleEndedIterator for $name<'a> {
|
|
|
|
fn next_back(&mut self) -> Option<Self::Item> {
|
|
|
|
if self.idx == self.n_structures {
|
2017-07-24 22:33:14 +00:00
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2017-08-30 11:39:09 +00:00
|
|
|
self.n_structures -= 1;
|
|
|
|
|
|
|
|
unsafe {
|
2018-09-28 09:00:08 +00:00
|
|
|
$get_item(self.caps, self.n_structures)
|
2017-08-30 11:39:09 +00:00
|
|
|
}
|
2017-07-10 21:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-30 11:39:09 +00:00
|
|
|
impl<'a> ExactSizeIterator for $name<'a> {}
|
|
|
|
}
|
2017-07-10 21:02:08 +00:00
|
|
|
);
|
|
|
|
|
2018-09-28 09:00:08 +00:00
|
|
|
define_iter!(
|
|
|
|
Iter,
|
|
|
|
&'a CapsRef,
|
|
|
|
&'a StructureRef,
|
|
|
|
|caps: &CapsRef, idx| {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr = ffi::gst_caps_get_structure(caps.as_ptr(), idx);
|
2018-09-28 09:00:08 +00:00
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(StructureRef::from_glib_borrow(
|
2020-11-21 13:46:48 +00:00
|
|
|
ptr as *const ffi::GstStructure,
|
2018-09-28 09:00:08 +00:00
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
define_iter!(
|
|
|
|
IterMut,
|
|
|
|
&'a mut CapsRef,
|
|
|
|
&'a mut StructureRef,
|
|
|
|
|caps: &CapsRef, idx| {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr = ffi::gst_caps_get_structure(caps.as_ptr(), idx);
|
2018-09-28 09:00:08 +00:00
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(StructureRef::from_glib_borrow_mut(
|
2020-11-21 13:46:48 +00:00
|
|
|
ptr as *mut ffi::GstStructure,
|
2018-09-28 09:00:08 +00:00
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
define_iter!(
|
|
|
|
IterFeatures,
|
|
|
|
&'a CapsRef,
|
|
|
|
(&'a StructureRef, &'a CapsFeaturesRef),
|
|
|
|
|caps: &CapsRef, idx| {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr1 = ffi::gst_caps_get_structure(caps.as_ptr(), idx);
|
|
|
|
let ptr2 = ffi::gst_caps_get_features(caps.as_ptr(), idx);
|
2018-09-28 09:00:08 +00:00
|
|
|
if ptr1.is_null() || ptr2.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some((
|
2020-11-21 13:46:48 +00:00
|
|
|
StructureRef::from_glib_borrow(ptr1 as *const ffi::GstStructure),
|
|
|
|
CapsFeaturesRef::from_glib_borrow(ptr2 as *const ffi::GstCapsFeatures),
|
2018-09-28 09:00:08 +00:00
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
define_iter!(
|
|
|
|
IterFeaturesMut,
|
|
|
|
&'a mut CapsRef,
|
|
|
|
(&'a mut StructureRef, &'a mut CapsFeaturesRef),
|
|
|
|
|caps: &CapsRef, idx| {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr1 = ffi::gst_caps_get_structure(caps.as_ptr(), idx);
|
|
|
|
let ptr2 = ffi::gst_caps_get_features(caps.as_ptr(), idx);
|
2018-09-28 09:00:08 +00:00
|
|
|
if ptr1.is_null() || ptr2.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some((
|
2020-11-21 13:46:48 +00:00
|
|
|
StructureRef::from_glib_borrow_mut(ptr1 as *mut ffi::GstStructure),
|
|
|
|
CapsFeaturesRef::from_glib_borrow_mut(ptr2 as *mut ffi::GstCapsFeatures),
|
2018-09-28 09:00:08 +00:00
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2017-07-10 21:02:08 +00:00
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
impl fmt::Debug for Caps {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
<CapsRef as fmt::Debug>::fmt(self, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Caps {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
<CapsRef as fmt::Display>::fmt(self, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialEq for Caps {
|
|
|
|
fn eq(&self, other: &Caps) -> bool {
|
|
|
|
CapsRef::eq(self, other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Eq for Caps {}
|
|
|
|
|
2017-07-10 21:02:08 +00:00
|
|
|
impl fmt::Debug for CapsRef {
|
2017-12-01 09:21:20 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2017-12-01 17:02:53 +00:00
|
|
|
f.debug_tuple("Caps").field(&self.to_string()).finish()
|
2017-12-01 09:21:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for CapsRef {
|
2017-07-10 21:02:08 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2020-11-21 13:46:48 +00:00
|
|
|
let s = unsafe { glib::GString::from_glib_full(ffi::gst_caps_to_string(self.as_ptr())) };
|
2019-10-04 06:11:30 +00:00
|
|
|
f.write_str(&s)
|
2017-07-10 21:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialEq for CapsRef {
|
|
|
|
fn eq(&self, other: &CapsRef) -> bool {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_caps_is_equal(self.as_ptr(), other.as_ptr())) }
|
2017-07-10 21:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Eq for CapsRef {}
|
|
|
|
|
2020-01-10 05:50:27 +00:00
|
|
|
pub enum NoFeature {}
|
|
|
|
pub enum HasFeatures {}
|
|
|
|
|
|
|
|
pub struct Builder<T> {
|
2020-11-21 13:46:48 +00:00
|
|
|
s: crate::Structure,
|
2020-01-10 05:50:27 +00:00
|
|
|
features: Option<CapsFeatures>,
|
|
|
|
phantom: PhantomData<T>,
|
2017-11-11 12:14:49 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 17:08:27 +00:00
|
|
|
impl<T> fmt::Debug for Builder<T> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
f.debug_struct("Builder")
|
|
|
|
.field("s", &self.s)
|
|
|
|
.field("features", &self.features)
|
|
|
|
.field("phantom", &self.phantom)
|
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-10 05:50:27 +00:00
|
|
|
impl Builder<NoFeature> {
|
|
|
|
fn new(name: &str) -> Builder<NoFeature> {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2017-11-11 12:14:49 +00:00
|
|
|
Builder {
|
2020-11-21 13:46:48 +00:00
|
|
|
s: crate::Structure::new_empty(name),
|
2018-09-28 09:00:08 +00:00
|
|
|
features: None,
|
2020-01-10 05:50:27 +00:00
|
|
|
phantom: PhantomData,
|
2017-11-11 12:14:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-10 05:50:27 +00:00
|
|
|
pub fn features(self, features: &[&str]) -> Builder<HasFeatures> {
|
|
|
|
Builder {
|
|
|
|
s: self.s,
|
|
|
|
features: Some(CapsFeatures::new(features)),
|
|
|
|
phantom: PhantomData,
|
|
|
|
}
|
2017-11-11 12:14:49 +00:00
|
|
|
}
|
|
|
|
|
2020-01-10 05:50:27 +00:00
|
|
|
pub fn any_features(self) -> Builder<HasFeatures> {
|
|
|
|
Builder {
|
|
|
|
s: self.s,
|
|
|
|
features: Some(CapsFeatures::new_any()),
|
|
|
|
phantom: PhantomData,
|
|
|
|
}
|
2018-09-28 09:00:08 +00:00
|
|
|
}
|
2020-01-10 05:50:27 +00:00
|
|
|
}
|
2018-09-28 09:00:08 +00:00
|
|
|
|
2020-01-10 05:50:27 +00:00
|
|
|
impl<T> Builder<T> {
|
|
|
|
pub fn field<'b, V: ToSendValue>(mut self, name: &'b str, value: &'b V) -> Self {
|
|
|
|
self.s.set(name, value);
|
2018-09-28 09:00:08 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2017-11-11 12:14:49 +00:00
|
|
|
pub fn build(self) -> Caps {
|
|
|
|
let mut caps = Caps::new_empty();
|
2018-09-28 09:00:08 +00:00
|
|
|
|
|
|
|
caps.get_mut()
|
|
|
|
.unwrap()
|
2020-01-10 05:50:27 +00:00
|
|
|
.append_structure_full(self.s, self.features);
|
2017-11-11 12:14:49 +00:00
|
|
|
caps
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-10 05:50:27 +00:00
|
|
|
pub enum AnyFeatures {}
|
|
|
|
pub enum SomeFeatures {}
|
|
|
|
|
|
|
|
pub struct BuilderFull<T> {
|
2020-11-21 13:46:48 +00:00
|
|
|
caps: crate::Caps,
|
2020-01-08 07:11:33 +00:00
|
|
|
features: Option<CapsFeatures>,
|
2020-01-10 05:50:27 +00:00
|
|
|
phantom: PhantomData<T>,
|
2020-01-08 07:11:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 17:08:27 +00:00
|
|
|
impl<T> fmt::Debug for BuilderFull<T> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
f.debug_struct("Builder")
|
|
|
|
.field("caps", &self.caps)
|
|
|
|
.field("features", &self.features)
|
|
|
|
.field("phantom", &self.phantom)
|
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-10 05:50:27 +00:00
|
|
|
impl BuilderFull<SomeFeatures> {
|
2020-01-08 07:11:33 +00:00
|
|
|
fn new() -> Self {
|
|
|
|
BuilderFull {
|
|
|
|
caps: Caps::new_empty(),
|
|
|
|
features: None,
|
2020-01-10 05:50:27 +00:00
|
|
|
phantom: PhantomData,
|
2020-01-08 07:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-11 08:53:35 +00:00
|
|
|
fn with_features(features: CapsFeatures) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2020-01-08 07:11:33 +00:00
|
|
|
BuilderFull {
|
|
|
|
caps: Caps::new_empty(),
|
|
|
|
features: Some(features),
|
2020-01-10 05:50:27 +00:00
|
|
|
phantom: PhantomData,
|
2020-01-08 07:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-10 05:50:27 +00:00
|
|
|
pub fn structure_with_features(self, structure: Structure, features: CapsFeatures) -> Self {
|
|
|
|
self.append_structure(structure, Some(features))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn structure_with_any_features(self, structure: Structure) -> Self {
|
|
|
|
self.append_structure(structure, Some(CapsFeatures::new_any()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BuilderFull<AnyFeatures> {
|
2020-06-11 08:53:35 +00:00
|
|
|
fn with_any_features() -> Self {
|
2020-01-08 07:11:33 +00:00
|
|
|
BuilderFull {
|
|
|
|
caps: Caps::new_empty(),
|
2020-01-10 05:50:27 +00:00
|
|
|
features: Some(CapsFeatures::new_any()),
|
|
|
|
phantom: PhantomData,
|
2020-01-08 07:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-10 05:50:27 +00:00
|
|
|
}
|
2020-01-08 07:11:33 +00:00
|
|
|
|
2020-01-10 05:50:27 +00:00
|
|
|
impl<T> BuilderFull<T> {
|
2020-01-08 07:11:33 +00:00
|
|
|
fn append_structure(mut self, structure: Structure, features: Option<CapsFeatures>) -> Self {
|
|
|
|
let features = {
|
2020-01-10 05:50:27 +00:00
|
|
|
match self.features {
|
|
|
|
None => features,
|
|
|
|
Some(ref result) => {
|
|
|
|
let mut result = result.clone();
|
|
|
|
match features {
|
|
|
|
None => Some(result),
|
|
|
|
Some(features) => {
|
|
|
|
features.iter().for_each(|feat| result.add(feat));
|
|
|
|
Some(result)
|
2020-01-08 07:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.caps
|
|
|
|
.get_mut()
|
|
|
|
.unwrap()
|
|
|
|
.append_structure_full(structure, features);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn structure(self, structure: Structure) -> Self {
|
|
|
|
self.append_structure(structure, None)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn build(self) -> Caps {
|
|
|
|
self.caps
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-10 21:02:08 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::Array;
|
|
|
|
use crate::Fraction;
|
2017-07-10 21:02:08 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_simple() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2017-07-10 21:02:08 +00:00
|
|
|
|
2018-09-28 09:00:08 +00:00
|
|
|
let mut caps = Caps::new_simple(
|
2017-07-10 21:02:08 +00:00
|
|
|
"foo/bar",
|
|
|
|
&[
|
2017-07-27 22:36:44 +00:00
|
|
|
("int", &12),
|
|
|
|
("bool", &true),
|
|
|
|
("string", &"bla"),
|
|
|
|
("fraction", &Fraction::new(1, 2)),
|
2017-07-28 15:56:27 +00:00
|
|
|
("array", &Array::new(&[&1, &2])),
|
2017-07-10 21:02:08 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
caps.to_string(),
|
2017-07-28 15:56:27 +00:00
|
|
|
"foo/bar, int=(int)12, bool=(boolean)true, string=(string)bla, fraction=(fraction)1/2, array=(int)< 1, 2 >"
|
|
|
|
);
|
2017-07-10 21:02:08 +00:00
|
|
|
|
2018-09-28 09:00:08 +00:00
|
|
|
{
|
|
|
|
let s = caps.get_structure(0).unwrap();
|
|
|
|
assert_eq!(
|
|
|
|
s,
|
|
|
|
Structure::new(
|
|
|
|
"foo/bar",
|
|
|
|
&[
|
|
|
|
("int", &12),
|
|
|
|
("bool", &true),
|
|
|
|
("string", &"bla"),
|
|
|
|
("fraction", &Fraction::new(1, 2)),
|
|
|
|
("array", &Array::new(&[&1, &2])),
|
|
|
|
],
|
2018-10-08 12:02:23 +00:00
|
|
|
)
|
|
|
|
.as_ref()
|
2018-09-28 09:00:08 +00:00
|
|
|
);
|
|
|
|
}
|
2018-10-28 13:47:02 +00:00
|
|
|
assert!(caps
|
|
|
|
.get_features(0)
|
|
|
|
.unwrap()
|
2020-11-21 13:46:48 +00:00
|
|
|
.is_equal(crate::CAPS_FEATURES_MEMORY_SYSTEM_MEMORY.as_ref()));
|
2018-09-28 09:00:08 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
let caps = caps.get_mut().unwrap();
|
|
|
|
caps.set_features(0, Some(CapsFeatures::new(&["foo:bla"])));
|
|
|
|
}
|
2018-10-28 13:47:02 +00:00
|
|
|
assert!(caps
|
|
|
|
.get_features(0)
|
|
|
|
.unwrap()
|
|
|
|
.is_equal(CapsFeatures::new(&["foo:bla"]).as_ref()));
|
2017-07-10 21:02:08 +00:00
|
|
|
}
|
2017-11-11 12:14:49 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_builder() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2017-11-11 12:14:49 +00:00
|
|
|
|
|
|
|
let caps = Caps::builder("foo/bar")
|
2017-11-26 21:58:02 +00:00
|
|
|
.field("int", &12)
|
|
|
|
.field("bool", &true)
|
|
|
|
.field("string", &"bla")
|
|
|
|
.field("fraction", &Fraction::new(1, 2))
|
|
|
|
.field("array", &Array::new(&[&1, &2]))
|
2017-11-11 12:14:49 +00:00
|
|
|
.build();
|
|
|
|
assert_eq!(
|
|
|
|
caps.to_string(),
|
|
|
|
"foo/bar, int=(int)12, bool=(boolean)true, string=(string)bla, fraction=(fraction)1/2, array=(int)< 1, 2 >"
|
|
|
|
);
|
2018-09-28 09:00:08 +00:00
|
|
|
|
|
|
|
let caps = Caps::builder("foo/bar")
|
|
|
|
.field("int", &12)
|
|
|
|
.any_features()
|
|
|
|
.build();
|
|
|
|
assert_eq!(caps.to_string(), "foo/bar(ANY), int=(int)12");
|
|
|
|
|
|
|
|
let caps = Caps::builder("foo/bar")
|
|
|
|
.field("int", &12)
|
|
|
|
.features(&["foo:bla", "foo:baz"])
|
|
|
|
.build();
|
|
|
|
assert_eq!(caps.to_string(), "foo/bar(foo:bla, foo:baz), int=(int)12");
|
2017-11-11 12:14:49 +00:00
|
|
|
}
|
2019-06-18 11:03:19 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_display() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2019-06-18 11:03:19 +00:00
|
|
|
|
|
|
|
let caps = Caps::new_simple("foo/bar", &[]);
|
|
|
|
format!("{}", caps);
|
|
|
|
}
|
2020-01-08 07:11:33 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_builder_full() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2020-01-08 07:11:33 +00:00
|
|
|
|
|
|
|
let caps = Caps::builder_full()
|
|
|
|
.structure(Structure::builder("audio/x-raw").build())
|
|
|
|
.structure(Structure::builder("video/x-raw").build())
|
|
|
|
.build();
|
|
|
|
assert_eq!(caps.to_string(), "audio/x-raw; video/x-raw");
|
|
|
|
|
|
|
|
let caps = Caps::builder_full()
|
|
|
|
.structure(
|
|
|
|
Structure::builder("audio/x-raw")
|
|
|
|
.field("format", &"S16LE")
|
|
|
|
.build(),
|
|
|
|
)
|
|
|
|
.structure(Structure::builder("video/x-raw").build())
|
|
|
|
.build();
|
|
|
|
assert_eq!(
|
|
|
|
caps.to_string(),
|
|
|
|
"audio/x-raw, format=(string)S16LE; video/x-raw"
|
|
|
|
);
|
|
|
|
|
|
|
|
let caps = Caps::builder_full()
|
|
|
|
.structure_with_any_features(Structure::builder("audio/x-raw").build())
|
|
|
|
.structure_with_features(
|
|
|
|
Structure::builder("video/x-raw").build(),
|
|
|
|
CapsFeatures::new(&["foo:bla", "foo:baz"]),
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
assert_eq!(
|
|
|
|
caps.to_string(),
|
|
|
|
"audio/x-raw(ANY); video/x-raw(foo:bla, foo:baz)"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_builder_full_with_features() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2020-01-08 07:11:33 +00:00
|
|
|
|
|
|
|
let caps = Caps::builder_full_with_features(CapsFeatures::new(&["foo:bla"]))
|
|
|
|
.structure(Structure::builder("audio/x-raw").build())
|
|
|
|
.structure_with_features(
|
|
|
|
Structure::builder("video/x-raw").build(),
|
|
|
|
CapsFeatures::new(&["foo:baz"]),
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
assert_eq!(
|
|
|
|
caps.to_string(),
|
|
|
|
"audio/x-raw(foo:bla); video/x-raw(foo:bla, foo:baz)"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_builder_full_with_any_features() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2020-01-08 07:11:33 +00:00
|
|
|
|
|
|
|
let caps = Caps::builder_full_with_any_features()
|
|
|
|
.structure(Structure::builder("audio/x-raw").build())
|
|
|
|
.structure(Structure::builder("video/x-raw").build())
|
|
|
|
.build();
|
|
|
|
assert_eq!(caps.to_string(), "audio/x-raw(ANY); video/x-raw(ANY)");
|
|
|
|
|
|
|
|
let caps = Caps::builder_full_with_any_features()
|
|
|
|
.structure(Structure::builder("audio/x-raw").build())
|
|
|
|
.build();
|
2020-01-10 05:50:27 +00:00
|
|
|
assert_eq!(caps.to_string(), "audio/x-raw(ANY)");
|
2020-01-08 07:11:33 +00:00
|
|
|
}
|
2020-04-20 10:30:05 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_new_from_iter() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2020-04-20 10:30:05 +00:00
|
|
|
|
|
|
|
let caps = Caps::builder_full_with_any_features()
|
|
|
|
.structure(Structure::builder("audio/x-raw").build())
|
|
|
|
.structure(Structure::builder("video/x-raw").build())
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let audio = Caps::from_iter(caps.iter().filter(|s| s.get_name() == "audio/x-raw"));
|
|
|
|
assert_eq!(audio.to_string(), "audio/x-raw");
|
|
|
|
|
|
|
|
let audio = Caps::from_iter_with_features(
|
|
|
|
caps.iter_with_features()
|
|
|
|
.filter(|(s, _)| s.get_name() == "audio/x-raw"),
|
|
|
|
);
|
|
|
|
assert_eq!(audio.to_string(), "audio/x-raw(ANY)");
|
|
|
|
}
|
2017-07-10 21:02:08 +00:00
|
|
|
}
|