gstreamer/
allocation_params.rs
1use std::{marker::PhantomData, mem};
4
5use glib::translate::*;
6
7use crate::{ffi, MemoryFlags};
8
9#[derive(Debug, Clone)]
11#[doc(alias = "GstAllocationParams")]
12#[repr(transparent)]
13pub struct AllocationParams(ffi::GstAllocationParams);
14
15unsafe impl Send for AllocationParams {}
16unsafe impl Sync for AllocationParams {}
17
18impl Default for AllocationParams {
19 fn default() -> Self {
20 unsafe {
21 let mut params = mem::MaybeUninit::uninit();
22 ffi::gst_allocation_params_init(params.as_mut_ptr());
23 AllocationParams(params.assume_init())
24 }
25 }
26}
27
28impl AllocationParams {
29 #[doc(alias = "get_flags")]
30 #[inline]
31 pub fn flags(&self) -> MemoryFlags {
32 unsafe { from_glib(self.0.flags) }
33 }
34
35 #[doc(alias = "get_align")]
36 #[inline]
37 pub fn align(&self) -> usize {
38 self.0.align
39 }
40
41 #[doc(alias = "get_prefix")]
42 #[inline]
43 pub fn prefix(&self) -> usize {
44 self.0.prefix
45 }
46
47 #[doc(alias = "get_padding")]
48 #[inline]
49 pub fn padding(&self) -> usize {
50 self.0.padding
51 }
52
53 pub fn new(flags: MemoryFlags, align: usize, prefix: usize, padding: usize) -> Self {
65 assert_initialized_main_thread!();
66 let params = unsafe {
67 ffi::GstAllocationParams {
68 flags: flags.into_glib(),
69 align,
70 prefix,
71 padding,
72 ..mem::zeroed()
73 }
74 };
75
76 params.into()
77 }
78
79 #[inline]
80 pub fn as_ptr(&self) -> *const ffi::GstAllocationParams {
81 &self.0
82 }
83}
84
85impl From<ffi::GstAllocationParams> for AllocationParams {
86 #[inline]
87 fn from(params: ffi::GstAllocationParams) -> Self {
88 skip_assert_initialized!();
89 AllocationParams(params)
90 }
91}
92
93#[doc(hidden)]
94impl<'a> ToGlibPtr<'a, *const ffi::GstAllocationParams> for AllocationParams {
95 type Storage = PhantomData<&'a Self>;
96
97 #[inline]
98 fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GstAllocationParams, Self> {
99 Stash(&self.0, PhantomData)
100 }
101}
102
103impl FromGlib<ffi::GstAllocationParams> for AllocationParams {
104 #[allow(unused_unsafe)]
105 #[inline]
106 unsafe fn from_glib(value: ffi::GstAllocationParams) -> Self {
107 skip_assert_initialized!();
108 Self::from(value)
109 }
110}