1pub use crate::video::types::{
4 VideoDecodeCapabilities, VideoDeviceCapabilities, VideoEncodeCapabilities,
5};
6use crate::{Result, Runtime};
7
8#[derive(Clone, Copy, Debug, PartialEq, Eq)]
10pub enum VideoChromaSubsampling {
11 Monochrome,
12 Yuv420,
13 Yuv422,
14 Yuv444,
15}
16
17#[derive(Clone, Copy, Debug, PartialEq, Eq)]
19pub enum VideoComponentBitDepth {
20 Eight,
21 Ten,
22 Twelve,
23}
24
25#[derive(Clone, Copy, Debug, PartialEq, Eq)]
27pub enum H264Profile {
28 Baseline,
29 Main,
30 High,
31 High10,
32 High444Predictive,
33}
34
35#[derive(Clone, Copy, Debug, PartialEq, Eq)]
37pub enum H264PictureLayout {
38 Progressive,
39 InterlacedInterleavedLines,
40 InterlacedSeparatePlanes,
41}
42
43#[derive(Clone, Copy, Debug, PartialEq, Eq)]
45pub enum H265Profile {
46 Main,
47 Main10,
48 MainStillPicture,
49 FormatRangeExtensions,
50 ScreenContentCodingExtensions,
51}
52
53#[derive(Clone, Copy, Debug, PartialEq, Eq)]
55pub enum Av1Profile {
56 Main,
57 High,
58 Professional,
59}
60
61#[derive(Clone, Copy, Debug, PartialEq, Eq)]
63pub enum Vp9Profile {
64 Profile0,
65 Profile1,
66 Profile2,
67 Profile3,
68}
69
70#[derive(Clone, Copy, Debug, PartialEq, Eq)]
72pub enum VideoDecodeProfile {
73 H264 {
74 profile: H264Profile,
75 picture_layout: H264PictureLayout,
76 chroma_subsampling: VideoChromaSubsampling,
77 luma_bit_depth: VideoComponentBitDepth,
78 chroma_bit_depth: VideoComponentBitDepth,
79 },
80 H265 {
81 profile: H265Profile,
82 chroma_subsampling: VideoChromaSubsampling,
83 luma_bit_depth: VideoComponentBitDepth,
84 chroma_bit_depth: VideoComponentBitDepth,
85 },
86 Av1 {
87 profile: Av1Profile,
88 film_grain_support: bool,
89 chroma_subsampling: VideoChromaSubsampling,
90 luma_bit_depth: VideoComponentBitDepth,
91 chroma_bit_depth: VideoComponentBitDepth,
92 },
93 Vp9 {
94 profile: Vp9Profile,
95 chroma_subsampling: VideoChromaSubsampling,
96 luma_bit_depth: VideoComponentBitDepth,
97 chroma_bit_depth: VideoComponentBitDepth,
98 },
99}
100
101impl VideoDecodeProfile {
102 pub const fn h264_420_8bit(profile: H264Profile) -> Self {
104 Self::H264 {
105 profile,
106 picture_layout: H264PictureLayout::Progressive,
107 chroma_subsampling: VideoChromaSubsampling::Yuv420,
108 luma_bit_depth: VideoComponentBitDepth::Eight,
109 chroma_bit_depth: VideoComponentBitDepth::Eight,
110 }
111 }
112
113 pub const fn h265_420(profile: H265Profile, bit_depth: VideoComponentBitDepth) -> Self {
115 Self::H265 {
116 profile,
117 chroma_subsampling: VideoChromaSubsampling::Yuv420,
118 luma_bit_depth: bit_depth,
119 chroma_bit_depth: bit_depth,
120 }
121 }
122
123 pub const fn av1_420(
125 profile: Av1Profile,
126 bit_depth: VideoComponentBitDepth,
127 film_grain_support: bool,
128 ) -> Self {
129 Self::Av1 {
130 profile,
131 film_grain_support,
132 chroma_subsampling: VideoChromaSubsampling::Yuv420,
133 luma_bit_depth: bit_depth,
134 chroma_bit_depth: bit_depth,
135 }
136 }
137
138 pub const fn vp9_420(profile: Vp9Profile, bit_depth: VideoComponentBitDepth) -> Self {
140 Self::Vp9 {
141 profile,
142 chroma_subsampling: VideoChromaSubsampling::Yuv420,
143 luma_bit_depth: bit_depth,
144 chroma_bit_depth: bit_depth,
145 }
146 }
147}
148
149#[derive(Clone, Copy, Debug, PartialEq, Eq)]
151pub enum VideoEncodeProfile {
152 H264 {
153 profile: H264Profile,
154 chroma_subsampling: VideoChromaSubsampling,
155 luma_bit_depth: VideoComponentBitDepth,
156 chroma_bit_depth: VideoComponentBitDepth,
157 },
158 H265 {
159 profile: H265Profile,
160 chroma_subsampling: VideoChromaSubsampling,
161 luma_bit_depth: VideoComponentBitDepth,
162 chroma_bit_depth: VideoComponentBitDepth,
163 },
164}
165
166impl VideoEncodeProfile {
167 pub const fn h264_high_420_8bit() -> Self {
169 Self::H264 {
170 profile: H264Profile::High,
171 chroma_subsampling: VideoChromaSubsampling::Yuv420,
172 luma_bit_depth: VideoComponentBitDepth::Eight,
173 chroma_bit_depth: VideoComponentBitDepth::Eight,
174 }
175 }
176
177 pub const fn h265_main_420_8bit() -> Self {
179 Self::H265 {
180 profile: H265Profile::Main,
181 chroma_subsampling: VideoChromaSubsampling::Yuv420,
182 luma_bit_depth: VideoComponentBitDepth::Eight,
183 chroma_bit_depth: VideoComponentBitDepth::Eight,
184 }
185 }
186}
187
188#[derive(Clone, Copy, Debug, PartialEq, Eq)]
190pub struct VideoExtent {
191 pub width: u32,
192 pub height: u32,
193}
194
195#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
197pub enum VideoPixelFormat {
198 Yuv420Planar8,
200 Nv12,
202 Yuv420Planar10,
204 P010,
206 P012,
208}
209
210#[derive(Clone, Copy, Debug, PartialEq, Eq)]
212pub struct VideoImageFormat {
213 pub(crate) pixel_format: VideoPixelFormat,
214 pub(crate) optimal_tiling: bool,
215 pub(crate) sampled: bool,
216 pub(crate) storage: bool,
217 pub(crate) transfer_source: bool,
218 pub(crate) transfer_destination: bool,
219}
220
221impl VideoImageFormat {
222 pub const fn pixel_format(self) -> VideoPixelFormat {
224 self.pixel_format
225 }
226
227 pub const fn optimal_tiling(self) -> bool {
229 self.optimal_tiling
230 }
231
232 pub const fn sampled(self) -> bool {
234 self.sampled
235 }
236
237 pub const fn storage(self) -> bool {
239 self.storage
240 }
241
242 pub const fn transfer_source(self) -> bool {
244 self.transfer_source
245 }
246
247 pub const fn transfer_destination(self) -> bool {
249 self.transfer_destination
250 }
251}
252
253#[derive(Clone, Debug, PartialEq, Eq)]
255pub struct VideoDecodeFormats {
256 pub(crate) profile: VideoDecodeProfile,
257 pub(crate) output: Vec<VideoImageFormat>,
258 pub(crate) dpb: Vec<VideoImageFormat>,
259 pub(crate) unrecognized_output_formats: usize,
260 pub(crate) unrecognized_dpb_formats: usize,
261}
262
263#[derive(Clone, Debug, PartialEq, Eq)]
265pub struct VideoEncodeFormats {
266 pub(crate) profile: VideoEncodeProfile,
267 pub(crate) input: Vec<VideoImageFormat>,
268 pub(crate) dpb: Vec<VideoImageFormat>,
269 pub(crate) unrecognized_input_formats: usize,
270 pub(crate) unrecognized_dpb_formats: usize,
271}
272
273impl VideoEncodeFormats {
274 pub const fn profile(&self) -> VideoEncodeProfile {
275 self.profile
276 }
277 pub fn input(&self) -> &[VideoImageFormat] {
278 &self.input
279 }
280 pub fn dpb(&self) -> &[VideoImageFormat] {
281 &self.dpb
282 }
283 pub const fn unrecognized_input_formats(&self) -> usize {
284 self.unrecognized_input_formats
285 }
286 pub const fn unrecognized_dpb_formats(&self) -> usize {
287 self.unrecognized_dpb_formats
288 }
289}
290
291impl VideoDecodeFormats {
292 pub const fn profile(&self) -> VideoDecodeProfile {
294 self.profile
295 }
296
297 pub fn output(&self) -> &[VideoImageFormat] {
299 &self.output
300 }
301
302 pub fn dpb(&self) -> &[VideoImageFormat] {
304 &self.dpb
305 }
306
307 pub const fn unrecognized_output_formats(&self) -> usize {
309 self.unrecognized_output_formats
310 }
311
312 pub const fn unrecognized_dpb_formats(&self) -> usize {
314 self.unrecognized_dpb_formats
315 }
316}
317
318#[derive(Clone, Copy, Debug, PartialEq, Eq)]
320pub enum VideoDecodeLevel {
321 H264(u32),
322 H265(u32),
323 Av1(u32),
324 Vp9(u32),
325}
326
327#[derive(Clone, Copy, Debug, PartialEq, Eq)]
329pub enum VideoEncodeCodecCapabilities {
330 H264 {
331 max_level: u32,
333 max_slice_count: u32,
334 max_p_l0_references: u32,
335 max_b_l0_references: u32,
336 max_l1_references: u32,
337 max_temporal_layers: u32,
338 min_qp: i32,
339 max_qp: i32,
340 },
341 H265 {
342 max_level: u32,
343 max_slice_segment_count: u32,
344 max_tiles: VideoExtent,
345 ctb_size_16: bool,
346 ctb_size_32: bool,
347 ctb_size_64: bool,
348 transform_size_4: bool,
349 transform_size_8: bool,
350 transform_size_16: bool,
351 transform_size_32: bool,
352 max_p_l0_references: u32,
353 max_b_l0_references: u32,
354 max_l1_references: u32,
355 max_sub_layers: u32,
356 min_qp: i32,
357 max_qp: i32,
358 },
359}
360
361impl VideoEncodeCapabilities {
362 pub const fn profile(self) -> VideoEncodeProfile {
363 self.profile
364 }
365 pub const fn min_coded_extent(self) -> VideoExtent {
366 self.min_coded_extent
367 }
368 pub const fn max_coded_extent(self) -> VideoExtent {
369 self.max_coded_extent
370 }
371 pub const fn picture_access_granularity(self) -> VideoExtent {
372 self.picture_access_granularity
373 }
374 pub const fn input_picture_granularity(self) -> VideoExtent {
375 self.input_picture_granularity
376 }
377 pub const fn min_bitstream_offset_alignment(self) -> u64 {
378 self.min_bitstream_offset_alignment
379 }
380 pub const fn min_bitstream_size_alignment(self) -> u64 {
381 self.min_bitstream_size_alignment
382 }
383 pub const fn max_dpb_slots(self) -> u32 {
384 self.max_dpb_slots
385 }
386 pub const fn max_active_reference_pictures(self) -> u32 {
387 self.max_active_reference_pictures
388 }
389 pub const fn max_rate_control_layers(self) -> u32 {
390 self.max_rate_control_layers
391 }
392 pub const fn max_bitrate(self) -> u64 {
393 self.max_bitrate
394 }
395 pub const fn max_quality_levels(self) -> u32 {
396 self.max_quality_levels
397 }
398 pub const fn supports_constant_qp(self) -> bool {
399 self.constant_qp
400 }
401 pub const fn supports_cbr(self) -> bool {
402 self.cbr
403 }
404 pub const fn supports_vbr(self) -> bool {
405 self.vbr
406 }
407 pub const fn supports_feedback_offset(self) -> bool {
408 self.feedback_offset
409 }
410 pub const fn supports_feedback_bytes_written(self) -> bool {
411 self.feedback_bytes_written
412 }
413 pub const fn supports_feedback_overrides(self) -> bool {
414 self.feedback_overrides
415 }
416 pub const fn protected_content(self) -> bool {
417 self.protected_content
418 }
419 pub const fn separate_reference_images(self) -> bool {
420 self.separate_reference_images
421 }
422 pub const fn codec(self) -> VideoEncodeCodecCapabilities {
423 self.codec
424 }
425}
426
427impl VideoDecodeCapabilities {
428 pub const fn profile(self) -> VideoDecodeProfile {
430 self.profile
431 }
432
433 pub const fn min_coded_extent(self) -> VideoExtent {
435 self.min_coded_extent
436 }
437
438 pub const fn max_coded_extent(self) -> VideoExtent {
440 self.max_coded_extent
441 }
442
443 pub const fn picture_access_granularity(self) -> VideoExtent {
445 self.picture_access_granularity
446 }
447
448 pub const fn min_bitstream_offset_alignment(self) -> u64 {
450 self.min_bitstream_offset_alignment
451 }
452
453 pub const fn min_bitstream_size_alignment(self) -> u64 {
455 self.min_bitstream_size_alignment
456 }
457
458 pub const fn max_dpb_slots(self) -> u32 {
460 self.max_dpb_slots
461 }
462
463 pub const fn max_active_reference_pictures(self) -> u32 {
465 self.max_active_reference_pictures
466 }
467
468 pub const fn level(self) -> VideoDecodeLevel {
470 self.level
471 }
472
473 pub const fn field_offset_granularity(self) -> Option<(i32, i32)> {
475 self.field_offset_granularity
476 }
477
478 pub const fn dpb_and_output_coincide(self) -> bool {
480 self.dpb_and_output_coincide
481 }
482
483 pub const fn dpb_and_output_distinct(self) -> bool {
485 self.dpb_and_output_distinct
486 }
487
488 pub const fn protected_content(self) -> bool {
490 self.protected_content
491 }
492
493 pub const fn separate_reference_images(self) -> bool {
495 self.separate_reference_images
496 }
497}
498
499impl VideoDeviceCapabilities {
500 pub const fn decode_queue_family(self) -> Option<u32> {
502 self.decode_queue_family
503 }
504
505 pub const fn encode_queue_family(self) -> Option<u32> {
507 self.encode_queue_family
508 }
509
510 pub const fn supports_decode_result_status_queries(self) -> bool {
512 self.decode_result_status_queries
513 }
514
515 pub const fn supports_encode_result_status_queries(self) -> bool {
517 self.encode_result_status_queries
518 }
519
520 pub const fn supports_h264_decode(self) -> bool {
522 self.h264_decode
523 }
524
525 pub const fn supports_h265_decode(self) -> bool {
527 self.h265_decode
528 }
529
530 pub const fn supports_av1_decode(self) -> bool {
532 self.av1_decode
533 }
534
535 pub const fn supports_vp9_decode(self) -> bool {
537 self.vp9_decode
538 }
539
540 pub const fn supports_h264_encode(self) -> bool {
542 self.h264_encode
543 }
544
545 pub const fn supports_h265_encode(self) -> bool {
547 self.h265_encode
548 }
549
550 pub const fn supports_av1_encode(self) -> bool {
552 self.av1_encode
553 }
554
555 pub const fn video_queues_enabled(self) -> bool {
557 self.video_queues_enabled
558 }
559
560 pub const fn decoder_sessions_available(self) -> bool {
562 self.decoder_sessions_available
563 }
564
565 pub const fn encoder_sessions_available(self) -> bool {
567 self.encoder_sessions_available
568 }
569}
570
571pub fn query_device_capabilities(runtime: &Runtime) -> Result<VideoDeviceCapabilities> {
582 runtime.query_video_device_capabilities()
583}
584
585pub fn query_decode_capabilities(
596 runtime: &Runtime,
597 profile: VideoDecodeProfile,
598) -> Result<VideoDecodeCapabilities> {
599 runtime.query_video_decode_capabilities(profile)
600}
601
602pub fn query_decode_formats(
609 runtime: &Runtime,
610 profile: VideoDecodeProfile,
611) -> Result<VideoDecodeFormats> {
612 runtime.query_video_decode_formats(profile)
613}
614
615pub fn query_encode_capabilities(
617 runtime: &Runtime,
618 profile: VideoEncodeProfile,
619) -> Result<VideoEncodeCapabilities> {
620 runtime.query_video_encode_capabilities(profile)
621}
622
623pub fn query_encode_formats(
625 runtime: &Runtime,
626 profile: VideoEncodeProfile,
627) -> Result<VideoEncodeFormats> {
628 runtime.query_video_encode_formats(profile)
629}