Struct Stream

Source
pub struct Stream { /* private fields */ }
Expand description

STREAM component.

Implementations§

Source§

impl Stream

Source

pub fn new( sample_rate: usize, channels: usize, bits_per_sample: usize, ) -> Result<Self, VerifyError>

Constructs Stream with the given meta information.

§Errors

Returns error if an input argument is invalid.

§Examples
let stream = Stream::new(16000, 1, 16).unwrap();
assert_eq!(stream.stream_info().channels(), 1);
Source

pub fn with_stream_info(stream_info: StreamInfo) -> Self

Constructs Stream with the given StreamInfo.

§Examples
let stream_info = StreamInfo::new(16000, 1, 16).unwrap();
let stream = Stream::with_stream_info(stream_info);
assert_eq!(stream.stream_info().sample_rate(), 16000);
Source

pub fn stream_info(&self) -> &StreamInfo

Returns a reference to StreamInfo associated with self.

§Panics

Panics if self is corrupted by manually modifying fields.

§Examples
let stream = Stream::new(16000, 1, 24).unwrap();
assert_eq!(stream.stream_info().bits_per_sample(), 24);
Source

pub fn stream_info_mut(&mut self) -> &mut StreamInfo

Returns a mutable reference to StreamInfo associated with self.

§Panics

Panics if self is corrupted by manually modifying fields.

§Examples
let mut stream = Stream::new(16000, 1, 24).unwrap();
stream.stream_info_mut().set_total_samples(123456);
assert_eq!(stream.stream_info().total_samples(), 123456);
Source

pub fn add_frame(&mut self, frame: Frame)

Appends Frame to this Stream and updates StreamInfo.

This also updates frame statistics in stream_info but does not update MD5 checksums. For updating those, call set_md5_digest manually via Self::stream_info_mut.

§Examples
let (signal_len, block_size, channels, sample_rate) = (32000, 160, 2, 16000);
let frame = make_example_frame(signal_len, block_size, channels, sample_rate);

let mut stream = Stream::new(16000, 1, 24).unwrap();
stream.add_frame(frame);
assert_eq!(stream.frame_count(), 1);
Source

pub fn add_metadata_block(&mut self, metadata: MetadataBlockData)

Add MetadataBlockData to this Stream.

§Examples
let mut stream = Stream::new(16000, 1, 24).unwrap();
stream.add_metadata_block(
    MetadataBlockData::new_unknown(2, &[0xFF]).unwrap()
);
let mut sink = ByteSink::new();
stream.write(&mut sink);
let bytes = sink.as_slice();
let first_header_byte = bytes[4];
assert_eq!(first_header_byte, 0x00); // lastflag + type (STREAMINFO=0)
let second_header_byte = bytes[bytes.len() - 5];
assert_eq!(second_header_byte, 0x82); // lastflag + type (=2)
Source

pub fn frame(&self, n: usize) -> Option<&Frame>

Returns Frame for the given frame number.

§Examples
let (signal_len, block_size, channels, sample_rate) = (32000, 160, 2, 16000);
let stream = make_example_stream(signal_len, block_size, channels, sample_rate);
let frame0 = stream.frame(0).expect("0-th frame is not found.");
let frame19 = stream.frame(19).expect("19-th frame is not found.");
assert!(frame0.count_bits() > 0);
assert!(frame19.count_bits() > 0);
assert!(stream.frame(200).is_none());
Source

pub fn frame_count(&self) -> usize

Returns the number of Frames in the stream.

§Examples
let (signal_len, block_size, channels, sample_rate) = (32000, 160, 2, 16000);
let stream = make_example_stream(signal_len, block_size, channels, sample_rate);
assert_eq!(stream.frame_count(), 200);

Trait Implementations§

Source§

impl BitRepr for Stream

Source§

fn count_bits(&self) -> usize

Counts the number of bits required to store the component.
Source§

fn write<S: BitSink>(&self, dest: &mut S) -> Result<(), OutputError<S>>

Writes the bit sequence to BitSink. Read more
Source§

impl<'de> Deserialize<'de> for Stream

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Stream

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Verify for Stream

Source§

fn verify(&self) -> Result<(), VerifyError>

Verifies there’s no internal data inconsistency. Read more
Source§

fn into_verified(self) -> Result<Verified<Self>, (Self, VerifyError)>

Wraps into Verified to indicate that the data is already verified. Read more
Source§

unsafe fn assume_verified(self) -> Verified<Self>

Wraps into Verified without actual verification. Read more

Auto Trait Implementations§

§

impl Freeze for Stream

§

impl RefUnwindSafe for Stream

§

impl Send for Stream

§

impl Sync for Stream

§

impl Unpin for Stream

§

impl UnwindSafe for Stream

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> Same for T

Source§

type Output = T

Should always be Self
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,