Commit e8daa5c8 authored by Luc Trudeau's avatar Luc Trudeau

Move frame_number inside FrameInvariants

parent 8a74a222
...@@ -12,18 +12,16 @@ fn main() { ...@@ -12,18 +12,16 @@ fn main() {
Some(rec_file) => Some(y4m::encode(width, height, y4m::Ratio::new(30,1)).write_header(rec_file).unwrap()), Some(rec_file) => Some(y4m::encode(width, height, y4m::Ratio::new(30,1)).write_header(rec_file).unwrap()),
None => None None => None
}; };
let fi = FrameInvariants::new(width, height); let mut fi = FrameInvariants::new(width, height);
let sequence = Sequence::new(); let sequence = Sequence::new();
write_ivf_header(&mut files.output_file, fi.sb_width*64, fi.sb_height*64); write_ivf_header(&mut files.output_file, fi.sb_width*64, fi.sb_height*64);
let mut frame_number = 0;
loop { loop {
if !process_frame(frame_number, &sequence, &fi, if !process_frame(&sequence, &fi, &mut files.output_file, &mut y4m_dec, y4m_enc.as_mut()) {
&mut files.output_file, &mut y4m_dec, y4m_enc.as_mut()) {
break; break;
} }
frame_number += 1; fi.number += 1;
if frame_number == files.limit { if fi.number == files.limit {
break; break;
} }
} }
......
...@@ -16,11 +16,10 @@ fn main() { ...@@ -16,11 +16,10 @@ fn main() {
Some(rec_file) => Some(y4m::encode(width, height, y4m::Ratio::new(30,1)).write_header(rec_file).unwrap()), Some(rec_file) => Some(y4m::encode(width, height, y4m::Ratio::new(30,1)).write_header(rec_file).unwrap()),
None => None None => None
}; };
let fi = FrameInvariants::new(width, height); let mut fi = FrameInvariants::new(width, height);
let sequence = Sequence::new(); let sequence = Sequence::new();
write_ivf_header(&mut files.output_file, fi.sb_width*64, fi.sb_height*64); write_ivf_header(&mut files.output_file, fi.sb_width*64, fi.sb_height*64);
let mut frame_number = 0;
let mut rl = Editor::<()>::new(); let mut rl = Editor::<()>::new();
let _ = rl.load_history(".rav1e-history"); let _ = rl.load_history(".rav1e-history");
loop { loop {
...@@ -30,10 +29,9 @@ fn main() { ...@@ -30,10 +29,9 @@ fn main() {
rl.add_history_entry(&line); rl.add_history_entry(&line);
match line.split_whitespace().next() { match line.split_whitespace().next() {
Some("process_frame") => { Some("process_frame") => {
process_frame(frame_number, &sequence, &fi, process_frame(&sequence, &fi, &mut files.output_file, &mut y4m_dec, y4m_enc.as_mut());
&mut files.output_file, &mut y4m_dec, y4m_enc.as_mut()); fi.number += 1;
frame_number += 1; if fi.number == files.limit {
if frame_number == files.limit {
break; break;
} }
}, },
......
...@@ -124,6 +124,7 @@ pub enum FrameType { ...@@ -124,6 +124,7 @@ pub enum FrameType {
Inter Inter
} }
// Frame Invariants are invariant inside a frame
#[allow(dead_code)] #[allow(dead_code)]
pub struct FrameInvariants { pub struct FrameInvariants {
pub qindex: usize, pub qindex: usize,
...@@ -132,6 +133,7 @@ pub struct FrameInvariants { ...@@ -132,6 +133,7 @@ pub struct FrameInvariants {
pub sb_width: usize, pub sb_width: usize,
pub sb_height: usize, pub sb_height: usize,
pub frame_type: FrameType, pub frame_type: FrameType,
pub number: u64,
} }
impl FrameInvariants { impl FrameInvariants {
...@@ -143,6 +145,7 @@ impl FrameInvariants { ...@@ -143,6 +145,7 @@ impl FrameInvariants {
sb_width: (width+63)/64, sb_width: (width+63)/64,
sb_height: (height+63)/64, sb_height: (height+63)/64,
frame_type: FrameType::Intra, frame_type: FrameType::Intra,
number: 0,
} }
} }
} }
...@@ -419,7 +422,7 @@ fn encode_frame(sequence: &Sequence, fi: &FrameInvariants, fs: &mut FrameState) ...@@ -419,7 +422,7 @@ fn encode_frame(sequence: &Sequence, fi: &FrameInvariants, fs: &mut FrameState)
} }
/// Encode and write a frame. /// Encode and write a frame.
pub fn process_frame(frame_number: u64, sequence: &Sequence, fi: &FrameInvariants, pub fn process_frame(sequence: &Sequence, fi: &FrameInvariants,
output_file: &mut Write, output_file: &mut Write,
y4m_dec: &mut y4m::Decoder<Box<Read>>, y4m_dec: &mut y4m::Decoder<Box<Read>>,
y4m_enc: Option<&mut y4m::Encoder<Box<Write>>>) -> bool { y4m_enc: Option<&mut y4m::Encoder<Box<Write>>>) -> bool {
...@@ -430,7 +433,7 @@ pub fn process_frame(frame_number: u64, sequence: &Sequence, fi: &FrameInvariant ...@@ -430,7 +433,7 @@ pub fn process_frame(frame_number: u64, sequence: &Sequence, fi: &FrameInvariant
let y4m_y = y4m_frame.get_y_plane(); let y4m_y = y4m_frame.get_y_plane();
let y4m_u = y4m_frame.get_u_plane(); let y4m_u = y4m_frame.get_u_plane();
let y4m_v = y4m_frame.get_v_plane(); let y4m_v = y4m_frame.get_v_plane();
eprintln!("Frame {}", frame_number); eprintln!("Frame {}", fi.frame_number);
let mut fs = FrameState::new(&fi); let mut fs = FrameState::new(&fi);
for y in 0..height { for y in 0..height {
for x in 0..width { for x in 0..width {
...@@ -451,7 +454,7 @@ pub fn process_frame(frame_number: u64, sequence: &Sequence, fi: &FrameInvariant ...@@ -451,7 +454,7 @@ pub fn process_frame(frame_number: u64, sequence: &Sequence, fi: &FrameInvariant
} }
} }
let packet = encode_frame(&sequence, &fi, &mut fs); let packet = encode_frame(&sequence, &fi, &mut fs);
write_ivf_frame(output_file, frame_number, packet.as_ref()); write_ivf_frame(output_file, fi.number, packet.as_ref());
match y4m_enc { match y4m_enc {
Some(mut y4m_enc) => { Some(mut y4m_enc) => {
let mut rec_y = vec![128 as u8; width*height]; let mut rec_y = vec![128 as u8; width*height];
......
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