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