Struct Vorbis Writer
pub struct VorbisWriter<W: Write> { /* private fields */ }Expand description
Incremental lossy Ogg Vorbis writer. Construct/use/finish/drop on one worker;
the safe backend is not Send/Sync. All codec/sink methods can allocate/block
and belong outside callbacks. Interleaved finite [-1,1] input is explicitly
rejected on overload; no clipping, rate conversion, device/clock/path policy.
Wrapper retains prepared 4096-frame planar scratch and one physical Ogg page
(at most 65307 bytes). Backend working storage remains its contract. Each
write accepts at most 65536 complete frames. Headers and the priming packet
must terminate within a physical page; continued headers, mixed header/audio
pages and spanning priming packets reject rather than guessing timestamps.
Whole-call preflight failures preserve state; encoding/I/O/output-capacity
failure after acceptance poisons and may leave an irreversible encoded prefix.
Sink receives no framework writes/flushes from Drop, including after failure.
Caller-provided sink Drop remains its own contract. Only explicit nonempty
finish writes EOS, flushes and returns the sink; a failed finish consumes it.
No exact PCM/perceptual-quality/deadline claim. Automatic prepared capture
uses crate::VorbisRecordingWorker, which creates this codec locally.
use ravet_audio_file::{VorbisFormat, VorbisWriter};
let writer = VorbisWriter::new(Vec::new(), VorbisFormat {
channels: 1, sample_rate: 48000, quality: 0.5, stream_serial: 1,
}, 4096, 65536).unwrap();
std::thread::spawn(move || drop(writer));Implementations§
§impl<W: Write> VorbisWriter<W>
impl<W: Write> VorbisWriter<W>
pub fn new(
destination: W,
format: VorbisFormat,
maximum_frames: u64,
maximum_bytes: u64,
) -> Result<Self, Error>
pub fn new( destination: W, format: VorbisFormat, maximum_frames: u64, maximum_bytes: u64, ) -> Result<Self, Error>
Validate mono 8000..96000/stereo 16000..96000 Hz, finite quality -0.2..1, total frames 1..16777216 and output bytes 1..67108864 before preparation/header output. Writes start at the caller’s current sink position; no seek/truncate occurs. Header I/O/capacity errors may leave a partial prefix and consume the sink. Caller serial identifies one logical stream; chaining/multiplexing requires distinct caller-selected serials and is outside this writer’s contract.
pub fn format(&self) -> VorbisFormat
pub fn accepted_frames(&self) -> u64
pub fn accepted_frames(&self) -> u64
Submitted frames, including a failing accepted codec batch. Not finalized.
pub fn written_bytes(&self) -> u64
pub fn written_bytes(&self) -> u64
Bytes actually accepted by the sink, including any failed partial write.
pub fn is_poisoned(&self) -> bool
pub fn write_frames(&mut self, samples: &[f32]) -> Result<(), Error>
pub fn write_frames(&mut self, samples: &[f32]) -> Result<(), Error>
Validate shape/finite [-1,1]/per-call and total bounds before acceptance. Empty input is a no-op; it does not signal encoder EOS. Backend batches stay at most 4096 frames regardless of call size.