use std::ffi::c_void;
use std::os::raw::{c_int, c_uchar, c_uint, c_ulong, c_ulonglong};
pub type CUresult = c_int;
pub type CUdevice = c_int;
pub type CUcontext = *mut c_void;
pub type CUdeviceptr = c_ulonglong;
pub type FnCuInit = unsafe extern "C" fn(c_uint) -> CUresult;
pub type FnCuDeviceGet = unsafe extern "C" fn(*mut CUdevice, c_int) -> CUresult;
pub type FnCuCtxCreate = unsafe extern "C" fn(*mut CUcontext, c_uint, CUdevice) -> CUresult;
pub type FnCuCtxDestroy = unsafe extern "C" fn(CUcontext) -> CUresult;
pub type FnCuCtxPushCurrent = unsafe extern "C" fn(CUcontext) -> CUresult;
pub type FnCuCtxPopCurrent = unsafe extern "C" fn(*mut CUcontext) -> CUresult;
pub type FnCuMemcpy2D = unsafe extern "C" fn(*const CudaMemcpy2D) -> CUresult;
pub const CU_MEMORYTYPE_HOST: c_uint = 1;
pub const CU_MEMORYTYPE_DEVICE: c_uint = 2;
#[repr(C)]
pub struct CudaMemcpy2D {
pub src_x_in_bytes: usize,
pub src_y: usize,
pub src_memory_type: c_uint,
pub src_host: *const c_void,
pub src_device: CUdeviceptr,
pub src_array: *const c_void,
pub src_pitch: usize,
pub dst_x_in_bytes: usize,
pub dst_y: usize,
pub dst_memory_type: c_uint,
pub dst_host: *mut c_void,
pub dst_device: CUdeviceptr,
pub dst_array: *const c_void,
pub dst_pitch: usize,
pub width_in_bytes: usize,
pub height: usize,
}
pub type CUvideoparser = *mut c_void;
pub type CUvideodecoder = *mut c_void;
#[repr(C)]
#[derive(Clone, Copy)]
pub struct CuVideoFormat {
pub codec: c_int,
pub frame_rate_num: c_uint,
pub frame_rate_den: c_uint,
pub progressive_sequence: u8,
pub bit_depth_luma_minus8: u8,
pub bit_depth_chroma_minus8: u8,
pub min_num_decode_surfaces: u8,
pub coded_width: c_uint,
pub coded_height: c_uint,
pub display_area_left: c_int,
pub display_area_top: c_int,
pub display_area_right: c_int,
pub display_area_bottom: c_int,
pub chroma_format: c_int,
pub bitrate: c_uint,
pub display_aspect_num: c_int,
pub display_aspect_den: c_int,
pub video_signal_description: [u8; 8],
pub seqhdr_data_length: c_uint,
pub _reserved_tail: [u8; 1024],
}
#[repr(C)]
pub struct CuVideoParserParams {
pub codec_type: c_int,
pub max_num_decode_surfaces: c_uint,
pub clock_rate: c_uint,
pub error_threshold: c_uint,
pub max_display_delay: c_uint,
pub reserved1: [c_uint; 5],
pub user_data: *mut c_void,
pub pfn_sequence_callback: Option<unsafe extern "C" fn(*mut c_void, *mut CuVideoFormat) -> c_int>,
pub pfn_decode_picture: Option<unsafe extern "C" fn(*mut c_void, *mut CuVideoPicParams) -> c_int>,
pub pfn_display_picture: Option<unsafe extern "C" fn(*mut c_void, *mut CuVideoDispInfo) -> c_int>,
pub pfn_get_operating_point: Option<unsafe extern "C" fn(*mut c_void, *mut c_void) -> c_int>,
pub pfn_get_sei_msg: Option<unsafe extern "C" fn(*mut c_void, *mut c_void) -> c_int>,
pub reserved2: [*mut c_void; 5],
pub ext_video_info: *mut c_void,
}
#[repr(C)]
pub struct CuVideoSourceDataPacket {
pub flags: c_ulong,
pub payload_size: c_ulong,
pub payload: *const u8,
pub timestamp: c_ulonglong,
}
#[repr(C)]
pub struct CuVideoDecodeCreateInfo {
pub code_width: c_ulong,
pub coded_height: c_ulong,
pub num_decode_surfaces: c_ulong,
pub codec_type: c_int,
pub chroma_format: c_int,
pub creation_flags: c_ulong,
pub bit_depth_minus8: c_ulong,
pub intra_decode_only: c_ulong,
pub max_width: c_ulong,
pub max_height: c_ulong,
pub reserved1: c_ulong,
pub display_area_left: i16,
pub display_area_top: i16,
pub display_area_right: i16,
pub display_area_bottom: i16,
pub output_format: c_int,
pub deinterlace_mode: c_int,
pub target_width: c_ulong,
pub target_height: c_ulong,
pub num_output_surfaces: c_ulong,
pub vid_lock: *mut c_void,
pub target_rect_left: i16,
pub target_rect_top: i16,
pub target_rect_right: i16,
pub target_rect_bottom: i16,
pub enable_histogram: c_ulong,
pub reserved2: [c_ulong; 4],
}
#[repr(C)]
pub struct CuVideoPicParams {
pub pic_width_in_mbs: c_int,
pub pic_height_in_mbs: c_int,
pub curr_pic_idx: c_int,
pub field_pic_flag: c_int,
pub bottom_field_flag: c_int,
pub second_field: c_int,
pub n_bitstream_data_len: c_uint,
pub p_bitstream_data: *const u8,
pub n_num_slices: c_uint,
pub p_slice_data_offsets: *const c_uint,
pub ref_pic_flag: c_int,
pub intra_pic_flag: c_int,
pub reserved: [c_uint; 30],
pub codec_specific: [c_uint; 1024],
}
#[repr(C)]
pub struct CuVideoDispInfo {
pub picture_index: c_int,
pub progressive_frame: c_int,
pub top_field_first: c_int,
pub repeat_first_field: c_int,
pub timestamp: c_ulonglong,
}
#[repr(C)]
#[allow(dead_code)]
struct CuVideoH264DpbEntry {
pic_idx: c_int,
frame_idx: c_int,
is_long_term: c_int,
not_existing: c_int,
used_for_reference: c_int,
field_order_cnt: [c_int; 2],
}
const _: () = assert!(std::mem::size_of::<CuVideoH264DpbEntry>() == 28);
const _: () = assert!(std::mem::size_of::<[CuVideoH264DpbEntry; 16]>() == 448);
#[repr(C)]
#[allow(dead_code)]
struct CuVideoH264PicParamsShape {
sps_pps_scalars: [c_int; 32],
dpb: [CuVideoH264DpbEntry; 16],
weight_scale_4x4: [[u8; 16]; 6],
weight_scale_8x8: [[u8; 64]; 2],
fmo_aso_extras: [u8; 256],
reserved_tail: [u8; 1024],
}
const _: () = assert!(std::mem::size_of::<CuVideoH264PicParamsShape>() <= 4096);
#[repr(C)]
#[allow(dead_code)]
struct CuVideoHevcPicParamsShape {
sps_pps_scalars: [c_int; 64],
ref_pic_idx: [c_int; 16],
pic_order_cnt_val: [c_int; 16],
is_long_term: [c_uchar; 16],
rps_sets: [[c_uchar; 8]; 3],
scaling_list_4x4: [[c_uchar; 16]; 6],
scaling_list_8x8: [[c_uchar; 64]; 6],
scaling_list_16x16: [[c_uchar; 64]; 6],
scaling_list_32x32: [[c_uchar; 64]; 2],
scaling_list_dc_16x16: [c_uchar; 6],
scaling_list_dc_32x32: [c_uchar; 2],
reserved_tail: [u8; 256],
}
const _: () = assert!(std::mem::size_of::<CuVideoHevcPicParamsShape>() <= 4096);
#[repr(C)]
#[allow(dead_code)]
struct CuVideoAv1PicParamsShape {
seq_header_scalars: [c_int; 32],
ref_frame_map: [c_int; 8],
tile_col_start_sb: [c_int; 64],
tile_row_start_sb: [c_int; 64],
loop_filter: [c_int; 16],
film_grain: [u8; 512],
reserved_tail: [u8; 256],
}
const _: () = assert!(std::mem::size_of::<CuVideoAv1PicParamsShape>() <= 4096);
#[repr(C)]
#[allow(dead_code)]
struct CuVideoVp9PicParamsShape {
profile_and_scalars: [c_int; 32],
ref_frame_map: [c_int; 8],
probs: [u8; 384],
reserved_tail: [u8; 128],
}
const _: () = assert!(std::mem::size_of::<CuVideoVp9PicParamsShape>() <= 4096);
#[repr(C)]
#[allow(dead_code)]
struct CuVideoVp8PicParamsShape {
profile_and_scalars: [c_int; 16],
last_ref: c_int,
golden_ref: c_int,
alt_ref: c_int,
tables: [u8; 256],
reserved_tail: [u8; 64],
}
const _: () = assert!(std::mem::size_of::<CuVideoVp8PicParamsShape>() <= 4096);
#[repr(C)]
#[allow(dead_code)]
struct CuVideoMpeg2PicParamsShape {
forward_ref_pic_idx: c_int,
backward_ref_pic_idx: c_int,
picture_coding_type: c_int,
full_pel_forward_vector: c_int,
full_pel_backward_vector: c_int,
f_code: [[c_int; 2]; 2],
intra_dc_precision: c_int,
frame_pred_frame_dct: c_int,
concealment_motion_vectors: c_int,
q_scale_type: c_int,
intra_vlc_format: c_int,
alternate_scan: c_int,
top_field_first: c_int,
quant_matrix_intra: [c_uchar; 64],
quant_matrix_inter: [c_uchar; 64],
reserved_tail: [u8; 32],
}
const _: () = assert!(std::mem::size_of::<CuVideoMpeg2PicParamsShape>() <= 4096);
#[repr(C)]
#[allow(dead_code)]
struct CuVideoMpeg4PicParamsShape {
forward_ref_pic_idx: c_int,
backward_ref_pic_idx: c_int,
vop_time_increment_resolution: c_int,
vop_coding_type: c_int,
interlaced: c_int,
quant_type: c_int,
quarter_sample: c_int,
short_video_header: c_int,
divx_flags: c_int,
top_field_first: c_int,
rounding_control: c_int,
alternate_vertical_scan_flag: c_int,
quant_matrix_intra: [c_uchar; 64],
quant_matrix_inter: [c_uchar; 64],
reserved_tail: [u8; 32],
}
const _: () = assert!(std::mem::size_of::<CuVideoMpeg4PicParamsShape>() <= 4096);
#[repr(C)]
pub struct CuVideoProcParams {
pub progressive_frame: c_int,
pub second_field: c_int,
pub top_field_first: c_int,
pub unpaired_field: c_int,
pub reserved_flags: c_uint,
pub reserved_zero: c_uint,
pub raw_input_dptr: c_ulonglong,
pub raw_input_pitch: c_uint,
pub raw_input_format: c_uint,
pub raw_output_dptr: c_ulonglong,
pub raw_output_pitch: c_uint,
pub reserved1: c_uint,
pub output_stream: *mut c_void,
pub reserved: [c_uint; 46],
pub histogram_dptr: *mut c_void,
pub reserved2: [*mut c_void; 1],
}
const _: () = assert!(std::mem::size_of::<CuVideoParserParams>() == 136);
const _: () = assert!(std::mem::size_of::<CuVideoFormat>() >= 72);
const _: () = assert!(std::mem::size_of::<CuVideoPicParams>() == 4280);
const _: () = assert!(std::mem::size_of::<[c_uint; 1024]>() == 4096);
const _: () = assert!(std::mem::size_of::<CuVideoDispInfo>() == 24);
#[cfg(target_os = "windows")]
const _: () = assert!(std::mem::size_of::<CuVideoSourceDataPacket>() == 24);
#[cfg(all(target_os = "linux", target_pointer_width = "64"))]
const _: () = assert!(std::mem::size_of::<CuVideoSourceDataPacket>() == 32);
#[cfg(target_os = "windows")]
const _: () = assert!(std::mem::size_of::<CuVideoDecodeCreateInfo>() == 112);
const _: () = assert!(std::mem::size_of::<CuVideoProcParams>() == 264);
pub type FnCuvidCreateVideoParser =
unsafe extern "C" fn(*mut CUvideoparser, *mut CuVideoParserParams) -> CUresult;
pub type FnCuvidParseVideoData =
unsafe extern "C" fn(CUvideoparser, *mut CuVideoSourceDataPacket) -> CUresult;
pub type FnCuvidDestroyVideoParser = unsafe extern "C" fn(CUvideoparser) -> CUresult;
pub type FnCuvidCreateDecoder =
unsafe extern "C" fn(*mut CUvideodecoder, *mut CuVideoDecodeCreateInfo) -> CUresult;
pub type FnCuvidDestroyDecoder = unsafe extern "C" fn(CUvideodecoder) -> CUresult;
pub type FnCuvidDecodePicture =
unsafe extern "C" fn(CUvideodecoder, *mut CuVideoPicParams) -> CUresult;
pub type FnCuvidMapVideoFrame = unsafe extern "C" fn(
CUvideodecoder,
c_int,
*mut CUdeviceptr,
*mut c_uint,
*mut CuVideoProcParams,
) -> CUresult;
pub type FnCuvidUnmapVideoFrame = unsafe extern "C" fn(CUvideodecoder, CUdeviceptr) -> CUresult;
pub type FnCuvidGetDecoderCaps = unsafe extern "C" fn(*mut CuVideoDecodeCaps) -> CUresult;
#[repr(C)]
#[derive(Clone, Copy)]
pub struct CuVideoDecodeCaps {
pub codec_type: c_int,
pub chroma_format: c_int,
pub bit_depth_minus8: u32,
pub reserved1: [u32; 3],
pub is_supported: u8,
pub num_nvdecs: u8,
pub output_format_mask: u16,
pub max_width: u32,
pub max_height: u32,
pub max_mb_count: u32,
pub min_width: u16,
pub min_height: u16,
pub num_output_surfaces: u8,
pub reserved2: [u8; 3],
pub reserved3: [u32; 8],
}
const _: () = assert!(std::mem::size_of::<CuVideoDecodeCaps>() == 80);
pub const CUVID_H264: c_int = 4;
pub const CUVID_HEVC: c_int = 8;
pub const CUVID_VP8: c_int = 9;
pub const CUVID_VP9: c_int = 10;
pub const CUVID_AV1: c_int = 11;
pub const CUVID_MPEG2: c_int = 1;
pub const CUVID_MPEG4: c_int = 3;
pub const CUVID_PKT_ENDOFSTREAM: c_ulong = 1;
pub const CUVID_PKT_TIMESTAMP: c_ulong = 2;
pub const CUVID_FMT_NV12: c_int = 0;
pub const CUVID_FMT_P016: c_int = 1;
pub const CUVID_CHROMA_420: c_int = 1;
pub const CUVID_CREATE_PREFER_CUVID: c_ulong = 0x01;
#[repr(C)]
#[allow(dead_code)]
pub struct CuVideoOperatingPointInfo {
codec: c_int,
reserved: [u8; 1024],
}
const _: () = assert!(std::mem::size_of::<CuVideoOperatingPointInfo>() <= 1024 + 8);