use std::collections::VecDeque;
use crate::frame::PixelFormat;
use crate::qsv_ffi::{MfxBitstream, MfxExtBuffer};
use super::ffi::{
FnEncodeClose, FnEncodeFrameAsync, FnMfxClose, FnMfxUnload, FnSyncOperation, MfxLoader,
MfxSession,
};
use super::ffi::{
MfxExtAv1TileParam, MfxExtCodingOption3, MfxExtVideoSignalInfo,
};
use super::surface::{RING_SIZE, SurfaceSlot};
pub(super) struct QsvSession {
pub(super) session: MfxSession,
pub(super) width: u32,
pub(super) height: u32,
pub(super) pts_timescale: u64,
pub(super) input_pixel_format: PixelFormat,
pub(super) fn_mfx_close: FnMfxClose,
pub(super) fn_encode_close: FnEncodeClose,
pub(super) fn_encode_frame_async: FnEncodeFrameAsync,
pub(super) fn_sync_operation: FnSyncOperation,
pub(super) loader: MfxLoader,
pub(super) fn_unload: FnMfxUnload,
#[allow(dead_code)]
pub(super) tile_ext: Box<MfxExtAv1TileParam>,
#[allow(dead_code)]
pub(super) coding_option3_ext: Option<Box<MfxExtCodingOption3>>,
#[allow(dead_code)]
pub(super) signal_info_ext: Box<MfxExtVideoSignalInfo>,
#[allow(dead_code)]
pub(super) ext_param_array: Vec<*mut MfxExtBuffer>,
pub(super) surfaces: [SurfaceSlot; RING_SIZE],
pub(super) ring_idx: usize,
pub(super) inflight: VecDeque<usize>,
pub(super) input_pitch: u32,
pub(super) height_aligned: u32,
pub(super) bitstream: MfxBitstream,
pub(super) _bitstream_buf: Box<[u8]>,
}
unsafe impl Send for QsvSession {}
impl Drop for QsvSession {
fn drop(&mut self) {
unsafe {
if !self.session.is_null() {
let _ = (self.fn_encode_close)(self.session);
let _ = (self.fn_mfx_close)(self.session);
}
if !self.loader.is_null() {
(self.fn_unload)(self.loader);
}
}
}
}