1use crate::utils::{
5 result::{Error, SpaResult, SpaSuccess},
6 Fraction, Rectangle,
7};
8
9use std::{ffi::CStr, fmt::Debug};
10
11#[cfg(feature = "v0_3_65")]
12use crate::utils::fmt_pascal_case;
13
14#[derive(Copy, Clone, PartialEq, Eq)]
15pub struct VideoFormat(pub spa_sys::spa_video_format);
16
17#[allow(non_upper_case_globals)]
18impl VideoFormat {
19 pub const Unknown: Self = Self(spa_sys::SPA_VIDEO_FORMAT_UNKNOWN);
20 pub const Encoded: Self = Self(spa_sys::SPA_VIDEO_FORMAT_ENCODED);
21
22 pub const I420: Self = Self(spa_sys::SPA_VIDEO_FORMAT_I420);
23 pub const YV12: Self = Self(spa_sys::SPA_VIDEO_FORMAT_YV12);
24 pub const YUY2: Self = Self(spa_sys::SPA_VIDEO_FORMAT_YUY2);
25 pub const UYVY: Self = Self(spa_sys::SPA_VIDEO_FORMAT_UYVY);
26 pub const AYUV: Self = Self(spa_sys::SPA_VIDEO_FORMAT_AYUV);
27 pub const RGBx: Self = Self(spa_sys::SPA_VIDEO_FORMAT_RGBx);
28 pub const BGRx: Self = Self(spa_sys::SPA_VIDEO_FORMAT_BGRx);
29 pub const xRGB: Self = Self(spa_sys::SPA_VIDEO_FORMAT_xRGB);
30 pub const xBGR: Self = Self(spa_sys::SPA_VIDEO_FORMAT_xBGR);
31 pub const RGBA: Self = Self(spa_sys::SPA_VIDEO_FORMAT_RGBA);
32 pub const BGRA: Self = Self(spa_sys::SPA_VIDEO_FORMAT_BGRA);
33 pub const ARGB: Self = Self(spa_sys::SPA_VIDEO_FORMAT_ARGB);
34 pub const ABGR: Self = Self(spa_sys::SPA_VIDEO_FORMAT_ABGR);
35 pub const RGB: Self = Self(spa_sys::SPA_VIDEO_FORMAT_RGB);
36 pub const BGR: Self = Self(spa_sys::SPA_VIDEO_FORMAT_BGR);
37 pub const Y41B: Self = Self(spa_sys::SPA_VIDEO_FORMAT_Y41B);
38 pub const Y42B: Self = Self(spa_sys::SPA_VIDEO_FORMAT_Y42B);
39 pub const YVYU: Self = Self(spa_sys::SPA_VIDEO_FORMAT_YVYU);
40 pub const Y444: Self = Self(spa_sys::SPA_VIDEO_FORMAT_Y444);
41 pub const v210: Self = Self(spa_sys::SPA_VIDEO_FORMAT_v210);
42 pub const v216: Self = Self(spa_sys::SPA_VIDEO_FORMAT_v216);
43 pub const NV12: Self = Self(spa_sys::SPA_VIDEO_FORMAT_NV12);
44 pub const NV21: Self = Self(spa_sys::SPA_VIDEO_FORMAT_NV21);
45 pub const GRAY8: Self = Self(spa_sys::SPA_VIDEO_FORMAT_GRAY8);
46 pub const GRAY16_BE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_GRAY16_BE);
47 pub const GRAY16_LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_GRAY16_LE);
48 pub const v308: Self = Self(spa_sys::SPA_VIDEO_FORMAT_v308);
49 pub const RGB16: Self = Self(spa_sys::SPA_VIDEO_FORMAT_RGB16);
50 pub const BGR16: Self = Self(spa_sys::SPA_VIDEO_FORMAT_BGR16);
51 pub const RGB15: Self = Self(spa_sys::SPA_VIDEO_FORMAT_RGB15);
52 pub const BGR15: Self = Self(spa_sys::SPA_VIDEO_FORMAT_BGR15);
53 pub const UYVP: Self = Self(spa_sys::SPA_VIDEO_FORMAT_UYVP);
54 pub const A420: Self = Self(spa_sys::SPA_VIDEO_FORMAT_A420);
55 pub const RGB8P: Self = Self(spa_sys::SPA_VIDEO_FORMAT_RGB8P);
56 pub const YUV9: Self = Self(spa_sys::SPA_VIDEO_FORMAT_YUV9);
57 pub const YVU9: Self = Self(spa_sys::SPA_VIDEO_FORMAT_YVU9);
58 pub const IYU1: Self = Self(spa_sys::SPA_VIDEO_FORMAT_IYU1);
59 pub const ARGB64: Self = Self(spa_sys::SPA_VIDEO_FORMAT_ARGB64);
60 pub const AYUV64: Self = Self(spa_sys::SPA_VIDEO_FORMAT_AYUV64);
61 pub const r210: Self = Self(spa_sys::SPA_VIDEO_FORMAT_r210);
62 pub const I420_10BE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_I420_10BE);
63 pub const I420_10LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_I420_10LE);
64 pub const I422_10BE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_I422_10BE);
65 pub const I422_10LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_I422_10LE);
66 pub const Y444_10BE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_Y444_10BE);
67 pub const Y444_10LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_Y444_10LE);
68 pub const GBR: Self = Self(spa_sys::SPA_VIDEO_FORMAT_GBR);
69 pub const GBR_10BE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_GBR_10BE);
70 pub const GBR_10LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_GBR_10LE);
71 pub const NV16: Self = Self(spa_sys::SPA_VIDEO_FORMAT_NV16);
72 pub const NV24: Self = Self(spa_sys::SPA_VIDEO_FORMAT_NV24);
73 pub const NV12_64Z32: Self = Self(spa_sys::SPA_VIDEO_FORMAT_NV12_64Z32);
74 pub const A420_10BE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_A420_10BE);
75 pub const A420_10LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_A420_10LE);
76 pub const A422_10BE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_A422_10BE);
77 pub const A422_10LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_A422_10LE);
78 pub const A444_10BE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_A444_10BE);
79 pub const A444_10LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_A444_10LE);
80 pub const NV61: Self = Self(spa_sys::SPA_VIDEO_FORMAT_NV61);
81 pub const P010_10BE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_P010_10BE);
82 pub const P010_10LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_P010_10LE);
83 pub const IYU2: Self = Self(spa_sys::SPA_VIDEO_FORMAT_IYU2);
84 pub const VYUY: Self = Self(spa_sys::SPA_VIDEO_FORMAT_VYUY);
85 pub const GBRA: Self = Self(spa_sys::SPA_VIDEO_FORMAT_GBRA);
86 pub const GBRA_10BE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_GBRA_10BE);
87 pub const GBRA_10LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_GBRA_10LE);
88 pub const GBR_12BE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_GBR_12BE);
89 pub const GBR_12LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_GBR_12LE);
90 pub const GBRA_12BE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_GBRA_12BE);
91 pub const GBRA_12LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_GBRA_12LE);
92 pub const I420_12BE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_I420_12BE);
93 pub const I420_12LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_I420_12LE);
94 pub const I422_12BE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_I422_12BE);
95 pub const I422_12LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_I422_12LE);
96 pub const Y444_12BE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_Y444_12BE);
97 pub const Y444_12LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_Y444_12LE);
98
99 pub const RGBA_F16: Self = Self(spa_sys::SPA_VIDEO_FORMAT_RGBA_F16);
100 pub const RGBA_F32: Self = Self(spa_sys::SPA_VIDEO_FORMAT_RGBA_F32);
101
102 pub const xRGB_210LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_xRGB_210LE);
104 pub const xBGR_210LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_xBGR_210LE);
106 pub const RGBx_102LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_RGBx_102LE);
108 pub const BGRx_102LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_BGRx_102LE);
110 pub const ARGB_210LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_ARGB_210LE);
112 pub const ABGR_210LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_ABGR_210LE);
114 pub const RGBA_102LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_RGBA_102LE);
116 pub const BGRA_102LE: Self = Self(spa_sys::SPA_VIDEO_FORMAT_BGRA_102LE);
118
119 pub const DSP_F32: Self = Self(spa_sys::SPA_VIDEO_FORMAT_DSP_F32);
121
122 pub fn from_raw(raw: spa_sys::spa_video_format) -> Self {
124 Self(raw)
125 }
126
127 pub fn as_raw(&self) -> spa_sys::spa_video_format {
129 self.0
130 }
131}
132
133impl Debug for VideoFormat {
134 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
135 match *self {
136 VideoFormat::Unknown => f.write_str("VideoFormat::Unknown"),
137 _ => {
138 let c_str = unsafe {
139 let c_buf = spa_sys::spa_debug_type_find_short_name(
140 spa_sys::spa_type_video_format,
141 self.as_raw(),
142 );
143 if c_buf.is_null() {
144 return f.write_str("Unsupported");
145 }
146 CStr::from_ptr(c_buf)
147 };
148 let name = format!("VideoFormat::{}", c_str.to_string_lossy());
149 f.write_str(&name)
150 }
151 }
152 }
153}
154
155bitflags::bitflags! {
156 #[derive(Debug, PartialEq, Eq, Clone, Copy)]
157 pub struct VideoFlags: u32 {
158 const NONE = spa_sys::SPA_VIDEO_FLAG_NONE;
160 const VARIABLE_FPS = spa_sys::SPA_VIDEO_FLAG_VARIABLE_FPS;
162 const PREMULTIPLIED_ALPHA = spa_sys::SPA_VIDEO_FLAG_PREMULTIPLIED_ALPHA;
164 #[cfg(feature = "v0_3_65")]
166 const MODIFIER = spa_sys::SPA_VIDEO_FLAG_MODIFIER;
167 #[cfg(feature = "v0_3_75")]
168 const MODIFIER_FIXATION_REQUIRED = spa_sys::SPA_VIDEO_FLAG_MODIFIER_FIXATION_REQUIRED;
170 }
171}
172
173#[derive(Copy, Clone, PartialEq, Eq)]
174pub struct VideoInterlaceMode(pub spa_sys::spa_video_interlace_mode);
175
176#[allow(non_upper_case_globals)]
177impl VideoInterlaceMode {
178 pub const Progressive: Self = Self(spa_sys::SPA_VIDEO_INTERLACE_MODE_PROGRESSIVE);
180 pub const Interleaved: Self = Self(spa_sys::SPA_VIDEO_INTERLACE_MODE_INTERLEAVED);
183 pub const Mixed: Self = Self(spa_sys::SPA_VIDEO_INTERLACE_MODE_MIXED);
185 pub const Fields: Self = Self(spa_sys::SPA_VIDEO_INTERLACE_MODE_FIELDS);
189
190 pub fn from_raw(raw: spa_sys::spa_video_interlace_mode) -> Self {
192 Self(raw)
193 }
194
195 pub fn as_raw(&self) -> spa_sys::spa_video_interlace_mode {
197 self.0
198 }
199}
200
201#[cfg(feature = "v0_3_65")]
202impl Debug for VideoInterlaceMode {
203 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
204 let c_str = unsafe {
205 let c_buf = spa_sys::spa_debug_type_find_short_name(
206 spa_sys::spa_type_video_interlace_mode,
207 self.as_raw(),
208 );
209 if c_buf.is_null() {
210 return f.write_str("Unsupported");
211 }
212 CStr::from_ptr(c_buf)
213 };
214 f.write_str("VideoInterlaceMode::")?;
215 fmt_pascal_case(f, &c_str.to_string_lossy())
216 }
217}
218
219#[cfg_attr(not(feature = "v1_6_0"), derive(Debug))]
220#[derive(Copy, Clone, PartialEq, Eq)]
221pub struct VideoColorRange(pub spa_sys::spa_video_color_range);
222
223#[allow(non_upper_case_globals)]
224impl VideoColorRange {
225 pub const Unknown: Self = Self(spa_sys::SPA_VIDEO_COLOR_RANGE_UNKNOWN);
226 pub const Full: Self = Self(spa_sys::SPA_VIDEO_COLOR_RANGE_0_255);
227 pub const Limited: Self = Self(spa_sys::SPA_VIDEO_COLOR_RANGE_16_235);
228
229 pub fn from_raw(raw: spa_sys::spa_video_color_range) -> Self {
230 Self(raw)
231 }
232
233 pub fn as_raw(&self) -> spa_sys::spa_video_color_range {
234 self.0
235 }
236}
237
238#[cfg(feature = "v1_6_0")]
239impl Debug for VideoColorRange {
240 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
241 let c_str = unsafe {
242 let c_buf = spa_sys::spa_debug_type_find_short_name(
243 spa_sys::spa_type_video_color_range,
244 self.as_raw(),
245 );
246 if c_buf.is_null() {
247 return f.write_str("Unsupported");
248 }
249 CStr::from_ptr(c_buf)
250 };
251 f.write_str("VideoColorRange::")?;
252 fmt_pascal_case(f, &c_str.to_string_lossy())
253 }
254}
255
256#[cfg_attr(not(feature = "v1_6_0"), derive(Debug))]
257#[derive(Copy, Clone, PartialEq, Eq)]
258pub struct VideoColorMatrix(pub spa_sys::spa_video_color_matrix);
259
260#[allow(non_upper_case_globals)]
261impl VideoColorMatrix {
262 pub const Unknown: Self = Self(spa_sys::SPA_VIDEO_COLOR_MATRIX_UNKNOWN);
263 pub const RGB: Self = Self(spa_sys::SPA_VIDEO_COLOR_MATRIX_RGB);
264 pub const FCC: Self = Self(spa_sys::SPA_VIDEO_COLOR_MATRIX_FCC);
265 pub const BT709: Self = Self(spa_sys::SPA_VIDEO_COLOR_MATRIX_BT709);
266 pub const BT601: Self = Self(spa_sys::SPA_VIDEO_COLOR_MATRIX_BT601);
267 pub const SMPTE240M: Self = Self(spa_sys::SPA_VIDEO_COLOR_MATRIX_SMPTE240M);
268 pub const BT2020: Self = Self(spa_sys::SPA_VIDEO_COLOR_MATRIX_BT2020);
269
270 pub fn from_raw(raw: spa_sys::spa_video_color_matrix) -> Self {
271 Self(raw)
272 }
273
274 pub fn as_raw(&self) -> spa_sys::spa_video_color_matrix {
275 self.0
276 }
277}
278
279#[cfg(feature = "v1_6_0")]
280impl Debug for VideoColorMatrix {
281 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
282 let c_str = unsafe {
283 let c_buf = spa_sys::spa_debug_type_find_short_name(
284 spa_sys::spa_type_video_color_matrix,
285 self.as_raw(),
286 );
287 if c_buf.is_null() {
288 return f.write_str("Unsupported");
289 }
290 CStr::from_ptr(c_buf)
291 };
292 f.write_str("VideoColorMatrix::")?;
293 fmt_pascal_case(f, &c_str.to_string_lossy())
294 }
295}
296
297#[cfg_attr(not(feature = "v1_6_0"), derive(Debug))]
298#[derive(Copy, Clone, PartialEq, Eq)]
299pub struct VideoTransferFunction(pub spa_sys::spa_video_transfer_function);
300
301#[allow(non_upper_case_globals)]
302impl VideoTransferFunction {
303 pub const Unknown: Self = Self(spa_sys::SPA_VIDEO_TRANSFER_UNKNOWN);
304 pub const Gamma10: Self = Self(spa_sys::SPA_VIDEO_TRANSFER_GAMMA10);
305 pub const Gamma18: Self = Self(spa_sys::SPA_VIDEO_TRANSFER_GAMMA18);
306 pub const Gamma20: Self = Self(spa_sys::SPA_VIDEO_TRANSFER_GAMMA20);
307 pub const Gamma22: Self = Self(spa_sys::SPA_VIDEO_TRANSFER_GAMMA22);
308 pub const BT709: Self = Self(spa_sys::SPA_VIDEO_TRANSFER_BT709);
309 pub const SMPTE240M: Self = Self(spa_sys::SPA_VIDEO_TRANSFER_SMPTE240M);
310 pub const SRGB: Self = Self(spa_sys::SPA_VIDEO_TRANSFER_SRGB);
311 pub const Gamma28: Self = Self(spa_sys::SPA_VIDEO_TRANSFER_GAMMA28);
312 pub const Log100: Self = Self(spa_sys::SPA_VIDEO_TRANSFER_LOG100);
313 pub const Log316: Self = Self(spa_sys::SPA_VIDEO_TRANSFER_LOG316);
314 pub const BT2020_12: Self = Self(spa_sys::SPA_VIDEO_TRANSFER_BT2020_12);
315 pub const AdobeRGB: Self = Self(spa_sys::SPA_VIDEO_TRANSFER_ADOBERGB);
316 #[cfg(feature = "v1_6_0")]
317 pub const BT2020_10: Self = Self(spa_sys::SPA_VIDEO_TRANSFER_BT2020_10);
318 #[cfg(feature = "v1_6_0")]
319 pub const SMPTE2084: Self = Self(spa_sys::SPA_VIDEO_TRANSFER_SMPTE2084);
320 #[cfg(feature = "v1_6_0")]
321 pub const ARIB_STD_B67: Self = Self(spa_sys::SPA_VIDEO_TRANSFER_ARIB_STD_B67);
322 #[cfg(feature = "v1_6_0")]
323 pub const BT601: Self = Self(spa_sys::SPA_VIDEO_TRANSFER_BT601);
324
325 pub fn from_raw(raw: spa_sys::spa_video_transfer_function) -> Self {
326 Self(raw)
327 }
328
329 pub fn as_raw(&self) -> spa_sys::spa_video_transfer_function {
330 self.0
331 }
332}
333
334#[cfg(feature = "v1_6_0")]
335impl Debug for VideoTransferFunction {
336 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
337 let c_str = unsafe {
338 let c_buf = spa_sys::spa_debug_type_find_short_name(
339 spa_sys::spa_type_video_transfer_function,
340 self.as_raw(),
341 );
342 if c_buf.is_null() {
343 return f.write_str("Unsupported");
344 }
345 CStr::from_ptr(c_buf)
346 };
347 f.write_str("VideoTransferFunction::")?;
348 fmt_pascal_case(f, &c_str.to_string_lossy())
349 }
350}
351
352#[cfg_attr(not(feature = "v1_6_0"), derive(Debug))]
353#[derive(Copy, Clone, PartialEq, Eq)]
354pub struct VideoColorPrimaries(pub spa_sys::spa_video_color_primaries);
355
356#[allow(non_upper_case_globals)]
357impl VideoColorPrimaries {
358 pub const Unknown: Self = Self(spa_sys::SPA_VIDEO_COLOR_PRIMARIES_UNKNOWN);
359 pub const BT709: Self = Self(spa_sys::SPA_VIDEO_COLOR_PRIMARIES_BT709);
360 pub const BT470M: Self = Self(spa_sys::SPA_VIDEO_COLOR_PRIMARIES_BT470M);
361 pub const BT470BG: Self = Self(spa_sys::SPA_VIDEO_COLOR_PRIMARIES_BT470BG);
362 pub const SMPTE170M: Self = Self(spa_sys::SPA_VIDEO_COLOR_PRIMARIES_SMPTE170M);
363 pub const SMPTE240M: Self = Self(spa_sys::SPA_VIDEO_COLOR_PRIMARIES_SMPTE240M);
364 pub const Film: Self = Self(spa_sys::SPA_VIDEO_COLOR_PRIMARIES_FILM);
365 pub const BT2020: Self = Self(spa_sys::SPA_VIDEO_COLOR_PRIMARIES_BT2020);
366 pub const AdobeRGB: Self = Self(spa_sys::SPA_VIDEO_COLOR_PRIMARIES_ADOBERGB);
367 #[cfg(feature = "v1_6_0")]
368 pub const SMPTEST428: Self = Self(spa_sys::SPA_VIDEO_COLOR_PRIMARIES_SMPTEST428);
369 #[cfg(feature = "v1_6_0")]
370 pub const SMPTERP431: Self = Self(spa_sys::SPA_VIDEO_COLOR_PRIMARIES_SMPTERP431);
371 #[cfg(feature = "v1_6_0")]
372 pub const SMPTEEG432: Self = Self(spa_sys::SPA_VIDEO_COLOR_PRIMARIES_SMPTEEG432);
373 #[cfg(feature = "v1_6_0")]
374 pub const EBU3213: Self = Self(spa_sys::SPA_VIDEO_COLOR_PRIMARIES_EBU3213);
375
376 pub fn from_raw(raw: spa_sys::spa_video_color_primaries) -> Self {
377 Self(raw)
378 }
379
380 pub fn as_raw(&self) -> spa_sys::spa_video_color_primaries {
381 self.0
382 }
383}
384
385#[cfg(feature = "v1_6_0")]
386impl Debug for VideoColorPrimaries {
387 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
388 let c_str = unsafe {
389 let c_buf = spa_sys::spa_debug_type_find_short_name(
390 spa_sys::spa_type_video_color_primaries,
391 self.as_raw(),
392 );
393 if c_buf.is_null() {
394 return f.write_str("Unsupported");
395 }
396 CStr::from_ptr(c_buf)
397 };
398 f.write_str("VideoColorPrimaries::")?;
399 fmt_pascal_case(f, &c_str.to_string_lossy())
400 }
401}
402
403#[repr(transparent)]
405#[derive(PartialEq, Eq, Clone, Copy)]
406pub struct VideoInfoRaw(spa_sys::spa_video_info_raw);
407
408impl VideoInfoRaw {
409 pub fn new() -> Self {
410 Self(spa_sys::spa_video_info_raw {
411 format: VideoFormat::Unknown.as_raw(),
412 flags: 0,
413 modifier: 0,
414 size: Rectangle {
415 width: 0,
416 height: 0,
417 },
418 framerate: Fraction { num: 0, denom: 0 },
419 max_framerate: Fraction { num: 0, denom: 0 },
420 views: 0,
421 interlace_mode: VideoInterlaceMode::Progressive.as_raw(),
422 pixel_aspect_ratio: Fraction { num: 0, denom: 0 },
423 multiview_mode: 0,
424 multiview_flags: 0,
425 chroma_site: 0,
426 color_range: 0,
427 color_matrix: 0,
428 transfer_function: 0,
429 color_primaries: 0,
430 })
431 }
432
433 pub fn set_format(&mut self, format: VideoFormat) {
434 self.0.format = format.as_raw();
435 }
436
437 pub fn format(self) -> VideoFormat {
438 VideoFormat::from_raw(self.0.format)
439 }
440
441 pub fn set_flags(&mut self, flags: VideoFlags) {
442 self.0.flags = flags.bits();
443 }
444
445 pub fn flags(self) -> VideoFlags {
446 VideoFlags::from_bits_retain(self.0.flags)
447 }
448
449 pub fn set_modifier(&mut self, modifier: u64) {
450 self.0.modifier = modifier;
451 }
452
453 pub fn modifier(self) -> u64 {
454 self.0.modifier
455 }
456
457 pub fn set_size(&mut self, size: Rectangle) {
458 self.0.size = size;
459 }
460
461 pub fn size(self) -> Rectangle {
462 self.0.size
463 }
464
465 pub fn set_framerate(&mut self, framerate: Fraction) {
466 self.0.framerate = framerate;
467 }
468
469 pub fn framerate(self) -> Fraction {
470 self.0.framerate
471 }
472
473 pub fn set_max_framerate(&mut self, max_framerate: Fraction) {
474 self.0.max_framerate = max_framerate;
475 }
476
477 pub fn max_framerate(self) -> Fraction {
478 self.0.max_framerate
479 }
480
481 pub fn set_views(&mut self, views: u32) {
482 self.0.views = views;
483 }
484
485 pub fn views(self) -> u32 {
486 self.0.views
487 }
488
489 pub fn set_interlace_mode(&mut self, interlace_mode: VideoInterlaceMode) {
490 self.0.interlace_mode = interlace_mode.as_raw();
491 }
492
493 pub fn interlace_mode(self) -> VideoInterlaceMode {
494 VideoInterlaceMode::from_raw(self.0.interlace_mode)
495 }
496
497 pub fn set_pixel_aspect_ratio(&mut self, pixel_aspect_ratio: Fraction) {
498 self.0.pixel_aspect_ratio = pixel_aspect_ratio;
499 }
500
501 pub fn pixel_aspect_ratio(self) -> Fraction {
502 self.0.pixel_aspect_ratio
503 }
504
505 pub fn set_multiview_mode(&mut self, multiview_mode: i32) {
506 self.0.multiview_mode = multiview_mode;
507 }
508
509 pub fn multiview_mode(self) -> i32 {
510 self.0.multiview_mode
511 }
512
513 pub fn set_multiview_flags(&mut self, multiview_flags: u32) {
514 self.0.multiview_flags = multiview_flags;
515 }
516
517 pub fn multiview_flags(self) -> u32 {
518 self.0.multiview_flags
519 }
520
521 pub fn set_chroma_site(&mut self, chroma_site: u32) {
522 self.0.chroma_site = chroma_site;
523 }
524
525 pub fn chroma_site(self) -> u32 {
526 self.0.chroma_site
527 }
528
529 pub fn set_color_range(&mut self, color_range: VideoColorRange) {
530 self.0.color_range = color_range.as_raw();
531 }
532
533 pub fn color_range(self) -> VideoColorRange {
534 VideoColorRange::from_raw(self.0.color_range)
535 }
536
537 pub fn set_color_matrix(&mut self, color_matrix: VideoColorMatrix) {
538 self.0.color_matrix = color_matrix.as_raw();
539 }
540
541 pub fn color_matrix(self) -> VideoColorMatrix {
542 VideoColorMatrix::from_raw(self.0.color_matrix)
543 }
544
545 pub fn set_transfer_function(&mut self, transfer_function: VideoTransferFunction) {
546 self.0.transfer_function = transfer_function.as_raw();
547 }
548
549 pub fn transfer_function(self) -> VideoTransferFunction {
550 VideoTransferFunction::from_raw(self.0.transfer_function)
551 }
552
553 pub fn set_color_primaries(&mut self, color_primaries: VideoColorPrimaries) {
554 self.0.color_primaries = color_primaries.as_raw();
555 }
556
557 pub fn color_primaries(self) -> VideoColorPrimaries {
558 VideoColorPrimaries::from_raw(self.0.color_primaries)
559 }
560
561 pub fn parse(&mut self, format: &crate::pod::Pod) -> Result<SpaSuccess, Error> {
563 let res = unsafe { spa_sys::spa_format_video_raw_parse(format.as_raw_ptr(), &mut self.0) };
564 SpaResult::from_c(res).into_result()
565 }
566
567 pub fn from_raw(raw: spa_sys::spa_video_info_raw) -> Self {
569 Self(raw)
570 }
571
572 pub fn as_raw(&self) -> spa_sys::spa_video_info_raw {
574 self.0
575 }
576}
577
578impl Default for VideoInfoRaw {
579 fn default() -> Self {
580 Self::new()
581 }
582}
583
584impl Debug for VideoInfoRaw {
585 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
586 #[cfg(feature = "v0_3_65")]
587 let interlace_mode = self.interlace_mode();
588 #[cfg(not(feature = "v0_3_65"))]
589 let interlace_mode = self.interlace_mode().as_raw();
590
591 f.debug_struct("VideoInfoRaw")
592 .field("format", &self.format())
593 .field("flags", &self.flags())
594 .field("modifier", &self.modifier())
595 .field("size", &self.size())
596 .field("framerate", &self.framerate())
597 .field("max_framerate", &self.max_framerate())
598 .field("views", &self.views())
599 .field("interlace_mode", &interlace_mode)
600 .field("pixel_aspect_ratio", &self.pixel_aspect_ratio())
601 .field("multiview_mode", &self.multiview_mode())
602 .field("multiview_flags", &self.multiview_flags())
603 .field("chroma_site", &self.chroma_site())
604 .field("color_range", &self.color_range())
605 .field("color_matrix", &self.color_matrix())
606 .field("transfer_function", &self.transfer_function())
607 .field("color_primaries", &self.color_primaries())
608 .finish()
609 }
610}
611
612#[cfg(test)]
613mod tests {
614 use super::*;
615
616 #[test]
617 #[cfg_attr(miri, ignore)]
618 fn debug_format() {
619 assert_eq!(
620 "VideoFormat::Unknown",
621 format!("{:?}", VideoFormat::Unknown)
622 );
623 assert_eq!("VideoFormat::YV12", format!("{:?}", VideoFormat::YV12));
624 assert_eq!("VideoFormat::RGBx", format!("{:?}", VideoFormat::RGBx));
625 assert_eq!("VideoFormat::xRGB", format!("{:?}", VideoFormat::xRGB));
626 assert_eq!(
627 "VideoFormat::GRAY16_BE",
628 format!("{:?}", VideoFormat::GRAY16_BE)
629 );
630 assert_eq!(
631 "VideoFormat::xRGB_210LE",
632 format!("{:?}", VideoFormat::xRGB_210LE)
633 );
634 #[cfg(feature = "v0_3_65")]
635 assert_eq!(
636 "VideoInterlaceMode::Progressive",
637 format!("{:?}", VideoInterlaceMode::Progressive)
638 );
639 }
640}