Skip to main content

gstreamer_video/
video_info_dma_drm.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::{fmt, marker::PhantomData, mem, ops, ptr, str};
4
5use glib::translate::*;
6use gst::prelude::*;
7
8use crate::{VideoFormat, VideoInfo, ffi};
9
10#[doc(alias = "gst_video_dma_drm_fourcc_from_format")]
11pub fn dma_drm_fourcc_from_format(v: VideoFormat) -> Result<u32, glib::BoolError> {
12    skip_assert_initialized!();
13    unsafe {
14        let res = ffi::gst_video_dma_drm_fourcc_from_format(v.into_glib());
15        if res == 0 {
16            Err(glib::bool_error!("Unsupported video format"))
17        } else {
18            Ok(res)
19        }
20    }
21}
22
23#[doc(alias = "gst_video_dma_drm_fourcc_to_format")]
24pub fn dma_drm_fourcc_to_format(v: u32) -> Result<VideoFormat, glib::BoolError> {
25    skip_assert_initialized!();
26    unsafe {
27        let res = ffi::gst_video_dma_drm_fourcc_to_format(v);
28        if res == ffi::GST_VIDEO_FORMAT_UNKNOWN {
29            Err(glib::bool_error!("Unsupported fourcc"))
30        } else {
31            Ok(from_glib(res))
32        }
33    }
34}
35
36#[doc(alias = "gst_video_dma_drm_fourcc_to_string")]
37pub fn dma_drm_fourcc_to_string(fourcc: u32, modifier: u64) -> glib::GString {
38    skip_assert_initialized!();
39    unsafe {
40        assert_ne!(fourcc, 0);
41        assert_ne!(modifier, 0x00ffffffffffffff);
42        glib::GString::from_glib_full(ffi::gst_video_dma_drm_fourcc_to_string(fourcc, modifier))
43    }
44}
45
46#[doc(alias = "gst_video_dma_drm_fourcc_from_string")]
47pub fn dma_drm_fourcc_from_str(v: &str) -> Result<(u32, u64), glib::BoolError> {
48    skip_assert_initialized!();
49    unsafe {
50        let mut modifier = mem::MaybeUninit::uninit();
51        let res =
52            ffi::gst_video_dma_drm_fourcc_from_string(v.to_glib_none().0, modifier.as_mut_ptr());
53        if res == 0 {
54            Err(glib::bool_error!("Can't parse fourcc string"))
55        } else {
56            Ok((res, modifier.assume_init()))
57        }
58    }
59}
60
61#[cfg(feature = "v1_26")]
62#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
63#[doc(alias = "gst_video_dma_drm_format_from_gst_format")]
64pub fn dma_drm_format_from_gst_format(v: VideoFormat) -> Result<(u32, u64), glib::BoolError> {
65    skip_assert_initialized!();
66    unsafe {
67        let mut modifier = mem::MaybeUninit::uninit();
68        let res =
69            ffi::gst_video_dma_drm_format_from_gst_format(v.into_glib(), modifier.as_mut_ptr());
70        if res == 0 {
71            Err(glib::bool_error!("Unsupported video format"))
72        } else {
73            Ok((res, modifier.assume_init()))
74        }
75    }
76}
77
78#[cfg(feature = "v1_26")]
79#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
80#[doc(alias = "gst_video_dma_drm_format_to_gst_format")]
81pub fn dma_drm_format_to_gst_format(
82    fourcc: u32,
83    modifier: u64,
84) -> Result<VideoFormat, glib::BoolError> {
85    skip_assert_initialized!();
86    unsafe {
87        let res = ffi::gst_video_dma_drm_format_to_gst_format(fourcc, modifier);
88        if res == ffi::GST_VIDEO_FORMAT_UNKNOWN {
89            Err(glib::bool_error!("Unsupported fourcc format / modifier"))
90        } else {
91            Ok(from_glib(res))
92        }
93    }
94}
95
96#[doc(alias = "gst_video_is_dma_drm_caps")]
97pub fn is_dma_drm_caps(caps: &gst::CapsRef) -> bool {
98    skip_assert_initialized!();
99    unsafe { from_glib(ffi::gst_video_is_dma_drm_caps(caps.as_ptr())) }
100}
101
102#[doc(alias = "GstVideoInfoDmaDrm")]
103#[derive(Clone)]
104#[repr(transparent)]
105pub struct VideoInfoDmaDrm(pub(crate) ffi::GstVideoInfoDmaDrm);
106
107impl ops::Deref for VideoInfoDmaDrm {
108    type Target = VideoInfo;
109
110    fn deref(&self) -> &Self::Target {
111        unsafe { &*(&self.0.vinfo as *const ffi::GstVideoInfo as *const VideoInfo) }
112    }
113}
114
115impl fmt::Debug for VideoInfoDmaDrm {
116    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
117        f.debug_struct("VideoInfoDmaDrm")
118            .field("info", &**self)
119            .field("drm_fourcc", &self.0.drm_fourcc)
120            .field("drm_modifier", &self.0.drm_modifier)
121            .finish()
122    }
123}
124
125impl VideoInfoDmaDrm {
126    pub fn new(info: VideoInfo, fourcc: u32, modifier: u64) -> VideoInfoDmaDrm {
127        assert_initialized_main_thread!();
128
129        VideoInfoDmaDrm(ffi::GstVideoInfoDmaDrm {
130            vinfo: info.0,
131            drm_fourcc: fourcc,
132            drm_modifier: modifier,
133            _gst_reserved: [0; 20],
134        })
135    }
136
137    #[inline]
138    pub fn is_valid(&self) -> bool {
139        !self.0.vinfo.finfo.is_null()
140            && self.0.vinfo.width > 0
141            && self.0.vinfo.height > 0
142            && self.0.vinfo.size > 0
143    }
144
145    #[doc(alias = "gst_video_info_dma_drm_from_caps")]
146    pub fn from_caps(caps: &gst::CapsRef) -> Result<Self, glib::error::BoolError> {
147        skip_assert_initialized!();
148
149        unsafe {
150            let mut info = mem::MaybeUninit::uninit();
151            if from_glib(ffi::gst_video_info_dma_drm_from_caps(
152                info.as_mut_ptr(),
153                caps.as_ptr(),
154            )) {
155                Ok(Self(info.assume_init()))
156            } else {
157                Err(glib::bool_error!(
158                    "Failed to create VideoInfoDmaDrm from caps"
159                ))
160            }
161        }
162    }
163
164    #[doc(alias = "gst_video_info_dma_drm_to_caps")]
165    pub fn to_caps(&self) -> Result<gst::Caps, glib::error::BoolError> {
166        unsafe {
167            let result = from_glib_full(ffi::gst_video_info_dma_drm_to_caps(mut_override(&self.0)));
168            match result {
169                Some(c) => Ok(c),
170                None => Err(glib::bool_error!(
171                    "Failed to create caps from VideoInfoDmaDrm"
172                )),
173            }
174        }
175    }
176
177    #[doc(alias = "gst_video_info_dma_drm_from_video_info")]
178    pub fn from_video_info(
179        video_info: &crate::VideoInfo,
180        modifier: u64,
181    ) -> Result<Self, glib::error::BoolError> {
182        skip_assert_initialized!();
183
184        unsafe {
185            let mut info = mem::MaybeUninit::uninit();
186            if from_glib(ffi::gst_video_info_dma_drm_from_video_info(
187                info.as_mut_ptr(),
188                video_info.to_glib_none().0,
189                modifier,
190            )) {
191                Ok(Self(info.assume_init()))
192            } else {
193                Err(glib::bool_error!(
194                    "Failed to create VideoInfoDmaDrm from VideoInfo"
195                ))
196            }
197        }
198    }
199
200    #[doc(alias = "gst_video_info_dma_drm_to_video_info")]
201    pub fn to_video_info(&self) -> Result<crate::VideoInfo, glib::error::BoolError> {
202        unsafe {
203            let mut video_info = mem::MaybeUninit::uninit();
204            if from_glib(ffi::gst_video_info_dma_drm_to_video_info(
205                mut_override(&self.0),
206                video_info.as_mut_ptr(),
207            )) {
208                Ok(crate::VideoInfo(video_info.assume_init()))
209            } else {
210                Err(glib::bool_error!(
211                    "Failed to create VideoInfo from VideoInfoDmaDrm"
212                ))
213            }
214        }
215    }
216
217    #[inline]
218    pub fn fourcc(&self) -> u32 {
219        self.0.drm_fourcc
220    }
221
222    #[inline]
223    pub fn modifier(&self) -> u64 {
224        self.0.drm_modifier
225    }
226}
227
228impl PartialEq for VideoInfoDmaDrm {
229    #[doc(alias = "gst_video_info_is_equal")]
230    fn eq(&self, other: &Self) -> bool {
231        unsafe {
232            from_glib(ffi::gst_video_info_is_equal(&self.0.vinfo, &other.0.vinfo))
233                && self.0.drm_fourcc == other.0.drm_fourcc
234                && self.0.drm_modifier == other.0.drm_modifier
235        }
236    }
237}
238
239impl Eq for VideoInfoDmaDrm {}
240
241unsafe impl Send for VideoInfoDmaDrm {}
242unsafe impl Sync for VideoInfoDmaDrm {}
243
244impl glib::types::StaticType for VideoInfoDmaDrm {
245    #[inline]
246    fn static_type() -> glib::types::Type {
247        unsafe { glib::translate::from_glib(ffi::gst_video_info_dma_drm_get_type()) }
248    }
249}
250
251impl glib::value::ValueType for VideoInfoDmaDrm {
252    type Type = Self;
253}
254
255#[doc(hidden)]
256unsafe impl<'a> glib::value::FromValue<'a> for VideoInfoDmaDrm {
257    type Checker = glib::value::GenericValueTypeOrNoneChecker<Self>;
258
259    unsafe fn from_value(value: &'a glib::Value) -> Self {
260        unsafe {
261            skip_assert_initialized!();
262            from_glib_none(glib::gobject_ffi::g_value_get_boxed(value.to_glib_none().0)
263                as *mut ffi::GstVideoInfoDmaDrm)
264        }
265    }
266}
267
268#[doc(hidden)]
269impl glib::value::ToValue for VideoInfoDmaDrm {
270    fn to_value(&self) -> glib::Value {
271        let mut value = glib::Value::for_value_type::<Self>();
272        unsafe {
273            glib::gobject_ffi::g_value_set_boxed(
274                value.to_glib_none_mut().0,
275                self.to_glib_none().0 as *mut _,
276            )
277        }
278        value
279    }
280
281    fn value_type(&self) -> glib::Type {
282        Self::static_type()
283    }
284}
285
286#[doc(hidden)]
287impl glib::value::ToValueOptional for VideoInfoDmaDrm {
288    fn to_value_optional(s: Option<&Self>) -> glib::Value {
289        skip_assert_initialized!();
290        let mut value = glib::Value::for_value_type::<Self>();
291        unsafe {
292            glib::gobject_ffi::g_value_set_boxed(
293                value.to_glib_none_mut().0,
294                s.to_glib_none().0 as *mut _,
295            )
296        }
297        value
298    }
299}
300
301#[doc(hidden)]
302impl From<VideoInfoDmaDrm> for glib::Value {
303    fn from(v: VideoInfoDmaDrm) -> glib::Value {
304        skip_assert_initialized!();
305        glib::value::ToValue::to_value(&v)
306    }
307}
308
309#[doc(hidden)]
310impl glib::translate::Uninitialized for VideoInfoDmaDrm {
311    #[inline]
312    unsafe fn uninitialized() -> Self {
313        unsafe { mem::zeroed() }
314    }
315}
316
317#[doc(hidden)]
318impl glib::translate::GlibPtrDefault for VideoInfoDmaDrm {
319    type GlibType = *mut ffi::GstVideoInfoDmaDrm;
320}
321
322#[doc(hidden)]
323impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstVideoInfoDmaDrm> for VideoInfoDmaDrm {
324    type Storage = PhantomData<&'a Self>;
325
326    #[inline]
327    fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstVideoInfoDmaDrm, Self> {
328        glib::translate::Stash(&self.0, PhantomData)
329    }
330
331    fn to_glib_full(&self) -> *const ffi::GstVideoInfoDmaDrm {
332        unimplemented!()
333    }
334}
335
336#[doc(hidden)]
337impl glib::translate::FromGlibPtrNone<*const ffi::GstVideoInfoDmaDrm> for VideoInfoDmaDrm {
338    #[inline]
339    unsafe fn from_glib_none(ptr: *const ffi::GstVideoInfoDmaDrm) -> Self {
340        unsafe { Self(ptr::read(ptr)) }
341    }
342}
343
344#[doc(hidden)]
345impl glib::translate::FromGlibPtrNone<*mut ffi::GstVideoInfoDmaDrm> for VideoInfoDmaDrm {
346    #[inline]
347    unsafe fn from_glib_none(ptr: *mut ffi::GstVideoInfoDmaDrm) -> Self {
348        unsafe { Self(ptr::read(ptr)) }
349    }
350}
351
352#[doc(hidden)]
353impl glib::translate::FromGlibPtrFull<*mut ffi::GstVideoInfoDmaDrm> for VideoInfoDmaDrm {
354    #[inline]
355    unsafe fn from_glib_full(ptr: *mut ffi::GstVideoInfoDmaDrm) -> Self {
356        unsafe {
357            let info = from_glib_none(ptr);
358            glib::ffi::g_free(ptr as *mut _);
359            info
360        }
361    }
362}