use crate::{Engine, Result};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum VideoChromaSubsampling {
Monochrome,
Yuv420,
Yuv422,
Yuv444,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum VideoComponentBitDepth {
Eight,
Ten,
Twelve,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum H264Profile {
Baseline,
Main,
High,
High444Predictive,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum H264PictureLayout {
Progressive,
InterlacedInterleavedLines,
InterlacedSeparatePlanes,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum H265Profile {
Main,
Main10,
MainStillPicture,
FormatRangeExtensions,
ScreenContentCodingExtensions,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Av1Profile {
Main,
High,
Professional,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Vp9Profile {
Profile0,
Profile1,
Profile2,
Profile3,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum VideoDecodeProfile {
H264 {
profile: H264Profile,
picture_layout: H264PictureLayout,
chroma_subsampling: VideoChromaSubsampling,
luma_bit_depth: VideoComponentBitDepth,
chroma_bit_depth: VideoComponentBitDepth,
},
H265 {
profile: H265Profile,
chroma_subsampling: VideoChromaSubsampling,
luma_bit_depth: VideoComponentBitDepth,
chroma_bit_depth: VideoComponentBitDepth,
},
Av1 {
profile: Av1Profile,
film_grain_support: bool,
chroma_subsampling: VideoChromaSubsampling,
luma_bit_depth: VideoComponentBitDepth,
chroma_bit_depth: VideoComponentBitDepth,
},
Vp9 {
profile: Vp9Profile,
chroma_subsampling: VideoChromaSubsampling,
luma_bit_depth: VideoComponentBitDepth,
chroma_bit_depth: VideoComponentBitDepth,
},
}
impl VideoDecodeProfile {
pub const fn h264_420_8bit(profile: H264Profile) -> Self {
Self::H264 {
profile,
picture_layout: H264PictureLayout::Progressive,
chroma_subsampling: VideoChromaSubsampling::Yuv420,
luma_bit_depth: VideoComponentBitDepth::Eight,
chroma_bit_depth: VideoComponentBitDepth::Eight,
}
}
pub const fn h265_420(profile: H265Profile, bit_depth: VideoComponentBitDepth) -> Self {
Self::H265 {
profile,
chroma_subsampling: VideoChromaSubsampling::Yuv420,
luma_bit_depth: bit_depth,
chroma_bit_depth: bit_depth,
}
}
pub const fn av1_420(
profile: Av1Profile,
bit_depth: VideoComponentBitDepth,
film_grain_support: bool,
) -> Self {
Self::Av1 {
profile,
film_grain_support,
chroma_subsampling: VideoChromaSubsampling::Yuv420,
luma_bit_depth: bit_depth,
chroma_bit_depth: bit_depth,
}
}
pub const fn vp9_420(profile: Vp9Profile, bit_depth: VideoComponentBitDepth) -> Self {
Self::Vp9 {
profile,
chroma_subsampling: VideoChromaSubsampling::Yuv420,
luma_bit_depth: bit_depth,
chroma_bit_depth: bit_depth,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum VideoEncodeProfile {
H264 {
profile: H264Profile,
chroma_subsampling: VideoChromaSubsampling,
luma_bit_depth: VideoComponentBitDepth,
chroma_bit_depth: VideoComponentBitDepth,
},
H265 {
profile: H265Profile,
chroma_subsampling: VideoChromaSubsampling,
luma_bit_depth: VideoComponentBitDepth,
chroma_bit_depth: VideoComponentBitDepth,
},
}
impl VideoEncodeProfile {
pub const fn h264_high_420_8bit() -> Self {
Self::H264 {
profile: H264Profile::High,
chroma_subsampling: VideoChromaSubsampling::Yuv420,
luma_bit_depth: VideoComponentBitDepth::Eight,
chroma_bit_depth: VideoComponentBitDepth::Eight,
}
}
pub const fn h265_main_420_8bit() -> Self {
Self::H265 {
profile: H265Profile::Main,
chroma_subsampling: VideoChromaSubsampling::Yuv420,
luma_bit_depth: VideoComponentBitDepth::Eight,
chroma_bit_depth: VideoComponentBitDepth::Eight,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct VideoExtent {
pub width: u32,
pub height: u32,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum VideoPixelFormat {
Yuv420Planar8,
Nv12,
Yuv420Planar10,
P010,
P012,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct VideoImageFormat {
pub(crate) pixel_format: VideoPixelFormat,
pub(crate) optimal_tiling: bool,
pub(crate) sampled: bool,
pub(crate) storage: bool,
pub(crate) transfer_source: bool,
pub(crate) transfer_destination: bool,
}
impl VideoImageFormat {
pub const fn pixel_format(self) -> VideoPixelFormat {
self.pixel_format
}
pub const fn optimal_tiling(self) -> bool {
self.optimal_tiling
}
pub const fn sampled(self) -> bool {
self.sampled
}
pub const fn storage(self) -> bool {
self.storage
}
pub const fn transfer_source(self) -> bool {
self.transfer_source
}
pub const fn transfer_destination(self) -> bool {
self.transfer_destination
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct VideoDecodeFormats {
pub(crate) profile: VideoDecodeProfile,
pub(crate) output: Vec<VideoImageFormat>,
pub(crate) dpb: Vec<VideoImageFormat>,
pub(crate) unrecognized_output_formats: usize,
pub(crate) unrecognized_dpb_formats: usize,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct VideoEncodeFormats {
pub(crate) profile: VideoEncodeProfile,
pub(crate) input: Vec<VideoImageFormat>,
pub(crate) dpb: Vec<VideoImageFormat>,
pub(crate) unrecognized_input_formats: usize,
pub(crate) unrecognized_dpb_formats: usize,
}
impl VideoEncodeFormats {
pub const fn profile(&self) -> VideoEncodeProfile {
self.profile
}
pub fn input(&self) -> &[VideoImageFormat] {
&self.input
}
pub fn dpb(&self) -> &[VideoImageFormat] {
&self.dpb
}
pub const fn unrecognized_input_formats(&self) -> usize {
self.unrecognized_input_formats
}
pub const fn unrecognized_dpb_formats(&self) -> usize {
self.unrecognized_dpb_formats
}
}
impl VideoDecodeFormats {
pub const fn profile(&self) -> VideoDecodeProfile {
self.profile
}
pub fn output(&self) -> &[VideoImageFormat] {
&self.output
}
pub fn dpb(&self) -> &[VideoImageFormat] {
&self.dpb
}
pub const fn unrecognized_output_formats(&self) -> usize {
self.unrecognized_output_formats
}
pub const fn unrecognized_dpb_formats(&self) -> usize {
self.unrecognized_dpb_formats
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum VideoDecodeLevel {
H264(u32),
H265(u32),
Av1(u32),
Vp9(u32),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct VideoDecodeCapabilities {
pub(crate) profile: VideoDecodeProfile,
pub(crate) min_coded_extent: VideoExtent,
pub(crate) max_coded_extent: VideoExtent,
pub(crate) picture_access_granularity: VideoExtent,
pub(crate) min_bitstream_offset_alignment: u64,
pub(crate) min_bitstream_size_alignment: u64,
pub(crate) max_dpb_slots: u32,
pub(crate) max_active_reference_pictures: u32,
pub(crate) level: VideoDecodeLevel,
pub(crate) field_offset_granularity: Option<(i32, i32)>,
pub(crate) dpb_and_output_coincide: bool,
pub(crate) dpb_and_output_distinct: bool,
pub(crate) protected_content: bool,
pub(crate) separate_reference_images: bool,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum VideoEncodeCodecCapabilities {
H264 {
max_level: u32,
max_slice_count: u32,
max_p_l0_references: u32,
max_b_l0_references: u32,
max_l1_references: u32,
max_temporal_layers: u32,
min_qp: i32,
max_qp: i32,
},
H265 {
max_level: u32,
max_slice_segment_count: u32,
max_tiles: VideoExtent,
ctb_size_16: bool,
ctb_size_32: bool,
ctb_size_64: bool,
transform_size_4: bool,
transform_size_8: bool,
transform_size_16: bool,
transform_size_32: bool,
max_p_l0_references: u32,
max_b_l0_references: u32,
max_l1_references: u32,
max_sub_layers: u32,
min_qp: i32,
max_qp: i32,
},
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct VideoEncodeCapabilities {
pub(crate) profile: VideoEncodeProfile,
pub(crate) min_coded_extent: VideoExtent,
pub(crate) max_coded_extent: VideoExtent,
pub(crate) picture_access_granularity: VideoExtent,
pub(crate) input_picture_granularity: VideoExtent,
pub(crate) min_bitstream_offset_alignment: u64,
pub(crate) min_bitstream_size_alignment: u64,
pub(crate) max_dpb_slots: u32,
pub(crate) max_active_reference_pictures: u32,
pub(crate) max_rate_control_layers: u32,
pub(crate) max_bitrate: u64,
pub(crate) max_quality_levels: u32,
pub(crate) constant_qp: bool,
pub(crate) cbr: bool,
pub(crate) vbr: bool,
pub(crate) feedback_offset: bool,
pub(crate) feedback_bytes_written: bool,
pub(crate) feedback_overrides: bool,
pub(crate) protected_content: bool,
pub(crate) separate_reference_images: bool,
pub(crate) codec: VideoEncodeCodecCapabilities,
}
impl VideoEncodeCapabilities {
pub const fn profile(self) -> VideoEncodeProfile {
self.profile
}
pub const fn min_coded_extent(self) -> VideoExtent {
self.min_coded_extent
}
pub const fn max_coded_extent(self) -> VideoExtent {
self.max_coded_extent
}
pub const fn picture_access_granularity(self) -> VideoExtent {
self.picture_access_granularity
}
pub const fn input_picture_granularity(self) -> VideoExtent {
self.input_picture_granularity
}
pub const fn min_bitstream_offset_alignment(self) -> u64 {
self.min_bitstream_offset_alignment
}
pub const fn min_bitstream_size_alignment(self) -> u64 {
self.min_bitstream_size_alignment
}
pub const fn max_dpb_slots(self) -> u32 {
self.max_dpb_slots
}
pub const fn max_active_reference_pictures(self) -> u32 {
self.max_active_reference_pictures
}
pub const fn max_rate_control_layers(self) -> u32 {
self.max_rate_control_layers
}
pub const fn max_bitrate(self) -> u64 {
self.max_bitrate
}
pub const fn max_quality_levels(self) -> u32 {
self.max_quality_levels
}
pub const fn supports_constant_qp(self) -> bool {
self.constant_qp
}
pub const fn supports_cbr(self) -> bool {
self.cbr
}
pub const fn supports_vbr(self) -> bool {
self.vbr
}
pub const fn supports_feedback_offset(self) -> bool {
self.feedback_offset
}
pub const fn supports_feedback_bytes_written(self) -> bool {
self.feedback_bytes_written
}
pub const fn supports_feedback_overrides(self) -> bool {
self.feedback_overrides
}
pub const fn protected_content(self) -> bool {
self.protected_content
}
pub const fn separate_reference_images(self) -> bool {
self.separate_reference_images
}
pub const fn codec(self) -> VideoEncodeCodecCapabilities {
self.codec
}
}
impl VideoDecodeCapabilities {
pub const fn profile(self) -> VideoDecodeProfile {
self.profile
}
pub const fn min_coded_extent(self) -> VideoExtent {
self.min_coded_extent
}
pub const fn max_coded_extent(self) -> VideoExtent {
self.max_coded_extent
}
pub const fn picture_access_granularity(self) -> VideoExtent {
self.picture_access_granularity
}
pub const fn min_bitstream_offset_alignment(self) -> u64 {
self.min_bitstream_offset_alignment
}
pub const fn min_bitstream_size_alignment(self) -> u64 {
self.min_bitstream_size_alignment
}
pub const fn max_dpb_slots(self) -> u32 {
self.max_dpb_slots
}
pub const fn max_active_reference_pictures(self) -> u32 {
self.max_active_reference_pictures
}
pub const fn level(self) -> VideoDecodeLevel {
self.level
}
pub const fn field_offset_granularity(self) -> Option<(i32, i32)> {
self.field_offset_granularity
}
pub const fn dpb_and_output_coincide(self) -> bool {
self.dpb_and_output_coincide
}
pub const fn dpb_and_output_distinct(self) -> bool {
self.dpb_and_output_distinct
}
pub const fn protected_content(self) -> bool {
self.protected_content
}
pub const fn separate_reference_images(self) -> bool {
self.separate_reference_images
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct VideoDeviceCapabilities {
pub(crate) decode_queue_family: Option<u32>,
pub(crate) encode_queue_family: Option<u32>,
pub(crate) decode_result_status_queries: bool,
pub(crate) encode_result_status_queries: bool,
pub(crate) h264_decode: bool,
pub(crate) h265_decode: bool,
pub(crate) av1_decode: bool,
pub(crate) vp9_decode: bool,
pub(crate) h264_encode: bool,
pub(crate) h265_encode: bool,
pub(crate) av1_encode: bool,
pub(crate) video_queues_enabled: bool,
pub(crate) decoder_sessions_available: bool,
pub(crate) encoder_sessions_available: bool,
}
impl VideoDeviceCapabilities {
pub const fn decode_queue_family(self) -> Option<u32> {
self.decode_queue_family
}
pub const fn encode_queue_family(self) -> Option<u32> {
self.encode_queue_family
}
pub const fn supports_decode_result_status_queries(self) -> bool {
self.decode_result_status_queries
}
pub const fn supports_encode_result_status_queries(self) -> bool {
self.encode_result_status_queries
}
pub const fn supports_h264_decode(self) -> bool {
self.h264_decode
}
pub const fn supports_h265_decode(self) -> bool {
self.h265_decode
}
pub const fn supports_av1_decode(self) -> bool {
self.av1_decode
}
pub const fn supports_vp9_decode(self) -> bool {
self.vp9_decode
}
pub const fn supports_h264_encode(self) -> bool {
self.h264_encode
}
pub const fn supports_h265_encode(self) -> bool {
self.h265_encode
}
pub const fn supports_av1_encode(self) -> bool {
self.av1_encode
}
pub const fn video_queues_enabled(self) -> bool {
self.video_queues_enabled
}
pub const fn decoder_sessions_available(self) -> bool {
self.decoder_sessions_available
}
pub const fn encoder_sessions_available(self) -> bool {
self.encoder_sessions_available
}
}
pub fn query_device_capabilities(engine: &Engine) -> Result<VideoDeviceCapabilities> {
engine.query_video_device_capabilities()
}
pub fn query_decode_capabilities(
engine: &Engine,
profile: VideoDecodeProfile,
) -> Result<VideoDecodeCapabilities> {
engine.query_video_decode_capabilities(profile)
}
pub fn query_decode_formats(
engine: &Engine,
profile: VideoDecodeProfile,
) -> Result<VideoDecodeFormats> {
engine.query_video_decode_formats(profile)
}
pub fn query_encode_capabilities(
engine: &Engine,
profile: VideoEncodeProfile,
) -> Result<VideoEncodeCapabilities> {
engine.query_video_encode_capabilities(profile)
}
pub fn query_encode_formats(
engine: &Engine,
profile: VideoEncodeProfile,
) -> Result<VideoEncodeFormats> {
engine.query_video_encode_formats(profile)
}