diff --git a/gstreamer/src/buffer.rs b/gstreamer/src/buffer.rs index 7200950d8..1f1abc701 100644 --- a/gstreamer/src/buffer.rs +++ b/gstreamer/src/buffer.rs @@ -57,11 +57,12 @@ impl GstRc { pub fn with_size(size: usize) -> Option { assert_initialized_main_thread!(); - let raw = unsafe { ffi::gst_buffer_new_allocate(ptr::null_mut(), size, ptr::null_mut()) }; - if raw.is_null() { - None - } else { - Some(unsafe { from_glib_full(raw) }) + unsafe { + from_glib_full(ffi::gst_buffer_new_allocate( + ptr::null_mut(), + size, + ptr::null_mut(), + )) } } @@ -73,14 +74,14 @@ impl GstRc { pub fn from_mut_slice + Send + 'static>(slice: T) -> Option { assert_initialized_main_thread!(); - let raw = unsafe { + unsafe { let mut b = Box::new(slice); let (size, data) = { let slice = (*b).as_mut(); (slice.len(), slice.as_mut_ptr()) }; let user_data = Box::into_raw(b); - ffi::gst_buffer_new_wrapped_full( + from_glib_full(ffi::gst_buffer_new_wrapped_full( ffi::GstMemoryFlags::empty(), data as glib_ffi::gpointer, size, @@ -88,27 +89,21 @@ impl GstRc { size, user_data as glib_ffi::gpointer, Some(Self::drop_box::), - ) - }; - - if raw.is_null() { - None - } else { - Some(unsafe { from_glib_full(raw) }) + )) } } pub fn from_slice + Send + 'static>(slice: T) -> Option { assert_initialized_main_thread!(); - let raw = unsafe { + unsafe { let b = Box::new(slice); let (size, data) = { let slice = (*b).as_ref(); (slice.len(), slice.as_ptr()) }; let user_data = Box::into_raw(b); - ffi::gst_buffer_new_wrapped_full( + from_glib_full(ffi::gst_buffer_new_wrapped_full( ffi::GST_MEMORY_FLAG_READONLY, data as glib_ffi::gpointer, size, @@ -116,13 +111,7 @@ impl GstRc { size, user_data as glib_ffi::gpointer, Some(Self::drop_box::), - ) - }; - - if raw.is_null() { - None - } else { - Some(unsafe { from_glib_full(raw) }) + )) } } @@ -212,19 +201,13 @@ impl BufferRef { pub fn copy_region(&self, offset: usize, size: Option) -> Option { let size_real = size.unwrap_or(usize::MAX); - let ptr = unsafe { - ffi::gst_buffer_copy_region( + unsafe { + from_glib_full(ffi::gst_buffer_copy_region( self.as_mut_ptr(), ffi::GST_BUFFER_COPY_ALL, offset, size_real, - ) - }; - - if ptr.is_null() { - None - } else { - Some(unsafe { from_glib_full(ptr) }) + )) } } diff --git a/gstreamer/src/caps.rs b/gstreamer/src/caps.rs index 049b3b8e8..30c797481 100644 --- a/gstreamer/src/caps.rs +++ b/gstreamer/src/caps.rs @@ -55,15 +55,7 @@ impl GstRc { 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); - - if caps_ptr.is_null() { - None - } else { - Some(from_glib_full(caps_ptr)) - } - } + unsafe { from_glib_full(ffi::gst_caps_from_string(value.to_glib_none().0)) } } pub fn fixate(caps: Self) -> Self { diff --git a/gstreamer/src/toc.rs b/gstreamer/src/toc.rs index 5adf725f3..82279b905 100644 --- a/gstreamer/src/toc.rs +++ b/gstreamer/src/toc.rs @@ -12,7 +12,8 @@ use std::mem; use ffi; use glib; -use glib::translate::{from_glib, from_glib_full, FromGlibPtrContainer, ToGlib, ToGlibPtr}; +use glib::translate::{from_glib, from_glib_full, from_glib_none, FromGlibPtrContainer, ToGlib, + ToGlibPtr}; use miniobject::*; use TocEntryType; @@ -41,16 +42,7 @@ impl TocRef { } pub fn find_entry(&self, uid: &str) -> Option { - unsafe { - let toc_entry = ffi::gst_toc_find_entry(self.as_ptr(), uid.to_glib_none().0); - if toc_entry.is_null() { - return None; - } - - Some(TocEntry::from_glib_none( - toc_entry as *const ffi::GstTocEntry, - )) - } + unsafe { from_glib_none(ffi::gst_toc_find_entry(self.as_ptr(), uid.to_glib_none().0)) } } pub fn get_entries(&self) -> Vec { @@ -64,14 +56,7 @@ impl TocRef { } pub fn get_tags(&self) -> Option { - unsafe { - let tags = ffi::gst_toc_get_tags(self.as_ptr()); - if tags.is_null() { - return None; - } - - Some(TagList::from_glib_none(tags as *const ffi::GstTagList)) - } + unsafe { from_glib_none(ffi::gst_toc_get_tags(self.as_ptr())) } } pub fn set_tags(&mut self, tag_list: TagList) { @@ -158,14 +143,7 @@ impl TocEntryRef { } pub fn get_parent(&self) -> Option { - unsafe { - let parent = ffi::gst_toc_entry_get_parent(self.as_mut_ptr()); - if parent.is_null() { - return None; - } - - Some(TocEntry::from_glib_none(parent as *const ffi::GstTocEntry)) - } + unsafe { from_glib_none(ffi::gst_toc_entry_get_parent(self.as_mut_ptr())) } } pub fn get_start_stop_times(&self) -> Option<(i64, i64)> { @@ -192,14 +170,7 @@ impl TocEntryRef { } pub fn get_tags(&self) -> Option { - unsafe { - let tags = ffi::gst_toc_entry_get_tags(self.as_ptr()); - if tags.is_null() { - return None; - } - - Some(TagList::from_glib_none(tags as *const ffi::GstTagList)) - } + unsafe { from_glib_none(ffi::gst_toc_entry_get_tags(self.as_ptr())) } } pub fn set_tags(&mut self, tag_list: TagList) {