gstreamer: Don't take mini objects by value for append() and similar operations

Compared to
  let foo = Foo::bar(foo);
the new form is easier to follow
  foo.bar();
This commit is contained in:
Sebastian Dröge 2020-03-07 00:31:30 +02:00
parent a07d6f2823
commit 9d5ae8ed14
3 changed files with 50 additions and 37 deletions

View file

@ -159,13 +159,11 @@ impl Buffer {
}
}
pub fn append(buffer: Self, other: Self) -> Self {
pub fn append(&mut self, other: Self) {
skip_assert_initialized!();
unsafe {
from_glib_full(gst_sys::gst_buffer_append(
buffer.into_ptr(),
other.into_ptr(),
))
let ptr = gst_sys::gst_buffer_append(self.as_mut_ptr(), other.into_ptr());
self.replace_ptr(ptr);
}
}
}

View file

@ -70,54 +70,64 @@ impl Caps {
caps
}
pub fn fixate(caps: Self) -> Self {
skip_assert_initialized!();
unsafe { from_glib_full(gst_sys::gst_caps_fixate(caps.into_ptr())) }
}
pub fn merge(caps: Self, other: Self) -> Self {
skip_assert_initialized!();
unsafe { from_glib_full(gst_sys::gst_caps_merge(caps.into_ptr(), other.into_ptr())) }
}
pub fn merge_structure(caps: Self, structure: Structure) -> Self {
pub fn fixate(&mut self) {
skip_assert_initialized!();
unsafe {
from_glib_full(gst_sys::gst_caps_merge_structure(
caps.into_ptr(),
structure.into_ptr(),
))
let ptr = gst_sys::gst_caps_fixate(self.as_mut_ptr());
self.replace_ptr(ptr);
}
}
pub fn merge_structure_full(
caps: Self,
structure: Structure,
features: Option<CapsFeatures>,
) -> Self {
pub fn merge(&mut self, other: Self) {
skip_assert_initialized!();
unsafe {
from_glib_full(gst_sys::gst_caps_merge_structure_full(
caps.into_ptr(),
let ptr = gst_sys::gst_caps_merge(self.as_mut_ptr(), other.into_ptr());
self.replace_ptr(ptr);
}
}
pub fn merge_structure(&mut self, structure: Structure) {
skip_assert_initialized!();
unsafe {
let ptr = gst_sys::gst_caps_merge_structure(self.as_mut_ptr(), structure.into_ptr());
self.replace_ptr(ptr);
}
}
pub fn merge_structure_full(&mut self, structure: Structure, features: Option<CapsFeatures>) {
skip_assert_initialized!();
unsafe {
let ptr = gst_sys::gst_caps_merge_structure_full(
self.as_mut_ptr(),
structure.into_ptr(),
features.map(|f| f.into_ptr()).unwrap_or(ptr::null_mut()),
))
);
self.replace_ptr(ptr);
}
}
pub fn normalize(caps: Self) -> Self {
pub fn normalize(&mut self) {
skip_assert_initialized!();
unsafe { from_glib_full(gst_sys::gst_caps_normalize(caps.into_ptr())) }
unsafe {
let ptr = gst_sys::gst_caps_normalize(self.as_mut_ptr());
self.replace_ptr(ptr);
}
}
pub fn simplify(caps: Self) -> Self {
pub fn simplify(&mut self) {
skip_assert_initialized!();
unsafe { from_glib_full(gst_sys::gst_caps_simplify(caps.into_ptr())) }
unsafe {
let ptr = gst_sys::gst_caps_simplify(self.as_mut_ptr());
self.replace_ptr(ptr);
}
}
pub fn truncate(caps: Self) -> Self {
pub fn truncate(&mut self) {
skip_assert_initialized!();
unsafe { from_glib_full(gst_sys::gst_caps_truncate(caps.into_ptr())) }
unsafe {
let ptr = gst_sys::gst_caps_truncate(self.as_mut_ptr());
self.replace_ptr(ptr);
}
}
}

View file

@ -61,16 +61,21 @@ impl<T: MiniObject> GstRc<T> {
}
}
pub unsafe fn replace_ptr(&mut self, ptr: *mut T::GstType) {
assert!(!ptr.is_null());
self.obj = ptr::NonNull::new_unchecked(ptr as *mut T);
}
pub fn make_mut(&mut self) -> &mut T {
unsafe {
if self.is_writable() {
return self.obj.as_mut();
}
let ptr = T::from_mut_ptr(gst_sys::gst_mini_object_make_writable(
let ptr = gst_sys::gst_mini_object_make_writable(
self.as_mut_ptr() as *mut gst_sys::GstMiniObject
) as *mut T::GstType);
self.obj = ptr::NonNull::new_unchecked(ptr);
);
self.replace_ptr(ptr as *mut T::GstType);
assert!(self.is_writable());
self.obj.as_mut()