buffer_pool: Add {get,set}_allocator bindings

This commit is contained in:
Vivia Nikolaidou 2019-05-12 17:50:03 +03:00 committed by Sebastian Dröge
parent 32e1d68d36
commit 6461a3abaa
3 changed files with 40 additions and 4 deletions

View file

@ -10,7 +10,7 @@ use std::ptr;
use gst_sys; use gst_sys;
use glib::translate::{from_glib_full, ToGlibPtr}; use glib::translate::from_glib_full;
use glib::IsA; use glib::IsA;
use AllocationParams; use AllocationParams;
@ -28,7 +28,7 @@ impl<O: IsA<Allocator>> AllocatorExtManual for O {
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
size, size,
match params { match params {
Some(val) => val.to_glib_none().0 as *mut _, Some(val) => val.as_ptr() as *mut _,
None => ptr::null_mut(), None => ptr::null_mut(),
}, },
); );

View file

@ -6,6 +6,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use AllocationParams;
use Allocator;
use BufferPool; use BufferPool;
use Structure; use Structure;
@ -144,7 +146,36 @@ impl BufferPoolConfig {
} }
} }
// TODO: get_allocator / set_allocator pub fn get_allocator(&self) -> Option<(Option<Allocator>, AllocationParams)> {
unsafe {
let mut allocator = ptr::null_mut();
let mut params = mem::zeroed();
let ret = from_glib(gst_sys::gst_buffer_pool_config_get_allocator(
self.0.to_glib_none().0,
&mut allocator,
&mut params,
));
if ret {
Some((from_glib_none(allocator), params.into()))
} else {
None
}
}
}
pub fn set_allocator(&self, allocator: Option<&Allocator>, params: Option<&AllocationParams>) {
assert!(allocator.is_some() || params.is_some());
unsafe {
gst_sys::gst_buffer_pool_config_set_allocator(
self.0.to_glib_none().0,
allocator.to_glib_none().0,
match params {
Some(val) => val.as_ptr(),
None => ptr::null(),
},
)
}
}
// TODO: options iterator // TODO: options iterator
} }

View file

@ -21,6 +21,7 @@ use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlibPtr};
use miniobject::MiniObject; use miniobject::MiniObject;
use AllocationParams; use AllocationParams;
use Allocator;
use MemoryFlags; use MemoryFlags;
gst_define_mini_object_wrapper!(Memory, MemoryRef, gst_sys::GstMemory, [Debug,], || { gst_define_mini_object_wrapper!(Memory, MemoryRef, gst_sys::GstMemory, [Debug,], || {
@ -43,7 +44,7 @@ impl fmt::Debug for MemoryRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Memory") f.debug_struct("Memory")
.field("ptr", unsafe { &self.as_ptr() }) .field("ptr", unsafe { &self.as_ptr() })
//.field("allocator", &self.get_allocator()) .field("allocator", &self.get_allocator())
.field("parent", &self.get_parent()) .field("parent", &self.get_parent())
.field("maxsize", &self.get_maxsize()) .field("maxsize", &self.get_maxsize())
.field("align", &self.get_align()) .field("align", &self.get_align())
@ -168,6 +169,10 @@ impl Memory {
} }
impl MemoryRef { impl MemoryRef {
pub fn get_allocator(&self) -> Option<Allocator> {
unsafe { from_glib_none(self.0.allocator) }
}
pub fn get_parent(&self) -> Option<&MemoryRef> { pub fn get_parent(&self) -> Option<&MemoryRef> {
unsafe { unsafe {
if self.0.parent.is_null() { if self.0.parent.is_null() {