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 crate::ffi; |
6 | use glib::translate::*; |
7 | |
8 | pub static BUFFER_POOL_OPTION_VIDEO_AFFINE_TRANSFORMATION_META: &glib::GStr = unsafe { |
9 | glib::GStr::from_utf8_with_nul_unchecked( |
10 | bytes:ffi::GST_BUFFER_POOL_OPTION_VIDEO_AFFINE_TRANSFORMATION_META, |
11 | ) |
12 | }; |
13 | pub static BUFFER_POOL_OPTION_VIDEO_ALIGNMENT: &glib::GStr = unsafe { |
14 | glib::GStr::from_utf8_with_nul_unchecked(bytes:ffi::GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT) |
15 | }; |
16 | pub static BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META: &glib::GStr = unsafe { |
17 | glib::GStr::from_utf8_with_nul_unchecked( |
18 | bytes:ffi::GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META, |
19 | ) |
20 | }; |
21 | pub static BUFFER_POOL_OPTION_VIDEO_META: &glib::GStr = |
22 | unsafe { glib::GStr::from_utf8_with_nul_unchecked(bytes:ffi::GST_BUFFER_POOL_OPTION_VIDEO_META) }; |
23 | |
24 | #[derive (Debug, Clone)] |
25 | #[doc (alias = "GstVideoAlignment" )] |
26 | pub struct VideoAlignment(pub(crate) ffi::GstVideoAlignment); |
27 | |
28 | impl VideoAlignment { |
29 | #[doc (alias = "get_padding_top" )] |
30 | #[inline ] |
31 | pub fn padding_top(&self) -> u32 { |
32 | self.0.padding_top |
33 | } |
34 | #[doc (alias = "get_padding_bottom" )] |
35 | #[inline ] |
36 | pub fn padding_bottom(&self) -> u32 { |
37 | self.0.padding_bottom |
38 | } |
39 | #[doc (alias = "get_padding_left" )] |
40 | #[inline ] |
41 | pub fn padding_left(&self) -> u32 { |
42 | self.0.padding_left |
43 | } |
44 | #[doc (alias = "get_padding_right" )] |
45 | #[inline ] |
46 | pub fn padding_right(&self) -> u32 { |
47 | self.0.padding_right |
48 | } |
49 | #[doc (alias = "get_stride_align" )] |
50 | #[inline ] |
51 | pub fn stride_align(&self) -> &[u32; ffi::GST_VIDEO_MAX_PLANES as usize] { |
52 | &self.0.stride_align |
53 | } |
54 | |
55 | pub fn new( |
56 | padding_top: u32, |
57 | padding_bottom: u32, |
58 | padding_left: u32, |
59 | padding_right: u32, |
60 | stride_align: &[u32; ffi::GST_VIDEO_MAX_PLANES as usize], |
61 | ) -> Self { |
62 | skip_assert_initialized!(); |
63 | |
64 | let videoalignment = ffi::GstVideoAlignment { |
65 | padding_top, |
66 | padding_bottom, |
67 | padding_left, |
68 | padding_right, |
69 | stride_align: *stride_align, |
70 | }; |
71 | |
72 | Self(videoalignment) |
73 | } |
74 | } |
75 | |
76 | impl PartialEq for VideoAlignment { |
77 | #[inline ] |
78 | fn eq(&self, other: &Self) -> bool { |
79 | self.padding_top() == other.padding_top() |
80 | && self.padding_bottom() == other.padding_bottom() |
81 | && self.padding_left() == other.padding_left() |
82 | && self.padding_right() == other.padding_right() |
83 | && self.stride_align() == other.stride_align() |
84 | } |
85 | } |
86 | |
87 | impl Eq for VideoAlignment {} |
88 | |
89 | #[doc (hidden)] |
90 | impl<'a> ToGlibPtr<'a, *const ffi::GstVideoAlignment> for VideoAlignment { |
91 | type Storage = PhantomData<&'a Self>; |
92 | |
93 | #[inline ] |
94 | fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GstVideoAlignment, Self> { |
95 | Stash(&self.0, PhantomData) |
96 | } |
97 | } |
98 | |
99 | pub trait VideoBufferPoolConfig { |
100 | #[doc (alias = "get_video_alignment" )] |
101 | fn video_alignment(&self) -> Option<VideoAlignment>; |
102 | |
103 | fn set_video_alignment(&mut self, align: &VideoAlignment); |
104 | } |
105 | |
106 | impl VideoBufferPoolConfig for gst::BufferPoolConfigRef { |
107 | #[doc (alias = "gst_buffer_pool_config_get_video_alignment" )] |
108 | fn video_alignment(&self) -> Option<VideoAlignment> { |
109 | unsafe { |
110 | let mut alignment = mem::MaybeUninit::uninit(); |
111 | let ret = from_glib(ffi::gst_buffer_pool_config_get_video_alignment( |
112 | self.as_ref().as_mut_ptr(), |
113 | alignment.as_mut_ptr(), |
114 | )); |
115 | if ret { |
116 | Some(VideoAlignment(alignment.assume_init())) |
117 | } else { |
118 | None |
119 | } |
120 | } |
121 | } |
122 | |
123 | #[doc (alias = "gst_buffer_pool_config_set_video_alignment" )] |
124 | fn set_video_alignment(&mut self, align: &VideoAlignment) { |
125 | unsafe { |
126 | ffi::gst_buffer_pool_config_set_video_alignment( |
127 | self.as_mut().as_mut_ptr(), |
128 | mut_override(&align.0), |
129 | ) |
130 | } |
131 | } |
132 | } |
133 | |