Skip to main content

v4l2r/decoder/format/
fwht.rs

1use super::{PatternSplitter, StreamSplitter};
2use std::io;
3
4static FRAME_HEADER: [u8; 8] = [0x4f, 0x4f, 0x4f, 0x4f, 0xff, 0xff, 0xff, 0xff];
5
6/// Iterator that returns exactly one frame worth of data from a FWHT stream.
7pub struct FwhtFrameParser<S: io::Read>(PatternSplitter<S>);
8
9/// Given a reader, return individual compressed FWHT frames.
10impl<S: io::Read> FwhtFrameParser<S> {
11    pub fn new(stream: S) -> Option<Self> {
12        Some(Self(PatternSplitter::new(FRAME_HEADER.to_vec(), stream)?))
13    }
14}
15
16impl<S: io::Read> Iterator for FwhtFrameParser<S> {
17    type Item = Vec<u8>;
18
19    /// Returns the next frame in the stream, header included.
20    fn next(&mut self) -> Option<Self::Item> {
21        self.0.next()
22    }
23}
24
25impl<S: io::Read> StreamSplitter for FwhtFrameParser<S> {}