Some more Caps cleanup

This commit is contained in:
Sebastian Dröge 2017-07-11 00:31:53 +03:00
parent 4964495b03
commit abe4248a96

View file

@ -26,30 +26,29 @@ unsafe impl MiniObject for CapsRef {
type GstType = ffi::GstCaps; type GstType = ffi::GstCaps;
} }
impl CapsRef { impl GstRc<CapsRef> {
pub fn new_empty() -> GstRc<Self> { pub fn new_empty() -> Self {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::gst_caps_new_empty()) } unsafe { from_glib_full(ffi::gst_caps_new_empty()) }
} }
pub fn new_any() -> GstRc<Self> { pub fn new_any() -> Self {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::gst_caps_new_any()) } unsafe { from_glib_full(ffi::gst_caps_new_any()) }
} }
pub fn new_simple(name: &str, values: &[(&str, glib::Value)]) -> GstRc<Self> { pub fn new_simple(name: &str, values: &[(&str, &glib::Value)]) -> Self {
let mut caps = CapsRef::new_empty(); assert_initialized_main_thread!();
let mut caps = Caps::new_empty();
let structure = unsafe { ffi::gst_structure_new_empty(name.to_glib_none().0) }; let structure = Structure::new(name, values);
caps.get_mut().unwrap().append_structure(structure);
unsafe {
ffi::gst_caps_append_structure(caps.as_mut_ptr(), structure);
}
caps.get_mut().unwrap().set_simple(values);
caps caps
} }
pub fn from_string(value: &str) -> Option<GstRc<Self>> { pub fn from_string(value: &str) -> Option<Self> {
assert_initialized_main_thread!();
unsafe { unsafe {
let caps_ptr = ffi::gst_caps_from_string(value.to_glib_none().0); let caps_ptr = ffi::gst_caps_from_string(value.to_glib_none().0);
@ -60,8 +59,10 @@ impl CapsRef {
} }
} }
} }
}
pub fn set_simple(&mut self, values: &[(&str, glib::Value)]) { impl CapsRef {
pub fn set_simple(&mut self, values: &[(&str, &glib::Value)]) {
for &(name, ref value) in values { for &(name, ref value) in values {
unsafe { unsafe {
ffi::gst_caps_set_value(self.as_mut_ptr(), name.to_glib_none().0, value.to_glib_none().0); ffi::gst_caps_set_value(self.as_mut_ptr(), name.to_glib_none().0, value.to_glib_none().0);
@ -101,6 +102,12 @@ impl CapsRef {
} }
} }
pub fn append_structure(&mut self, structure: Structure) {
unsafe {
ffi::gst_caps_append_structure(self.as_mut_ptr(), structure.into_ptr())
}
}
pub fn get_size(&self) -> u32 { pub fn get_size(&self) -> u32 {
unsafe { ffi::gst_caps_get_size(self.as_ptr()) } unsafe { ffi::gst_caps_get_size(self.as_ptr()) }
} }