use std::ffi::c_void;
use crate::sys::nvEncodeAPI::{
GUID,
NV_ENC_BUFFER_FORMAT,
NV_ENC_CONFIG,
NV_ENC_INITIALIZE_PARAMS,
NV_ENC_INITIALIZE_PARAMS_VER,
NV_ENC_INPUT_RESOURCE_TYPE,
NV_ENC_PIC_FLAGS,
NV_ENC_PIC_PARAMS,
NV_ENC_PIC_PARAMS_VER,
NV_ENC_REGISTER_RESOURCE,
NV_ENC_REGISTER_RESOURCE_VER,
};
#[deprecated(note = "use the safe wrapper `EncoderInitParams`")]
impl NV_ENC_INITIALIZE_PARAMS {
#[must_use]
pub fn new(encode_guid: GUID, width: u32, height: u32) -> Self {
NV_ENC_INITIALIZE_PARAMS {
version: NV_ENC_INITIALIZE_PARAMS_VER,
encodeGUID: encode_guid,
encodeWidth: width,
encodeHeight: height,
..Default::default()
}
}
pub fn preset_guid(&mut self, preset_guid: GUID) -> &mut Self {
self.presetGUID = preset_guid;
self
}
pub fn encode_config(&mut self, encode_config: &mut NV_ENC_CONFIG) -> &mut Self {
self.encodeConfig = encode_config;
self
}
pub fn display_aspect_ratio(&mut self, width: u32, height: u32) -> &mut Self {
self.darWidth = width;
self.darHeight = height;
self
}
pub fn framerate(&mut self, numerator: u32, denominator: u32) -> &mut Self {
self.frameRateNum = numerator;
self.frameRateDen = denominator;
self
}
pub fn enable_picture_type_decision(&mut self) -> &mut Self {
self.enablePTD = 1;
self
}
}
impl NV_ENC_PIC_PARAMS {
#[must_use]
pub fn end_of_stream() -> Self {
NV_ENC_PIC_PARAMS {
version: NV_ENC_PIC_PARAMS_VER,
encodePicFlags: NV_ENC_PIC_FLAGS::NV_ENC_PIC_FLAG_EOS as u32,
..Default::default()
}
}
}
impl NV_ENC_REGISTER_RESOURCE {
#[must_use]
pub fn new(
resource_type: NV_ENC_INPUT_RESOURCE_TYPE,
width: u32,
height: u32,
resource_to_register: *mut c_void,
buffer_format: NV_ENC_BUFFER_FORMAT,
) -> Self {
NV_ENC_REGISTER_RESOURCE {
version: NV_ENC_REGISTER_RESOURCE_VER,
resourceType: resource_type,
width,
height,
pitch: width,
resourceToRegister: resource_to_register,
registeredResource: std::ptr::null_mut(),
bufferFormat: buffer_format,
..Default::default()
}
}
#[must_use]
pub fn pitch(mut self, pitch: u32) -> Self {
self.pitch = pitch;
self
}
}