From abe4248a9645b87ba2fd31b91a1e611a1d21f820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 11 Jul 2017 00:31:53 +0300 Subject: [PATCH] Some more Caps cleanup --- gstreamer/src/caps.rs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/gstreamer/src/caps.rs b/gstreamer/src/caps.rs index b0131c66e..e5c994c9c 100644 --- a/gstreamer/src/caps.rs +++ b/gstreamer/src/caps.rs @@ -26,30 +26,29 @@ unsafe impl MiniObject for CapsRef { type GstType = ffi::GstCaps; } -impl CapsRef { - pub fn new_empty() -> GstRc { +impl GstRc { + pub fn new_empty() -> Self { + assert_initialized_main_thread!(); unsafe { from_glib_full(ffi::gst_caps_new_empty()) } } - pub fn new_any() -> GstRc { + pub fn new_any() -> Self { + assert_initialized_main_thread!(); unsafe { from_glib_full(ffi::gst_caps_new_any()) } } - pub fn new_simple(name: &str, values: &[(&str, glib::Value)]) -> GstRc { - let mut caps = CapsRef::new_empty(); + pub fn new_simple(name: &str, values: &[(&str, &glib::Value)]) -> Self { + assert_initialized_main_thread!(); + let mut caps = Caps::new_empty(); - let structure = unsafe { ffi::gst_structure_new_empty(name.to_glib_none().0) }; - - unsafe { - ffi::gst_caps_append_structure(caps.as_mut_ptr(), structure); - } - - caps.get_mut().unwrap().set_simple(values); + let structure = Structure::new(name, values); + caps.get_mut().unwrap().append_structure(structure); caps } - pub fn from_string(value: &str) -> Option> { + pub fn from_string(value: &str) -> Option { + assert_initialized_main_thread!(); unsafe { 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 { unsafe { 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 { unsafe { ffi::gst_caps_get_size(self.as_ptr()) } }