Add fields for dred support to the opus encoder configuration

This commit is contained in:
Jim Gustafson 2026-04-06 15:50:59 -07:00
parent fd98a5ca7a
commit 919261a9f9
4 changed files with 42 additions and 8 deletions

View File

@ -440,7 +440,7 @@ pub struct AudioConfig {
/// The Opus bandwidth value to use (Auto is the default).
pub bandwidth: AudioBandwidth,
/// The Opus complexity value to use.
pub complexity: i32,
pub complexity: u8,
/// The adaptation method to use. 0 means no adaptation (the default).
pub adaptation: i32,
/// Flag to enable the Opus constant bitrate mode.
@ -449,6 +449,10 @@ pub struct AudioConfig {
pub enable_dtx: bool,
/// Flag to enable the Opus in-band FEC.
pub enable_fec: bool,
/// The duration of DRED to use in 10ms units. Set to 0 to disable.
pub dred_duration: u8,
/// Minimum packet loss percentage reported to the encoder (0-100).
pub min_packet_loss_percent: u8,
/// None when using NetEq PLC, 0 use Opus PLC, 5 use Opus Deep PLC (if compiled),
/// 6 use Opus Deep PLC + LACE (if compiled), 7 use Opus Deep PLC + NoLACE (if compiled).
pub decoder_complexity: Option<u8>,
@ -514,6 +518,8 @@ impl Default for AudioConfig {
enable_cbr: true,
enable_dtx: true,
enable_fec: true,
dred_duration: 0,
min_packet_loss_percent: 0,
decoder_complexity: Some(0),
enable_tcc: false,
enable_high_pass_filter: true,

View File

@ -962,6 +962,15 @@ pub async fn start_cli(
args.push(format!("--dtx={}", call_config.audio.enable_dtx));
args.push(format!("--fec={}", call_config.audio.enable_fec));
args.push(format!(
"--dred-duration={}",
call_config.audio.dred_duration
));
args.push(format!(
"--min-packet-loss-percent={}",
call_config.audio.min_packet_loss_percent
));
if let Some(complexity) = call_config.audio.decoder_complexity {
args.push(format!("--decoder-complexity={}", complexity));
}

View File

@ -95,8 +95,8 @@ struct Args {
bandwidth: AudioBandwidth,
/// The encoding complexity for audio.
#[arg(long, default_value = "9", value_parser = clap::value_parser!(i32).range(0..=10))]
complexity: i32,
#[arg(long, default_value = "9", value_parser = clap::value_parser!(u8).range(0..=10))]
complexity: u8,
/// The size of an audio frame (ptime).
#[arg(long, default_value = "20", value_parser = clap::builder::PossibleValuesParser::new(["20", "40", "60", "80", "100", "120"]))]
@ -122,6 +122,14 @@ struct Args {
#[arg(long, action = clap::ArgAction::Set, default_value = "true")]
fec: bool,
/// The duration of dred to use in 10ms units. Set to 0 to disable (default).
#[arg(long, default_value = "0", value_parser = clap::value_parser!(u8).range(0..=100))]
dred_duration: u8,
/// Minimum packet loss percentage reported to encoder (0-100).
#[arg(long, default_value_t = 0, value_parser = clap::value_parser!(u8).range(0..=100))]
min_packet_loss_percent: u8,
/// Whether to use adaptation when encoding audio. Set to 0 to disable (default).
#[arg(long, default_value_t = 0)]
adaptation: i32,
@ -305,7 +313,8 @@ fn main() -> Result<()> {
enable_cbr: args.cbr,
enable_dtx: args.dtx,
enable_fec: args.fec,
dred_duration: 0,
dred_duration: args.dred_duration,
min_packet_loss_percent: args.min_packet_loss_percent,
},
audio_decoder_config: AudioDecoderConfig {
complexity: args.decoder_complexity,

View File

@ -367,7 +367,9 @@ pub struct RffiAudioEncoderConfig {
enable_dtx: bool,
enable_fec: bool,
dred_duration: u8,
dred_duration: i32,
min_packet_loss_percent: i32,
}
// A nice form of RffiAudioEncoderConfig
@ -386,15 +388,20 @@ pub struct AudioEncoderConfig {
// Default is Auto
pub bandwidth: AudioBandwidth,
// Valid range: 0-10 (10 most complex)
pub complexity: i32,
pub complexity: u8,
pub adaptation: i32,
pub enable_cbr: bool,
pub enable_dtx: bool,
pub enable_fec: bool,
// Valid range: 0-100
pub dred_duration: u8,
// Valid range: 0-100 (Used only for testing)
pub min_packet_loss_percent: u8,
}
impl Default for AudioEncoderConfig {
@ -417,6 +424,8 @@ impl Default for AudioEncoderConfig {
enable_fec: true,
dred_duration: 0,
min_packet_loss_percent: 0,
}
}
}
@ -431,12 +440,13 @@ impl AudioEncoderConfig {
min_bitrate_bps: self.min_bitrate_bps,
max_bitrate_bps: self.max_bitrate_bps,
bandwidth: self.bandwidth as i32,
complexity: self.complexity,
complexity: self.complexity as i32,
adaptation: self.adaptation,
enable_cbr: self.enable_cbr,
enable_dtx: self.enable_dtx,
enable_fec: self.enable_fec,
dred_duration: self.dred_duration,
dred_duration: self.dred_duration as i32,
min_packet_loss_percent: self.min_packet_loss_percent as i32,
}
}
}