pub struct OpusMSEncoder { /* private fields */ }Expand description
Multistream encoder: one Opus encoder per stream (coupled = stereo, the rest mono), coded per the channel layout and concatenated self-delimited.
Implementations§
Source§impl OpusMSEncoder
impl OpusMSEncoder
Sourcepub fn new(
sample_rate: i32,
channels: usize,
mapping_family: u8,
application: Application,
) -> Result<Self>
pub fn new( sample_rate: i32, channels: usize, mapping_family: u8, application: Application, ) -> Result<Self>
Create a surround encoder for channels channels.
mapping_family selects the layout: 0 for mono or stereo, 1 for the
Vorbis surround orders (quad, 5.0, 5.1, 6.1, 7.1) up to 8 channels.
These are the families RFC 7845 defines for an .opus file, and the
same value belongs in the OpusHead written
alongside. Any other value, or more than 8 channels, is
Error::InvalidArgument;
ChannelLayout::surround is where that decision is made.
Sourcepub fn set_bitrate(&mut self, total: i32)
pub fn set_bitrate(&mut self, total: i32)
Split the total bitrate across streams (each coupled stream gets 2x a mono stream’s share, matching its 2 channels).
Sourcepub fn nb_streams(&self) -> usize
pub fn nb_streams(&self) -> usize
Opus streams this encoder writes into each packet. Needed for the
OpusHead that describes the stream.
Sourcepub fn layout(&self) -> &ChannelLayout
pub fn layout(&self) -> &ChannelLayout
The channel layout this encoder codes to.
This is what an OpusHead for the stream has to
declare, and OpusHead::for_ms_encoder
takes it from here rather than making you derive it a second time.
Sourcepub fn bitrate_bps(&self) -> i32
pub fn bitrate_bps(&self) -> i32
Total target bitrate across all streams. Set it with
set_bitrate.
Sourcepub fn streams_mut(&mut self) -> &mut [OpusEncoder]
pub fn streams_mut(&mut self) -> &mut [OpusEncoder]
The per-stream encoders, so every OpusEncoder setting is reachable.
A multistream encoder is N ordinary encoders, and rather than mirror ten
settings here — a list that would go stale the moment OpusEncoder
gained an eleventh — this hands them over. Set the same thing on all of
them:
for e in enc.streams_mut() {
e.use_inband_fec = true;
e.packet_loss_perc = 10;
}bitrate_bps is the exception: it is split
across streams from a single total, so set it with
set_bitrate and let the split happen.
Sourcepub fn streams(&self) -> &[OpusEncoder]
pub fn streams(&self) -> &[OpusEncoder]
The per-stream encoders, for reading. See
streams_mut to change their settings.
Sourcepub fn encode(
&mut self,
input: &[f32],
frame_size: usize,
output: &mut [u8],
) -> Result<usize>
pub fn encode( &mut self, input: &[f32], frame_size: usize, output: &mut [u8], ) -> Result<usize>
Encode one frame of interleaved input into a multistream packet,
returning how many bytes of output it filled.
input holds frame_size * nb_channels samples. Unlike
OpusEncoder::encode, output.len() is a plain capacity here and not
a byte budget: a buffer too small is
Error::BufferTooSmall, whose needed
tells you exactly how big to make it, rather than a quietly smaller
packet. Each stream is coded to its own share of
bitrate_bps.
Sourcepub fn encode_s16(
&mut self,
input: &[i16],
frame_size: usize,
output: &mut [u8],
) -> Result<usize>
pub fn encode_s16( &mut self, input: &[i16], frame_size: usize, output: &mut [u8], ) -> Result<usize>
encode from 16-bit PCM.
Every stream is told its input came from 16 bits, exactly as
OpusEncoder::encode_s16 does for a single stream, and for the same
reason: the digital-silence floor sits at the source’s own precision.
Sourcepub fn sample_rate(&self) -> i32
pub fn sample_rate(&self) -> i32
The sample rate this encoder was created with.
Sourcepub fn reset_state(&mut self) -> Result<()>
pub fn reset_state(&mut self) -> Result<()>
Discard every stream’s coding state, keeping all settings, as
OpusEncoder::reset_state does for one.
Source§impl OpusMSEncoder
Bandwidth passthrough helper (so callers can cap all streams at once).
impl OpusMSEncoder
Bandwidth passthrough helper (so callers can cap all streams at once).
Sourcepub fn set_max_bandwidth(&mut self, bw: Bandwidth)
pub fn set_max_bandwidth(&mut self, bw: Bandwidth)
Cap the audio bandwidth of every stream at once, as
OpusEncoder::max_bandwidth does for one.