pub struct Stream { /* private fields */ }
Expand description
STREAM
component.
Implementations§
Source§impl Stream
impl Stream
Sourcepub fn new(
sample_rate: usize,
channels: usize,
bits_per_sample: usize,
) -> Result<Self, VerifyError>
pub fn new( sample_rate: usize, channels: usize, bits_per_sample: usize, ) -> Result<Self, VerifyError>
Sourcepub fn with_stream_info(stream_info: StreamInfo) -> Self
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);
Sourcepub fn stream_info(&self) -> &StreamInfo
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);
Sourcepub fn stream_info_mut(&mut self) -> &mut StreamInfo
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);
Sourcepub fn add_frame(&mut self, frame: Frame)
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);
Sourcepub fn add_metadata_block(&mut self, metadata: MetadataBlockData)
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)
Sourcepub fn frame(&self, n: usize) -> Option<&Frame>
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());
Sourcepub fn frame_count(&self) -> usize
pub fn frame_count(&self) -> usize
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Stream
impl<'de> Deserialize<'de> for Stream
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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 Verify for Stream
impl Verify for Stream
Source§fn verify(&self) -> Result<(), VerifyError>
fn verify(&self) -> Result<(), VerifyError>
Verifies there’s no internal data inconsistency. Read more
Source§fn into_verified(self) -> Result<Verified<Self>, (Self, VerifyError)>
fn into_verified(self) -> Result<Verified<Self>, (Self, VerifyError)>
Wraps into
Verified
to indicate that the data is already verified. Read moreSource§unsafe fn assume_verified(self) -> Verified<Self>
unsafe fn assume_verified(self) -> Verified<Self>
Wraps into
Verified
without actual verification. Read moreAuto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more