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