gstreamer/
allocation_params.rs
1use std::{marker::PhantomData, mem};
4
5use glib::translate::*;
6
7use crate::{ffi, MemoryFlags};
8
9#[derive(Debug, Clone, Copy)]
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 #[inline]
54 pub fn set_flags(&mut self, flags: MemoryFlags) {
55 self.0.flags = flags.into_glib();
56 }
57
58 #[inline]
59 pub fn set_align(&mut self, align: usize) {
60 self.0.align = align;
61 }
62
63 #[inline]
64 pub fn set_prefix(&mut self, prefix: usize) {
65 self.0.prefix = prefix;
66 }
67
68 #[inline]
69 pub fn set_padding(&mut self, padding: usize) {
70 self.0.padding = padding;
71 }
72
73 pub fn new(flags: MemoryFlags, align: usize, prefix: usize, padding: usize) -> Self {
85 assert_initialized_main_thread!();
86 let params = unsafe {
87 ffi::GstAllocationParams {
88 flags: flags.into_glib(),
89 align,
90 prefix,
91 padding,
92 ..mem::zeroed()
93 }
94 };
95
96 params.into()
97 }
98
99 #[inline]
100 pub fn as_ptr(&self) -> *const ffi::GstAllocationParams {
101 &self.0
102 }
103}
104
105impl From<ffi::GstAllocationParams> for AllocationParams {
106 #[inline]
107 fn from(params: ffi::GstAllocationParams) -> Self {
108 skip_assert_initialized!();
109 AllocationParams(params)
110 }
111}
112
113impl PartialEq for AllocationParams {
114 fn eq(&self, other: &Self) -> bool {
115 self.flags() == other.flags()
116 && self.align() == other.align()
117 && self.prefix() == other.prefix()
118 && self.padding() == other.padding()
119 }
120}
121
122impl Eq for AllocationParams {}
123
124#[doc(hidden)]
125impl<'a> ToGlibPtr<'a, *const ffi::GstAllocationParams> for AllocationParams {
126 type Storage = PhantomData<&'a Self>;
127
128 #[inline]
129 fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GstAllocationParams, Self> {
130 Stash(&self.0, PhantomData)
131 }
132}
133
134impl FromGlib<ffi::GstAllocationParams> for AllocationParams {
135 #[allow(unused_unsafe)]
136 #[inline]
137 unsafe fn from_glib(value: ffi::GstAllocationParams) -> Self {
138 skip_assert_initialized!();
139 Self::from(value)
140 }
141}