From 4c8ba6dfef0899650bf80d8e670557d48548cd63 Mon Sep 17 00:00:00 2001 From: Tad Hardesty Date: Thu, 30 Nov 2017 04:03:34 -0800 Subject: [PATCH] Add VBR and VBR constraint encoder CTLs --- src/lib.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 7a5d51a..339cc80 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,6 +31,10 @@ const OPUS_GET_SAMPLE_RATE: c_int = 4029; // out *i32 // Encoder CTLs const OPUS_SET_BITRATE: c_int = 4002; // in i32 const OPUS_GET_BITRATE: c_int = 4003; // out *i32 +const OPUS_SET_VBR: c_int = 4006; // in i32 +const OPUS_GET_VBR: c_int = 4007; // out *i32 +const OPUS_SET_VBR_CONSTRAINT: c_int = 4020; // in i32 +const OPUS_GET_VBR_CONSTRAINT: c_int = 4021; // out *i32 const OPUS_SET_INBAND_FEC: c_int = 4012; // in i32 const OPUS_GET_INBAND_FEC: c_int = 4013; // out *i32 const OPUS_SET_PACKET_LOSS_PERC: c_int = 4014; // in i32 @@ -310,6 +314,34 @@ impl Encoder { }) } + /// Enable or disable variable bitrate. + pub fn set_vbr(&mut self, vbr: bool) -> Result<()> { + let mut value: i32 = if vbr { 1 } else { 0 }; + enc_ctl!(self, OPUS_SET_VBR, value); + Ok(()) + } + + /// Determine if variable bitrate is enabled. + pub fn get_vbr(&mut self) -> Result { + let mut value: i32 = 0; + enc_ctl!(self, OPUS_GET_VBR, &mut value); + Ok(value != 0) + } + + /// Enable or disable constrained VBR. + pub fn set_vbr_constraint(&mut self, vbr: bool) -> Result<()> { + let mut value: i32 = if vbr { 1 } else { 0 }; + enc_ctl!(self, OPUS_SET_VBR_CONSTRAINT, value); + Ok(()) + } + + /// Determine if constrained VBR is enabled. + pub fn get_vbr_constraint(&mut self) -> Result { + let mut value: i32 = 0; + enc_ctl!(self, OPUS_GET_VBR_CONSTRAINT, &mut value); + Ok(value != 0) + } + /// Configures the encoder's use of inband forward error correction (FEC). pub fn set_inband_fec(&mut self, value: bool) -> Result<()> { let value: i32 = if value { 1 } else { 0 };