Skip to main content

BitstreamReader

Struct BitstreamReader 

Source
pub struct BitstreamReader<'bs, 'data: 'bs, S: ReaderState> { /* private fields */ }
Expand description

Reader for Bitstream.

Implementations§

Source§

impl<S: ReaderState> BitstreamReader<'_, '_, S>

Source

pub fn new<'bs, 'data>( bitstream: &'bs Bitstream<'data>, ) -> BitstreamReader<'bs, 'data, Beginning>

Construct BitstreamReader for Bitstream.

use oggopus_embedded::Bitstream;
let stream = Bitstream::new(include_bytes!("audio.opus"));
Source§

impl<'bs, 'data> BitstreamReader<'bs, 'data, Beginning>

Source

pub fn read_header(self) -> Result<'data, EitherHeaderOrEnded<'bs, 'data>>

Read a header packet from Bitstream.

Also skips the comments packet and returs BitstreamReader that can read the following opus packets.

let reader = stream.reader();
let (reader, header) = reader.read_header().unwrap();
if let ChannelMapping::Family0 { channels } = header.channels {
    println!(
        "{} channels at {} Hz with pre skip of {}",
        channels, header.sample_rate, header.pre_skip
    );
}
Source§

impl<'bs, 'data> BitstreamReader<'bs, 'data, InStream>

Source

pub fn next_packets<const BUFFER_SIZE: usize>( &self, ) -> Result<'data, EitherPacketsOrEnded<'bs, 'data, BUFFER_SIZE>>

Read next packets from Bitstream.

Returns also the next BitstreamReader to read further content.

let mut reader = match reader {
    Either::Continued(reader) => reader,
    _ => panic!("No more data"),
};
loop {
    let (new_reader, mut packets) = reader.next_packets::<1_024>().unwrap();
    while let Some(packet) = packets.next() {
        // Decode or whatever you need to do here
        println!("Got {} bytes of opus data", packet.data.len());
    }
    match new_reader {
        Either::Continued(new_reader) => {
            // Prepare for the next loop
            reader = new_reader;
        }
        Either::Ended(_reader) => {
            break; // You can also expect the next stream to start here
        }
    }
}
Source§

impl<'bs, 'data> BitstreamReader<'bs, 'data, EndOfStream>

Source

pub fn has_more(&self) -> bool

Return whether there is more data to read.

Source

pub fn next_reader(self) -> Option<BitstreamReader<'bs, 'data, Beginning>>

Get next reader for more data if there is any.

loop {
    let (new_reader, _packets) = reader.next_packets::<1_024>().unwrap();
    // ...
    match new_reader {
        Either::Continued(new_reader) => {
            reader = new_reader;
        }
        Either::Ended(old_reader) => {
            if let Some(new_reader) = old_reader.next_reader() {
                // Reinitialize decoding and continue looping
                let (new_reader, header) = new_reader.read_header().unwrap();
                if let Either::Continued(reader) = new_reader {
                }
            } else {
                break;
            }
        }
    }
}

Trait Implementations§

Source§

impl<'bs, 'data: 'bs, S: Debug + ReaderState> Debug for BitstreamReader<'bs, 'data, S>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'bs, 'data: 'bs, S: PartialEq + ReaderState> PartialEq for BitstreamReader<'bs, 'data, S>

Source§

fn eq(&self, other: &BitstreamReader<'bs, 'data, S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'bs, 'data: 'bs, S: ReaderState> StructuralPartialEq for BitstreamReader<'bs, 'data, S>

Auto Trait Implementations§

§

impl<'bs, 'data, S> Freeze for BitstreamReader<'bs, 'data, S>
where S: Freeze,

§

impl<'bs, 'data, S> RefUnwindSafe for BitstreamReader<'bs, 'data, S>
where S: RefUnwindSafe,

§

impl<'bs, 'data, S> Send for BitstreamReader<'bs, 'data, S>
where S: Send,

§

impl<'bs, 'data, S> Sync for BitstreamReader<'bs, 'data, S>
where S: Sync,

§

impl<'bs, 'data, S> Unpin for BitstreamReader<'bs, 'data, S>
where S: Unpin,

§

impl<'bs, 'data, S> UnsafeUnpin for BitstreamReader<'bs, 'data, S>
where S: UnsafeUnpin,

§

impl<'bs, 'data, S> UnwindSafe for BitstreamReader<'bs, 'data, S>
where S: UnwindSafe,

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