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