Skip to content

Commit

Permalink
Add usage type option
Browse files Browse the repository at this point in the history
  • Loading branch information
MMitsuha authored and ralfbiedert committed Dec 22, 2024
1 parent bd0c33a commit 44662aa
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions openh264/src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use crate::error::NativeErrorExt;
use crate::formats::YUVSource;
use crate::{Error, OpenH264API, Timestamp};
use openh264_sys2::{
videoFormatI420, EVideoFormatType, ISVCEncoder, ISVCEncoderVtbl, SEncParamBase, SEncParamExt, SFrameBSInfo, SLayerBSInfo,
SSourcePicture, API, ENCODER_OPTION, ENCODER_OPTION_DATAFORMAT, ENCODER_OPTION_SVC_ENCODE_PARAM_EXT,
ENCODER_OPTION_TRACE_LEVEL, RC_MODES, VIDEO_CODING_LAYER, WELS_LOG_DETAIL, WELS_LOG_QUIET,
videoFormatI420, EUsageType, EVideoFormatType, ISVCEncoder, ISVCEncoderVtbl, SEncParamBase, SEncParamExt, SFrameBSInfo,
SLayerBSInfo, SSourcePicture, API, CAMERA_VIDEO_REAL_TIME, ENCODER_OPTION, ENCODER_OPTION_DATAFORMAT,
ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, ENCODER_OPTION_TRACE_LEVEL, RC_MODES, SCREEN_CONTENT_REAL_TIME, VIDEO_CODING_LAYER,
WELS_LOG_DETAIL, WELS_LOG_QUIET,
};
use std::os::raw::{c_int, c_uchar, c_void};
use std::ptr::{addr_of_mut, null, null_mut};
Expand Down Expand Up @@ -164,6 +165,33 @@ impl Default for SpsPpsStrategy {
}
}

#[derive(Copy, Clone, Debug)]
pub enum UsageType {
CameraVideoRealTime,
ScreenContentRealTime,
CameraVideoNonRealTime,
ScreenContentNonRealTime,
InputContentTypeAll,
}

impl UsageType {
fn to_c(self) -> EUsageType {
match self {
UsageType::CameraVideoRealTime => CAMERA_VIDEO_REAL_TIME,
UsageType::ScreenContentRealTime => SCREEN_CONTENT_REAL_TIME,
UsageType::CameraVideoNonRealTime => openh264_sys2::CAMERA_VIDEO_NON_REAL_TIME,
UsageType::ScreenContentNonRealTime => openh264_sys2::SCREEN_CONTENT_NON_REAL_TIME,
UsageType::InputContentTypeAll => openh264_sys2::INPUT_CONTENT_TYPE_ALL,
}
}
}

impl Default for UsageType {
fn default() -> Self {
Self::CameraVideoRealTime
}
}

/// Configuration for the [`Encoder`].
///
/// Setting missing? Please file a PR!
Expand All @@ -179,6 +207,7 @@ pub struct EncoderConfig {
rate_control_mode: RateControlMode,
sps_pps_strategy: SpsPpsStrategy,
multiple_thread_idc: u16,
usage_type: UsageType,
}

impl EncoderConfig {
Expand All @@ -194,6 +223,7 @@ impl EncoderConfig {
rate_control_mode: Default::default(),
sps_pps_strategy: Default::default(),
multiple_thread_idc: 0,
usage_type: Default::default(),
}
}

Expand Down Expand Up @@ -221,6 +251,12 @@ impl EncoderConfig {
self
}

/// Sets usage type.
pub fn usage_type(mut self, value: UsageType) -> Self {
self.usage_type = value;
self
}

/// Sets the requested rate control mode.
pub fn rate_control_mode(mut self, value: RateControlMode) -> Self {
self.rate_control_mode = value;
Expand Down Expand Up @@ -377,6 +413,7 @@ impl Encoder {
params.fMaxFrameRate = self.config.max_frame_rate;
params.eSpsPpsIdStrategy = self.config.sps_pps_strategy.to_c();
params.iMultipleThreadIdc = self.config.multiple_thread_idc;
params.iUsageType = self.config.usage_type.to_c();

unsafe {
if self.previous_dimensions.is_none() {
Expand Down

0 comments on commit 44662aa

Please sign in to comment.