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)]
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    #[doc(alias = "get_padding_bottom")]
47    #[inline]
48    pub fn padding_bottom(&self) -> u32 {
49        self.0.padding_bottom
50    }
51    #[doc(alias = "get_padding_left")]
52    #[inline]
53    pub fn padding_left(&self) -> u32 {
54        self.0.padding_left
55    }
56    #[doc(alias = "get_padding_right")]
57    #[inline]
58    pub fn padding_right(&self) -> u32 {
59        self.0.padding_right
60    }
61    #[doc(alias = "get_stride_align")]
62    #[inline]
63    pub fn stride_align(&self) -> &[u32; ffi::GST_VIDEO_MAX_PLANES as usize] {
64        &self.0.stride_align
65    }
66
67    pub fn new(
68        padding_top: u32,
69        padding_bottom: u32,
70        padding_left: u32,
71        padding_right: u32,
72        stride_align: &[u32; ffi::GST_VIDEO_MAX_PLANES as usize],
73    ) -> Self {
74        skip_assert_initialized!();
75
76        let videoalignment = ffi::GstVideoAlignment {
77            padding_top,
78            padding_bottom,
79            padding_left,
80            padding_right,
81            stride_align: *stride_align,
82        };
83
84        Self(videoalignment)
85    }
86}
87
88impl PartialEq for VideoAlignment {
89    #[inline]
90    fn eq(&self, other: &Self) -> bool {
91        self.padding_top() == other.padding_top()
92            && self.padding_bottom() == other.padding_bottom()
93            && self.padding_left() == other.padding_left()
94            && self.padding_right() == other.padding_right()
95            && self.stride_align() == other.stride_align()
96    }
97}
98
99impl Eq for VideoAlignment {}
100
101#[doc(hidden)]
102impl<'a> ToGlibPtr<'a, *const ffi::GstVideoAlignment> for VideoAlignment {
103    type Storage = PhantomData<&'a Self>;
104
105    #[inline]
106    fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GstVideoAlignment, Self> {
107        Stash(&self.0, PhantomData)
108    }
109}
110
111pub trait VideoBufferPoolConfig {
112    #[doc(alias = "get_video_alignment")]
113    fn video_alignment(&self) -> Option<VideoAlignment>;
114
115    fn set_video_alignment(&mut self, align: &VideoAlignment);
116}
117
118impl VideoBufferPoolConfig for gst::BufferPoolConfigRef {
119    #[doc(alias = "gst_buffer_pool_config_get_video_alignment")]
120    fn video_alignment(&self) -> Option<VideoAlignment> {
121        unsafe {
122            let mut alignment = mem::MaybeUninit::uninit();
123            let ret = from_glib(ffi::gst_buffer_pool_config_get_video_alignment(
124                self.as_ref().as_mut_ptr(),
125                alignment.as_mut_ptr(),
126            ));
127            if ret {
128                Some(VideoAlignment(alignment.assume_init()))
129            } else {
130                None
131            }
132        }
133    }
134
135    #[doc(alias = "gst_buffer_pool_config_set_video_alignment")]
136    fn set_video_alignment(&mut self, align: &VideoAlignment) {
137        unsafe {
138            ffi::gst_buffer_pool_config_set_video_alignment(
139                self.as_mut().as_mut_ptr(),
140                mut_override(&align.0),
141            )
142        }
143    }
144}