Skip to content

Commit bde0cfc

Browse files
committed
Revert "Refactor process_frame in CLI"
This reverts commit 45ef0af.
1 parent 6a8dbbe commit bde0cfc

File tree

1 file changed

+54
-59
lines changed

1 file changed

+54
-59
lines changed

src/bin/rav1e.rs

Lines changed: 54 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,14 @@ impl<D: Decoder> Source<D> {
9595

9696
// Encode and write a frame.
9797
// Returns frame information in a `Result`.
98-
//
99-
// `Ok(None)` indicates that the encode is finished.
10098
fn process_frame<T: Pixel, D: Decoder>(
10199
ctx: &mut Context<T>, output_file: &mut dyn Muxer, source: &mut Source<D>,
102100
pass1file: Option<&mut File>, pass2file: Option<&mut File>,
103101
buffer: &mut [u8], buf_pos: &mut usize,
104102
mut y4m_enc: Option<&mut y4m::Encoder<'_, Box<dyn Write>>>,
105-
) -> Result<Option<FrameSummary>, CliError> {
103+
) -> Result<Option<Vec<FrameSummary>>, CliError> {
106104
let y4m_details = source.input.get_video_details();
105+
let mut frame_summaries = Vec::new();
107106
let mut pass1file = pass1file;
108107
let mut pass2file = pass2file;
109108
// Submit first pass data to pass 2.
@@ -143,60 +142,54 @@ fn process_frame<T: Pixel, D: Decoder>(
143142
}
144143
}
145144

146-
loop {
147-
let pkt_wrapped = ctx.receive_packet();
148-
match pkt_wrapped {
149-
Ok(pkt) => {
150-
output_file.write_frame(
151-
pkt.input_frameno as u64,
152-
pkt.data.as_ref(),
153-
pkt.frame_type,
154-
);
155-
if let (Some(ref mut y4m_enc_uw), Some(ref rec)) =
156-
(y4m_enc.as_mut(), &pkt.rec)
157-
{
158-
write_y4m_frame(y4m_enc_uw, rec, y4m_details);
159-
}
160-
return Ok(Some(pkt.into()));
161-
}
162-
Err(EncoderStatus::NeedMoreData) => {
163-
// Read another frame then try receive_packet again
164-
source.read_frame(ctx, y4m_details);
165-
continue;
166-
}
167-
Err(EncoderStatus::EnoughData) => {
168-
unreachable!();
145+
let pkt_wrapped = ctx.receive_packet();
146+
match pkt_wrapped {
147+
Ok(pkt) => {
148+
output_file.write_frame(
149+
pkt.input_frameno as u64,
150+
pkt.data.as_ref(),
151+
pkt.frame_type,
152+
);
153+
if let (Some(ref mut y4m_enc_uw), Some(ref rec)) =
154+
(y4m_enc.as_mut(), &pkt.rec)
155+
{
156+
write_y4m_frame(y4m_enc_uw, rec, y4m_details);
169157
}
170-
Err(EncoderStatus::LimitReached) => {
171-
if let Some(passfile) = pass1file.as_mut() {
172-
if let Some(outbuf) = ctx.twopass_out() {
173-
// The last block of data we get is the summary data that needs to go
174-
// at the start of the pass file.
175-
// Seek to the start so we can write it there.
176-
passfile
177-
.seek(std::io::SeekFrom::Start(0))
178-
.expect("Unable to seek in two-pass data file.");
179-
passfile
180-
.write_all(outbuf)
181-
.expect("Unable to write to two-pass data file.");
182-
}
158+
frame_summaries.push(pkt.into());
159+
}
160+
Err(EncoderStatus::NeedMoreData) => {
161+
source.read_frame(ctx, y4m_details);
162+
}
163+
Err(EncoderStatus::EnoughData) => {
164+
unreachable!();
165+
}
166+
Err(EncoderStatus::LimitReached) => {
167+
if let Some(passfile) = pass1file.as_mut() {
168+
if let Some(outbuf) = ctx.twopass_out() {
169+
// The last block of data we get is the summary data that needs to go
170+
// at the start of the pass file.
171+
// Seek to the start so we can write it there.
172+
passfile
173+
.seek(std::io::SeekFrom::Start(0))
174+
.expect("Unable to seek in two-pass data file.");
175+
passfile
176+
.write_all(outbuf)
177+
.expect("Unable to write to two-pass data file.");
183178
}
184-
// Indicate that we are finished with the encode
185-
return Ok(None);
186-
}
187-
e @ Err(EncoderStatus::Failure) => {
188-
let _ = e.map_err(|e| e.context("Failed to encode video"))?;
189-
}
190-
e @ Err(EncoderStatus::NotReady) => {
191-
let _ = e.map_err(|e| {
192-
e.context("Mismanaged handling of two-pass stats data")
193-
})?;
194-
}
195-
Err(EncoderStatus::Encoded) => {
196-
// Safely skip to the next attempt of receive_packet
197179
}
180+
return Ok(None);
181+
}
182+
e @ Err(EncoderStatus::Failure) => {
183+
let _ = e.map_err(|e| e.context("Failed to encode video"))?;
198184
}
185+
e @ Err(EncoderStatus::NotReady) => {
186+
let _ = e.map_err(|e| {
187+
e.context("Mismanaged handling of two-pass stats data")
188+
})?;
189+
}
190+
Err(EncoderStatus::Encoded) => {}
199191
}
192+
Ok(Some(frame_summaries))
200193
}
201194

202195
fn do_encode<T: Pixel, D: Decoder>(
@@ -233,13 +226,15 @@ fn do_encode<T: Pixel, D: Decoder>(
233226
y4m_enc.as_mut(),
234227
)? {
235228
if verbose != Verbose::Quiet {
236-
progress.add_frame(frame_info.clone());
237-
if verbose == Verbose::Verbose {
238-
info!("{} - {}", frame_info, progress);
239-
} else {
240-
// Print a one-line progress indicator that overrides itself with every update
241-
eprint!("\r{} ", progress);
242-
};
229+
for frame in frame_info {
230+
progress.add_frame(frame.clone());
231+
if verbose == Verbose::Verbose {
232+
info!("{} - {}", frame, progress);
233+
} else {
234+
// Print a one-line progress indicator that overrides itself with every update
235+
eprint!("\r{} ", progress);
236+
};
237+
}
243238

244239
output.flush().unwrap();
245240
}

0 commit comments

Comments
 (0)