gstreamer/
allocation_params.rs1use std::{marker::PhantomData, mem};
4
5use glib::translate::*;
6
7use crate::{ffi, MemoryFlags};
8
9#[derive(Debug, Clone, Copy)]
10#[doc(alias = "GstAllocationParams")]
11#[repr(transparent)]
12pub struct AllocationParams(ffi::GstAllocationParams);
13
14unsafe impl Send for AllocationParams {}
15unsafe impl Sync for AllocationParams {}
16
17impl Default for AllocationParams {
18 fn default() -> Self {
19 unsafe {
20 let mut params = mem::MaybeUninit::uninit();
21 ffi::gst_allocation_params_init(params.as_mut_ptr());
22 AllocationParams(params.assume_init())
23 }
24 }
25}
26
27impl 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 #[inline]
53 pub fn set_flags(&mut self, flags: MemoryFlags) {
54 self.0.flags = flags.into_glib();
55 }
56
57 #[inline]
58 pub fn set_align(&mut self, align: usize) {
59 self.0.align = align;
60 }
61
62 #[inline]
63 pub fn set_prefix(&mut self, prefix: usize) {
64 self.0.prefix = prefix;
65 }
66
67 #[inline]
68 pub fn set_padding(&mut self, padding: usize) {
69 self.0.padding = padding;
70 }
71
72 pub fn new(flags: MemoryFlags, align: usize, prefix: usize, padding: usize) -> Self {
73 assert_initialized_main_thread!();
74 let params = unsafe {
75 ffi::GstAllocationParams {
76 flags: flags.into_glib(),
77 align,
78 prefix,
79 padding,
80 ..mem::zeroed()
81 }
82 };
83
84 params.into()
85 }
86
87 #[inline]
88 pub fn as_ptr(&self) -> *const ffi::GstAllocationParams {
89 &self.0
90 }
91}
92
93impl From<ffi::GstAllocationParams> for AllocationParams {
94 #[inline]
95 fn from(params: ffi::GstAllocationParams) -> Self {
96 skip_assert_initialized!();
97 AllocationParams(params)
98 }
99}
100
101impl PartialEq for AllocationParams {
102 fn eq(&self, other: &Self) -> bool {
103 self.flags() == other.flags()
104 && self.align() == other.align()
105 && self.prefix() == other.prefix()
106 && self.padding() == other.padding()
107 }
108}
109
110impl Eq for AllocationParams {}
111
112#[doc(hidden)]
113impl<'a> ToGlibPtr<'a, *const ffi::GstAllocationParams> for AllocationParams {
114 type Storage = PhantomData<&'a Self>;
115
116 #[inline]
117 fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GstAllocationParams, Self> {
118 Stash(&self.0, PhantomData)
119 }
120}
121
122impl FromGlib<ffi::GstAllocationParams> for AllocationParams {
123 #[allow(unused_unsafe)]
124 #[inline]
125 unsafe fn from_glib(value: ffi::GstAllocationParams) -> Self {
126 skip_assert_initialized!();
127 Self::from(value)
128 }
129}