Skip to main content

AudioInfo

Struct AudioInfo 

Source
pub struct AudioInfo {
    pub codec: String,
    pub sample_rate: u32,
    pub channels: u16,
    pub timescale: u32,
    pub asc_bytes: Vec<u8>,
    pub codec_private: Vec<u8>,
}
Expand description

Parameters required to bolt an audio track onto Av1Mp4Muxer.

Four codec families are supported:

  • AAC-LC (Squad-18, task #63 v1): mono or stereo, sample_rate as the mdhd timescale per ISO/IEC 14496-14 standard practice, and the AudioSpecificConfig surfaced verbatim from the demuxer (see demux::AudioTrack::asc) so HE-AAC / xHE-AAC signalling bits survive the passthrough intact. Sample entry: mp4a + esds.
  • Opus (Squad-23): mono or stereo, sample_rate is the source’s InputSampleRate (typically 48000), mdhd timescale is pinned at 48000 per RFC 7845 §3 (Opus internally always operates at 48 kHz). Sample entry: Opus (4cc per RFC 7845 §4.4 — capital O) + dOps (Opus-Specific Box per §4.5). The OpusHead body bytes are carried in codec_private and emitted verbatim inside dOps.
  • AC-3 / Dolby Digital (Squad-26): up to 5.1 channels, sample_rate from the source’s syncframe (32 / 44.1 / 48 kHz). Sample entry: ac-3 + dac3 (ETSI TS 102 366 §F.4 / Annex F). The 3-byte dac3 body is carried in codec_private and emitted verbatim.
  • E-AC-3 / Dolby Digital Plus (Squad-26): up to 5.1 channels in v1 scope (single independent substream). Sample entry: ec-3 + dec3 (ETSI TS 102 366 §F.6). The dec3 body is carried in codec_private and emitted verbatim.

Discriminator: codec field. "aac" → AAC path; "opus" → Opus path; "ac3" → AC-3 path; "eac3" → E-AC-3 path. Anything else is rejected at with_audio() time.

Fields§

§codec: String

Human-readable codec tag. Muxer accepts "aac" (case-insensitive) and "opus" (case-insensitive). Anything else is rejected with a clear error — this is intentional (no stubs).

§sample_rate: u32

Audio sample rate in Hz. For AAC: typically 44100 / 48000; doubles as the mdhd timescale. For Opus: the source’s InputSampleRate (informational; the mdhd timescale is pinned to 48000 per RFC 7845 regardless of this value).

§channels: u16

Channel count. Both codecs support 1 (mono) and 2 (stereo) only; the muxer bails on other values.

§timescale: u32

Audio timescale in ticks per second. AAC: equals sample_rate. Opus: caller should pass 48000 (RFC 7845); the muxer additionally validates this for the Opus path.

§asc_bytes: Vec<u8>

AudioSpecificConfig bytes verbatim from the demuxer (AAC only). Embedded into the esds box’s DecoderSpecificInfo (tag 0x05) payload. Empty for non-AAC codecs.

§codec_private: Vec<u8>

Codec-private body bytes (Opus / AC-3 / E-AC-3). For Opus this MUST be the RFC 7845 §5.1 OpusHead payload (the same bytes a WebM/MKV CodecPrivate element would carry; see RFC 7845 §5.2 for the MKV mapping). Emitted verbatim as the body of the dOps box inside the Opus sample entry. For AC-3 this carries the 3-byte dac3 body (ETSI TS 102 366 §F.4); for E-AC-3 the variable-size dec3 body (§F.6). Empty for AAC.

Layout (RFC 7845 §5.1, 19 bytes minimum for ChannelMappingFamily=0 with the 8-byte ‘OpusHead’ magic prefix; the magic is NOT carried in dOps — only the post-magic body, which is 11 bytes minimum):

  • Version u8 = 1 (in OpusHead; mapped to 0 in dOps per §4.5)
  • OutputChannelCount u8
  • PreSkip u16 LE (in OpusHead; converted to BE for dOps per §4.5)
  • InputSampleRate u32 LE (LE in OpusHead, BE in dOps)
  • OutputGain i16 LE (LE in OpusHead, BE in dOps)
  • ChannelMappingFamily u8
  • (if family != 0: 1 + 1 + N additional bytes)

The byte-order conversion between OpusHead (Ogg LE convention) and dOps (ISOBMFF BE convention) is handled by build_dops in mux.rs. Callers should pass the OpusHead bytes (LE numeric fields) — that’s the form the MKV / WebM demuxer surfaces directly out of CodecPrivate.

Implementations§

Source§

impl AudioInfo

Source

pub fn aac_lc(sample_rate: u32, channels: u16, asc_bytes: Vec<u8>) -> Self

Convenience constructor for the AAC-LC path. Mirrors Squad-18’s original API surface so existing AAC call sites stay terse.

Source

pub fn opus( input_sample_rate: u32, channels: u16, codec_private: Vec<u8>, ) -> Self

Convenience constructor for the Opus path. Pins timescale to 48000 per RFC 7845 §3 — Opus is internally always 48 kHz so the mdhd timescale, not the source’s nominal InputSampleRate, is what drives sample-duration math on every player.

Source

pub fn ac3(sample_rate: u32, channels: u16, dac3_body: Vec<u8>) -> Self

Convenience constructor for the AC-3 (Dolby Digital) passthrough path (Squad-26). codec_private carries the 3-byte dac3 body payload (ETSI TS 102 366 §F.4) the muxer writes verbatim into the dac3 box. mdhd timescale = sample_rate (48000 / 44100 / 32000) — AC-3 doesn’t have Opus’s “internally fixed at 48 kHz” rule.

Source

pub fn eac3(sample_rate: u32, channels: u16, dec3_body: Vec<u8>) -> Self

Convenience constructor for the E-AC-3 (Dolby Digital Plus) passthrough path (Squad-26). codec_private carries the dec3 body payload (ETSI TS 102 366 §F.6) — variable size based on substream count; minimum ~5 bytes for the single-independent-substream case.

Trait Implementations§

Source§

impl Clone for AudioInfo

Source§

fn clone(&self) -> AudioInfo

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AudioInfo

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more