Skip to main content

OpusMSEncoder

Struct OpusMSEncoder 

Source
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

Source

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.

Source

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).

Source

pub fn nb_streams(&self) -> usize

Opus streams this encoder writes into each packet. Needed for the OpusHead that describes the stream.

Source

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.

Source

pub fn bitrate_bps(&self) -> i32

Total target bitrate across all streams. Set it with set_bitrate.

Source

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.

Source

pub fn streams(&self) -> &[OpusEncoder]

The per-stream encoders, for reading. See streams_mut to change their settings.

Source

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.

Source

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.

Source

pub fn sample_rate(&self) -> i32

The sample rate this encoder was created with.

Source

pub fn channels(&self) -> usize

The number of output channels this encoder codes.

Source

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).

Source

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.

Trait Implementations§

Source§

impl Debug for OpusMSEncoder

Shows the layout and per-stream settings, not the encoders’ coding state.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.