gstreamer-rs/gstreamer/src/allocation_params.rs

99 lines
2.3 KiB
Rust
Raw Normal View History

2020-12-15 10:53:31 +00:00
// Take a look at the license at the top of the repository in the LICENSE file.
use std::{marker::PhantomData, mem};
use glib::translate::*;
use crate::{ffi, MemoryFlags};
#[derive(Debug, Clone)]
#[doc(alias = "GstAllocationParams")]
#[repr(transparent)]
pub struct AllocationParams(ffi::GstAllocationParams);
unsafe impl Send for AllocationParams {}
unsafe impl Sync for AllocationParams {}
impl Default for AllocationParams {
fn default() -> Self {
unsafe {
let mut params = mem::MaybeUninit::uninit();
ffi::gst_allocation_params_init(params.as_mut_ptr());
AllocationParams(params.assume_init())
}
}
}
impl AllocationParams {
#[doc(alias = "get_flags")]
#[inline]
2021-04-11 19:39:50 +00:00
pub fn flags(&self) -> MemoryFlags {
unsafe { from_glib(self.0.flags) }
}
#[doc(alias = "get_align")]
#[inline]
2021-04-11 19:39:50 +00:00
pub fn align(&self) -> usize {
self.0.align
}
#[doc(alias = "get_prefix")]
#[inline]
2021-04-11 19:39:50 +00:00
pub fn prefix(&self) -> usize {
self.0.prefix
}
#[doc(alias = "get_padding")]
#[inline]
2021-04-11 19:39:50 +00:00
pub fn padding(&self) -> usize {
self.0.padding
}
pub fn new(flags: MemoryFlags, align: usize, prefix: usize, padding: usize) -> Self {
assert_initialized_main_thread!();
let params = unsafe {
ffi::GstAllocationParams {
flags: flags.into_glib(),
align,
prefix,
padding,
..mem::zeroed()
}
};
params.into()
}
#[inline]
pub fn as_ptr(&self) -> *const ffi::GstAllocationParams {
&self.0
}
}
impl From<ffi::GstAllocationParams> for AllocationParams {
#[inline]
fn from(params: ffi::GstAllocationParams) -> Self {
2020-03-22 14:18:47 +00:00
skip_assert_initialized!();
AllocationParams(params)
}
}
#[doc(hidden)]
impl<'a> ToGlibPtr<'a, *const ffi::GstAllocationParams> for AllocationParams {
type Storage = PhantomData<&'a Self>;
#[inline]
fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GstAllocationParams, Self> {
Stash(&self.0, PhantomData)
}
}
impl FromGlib<ffi::GstAllocationParams> for AllocationParams {
#[allow(unused_unsafe)]
#[inline]
unsafe fn from_glib(value: ffi::GstAllocationParams) -> Self {
skip_assert_initialized!();
Self::from(value)
}
}