mirror of
https://github.com/rustdesk/magnum-opus.git
synced 2026-05-20 00:20:31 +00:00
Add support for Max and Auto bitrates through an enum
This commit is contained in:
committed by
Tad Hardesty
parent
6c6bec4c0c
commit
09f9d16148
+28
-4
@@ -36,6 +36,10 @@ const OPUS_GET_INBAND_FEC: c_int = 4013; // out *i32
|
|||||||
const OPUS_SET_PACKET_LOSS_PERC: c_int = 4014; // in i32
|
const OPUS_SET_PACKET_LOSS_PERC: c_int = 4014; // in i32
|
||||||
const OPUS_GET_PACKET_LOSS_PERC: c_int = 4015; // out *i32
|
const OPUS_GET_PACKET_LOSS_PERC: c_int = 4015; // out *i32
|
||||||
|
|
||||||
|
// Bitrate
|
||||||
|
const OPUS_AUTO: c_int = -1000;
|
||||||
|
const OPUS_BITRATE_MAX: c_int = -1;
|
||||||
|
|
||||||
/// The possible applications for the codec.
|
/// The possible applications for the codec.
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
|
||||||
pub enum Application {
|
pub enum Application {
|
||||||
@@ -110,6 +114,17 @@ pub enum ErrorCode {
|
|||||||
Unknown = -8,
|
Unknown = -8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Possible bitrates.
|
||||||
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
|
pub enum Bitrate {
|
||||||
|
/// Explicit bitrate choice (in bits/second).
|
||||||
|
Bits(i32),
|
||||||
|
/// Maximum bitrate allowed (up to maximum number of bytes for the packet).
|
||||||
|
Max,
|
||||||
|
/// Default bitrate decided by the encoder (not recommended).
|
||||||
|
Auto,
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the libopus version string.
|
/// Get the libopus version string.
|
||||||
pub fn version() -> &'static str {
|
pub fn version() -> &'static str {
|
||||||
// verison string should always be ASCII
|
// verison string should always be ASCII
|
||||||
@@ -205,17 +220,26 @@ impl Encoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set the encoder's bitrate.
|
/// Set the encoder's bitrate.
|
||||||
pub fn set_bitrate(&mut self, value: i32) -> Result<()> {
|
pub fn set_bitrate(&mut self, value: Bitrate) -> Result<()> {
|
||||||
let result = unsafe { ffi::opus_encoder_ctl(self.ptr, OPUS_SET_BITRATE, value) };
|
let val: i32 = match value {
|
||||||
|
Bitrate::Auto => OPUS_AUTO,
|
||||||
|
Bitrate::Max => OPUS_BITRATE_MAX,
|
||||||
|
Bitrate::Bits(b) => b,
|
||||||
|
};
|
||||||
|
let result = unsafe { ffi::opus_encoder_ctl(self.ptr, OPUS_SET_BITRATE, val) };
|
||||||
check("opus_encoder_ctl(OPUS_SET_BITRATE)", result)
|
check("opus_encoder_ctl(OPUS_SET_BITRATE)", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the encoder's bitrate.
|
/// Get the encoder's bitrate.
|
||||||
pub fn get_bitrate(&mut self) -> Result<i32> {
|
pub fn get_bitrate(&mut self) -> Result<Bitrate> {
|
||||||
let mut value: i32 = 0;
|
let mut value: i32 = 0;
|
||||||
let result = unsafe { ffi::opus_encoder_ctl(self.ptr, OPUS_GET_BITRATE, &mut value) };
|
let result = unsafe { ffi::opus_encoder_ctl(self.ptr, OPUS_GET_BITRATE, &mut value) };
|
||||||
try!(check("opus_encoder_ctl(OPUS_GET_BITRATE)", result));
|
try!(check("opus_encoder_ctl(OPUS_GET_BITRATE)", result));
|
||||||
Ok(value)
|
Ok(match value {
|
||||||
|
OPUS_AUTO => Bitrate::Auto,
|
||||||
|
OPUS_BITRATE_MAX => Bitrate::Max,
|
||||||
|
_ => Bitrate::Bits(value),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Configures the encoder's use of inband forward error correction (FEC).
|
/// Configures the encoder's use of inband forward error correction (FEC).
|
||||||
|
|||||||
Reference in New Issue
Block a user