use std::ffi::c_void;
pub(super) type AmfResult = i32;
pub(super) const AMF_OK: AmfResult = 0;
#[allow(dead_code)]
pub(super) const AMF_FAIL: AmfResult = 1;
pub(super) const AMF_NEED_MORE_INPUT: AmfResult = 2022;
pub(super) const AMF_REPEAT: AmfResult = 2023;
pub(super) const AMF_EOF: AmfResult = 2024;
pub(super) const AMF_INPUT_FULL: AmfResult = 2020;
pub(super) const AMF_VERSION: u64 = amf_make_version(1, 4, 30, 0);
const fn amf_make_version(major: u64, minor: u64, sub_major: u64, sub_minor: u64) -> u64 {
(major << 48) | (minor << 32) | (sub_major << 16) | sub_minor
}
pub(super) const AMF_MEMORY_HOST: i32 = 1;
pub(super) const AMF_SURFACE_NV12: i32 = 1;
pub(super) const AMF_SURFACE_P010: i32 = 10;
pub(super) const AMF_PLANE_Y: i32 = 2;
pub(super) const AMF_PLANE_UV: i32 = 3;
pub(super) const AMF_VARIANT_INT64: i32 = 2;
pub(super) const AMF_RC_CQP: i64 = 1;
pub(super) const AMF_RC_QUALITY_VBR: i64 = 5;
pub(super) const AMF_OUTPUT_FRAME_TYPE_KEY: i64 = 0;
pub(super) const AMF_OUTPUT_FRAME_TYPE_INTRA_ONLY: i64 = 1;
pub(super) const AMF_USAGE_TRANSCODING: i64 = 0;
pub(super) const AMF_OUTPUT_MODE_FRAME: i64 = 0;
pub(super) const AMF_AV1_COLOR_BIT_DEPTH_8: i64 = 1;
pub(super) const AMF_AV1_COLOR_BIT_DEPTH_10: i64 = 2;
pub(super) const RING_SIZE: usize = 4;
pub(super) const INPUT_FULL_MAX_RETRIES: u32 = 16;
pub(super) const INPUT_FULL_BACKOFF_MS_INITIAL: u64 = 1;
pub(super) const INPUT_FULL_BACKOFF_MS_MAX: u64 = 16;
#[repr(C)]
#[derive(Clone, Copy)]
pub(super) struct AmfVariant {
pub(super) ty: i32,
pub(super) _pad: i32,
pub(super) value: [u8; 24],
}
const _: () = {
assert!(
std::mem::size_of::<AmfVariant>() == 32,
"AmfVariant must be 32 bytes"
);
assert!(
std::mem::offset_of!(AmfVariant, value) == 8,
"AmfVariant value payload must start at offset 8"
);
};
const _: () = assert!(AMF_SURFACE_NV12 == 1);
const _: () = assert!(AMF_SURFACE_P010 == 10);
const _: () = assert!(AMF_AV1_COLOR_BIT_DEPTH_8 == 1);
const _: () = assert!(AMF_AV1_COLOR_BIT_DEPTH_10 == 2);
impl AmfVariant {
pub(super) fn int64(v: i64) -> Self {
let mut value = [0u8; 24];
value[..8].copy_from_slice(&v.to_le_bytes());
Self {
ty: AMF_VARIANT_INT64,
_pad: 0,
value,
}
}
#[allow(dead_code)]
pub(super) fn as_int64(&self) -> Option<i64> {
if self.ty == AMF_VARIANT_INT64 {
let mut bytes = [0u8; 8];
bytes.copy_from_slice(&self.value[..8]);
Some(i64::from_le_bytes(bytes))
} else {
None
}
}
}
type QueryInterfaceFn = unsafe extern "C" fn(*mut c_void, *const c_void, *mut *mut c_void) -> i64;
type AcquireFn = unsafe extern "C" fn(*mut c_void) -> i64;
type ReleaseFn = unsafe extern "C" fn(*mut c_void) -> i64;
#[repr(C)]
pub(super) struct AmfFactoryVtbl {
pub(super) create_context:
unsafe extern "C" fn(*mut c_void, *mut *mut c_void) -> AmfResult,
pub(super) create_component:
unsafe extern "C" fn(*mut c_void, *mut c_void, *const u16, *mut *mut c_void) -> AmfResult,
pub(super) set_cache_folder: unsafe extern "C" fn(*mut c_void, *const u16) -> AmfResult,
pub(super) get_cache_folder: unsafe extern "C" fn(*mut c_void) -> *const u16,
pub(super) get_debug: unsafe extern "C" fn(*mut c_void, *mut *mut c_void) -> AmfResult,
pub(super) get_trace: unsafe extern "C" fn(*mut c_void, *mut *mut c_void) -> AmfResult,
pub(super) get_programs: unsafe extern "C" fn(*mut c_void, *mut *mut c_void) -> AmfResult,
}
#[repr(C)]
pub(super) struct AmfFactoryObj {
pub(super) vtbl: *const AmfFactoryVtbl,
}
#[repr(C)]
pub(super) struct AmfContextVtbl {
query_interface: QueryInterfaceFn,
acquire: AcquireFn,
pub(super) release: ReleaseFn,
pub(super) terminate: unsafe extern "C" fn(*mut c_void) -> AmfResult,
pub(super) init_dx11: unsafe extern "C" fn(*mut c_void, *mut c_void, i32) -> AmfResult,
get_dx11_device: unsafe extern "C" fn(*mut c_void, i32) -> *mut c_void,
lock_dx11: unsafe extern "C" fn(*mut c_void) -> AmfResult,
unlock_dx11: unsafe extern "C" fn(*mut c_void) -> AmfResult,
init_opencl: unsafe extern "C" fn(*mut c_void, *mut c_void) -> AmfResult,
get_opencl_context: unsafe extern "C" fn(*mut c_void) -> *mut c_void,
get_opencl_command_queue: unsafe extern "C" fn(*mut c_void) -> *mut c_void,
get_opencl_device_id: unsafe extern "C" fn(*mut c_void) -> *mut c_void,
convert_to_opencl: unsafe extern "C" fn(*mut c_void, *mut c_void) -> AmfResult,
lock_opencl: unsafe extern "C" fn(*mut c_void) -> AmfResult,
unlock_opencl: unsafe extern "C" fn(*mut c_void) -> AmfResult,
init_opengl:
unsafe extern "C" fn(*mut c_void, *mut c_void, *mut c_void, *mut c_void) -> AmfResult,
get_opengl_context: unsafe extern "C" fn(*mut c_void) -> *mut c_void,
get_opengl_drawable: unsafe extern "C" fn(*mut c_void) -> *mut c_void,
convert_to_opengl: unsafe extern "C" fn(*mut c_void, *mut c_void) -> AmfResult,
lock_opengl: unsafe extern "C" fn(*mut c_void) -> AmfResult,
unlock_opengl: unsafe extern "C" fn(*mut c_void) -> AmfResult,
pub(super) init_vulkan: unsafe extern "C" fn(*mut c_void, *mut c_void) -> AmfResult,
get_vulkan_device: unsafe extern "C" fn(*mut c_void) -> *mut c_void,
lock_vulkan: unsafe extern "C" fn(*mut c_void) -> AmfResult,
unlock_vulkan: unsafe extern "C" fn(*mut c_void) -> AmfResult,
alloc_buffer:
unsafe extern "C" fn(*mut c_void, i32, usize, *mut *mut c_void) -> AmfResult,
pub(super) alloc_surface: unsafe extern "C" fn(
*mut c_void,
i32, // memory type
i32, // surface format
i32, // width
i32, // height
*mut *mut c_void,
) -> AmfResult,
create_surface_from_host_native: unsafe extern "C" fn(
*mut c_void,
i32,
i32,
i32,
i32,
i32,
*mut c_void,
*mut *mut c_void,
*mut c_void,
) -> AmfResult,
}
#[repr(C)]
pub(super) struct AmfContextObj {
pub(super) vtbl: *const AmfContextVtbl,
}
#[repr(C)]
pub(super) struct AmfComponentVtbl {
pub(super) query_interface: QueryInterfaceFn,
pub(super) acquire: AcquireFn,
pub(super) release: ReleaseFn,
pub(super) set_property:
unsafe extern "C" fn(*mut c_void, *const u16, AmfVariant) -> AmfResult,
pub(super) get_property:
unsafe extern "C" fn(*mut c_void, *const u16, *mut AmfVariant) -> AmfResult,
pub(super) init: unsafe extern "C" fn(*mut c_void, i32, i32, i32) -> AmfResult,
pub(super) reinit: unsafe extern "C" fn(*mut c_void, i32, i32) -> AmfResult,
pub(super) terminate: unsafe extern "C" fn(*mut c_void) -> AmfResult,
pub(super) drain: unsafe extern "C" fn(*mut c_void) -> AmfResult,
pub(super) flush: unsafe extern "C" fn(*mut c_void) -> AmfResult,
pub(super) submit_input: unsafe extern "C" fn(*mut c_void, *mut c_void) -> AmfResult,
pub(super) query_output: unsafe extern "C" fn(*mut c_void, *mut *mut c_void) -> AmfResult,
pub(super) get_context: unsafe extern "C" fn(*mut c_void) -> *mut c_void,
pub(super) set_output_data_allocator_cb:
unsafe extern "C" fn(*mut c_void, *mut c_void) -> AmfResult,
pub(super) get_caps: unsafe extern "C" fn(*mut c_void, *mut *mut c_void) -> AmfResult,
pub(super) optimize: unsafe extern "C" fn(*mut c_void, *mut c_void) -> AmfResult,
}
#[repr(C)]
pub(super) struct AmfComponentObj {
pub(super) vtbl: *const AmfComponentVtbl,
}
#[repr(C)]
pub(super) struct AmfSurfaceVtbl {
pub(super) query_interface: QueryInterfaceFn,
pub(super) acquire: AcquireFn,
pub(super) release: ReleaseFn,
pub(super) set_property:
unsafe extern "C" fn(*mut c_void, *const u16, AmfVariant) -> AmfResult,
pub(super) get_property:
unsafe extern "C" fn(*mut c_void, *const u16, *mut AmfVariant) -> AmfResult,
pub(super) duplicate: unsafe extern "C" fn(*mut c_void, i32, *mut *mut c_void) -> AmfResult,
pub(super) get_pts: unsafe extern "C" fn(*mut c_void) -> i64,
pub(super) set_pts: unsafe extern "C" fn(*mut c_void, i64),
pub(super) get_duration: unsafe extern "C" fn(*mut c_void) -> i64,
pub(super) set_duration: unsafe extern "C" fn(*mut c_void, i64),
pub(super) get_planes_count: unsafe extern "C" fn(*mut c_void) -> usize,
pub(super) get_plane_at: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void,
pub(super) get_plane: unsafe extern "C" fn(*mut c_void, i32) -> *mut c_void,
}
#[repr(C)]
pub(super) struct AmfSurfaceObj {
pub(super) vtbl: *const AmfSurfaceVtbl,
}
#[repr(C)]
pub(super) struct AmfPlaneVtbl {
query_interface: QueryInterfaceFn,
acquire: AcquireFn,
release: ReleaseFn,
get_type: unsafe extern "C" fn(*mut c_void) -> i32,
pub(super) get_native: unsafe extern "C" fn(*mut c_void) -> *mut c_void,
get_pixel_size_in_bytes: unsafe extern "C" fn(*mut c_void) -> i32,
get_offset_x: unsafe extern "C" fn(*mut c_void) -> i32,
get_offset_y: unsafe extern "C" fn(*mut c_void) -> i32,
get_width: unsafe extern "C" fn(*mut c_void) -> i32,
get_height: unsafe extern "C" fn(*mut c_void) -> i32,
pub(super) get_h_pitch: unsafe extern "C" fn(*mut c_void) -> i32,
get_v_pitch: unsafe extern "C" fn(*mut c_void) -> i32,
}
#[repr(C)]
pub(super) struct AmfPlaneObj {
pub(super) vtbl: *const AmfPlaneVtbl,
}
#[repr(C)]
pub(super) struct AmfBufferVtbl {
pub(super) query_interface: QueryInterfaceFn,
acquire: AcquireFn,
pub(super) release: ReleaseFn,
set_property: unsafe extern "C" fn(*mut c_void, *const u16, AmfVariant) -> AmfResult,
pub(super) get_property:
unsafe extern "C" fn(*mut c_void, *const u16, *mut AmfVariant) -> AmfResult,
duplicate: unsafe extern "C" fn(*mut c_void, i32, *mut *mut c_void) -> AmfResult,
pub(super) get_pts: unsafe extern "C" fn(*mut c_void) -> i64,
set_pts: unsafe extern "C" fn(*mut c_void, i64),
get_duration: unsafe extern "C" fn(*mut c_void) -> i64,
set_duration: unsafe extern "C" fn(*mut c_void, i64),
pub(super) get_native: unsafe extern "C" fn(*mut c_void) -> *mut c_void,
pub(super) get_size: unsafe extern "C" fn(*mut c_void) -> usize,
}
#[repr(C)]
pub(super) struct AmfBufferObj {
pub(super) vtbl: *const AmfBufferVtbl,
}
pub(super) const AMF_IID_BUFFER: [u8; 16] = [
0xbe, 0x5d, 0xd7, 0xb1, 0x6c, 0x0e, 0x4c, 0x43, 0xb7, 0x28, 0x02, 0x85, 0x98, 0x37, 0x85,
0x7d,
];
pub(super) type FnAmfInit = unsafe extern "C" fn(u64, *mut *mut c_void) -> AmfResult;