mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 19:11:06 +00:00
gstreamer: Store ffi::GstCaps inside gst::Caps and equivalent for other miniobjects
Simplifies code and prepares for the next changes.
This commit is contained in:
parent
21ff418b0f
commit
8d983066f5
1 changed files with 9 additions and 9 deletions
|
@ -4,7 +4,7 @@
|
||||||
macro_rules! mini_object_wrapper(
|
macro_rules! mini_object_wrapper(
|
||||||
($name:ident, $ref_name:ident, $ffi_name:path, $get_type:expr) => {
|
($name:ident, $ref_name:ident, $ffi_name:path, $get_type:expr) => {
|
||||||
pub struct $name {
|
pub struct $name {
|
||||||
obj: std::ptr::NonNull<$ref_name>,
|
obj: std::ptr::NonNull<$ffi_name>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
|
@ -18,7 +18,7 @@ macro_rules! mini_object_wrapper(
|
||||||
$crate::ffi::gst_mini_object_ref(ptr as *mut $crate::ffi::GstMiniObject);
|
$crate::ffi::gst_mini_object_ref(ptr as *mut $crate::ffi::GstMiniObject);
|
||||||
|
|
||||||
$name {
|
$name {
|
||||||
obj: std::ptr::NonNull::new_unchecked(ptr as *mut $ffi_name as *mut $ref_name),
|
obj: std::ptr::NonNull::new_unchecked(ptr as *mut $ffi_name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ macro_rules! mini_object_wrapper(
|
||||||
assert!(!ptr.is_null());
|
assert!(!ptr.is_null());
|
||||||
|
|
||||||
$name {
|
$name {
|
||||||
obj: std::ptr::NonNull::new_unchecked(ptr as *mut $ffi_name as *mut $ref_name),
|
obj: std::ptr::NonNull::new_unchecked(ptr as *mut $ffi_name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,19 +36,19 @@ macro_rules! mini_object_wrapper(
|
||||||
assert!(!ptr.is_null());
|
assert!(!ptr.is_null());
|
||||||
|
|
||||||
$crate::glib::translate::Borrowed::new($name {
|
$crate::glib::translate::Borrowed::new($name {
|
||||||
obj: std::ptr::NonNull::new_unchecked(ptr as *mut $ffi_name as *mut $ref_name),
|
obj: std::ptr::NonNull::new_unchecked(ptr as *mut $ffi_name),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn replace_ptr(&mut self, ptr: *mut $ffi_name) {
|
pub unsafe fn replace_ptr(&mut self, ptr: *mut $ffi_name) {
|
||||||
assert!(!ptr.is_null());
|
assert!(!ptr.is_null());
|
||||||
self.obj = std::ptr::NonNull::new_unchecked(ptr as *mut $ref_name);
|
self.obj = std::ptr::NonNull::new_unchecked(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_mut(&mut self) -> &mut $ref_name {
|
pub fn make_mut(&mut self) -> &mut $ref_name {
|
||||||
unsafe {
|
unsafe {
|
||||||
if self.is_writable() {
|
if self.is_writable() {
|
||||||
return self.obj.as_mut();
|
return &mut *(self.obj.as_mut() as *mut $ffi_name as *mut $ref_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
let ptr = $crate::ffi::gst_mini_object_make_writable(
|
let ptr = $crate::ffi::gst_mini_object_make_writable(
|
||||||
|
@ -57,13 +57,13 @@ macro_rules! mini_object_wrapper(
|
||||||
self.replace_ptr(ptr as *mut $ffi_name);
|
self.replace_ptr(ptr as *mut $ffi_name);
|
||||||
assert!(self.is_writable());
|
assert!(self.is_writable());
|
||||||
|
|
||||||
self.obj.as_mut()
|
&mut *(self.obj.as_mut() as *mut $ffi_name as *mut $ref_name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_mut(&mut self) -> Option<&mut $ref_name> {
|
pub fn get_mut(&mut self) -> Option<&mut $ref_name> {
|
||||||
if self.is_writable() {
|
if self.is_writable() {
|
||||||
Some(unsafe { self.obj.as_mut() })
|
Some(unsafe { &mut *(self.obj.as_mut() as *mut $ffi_name as *mut $ref_name) })
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ macro_rules! mini_object_wrapper(
|
||||||
type Target = $ref_name;
|
type Target = $ref_name;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
unsafe { &*(self.obj.as_ptr() as *const Self::Target) }
|
unsafe { &*(self.obj.as_ref() as *const $ffi_name as *const $ref_name) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue