2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2018-03-07 09:07:30 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::AllocationParams;
|
|
|
|
use crate::Allocator;
|
|
|
|
use crate::BufferPool;
|
|
|
|
use crate::Structure;
|
2022-02-01 09:12:05 +00:00
|
|
|
use crate::StructureRef;
|
2018-03-07 09:07:30 +00:00
|
|
|
|
2021-04-26 12:15:53 +00:00
|
|
|
use glib::prelude::*;
|
2021-04-28 12:34:56 +00:00
|
|
|
use glib::translate::*;
|
2018-03-07 09:07:30 +00:00
|
|
|
|
|
|
|
use std::mem;
|
|
|
|
use std::ops;
|
2022-02-01 09:12:05 +00:00
|
|
|
use std::ops::Deref;
|
|
|
|
use std::ops::DerefMut;
|
2018-04-01 08:30:03 +00:00
|
|
|
use std::ptr;
|
2018-03-07 09:07:30 +00:00
|
|
|
|
2020-01-30 21:10:26 +00:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
2022-02-01 09:12:05 +00:00
|
|
|
#[repr(transparent)]
|
2018-03-07 09:07:30 +00:00
|
|
|
pub struct BufferPoolConfig(Structure);
|
|
|
|
|
2022-02-01 09:12:05 +00:00
|
|
|
impl Deref for BufferPoolConfig {
|
|
|
|
type Target = BufferPoolConfigRef;
|
|
|
|
|
|
|
|
fn deref(&self) -> &BufferPoolConfigRef {
|
|
|
|
unsafe { &*(self.0.as_ptr() as *const StructureRef as *const BufferPoolConfigRef) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DerefMut for BufferPoolConfig {
|
|
|
|
fn deref_mut(&mut self) -> &mut BufferPoolConfigRef {
|
|
|
|
unsafe { &mut *(self.0.as_ptr() as *mut StructureRef as *mut BufferPoolConfigRef) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsRef<BufferPoolConfigRef> for BufferPoolConfig {
|
|
|
|
fn as_ref(&self) -> &BufferPoolConfigRef {
|
|
|
|
self.deref()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsMut<BufferPoolConfigRef> for BufferPoolConfig {
|
|
|
|
fn as_mut(&mut self) -> &mut BufferPoolConfigRef {
|
|
|
|
self.deref_mut()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct BufferPoolConfigRef(StructureRef);
|
|
|
|
|
|
|
|
impl BufferPoolConfigRef {
|
|
|
|
pub unsafe fn from_glib_borrow<'a>(ptr: *const ffi::GstStructure) -> &'a BufferPoolConfigRef {
|
|
|
|
assert!(!ptr.is_null());
|
|
|
|
|
|
|
|
&*(ptr as *mut StructureRef as *mut BufferPoolConfigRef)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub unsafe fn from_glib_borrow_mut<'a>(
|
|
|
|
ptr: *mut ffi::GstStructure,
|
|
|
|
) -> &'a mut BufferPoolConfigRef {
|
|
|
|
assert!(!ptr.is_null());
|
|
|
|
|
|
|
|
&mut *(ptr as *mut StructureRef as *mut BufferPoolConfigRef)
|
|
|
|
}
|
|
|
|
|
2022-08-11 14:02:02 +00:00
|
|
|
pub fn as_ptr(&self) -> *const ffi::GstStructure {
|
2022-02-01 09:12:05 +00:00
|
|
|
self as *const Self as *const ffi::GstStructure
|
|
|
|
}
|
|
|
|
|
2022-08-11 14:02:02 +00:00
|
|
|
pub fn as_mut_ptr(&self) -> *mut ffi::GstStructure {
|
2022-02-01 09:12:05 +00:00
|
|
|
self as *const Self as *mut ffi::GstStructure
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ops::Deref for BufferPoolConfigRef {
|
2020-11-21 13:46:48 +00:00
|
|
|
type Target = crate::StructureRef;
|
2018-03-07 09:07:30 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn deref(&self) -> &crate::StructureRef {
|
2022-02-01 09:12:05 +00:00
|
|
|
&self.0
|
2018-03-07 09:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-01 09:12:05 +00:00
|
|
|
impl ops::DerefMut for BufferPoolConfigRef {
|
2020-11-21 13:46:48 +00:00
|
|
|
fn deref_mut(&mut self) -> &mut crate::StructureRef {
|
2022-02-01 09:12:05 +00:00
|
|
|
&mut self.0
|
2018-03-07 09:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-01 09:12:05 +00:00
|
|
|
impl AsRef<crate::StructureRef> for BufferPoolConfigRef {
|
2020-11-21 13:46:48 +00:00
|
|
|
fn as_ref(&self) -> &crate::StructureRef {
|
2022-02-01 09:12:05 +00:00
|
|
|
&self.0
|
2018-03-07 09:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-01 09:12:05 +00:00
|
|
|
impl AsMut<crate::StructureRef> for BufferPoolConfigRef {
|
2020-11-21 13:46:48 +00:00
|
|
|
fn as_mut(&mut self) -> &mut crate::StructureRef {
|
2022-02-01 09:12:05 +00:00
|
|
|
&mut self.0
|
2018-03-07 09:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-01 09:12:05 +00:00
|
|
|
impl BufferPoolConfigRef {
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_buffer_pool_config_add_option")]
|
2018-03-07 09:07:30 +00:00
|
|
|
pub fn add_option(&mut self, option: &str) {
|
|
|
|
unsafe {
|
2022-02-01 09:12:05 +00:00
|
|
|
ffi::gst_buffer_pool_config_add_option(self.0.as_mut_ptr(), option.to_glib_none().0);
|
2018-03-07 09:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_buffer_pool_config_has_option")]
|
2018-03-07 09:07:30 +00:00
|
|
|
pub fn has_option(&self, option: &str) -> bool {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_buffer_pool_config_has_option(
|
2022-02-01 09:12:05 +00:00
|
|
|
self.0.as_mut_ptr(),
|
2018-03-07 09:07:30 +00:00
|
|
|
option.to_glib_none().0,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_options")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_buffer_pool_config_n_options")]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn options(&self) -> Vec<String> {
|
2018-03-07 09:07:30 +00:00
|
|
|
unsafe {
|
2022-02-01 09:12:05 +00:00
|
|
|
let n = ffi::gst_buffer_pool_config_n_options(self.0.as_mut_ptr()) as usize;
|
2018-03-07 09:07:30 +00:00
|
|
|
let mut options = Vec::with_capacity(n);
|
|
|
|
|
|
|
|
for i in 0..n {
|
2020-11-21 13:46:48 +00:00
|
|
|
options.push(from_glib_none(ffi::gst_buffer_pool_config_get_option(
|
2022-02-01 09:12:05 +00:00
|
|
|
self.0.as_mut_ptr(),
|
2018-03-07 09:07:30 +00:00
|
|
|
i as u32,
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
|
|
|
options
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_buffer_pool_config_set_params")]
|
2019-05-23 18:19:24 +00:00
|
|
|
pub fn set_params(
|
2018-03-07 09:07:30 +00:00
|
|
|
&mut self,
|
2020-11-21 13:46:48 +00:00
|
|
|
caps: Option<&crate::Caps>,
|
2018-03-07 09:07:30 +00:00
|
|
|
size: u32,
|
|
|
|
min_buffers: u32,
|
|
|
|
max_buffers: u32,
|
|
|
|
) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_buffer_pool_config_set_params(
|
2022-02-01 09:12:05 +00:00
|
|
|
self.0.as_mut_ptr(),
|
2018-03-07 09:07:30 +00:00
|
|
|
caps.to_glib_none().0,
|
|
|
|
size,
|
|
|
|
min_buffers,
|
|
|
|
max_buffers,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_params")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_buffer_pool_config_get_params")]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn params(&self) -> Option<(Option<crate::Caps>, u32, u32, u32)> {
|
2018-03-07 09:07:30 +00:00
|
|
|
unsafe {
|
|
|
|
let mut caps = ptr::null_mut();
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut size = mem::MaybeUninit::uninit();
|
|
|
|
let mut min_buffers = mem::MaybeUninit::uninit();
|
|
|
|
let mut max_buffers = mem::MaybeUninit::uninit();
|
2018-03-07 09:07:30 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret: bool = from_glib(ffi::gst_buffer_pool_config_get_params(
|
2022-02-01 09:12:05 +00:00
|
|
|
self.0.as_mut_ptr(),
|
2018-03-07 09:07:30 +00:00
|
|
|
&mut caps,
|
2019-07-11 12:34:28 +00:00
|
|
|
size.as_mut_ptr(),
|
|
|
|
min_buffers.as_mut_ptr(),
|
|
|
|
max_buffers.as_mut_ptr(),
|
2018-03-07 09:07:30 +00:00
|
|
|
));
|
|
|
|
if !ret {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2019-07-11 12:34:28 +00:00
|
|
|
Some((
|
|
|
|
from_glib_none(caps),
|
|
|
|
size.assume_init(),
|
|
|
|
min_buffers.assume_init(),
|
|
|
|
max_buffers.assume_init(),
|
|
|
|
))
|
2018-03-07 09:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_buffer_pool_config_validate_params")]
|
2019-05-23 18:19:24 +00:00
|
|
|
pub fn validate_params(
|
2018-03-07 09:07:30 +00:00
|
|
|
&self,
|
2020-11-21 13:46:48 +00:00
|
|
|
caps: Option<&crate::Caps>,
|
2018-03-07 09:07:30 +00:00
|
|
|
size: u32,
|
|
|
|
min_buffers: u32,
|
|
|
|
max_buffers: u32,
|
2019-01-16 20:23:56 +00:00
|
|
|
) -> Result<(), glib::BoolError> {
|
2018-03-07 09:07:30 +00:00
|
|
|
unsafe {
|
2020-12-17 22:38:06 +00:00
|
|
|
glib::result_from_gboolean!(
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_buffer_pool_config_validate_params(
|
2022-02-01 09:12:05 +00:00
|
|
|
self.0.as_mut_ptr(),
|
2019-01-16 20:23:56 +00:00
|
|
|
caps.to_glib_none().0,
|
|
|
|
size,
|
|
|
|
min_buffers,
|
|
|
|
max_buffers,
|
|
|
|
),
|
|
|
|
"Parameters are not valid in this context"
|
|
|
|
)
|
2018-03-07 09:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_allocator")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_buffer_pool_config_get_allocator")]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn allocator(&self) -> Option<(Option<Allocator>, AllocationParams)> {
|
2019-05-12 14:50:03 +00:00
|
|
|
unsafe {
|
|
|
|
let mut allocator = ptr::null_mut();
|
2019-07-11 13:02:46 +00:00
|
|
|
let mut params = mem::MaybeUninit::zeroed();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_buffer_pool_config_get_allocator(
|
2022-02-01 09:12:05 +00:00
|
|
|
self.0.as_mut_ptr(),
|
2019-05-12 14:50:03 +00:00
|
|
|
&mut allocator,
|
2019-07-11 13:02:46 +00:00
|
|
|
params.as_mut_ptr(),
|
2019-05-12 14:50:03 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2019-07-11 13:02:46 +00:00
|
|
|
Some((from_glib_none(allocator), params.assume_init().into()))
|
2019-05-12 14:50:03 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_buffer_pool_config_set_allocator")]
|
2019-05-12 14:50:03 +00:00
|
|
|
pub fn set_allocator(&self, allocator: Option<&Allocator>, params: Option<&AllocationParams>) {
|
|
|
|
assert!(allocator.is_some() || params.is_some());
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_buffer_pool_config_set_allocator(
|
2022-02-01 09:12:05 +00:00
|
|
|
self.0.as_mut_ptr(),
|
2019-05-12 14:50:03 +00:00
|
|
|
allocator.to_glib_none().0,
|
|
|
|
match params {
|
|
|
|
Some(val) => val.as_ptr(),
|
|
|
|
None => ptr::null(),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2018-03-07 09:07:30 +00:00
|
|
|
// TODO: options iterator
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2021-06-01 13:15:59 +00:00
|
|
|
#[doc(alias = "GstBufferPoolAcquireParams")]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub struct BufferPoolAcquireParams(ffi::GstBufferPoolAcquireParams);
|
2018-03-07 09:07:30 +00:00
|
|
|
|
2019-12-18 15:04:42 +00:00
|
|
|
unsafe impl Send for BufferPoolAcquireParams {}
|
|
|
|
unsafe impl Sync for BufferPoolAcquireParams {}
|
|
|
|
|
2018-03-07 09:07:30 +00:00
|
|
|
impl BufferPoolAcquireParams {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn with_flags(flags: crate::BufferPoolAcquireFlags) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2020-11-21 13:46:48 +00:00
|
|
|
BufferPoolAcquireParams(ffi::GstBufferPoolAcquireParams {
|
|
|
|
format: ffi::GST_FORMAT_UNDEFINED,
|
2018-03-07 09:07:30 +00:00
|
|
|
start: -1,
|
|
|
|
stop: -1,
|
2021-04-27 15:15:46 +00:00
|
|
|
flags: flags.into_glib(),
|
2018-03-07 09:07:30 +00:00
|
|
|
_gst_reserved: [ptr::null_mut(); 4],
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn with_start_stop<T: crate::SpecificFormattedValue>(
|
2018-03-07 09:07:30 +00:00
|
|
|
start: T,
|
|
|
|
stop: T,
|
2020-11-21 13:46:48 +00:00
|
|
|
flags: crate::BufferPoolAcquireFlags,
|
2018-03-07 09:07:30 +00:00
|
|
|
) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2018-03-07 09:07:30 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
BufferPoolAcquireParams(ffi::GstBufferPoolAcquireParams {
|
2021-04-27 15:15:46 +00:00
|
|
|
format: start.format().into_glib(),
|
2020-10-27 17:27:16 +00:00
|
|
|
start: start.into_raw_value(),
|
|
|
|
stop: stop.into_raw_value(),
|
2021-04-27 15:15:46 +00:00
|
|
|
flags: flags.into_glib(),
|
2018-03-07 09:07:30 +00:00
|
|
|
_gst_reserved: [ptr::null_mut(); 4],
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn flags(&self) -> crate::BufferPoolAcquireFlags {
|
2020-12-08 14:07:12 +00:00
|
|
|
unsafe { from_glib(self.0.flags) }
|
2018-03-07 09:07:30 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn format(&self) -> crate::Format {
|
2020-12-08 14:07:12 +00:00
|
|
|
unsafe { from_glib(self.0.format) }
|
2018-03-07 09:07:30 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn start(&self) -> crate::GenericFormattedValue {
|
2020-12-08 14:07:12 +00:00
|
|
|
unsafe { crate::GenericFormattedValue::new(from_glib(self.0.format), self.0.start) }
|
2018-03-07 09:07:30 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn stop(&self) -> crate::GenericFormattedValue {
|
2020-12-08 14:07:12 +00:00
|
|
|
unsafe { crate::GenericFormattedValue::new(from_glib(self.0.format), self.0.stop) }
|
2018-03-07 09:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialEq for BufferPoolAcquireParams {
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
2018-07-27 10:36:40 +00:00
|
|
|
self.format() == other.format()
|
|
|
|
&& self.start() == other.start()
|
2018-03-07 09:07:30 +00:00
|
|
|
&& self.stop() == other.stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Eq for BufferPoolAcquireParams {}
|
|
|
|
|
2019-05-06 11:57:24 +00:00
|
|
|
#[doc(hidden)]
|
2020-11-21 13:46:48 +00:00
|
|
|
impl<'a> ToGlibPtr<'a, *const ffi::GstBufferPoolAcquireParams> for BufferPoolAcquireParams {
|
2019-05-06 11:57:24 +00:00
|
|
|
type Storage = &'a Self;
|
|
|
|
|
|
|
|
fn to_glib_none(
|
|
|
|
&'a self,
|
2020-11-21 13:46:48 +00:00
|
|
|
) -> glib::translate::Stash<'a, *const ffi::GstBufferPoolAcquireParams, Self> {
|
2019-05-06 11:57:24 +00:00
|
|
|
glib::translate::Stash(&self.0, self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2020-11-21 13:46:48 +00:00
|
|
|
impl<'a> ToGlibPtrMut<'a, *mut ffi::GstBufferPoolAcquireParams> for BufferPoolAcquireParams {
|
2019-05-06 11:57:24 +00:00
|
|
|
type Storage = &'a mut Self;
|
|
|
|
|
|
|
|
fn to_glib_none_mut(
|
|
|
|
&'a mut self,
|
2020-11-21 13:46:48 +00:00
|
|
|
) -> glib::translate::StashMut<'a, *mut ffi::GstBufferPoolAcquireParams, Self> {
|
2019-05-06 11:57:24 +00:00
|
|
|
glib::translate::StashMut(&mut self.0, self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-01 09:12:05 +00:00
|
|
|
#[doc(hidden)]
|
|
|
|
impl FromGlibPtrNone<*mut ffi::GstBufferPoolAcquireParams> for BufferPoolAcquireParams {
|
|
|
|
unsafe fn from_glib_none(ptr: *mut ffi::GstBufferPoolAcquireParams) -> Self {
|
|
|
|
Self(*ptr)
|
|
|
|
}
|
2018-05-09 09:20:59 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 09:22:42 +00:00
|
|
|
pub trait BufferPoolExtManual: 'static {
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_config")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_buffer_pool_get_config")]
|
2021-04-11 19:39:50 +00:00
|
|
|
fn config(&self) -> BufferPoolConfig;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_buffer_pool_set_config")]
|
2018-03-07 09:07:30 +00:00
|
|
|
fn set_config(&self, config: BufferPoolConfig) -> Result<(), glib::error::BoolError>;
|
|
|
|
|
|
|
|
fn is_flushing(&self) -> bool;
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_buffer_pool_acquire_buffer")]
|
2019-05-23 18:19:24 +00:00
|
|
|
fn acquire_buffer(
|
2018-03-07 09:07:30 +00:00
|
|
|
&self,
|
2019-05-23 18:19:24 +00:00
|
|
|
params: Option<&BufferPoolAcquireParams>,
|
2020-11-21 13:46:48 +00:00
|
|
|
) -> Result<crate::Buffer, crate::FlowError>;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_buffer_pool_release_buffer")]
|
2020-11-21 13:46:48 +00:00
|
|
|
fn release_buffer(&self, buffer: crate::Buffer);
|
2018-03-07 09:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<O: IsA<BufferPool>> BufferPoolExtManual for O {
|
2021-04-11 19:39:50 +00:00
|
|
|
fn config(&self) -> BufferPoolConfig {
|
2018-03-07 09:07:30 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr = ffi::gst_buffer_pool_get_config(self.as_ref().to_glib_none().0);
|
2018-03-07 09:07:30 +00:00
|
|
|
BufferPoolConfig(from_glib_full(ptr))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_config(&self, config: BufferPoolConfig) -> Result<(), glib::error::BoolError> {
|
|
|
|
unsafe {
|
2020-12-17 22:38:06 +00:00
|
|
|
glib::result_from_gboolean!(
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_buffer_pool_set_config(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2022-05-06 19:41:15 +00:00
|
|
|
config.0.into_glib_ptr()
|
2019-01-16 11:32:58 +00:00
|
|
|
),
|
2018-03-07 09:07:30 +00:00
|
|
|
"Failed to set config",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_flushing(&self) -> bool {
|
|
|
|
unsafe {
|
2019-01-16 11:32:58 +00:00
|
|
|
let stash = self.as_ref().to_glib_none();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr: *mut ffi::GstBufferPool = stash.0;
|
2018-03-07 09:07:30 +00:00
|
|
|
|
|
|
|
from_glib((*ptr).flushing)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-23 18:19:24 +00:00
|
|
|
fn acquire_buffer(
|
2018-03-07 09:07:30 +00:00
|
|
|
&self,
|
2019-05-23 18:19:24 +00:00
|
|
|
params: Option<&BufferPoolAcquireParams>,
|
2020-11-21 13:46:48 +00:00
|
|
|
) -> Result<crate::Buffer, crate::FlowError> {
|
2019-05-23 18:19:24 +00:00
|
|
|
let params_ptr = params.to_glib_none().0 as *mut _;
|
2018-03-07 09:07:30 +00:00
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let mut buffer = ptr::null_mut();
|
2021-04-28 12:34:56 +00:00
|
|
|
crate::FlowSuccess::try_from_glib(ffi::gst_buffer_pool_acquire_buffer(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2018-03-07 09:07:30 +00:00
|
|
|
&mut buffer,
|
|
|
|
params_ptr,
|
2021-04-28 12:34:56 +00:00
|
|
|
))
|
|
|
|
.map(|_| from_glib_full(buffer))
|
2018-03-07 09:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn release_buffer(&self, buffer: crate::Buffer) {
|
2018-03-07 09:07:30 +00:00
|
|
|
unsafe {
|
2022-05-06 19:41:15 +00:00
|
|
|
ffi::gst_buffer_pool_release_buffer(
|
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
buffer.into_glib_ptr(),
|
|
|
|
);
|
2018-03-07 09:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::prelude::*;
|
2018-03-07 09:07:30 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_pool() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2018-03-07 09:07:30 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let pool = crate::BufferPool::new();
|
2021-04-11 19:39:50 +00:00
|
|
|
let mut config = pool.config();
|
2021-10-24 15:57:15 +00:00
|
|
|
config.set_params(Some(&crate::Caps::builder("foo/bar").build()), 1024, 0, 2);
|
2018-03-07 09:07:30 +00:00
|
|
|
pool.set_config(config).unwrap();
|
|
|
|
|
|
|
|
pool.set_active(true).unwrap();
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let params =
|
|
|
|
crate::BufferPoolAcquireParams::with_flags(crate::BufferPoolAcquireFlags::DONTWAIT);
|
2018-03-07 09:07:30 +00:00
|
|
|
|
2019-05-23 18:19:24 +00:00
|
|
|
let _buf1 = pool.acquire_buffer(Some(¶ms)).unwrap();
|
|
|
|
let buf2 = pool.acquire_buffer(Some(¶ms)).unwrap();
|
2018-03-07 09:07:30 +00:00
|
|
|
|
2019-05-23 18:19:24 +00:00
|
|
|
assert!(pool.acquire_buffer(Some(¶ms)).is_err());
|
2018-03-07 09:07:30 +00:00
|
|
|
|
|
|
|
drop(buf2);
|
2019-05-23 18:19:24 +00:00
|
|
|
let _buf2 = pool.acquire_buffer(Some(¶ms)).unwrap();
|
2018-03-07 09:07:30 +00:00
|
|
|
|
|
|
|
pool.set_active(false).unwrap();
|
|
|
|
}
|
|
|
|
}
|