Skip to content

Commit c200bc2

Browse files
committed
wip: Do not emit pass data more than once
1 parent 116c9c7 commit c200bc2

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/api/context.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,15 @@ impl<T: Pixel> Context<T> {
376376
/// enum.EncoderStatus.html#variant.LimitReached
377377
///
378378
/// It will return a `RcData::Summary` once the encoder is flushed.
379-
pub fn rc_receive_pass_data(&mut self) -> RcData {
379+
pub fn rc_receive_pass_data(&mut self) -> Option<RcData> {
380380
if self.inner.done_processing() && self.inner.rc_state.pass1_data_retrieved
381381
{
382382
let data = self.inner.rc_state.emit_summary();
383-
RcData::Summary(data.to_vec().into_boxed_slice())
383+
Some(RcData::Summary(data.to_vec().into_boxed_slice()))
384+
} else if self.inner.rc_state.pass1_data_retrieved {
385+
None
384386
} else if let Some(data) = self.inner.rc_state.emit_frame_data() {
385-
RcData::Frame(data.to_vec().into_boxed_slice())
387+
Some(RcData::Frame(data.to_vec().into_boxed_slice()))
386388
} else {
387389
unreachable!(
388390
"The encoder received more frames than its internal limit allows"

src/bin/rav1e.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fn process_frame<T: Pixel, D: Decoder>(
204204
if let Some(passfile) = pass1file.as_mut() {
205205
if emit_pass_data {
206206
match ctx.rc_receive_pass_data() {
207-
RcData::Frame(outbuf) => {
207+
Some(RcData::Frame(outbuf)) => {
208208
let len = outbuf.len() as u64;
209209
passfile.write_all(&len.to_be_bytes()).map_err(|e| {
210210
e.context("Unable to write to two-pass data file.")
@@ -214,7 +214,7 @@ fn process_frame<T: Pixel, D: Decoder>(
214214
e.context("Unable to write to two-pass data file.")
215215
})?;
216216
}
217-
RcData::Summary(outbuf) => {
217+
Some(RcData::Summary(outbuf)) => {
218218
// The last packet of rate control data we get is the summary data.
219219
// Let's put it at the start of the file.
220220
passfile.seek(std::io::SeekFrom::Start(0)).map_err(|e| {
@@ -230,6 +230,7 @@ fn process_frame<T: Pixel, D: Decoder>(
230230
e.context("Unable to write to two-pass data file.")
231231
})?;
232232
}
233+
None => {}
233234
}
234235
}
235236
}

src/capi.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl EncContext {
264264
}
265265
}
266266

267-
fn rc_receive_pass_data(&mut self) -> rav1e::RcData {
267+
fn rc_receive_pass_data(&mut self) -> Option<rav1e::RcData> {
268268
match self {
269269
EncContext::U8(ctx) => ctx.rc_receive_pass_data(),
270270
EncContext::U16(ctx) => ctx.rc_receive_pass_data(),
@@ -873,6 +873,11 @@ pub enum RcDataKind {
873873
/// The information contained is required to encode its matching
874874
/// frame in a second pass encoding.
875875
Frame,
876+
/// There is no pass data available for now
877+
///
878+
/// This is emitted if rav1e_rc_receive_pass_data is called more
879+
/// often than it should.
880+
Empty,
876881
}
877882

878883
/// Return the Rate Control Summary Packet size
@@ -900,8 +905,9 @@ pub unsafe extern fn rav1e_rc_receive_pass_data(
900905
) -> RcDataKind {
901906
use crate::api::RcData::*;
902907
let (buf, kind) = match (*ctx).ctx.rc_receive_pass_data() {
903-
Summary(data) => (data, RcDataKind::Summary),
904-
Frame(data) => (data, RcDataKind::Frame),
908+
Some(Summary(data)) => (data, RcDataKind::Summary),
909+
Some(Frame(data)) => (data, RcDataKind::Frame),
910+
None => return RcDataKind::Empty,
905911
};
906912

907913
let mut full_buf = Vec::with_capacity(buf.len() + 8);

0 commit comments

Comments
 (0)