Commit 84f61fa4 authored by Josh Holmer's avatar Josh Holmer Committed by Luca Barbato

Fix low_latency mode which was broken in #718

Fixes #720
parent 56de6a44
......@@ -4,7 +4,6 @@ use std::fmt;
use std::fs::File;
use std::io;
use std::io::prelude::*;
use std::ops::Add;
use std::slice;
use std::sync::Arc;
use std::time::Instant;
......@@ -146,19 +145,6 @@ impl From<Packet> for FrameSummary {
}
}
impl Add<Packet> for FrameSummary {
type Output = FrameSummary;
fn add(self, rhs: Packet) -> <Self as Add<Packet>>::Output {
assert!(rhs.number == self.number);
Self {
size: self.size + rhs.data.len(),
number: self.number,
frame_type: self.frame_type,
}
}
}
impl fmt::Display for FrameSummary {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
......@@ -177,7 +163,7 @@ pub fn process_frame(
ctx: &mut Context, output_file: &mut dyn Write,
y4m_dec: &mut y4m::Decoder<'_, Box<dyn Read>>,
mut y4m_enc: Option<&mut y4m::Encoder<'_, Box<dyn Write>>>
) -> Result<Option<FrameSummary>, ()> {
) -> Result<Vec<FrameSummary>, ()> {
let width = y4m_dec.get_width();
let height = y4m_dec.get_height();
let y4m_bits = y4m_dec.get_bit_depth();
......@@ -221,7 +207,7 @@ pub fn process_frame(
};
let mut has_data = true;
let mut frame_summary = None;
let mut frame_summaries = Vec::new();
while has_data {
let pkt_wrapped = ctx.receive_packet();
match pkt_wrapped {
......@@ -303,17 +289,13 @@ pub fn process_frame(
y4m_enc_uw.write_frame(&rec_frame).unwrap();
}
}
if frame_summary.is_none() {
frame_summary = Some(pkt.into());
} else {
frame_summary = frame_summary.map(|f| f + pkt);
}
frame_summaries.push(pkt.into());
},
_ => { has_data = false; }
}
}
if read_frame {
Ok(frame_summary)
Ok(frame_summaries)
} else {
Err(())
}
......
......@@ -82,15 +82,16 @@ fn main() {
loop {
match process_frame(&mut ctx, &mut cli.io.output, &mut y4m_dec, y4m_enc.as_mut()) {
Ok(Some(frame_info)) => {
progress.add_frame(frame_info);
let _ = if cli.verbose {
writeln!(err, "{} - {}", frame_info, progress)
} else {
write!(err, "\r{} ", progress)
};
Ok(frame_info) => {
for frame in frame_info {
progress.add_frame(frame);
let _ = if cli.verbose {
writeln!(err, "{} - {}", frame, progress)
} else {
write!(err, "\r{} ", progress)
};
}
},
Ok(_) => (),
Err(_) => break,
};
......
......@@ -77,8 +77,7 @@ fn main() {
match line.split_whitespace().next() {
Some("process_frame") => {
match process_frame(&mut ctx, &mut io.output, &mut y4m_dec, y4m_enc.as_mut()) {
Ok(Some(frame_info)) => eprintln!("{}", frame_info),
Ok(_) => (),
Ok(Some(frame_info)) => frame_info.iter().for_each(|frame| eprintln!("{}", frame)),
Err(_) => break,
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment