sync + image

This commit is contained in:
2026-06-16 10:26:16 +02:00
parent 2d49da5cee
commit 8efb9c031e
8 changed files with 795 additions and 45 deletions

58
src/line_assembler.rs Normal file
View File

@ -0,0 +1,58 @@
use crate::{fm_demod::Sample, sync::SyncEvent};
pub struct VideoLine {
pub samples: Vec<Sample>,
}
pub struct VideoFrame {
pub lines: Vec<VideoLine>,
}
pub struct LineAssembler<I> {
pub inner: I,
pub current_line: Vec<Sample>,
pub current_frame: Vec<VideoLine>,
}
impl<I> LineAssembler<I> {
pub fn new(inner: I) -> Self {
Self {
inner,
current_line: Vec::new(),
current_frame: Vec::new(),
}
}
}
impl<I, E> Iterator for LineAssembler<I>
where
I: Iterator<Item = Result<SyncEvent, E>>,
{
type Item = Result<VideoFrame, E>;
fn next(&mut self) -> Option<Self::Item> {
loop {
match self.inner.next()? {
Ok(SyncEvent::VideoSample(s)) => {
self.current_line.push(s);
}
Ok(SyncEvent::HSync) => {
// Save the finished line
let line = VideoLine {
samples: std::mem::take(&mut self.current_line),
};
self.current_frame.push(line);
}
Ok(SyncEvent::VSync) => {
// Frame finished
let frame = VideoFrame {
lines: std::mem::take(&mut self.current_frame),
};
return Some(Ok(frame));
}
Err(e) => return Some(Err(e)),
}
}
}
}