Skip to main content

AudioEncoder

Trait AudioEncoder 

Source
pub trait AudioEncoder {
    // Required methods
    fn config(&self) -> &EncoderConfig;
    fn format(&self) -> AudioEncoderFormat;
    fn encode<'a>(
        &'a mut self,
        index: FrameIndex,
        buffer: AudioBuffer,
    ) -> EncoderFuture<'a, Vec<EncodedSample>>;
    fn finish<'a>(&'a mut self) -> EncoderFuture<'a, AudioDrain>;
}
Expand description

Backend-neutral audio encoder contract.

§Where the audio encoders come from

zvidlib writes no audio codec of its own design. Each encoder behind this trait is either the platform’s or a faithful port of the codec’s reference encoder, so the quality a caller gets is the reference’s rather than a reimplementation’s:

  • AAC-LC: native_aac_audio_encoder_factory delegates to the operating system’s encoder, AudioToolbox on macOS and Media Foundation on Windows, and reports HardwareUnavailable elsewhere; the browser build encodes through WebCodecs. A pure-Rust AAC-LC encoder is a large subsystem in its own right – filter bank, psychoacoustic model, quantization and rate control – with no open reference implementation to port, and the platforms already have good ones (issue #174).
  • Opus: native_opus_audio_encoder_factory runs opus-pure, a pure-Rust port of libopus, on every target; the browser build can also encode through WebCodecs.
  • Vorbis: native_vorbis_audio_encoder_factory runs zvidlib’s own port of the libvorbis 1.3.7 encoder, whose packets are bit-identical to libvorbis’s for the same input and quality.

The concern behind issue #174 was that a mediocre encoder shipped under this crate’s name is worse for callers than none, because it is harder to route around. A port of the reference encoder answers that concern where an original design could not. crate::MediaOutput muxes an audio track given any AudioEncoder, so a caller with an encoder of its own still plugs it in here.

Required Methods§

Source

fn config(&self) -> &EncoderConfig

Source

fn format(&self) -> AudioEncoderFormat

Source

fn encode<'a>( &'a mut self, index: FrameIndex, buffer: AudioBuffer, ) -> EncoderFuture<'a, Vec<EncodedSample>>

Source

fn finish<'a>(&'a mut self) -> EncoderFuture<'a, AudioDrain>

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§