gstreamer_video/
video_buffer_pool.rs

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 crate::ffi;
6use glib::translate::*;
7
8pub static BUFFER_POOL_OPTION_VIDEO_AFFINE_TRANSFORMATION_META: &glib::GStr = unsafe {
9    glib::GStr::from_utf8_with_nul_unchecked(
10        ffi::GST_BUFFER_POOL_OPTION_VIDEO_AFFINE_TRANSFORMATION_META,
11    )
12};
13/// A bufferpool option to enable extra padding. When a bufferpool supports this
14/// option, `gst_buffer_pool_config_set_video_alignment()` can be called.
15///
16/// When this option is enabled on the bufferpool,
17/// `GST_BUFFER_POOL_OPTION_VIDEO_META` should also be enabled.
18pub static BUFFER_POOL_OPTION_VIDEO_ALIGNMENT: &glib::GStr = unsafe {
19    glib::GStr::from_utf8_with_nul_unchecked(ffi::GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT)
20};
21/// An option that can be activated on a bufferpool to request gl texture upload
22/// meta on buffers from the pool.
23///
24/// When this option is enabled on the bufferpool,
25/// `GST_BUFFER_POOL_OPTION_VIDEO_META` should also be enabled.
26pub static BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META: &glib::GStr = unsafe {
27    glib::GStr::from_utf8_with_nul_unchecked(
28        ffi::GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META,
29    )
30};
31/// An option that can be activated on bufferpool to request video metadata
32/// on buffers from the pool.
33pub static BUFFER_POOL_OPTION_VIDEO_META: &glib::GStr =
34    unsafe { glib::GStr::from_utf8_with_nul_unchecked(ffi::GST_BUFFER_POOL_OPTION_VIDEO_META) };
35
36#[derive(Debug, Clone, Copy)]
37#[doc(alias = "GstVideoAlignment")]
38pub struct VideoAlignment(pub(crate) ffi::GstVideoAlignment);
39
40impl VideoAlignment {
41    #[doc(alias = "get_padding_top")]
42    #[inline]
43    pub fn padding_top(&self) -> u32 {
44        self.0.padding_top
45    }
46
47    #[doc(alias = "get_padding_bottom")]
48    #[inline]
49    pub fn padding_bottom(&self) -> u32 {
50        self.0.padding_bottom
51    }
52
53    #[doc(alias = "get_padding_left")]
54    #[inline]
55    pub fn padding_left(&self) -> u32 {
56        self.0.padding_left
57    }
58
59    #[doc(alias = "get_padding_right")]
60    #[inline]
61    pub fn padding_right(&self) -> u32 {
62        self.0.padding_right
63    }
64
65    #[doc(alias = "get_stride_align")]
66    #[inline]
67    pub fn stride_align(&self) -> &[u32; crate::VIDEO_MAX_PLANES] {
68        &self.0.stride_align
69    }
70
71    #[inline]
72    pub fn set_padding_top(&mut self, padding_top: u32) {
73        self.0.padding_top = padding_top;
74    }
75
76    #[inline]
77    pub fn set_padding_bottom(&mut self, padding_bottom: u32) {
78        self.0.padding_bottom = padding_bottom;
79    }
80
81    #[inline]
82    pub fn set_padding_left(&mut self, padding_left: u32) {
83        self.0.padding_left = padding_left;
84    }
85
86    #[inline]
87    pub fn set_padding_right(&mut self, padding_right: u32) {
88        self.0.padding_right = padding_right;
89    }
90
91    #[inline]
92    pub fn stride_align_mut(&mut self) -> &mut [u32; crate::VIDEO_MAX_PLANES] {
93        &mut self.0.stride_align
94    }
95
96    pub fn new(
97        padding_top: u32,
98        padding_bottom: u32,
99        padding_left: u32,
100        padding_right: u32,
101        stride_align: &[u32; crate::VIDEO_MAX_PLANES],
102    ) -> Self {
103        skip_assert_initialized!();
104
105        let videoalignment = ffi::GstVideoAlignment {
106            padding_top,
107            padding_bottom,
108            padding_left,
109            padding_right,
110            stride_align: *stride_align,
111        };
112
113        Self(videoalignment)
114    }
115}
116
117impl PartialEq for VideoAlignment {
118    #[inline]
119    fn eq(&self, other: &Self) -> bool {
120        self.padding_top() == other.padding_top()
121            && self.padding_bottom() == other.padding_bottom()
122            && self.padding_left() == other.padding_left()
123            && self.padding_right() == other.padding_right()
124            && self.stride_align() == other.stride_align()
125    }
126}
127
128impl Eq for VideoAlignment {}
129
130impl Default for VideoAlignment {
131    fn default() -> Self {
132        unsafe {
133            let mut align = mem::MaybeUninit::uninit();
134            ffi::gst_video_alignment_reset(align.as_mut_ptr());
135            VideoAlignment(align.assume_init())
136        }
137    }
138}
139
140#[doc(hidden)]
141impl<'a> ToGlibPtr<'a, *const ffi::GstVideoAlignment> for VideoAlignment {
142    type Storage = PhantomData<&'a Self>;
143
144    #[inline]
145    fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GstVideoAlignment, Self> {
146        Stash(&self.0, PhantomData)
147    }
148}
149
150pub trait VideoBufferPoolConfig {
151    #[doc(alias = "get_video_alignment")]
152    fn video_alignment(&self) -> Option<VideoAlignment>;
153
154    fn set_video_alignment(&mut self, align: &VideoAlignment);
155}
156
157impl VideoBufferPoolConfig for gst::BufferPoolConfigRef {
158    #[doc(alias = "gst_buffer_pool_config_get_video_alignment")]
159    fn video_alignment(&self) -> Option<VideoAlignment> {
160        unsafe {
161            let mut alignment = mem::MaybeUninit::uninit();
162            let ret = from_glib(ffi::gst_buffer_pool_config_get_video_alignment(
163                self.as_ref().as_mut_ptr(),
164                alignment.as_mut_ptr(),
165            ));
166            if ret {
167                Some(VideoAlignment(alignment.assume_init()))
168            } else {
169                None
170            }
171        }
172    }
173
174    #[doc(alias = "gst_buffer_pool_config_set_video_alignment")]
175    fn set_video_alignment(&mut self, align: &VideoAlignment) {
176        unsafe {
177            ffi::gst_buffer_pool_config_set_video_alignment(
178                self.as_mut().as_mut_ptr(),
179                mut_override(&align.0),
180            )
181        }
182    }
183}