forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-av1facade' (02529d9e): the streaming facade holds one picture so its lookahead matches encode_sequence; facade bytes proven identical to the gate path

Browse files at this commit

c2623dd9353dee24f7627e599713dd0242495b73Ahmet Kaan GümüşParent: c72674b921a9a8
encode_frames returns the previous picture's packet, flush codes the last;
encode() returns an empty first packet. EC_AV1_GATE_FACADE=1 runs the BD
gate through the facade and prints the same numbers. Every caller must
flush at end of stream.
crates/ec-av1/src/encode.rsmodified+26 -15
@@ -11758,18 +11758,21 @@ mod tests {
1175811758 })
1175911759 }
1176011760
11761- /// [`our_ladder`] through the streaming facade with a coding pyramid: the
11762- /// four points are the same `base_q_idx` ladder, but each stream is
11763- /// reordered (hidden `ALTREF` first, `show_existing_frame` last per
11764- /// group) and each level is coded at its own quantizer offset. Returns
11765- /// the ladder, the wall, and — per pyramid level over the whole ladder —
11766- /// how many frames and how many bytes it spent.
11767- fn our_ladder_pyramid(
11761+ /// [`our_ladder`] through the streaming facade — the surface the editor's
11762+ /// export drives (`EC_AV1_GATE_FACADE=1`). With a [`crate::encoder::Pyramid`]
11763+ /// each stream is also reordered (hidden `ALTREF` first,
11764+ /// `show_existing_frame` last per group) and each level is coded at its
11765+ /// own quantizer offset; without one it is the flat ladder, which
11766+ /// `encoder::tests::the_facade_codes_the_same_bytes_as_encode_sequence`
11767+ /// pins byte-identical to [`our_ladder`]'s, so this arm must print the
11768+ /// same BD numbers. Returns the ladder, the wall, and — per pyramid level
11769+ /// over the whole ladder — how many frames and how many bytes it spent.
11770+ fn our_ladder_facade(
1176811771 name: &str,
1176911772 source: &[Picture],
1177011773 width: usize,
1177111774 height: usize,
11772- pyramid: crate::encoder::Pyramid,
11775+ pyramid: Option<crate::encoder::Pyramid>,
1177311776 ) -> (Vec<(f64, f64)>, f64, [usize; 4], [usize; 4]) {
1177411777 use crate::encoder::{Av1Encoder, Colour, EncoderConfig, Level};
1177511778 let slot = |l: Level| match l {
@@ -11792,7 +11795,10 @@ mod tests {
1179211795 tile_rows_log2: 0,
1179311796 };
1179411797 let start = std::time::Instant::now();
11795- let mut enc = Av1Encoder::with_pyramid(config, pyramid).unwrap();
11798+ let mut enc = match pyramid {
11799+ None => Av1Encoder::new(config).unwrap(),
11800+ Some(p) => Av1Encoder::with_pyramid(config, p).unwrap(),
11801+ };
1179611802 let mut packets = Vec::new();
1179711803 for picture in source {
1179811804 packets.extend(enc.encode_frames(picture).unwrap());
@@ -12121,13 +12127,18 @@ mod tests {
1212112127 let _ = crate::tile::take_compound_size_hits();
1212212128 let _ = crate::tile::take_compound_leaf_mode_hits();
1212312129 let _ = crate::motion::take_census();
12124- let (ours, ours_wall) = match pyramid_from_env() {
12125- None => our_ladder(name, &source, width, height, fctx),
12126- Some(pyramid) => {
12130+ let pyramid_env = pyramid_from_env();
12131+ // The entry-surface arm: run the SAME ladder through the
12132+ // streaming facade the editor's export calls, which must print
12133+ // the same BD numbers as the sequence path.
12134+ let facade = std::env::var_os("EC_AV1_GATE_FACADE").is_some();
12135+ let (ours, ours_wall) = match (facade, pyramid_env) {
12136+ (false, None) => our_ladder(name, &source, width, height, fctx),
12137+ (_, pyramid) => {
1212712138 let (ladder, wall, counts, bytes) =
12128- our_ladder_pyramid(name, &source, width, height, pyramid);
12139+ our_ladder_facade(name, &source, width, height, pyramid);
1212912140 eprintln!(
12130- "{name}: pyramid {pyramid:?} -- frames key {} arf {} leaf {} \
12141+ "{name}: facade, pyramid {pyramid:?} -- frames key {} arf {} leaf {} \
1213112142 show_existing {}; bytes key {} arf {} leaf {} show_existing {}",
1213212143 counts[0], counts[1], counts[2], counts[3],
1213312144 bytes[0], bytes[1], bytes[2], bytes[3],
@@ -12555,7 +12566,7 @@ mod tests {
1255512566 None => our_ladder(name, &source, cw, ch, fctx),
1255612567 Some(pyramid) => {
1255712568 let (ladder, wall, counts, bytes) =
12558- our_ladder_pyramid(name, &source, cw, ch, pyramid);
12569+ our_ladder_facade(name, &source, cw, ch, Some(pyramid));
1255912570 eprintln!(
1256012571 "{name}: pyramid {pyramid:?} -- frames key {} arf {} leaf {} \
1256112572 show_existing {}; bytes key {} arf {} leaf {} show_existing {}",
crates/ec-av1/src/encoder.rsmodified+164 -63
@@ -1,14 +1,16 @@
11 //! The streaming encoder facade — I11 of `lanes/av1-inter-plan.md`, the
22 //! surface `edith_replica`'s engine calls in place of rav1e.
33 //!
4-//! One picture in, one [`Packet`] out, same contract as the repo's other
5-//! software encoder shims (`shims/rusty_h264`'s `Encoder::try_encode`,
6-//! "nothing is ever held back"): [`Av1Encoder::encode`] never buffers a
7-//! picture past its own call, so there is no flush to drain. That contract
8-//! still holds for every caller that does not opt into a coding pyramid;
9-//! [`Av1Encoder::with_pyramid`] does reorder pictures, and such a stream is
10-//! driven through [`Av1Encoder::encode_frames`] (zero or more packets per
11-//! picture) and [`Av1Encoder::flush`] instead. Internally it
4+//! ONE FRAME OF LATENCY, everywhere: a picture handed to
5+//! [`Av1Encoder::encode`]/[`Av1Encoder::encode_frames`] is held until the
6+//! NEXT picture arrives, because an inter frame's per-superblock temporal
7+//! lambda map reads the next source picture as its lookahead (lane-av1tpl)
8+//! — exactly as [`crate::encode::encode_sequence`] does, so the facade and
9+//! the sequence path now code the same bytes for the same pictures. A
10+//! stream therefore ENDS with [`Av1Encoder::flush`], which codes whatever is
11+//! still held. [`Av1Encoder::with_pyramid`] holds a whole mini-GOP for the
12+//! same kind of reason (it reorders pictures) and is driven through
13+//! [`Av1Encoder::encode_frames`]/[`Av1Encoder::flush`] too. Internally it
1214 //! is [`crate::encode::encode_key_frame_inner`] and
1315 //! [`crate::encode::encode_inter_frame`] driven by a small state machine —
1416 //! a key frame every `gop` pictures, an inter frame predicting from the
@@ -534,6 +536,10 @@ pub struct Av1Encoder {
534536 dpb: [Option<DpbSlot>; 8],
535537 /// Pictures held back waiting for their mini-GOP's hidden frame.
536538 pending: Vec<(u64, Picture)>,
539+ /// The flat path's one-picture delay queue: the picture whose packet the
540+ /// NEXT call returns, coded with that call's picture as its lookahead
541+ /// (lane-av1facade). Unused in pyramid mode, which buffers in `pending`.
542+ held: Option<Picture>,
537543 /// Which of [`ANCHOR_SLOTS`] the group about to be coded reads as its
538544 /// anchor.
539545 anchor: usize,
@@ -601,6 +607,7 @@ impl Av1Encoder {
601607 pyramid: None,
602608 dpb: [const { None }; 8],
603609 pending: Vec::new(),
610+ held: None,
604611 anchor: 0,
605612 next_dts: 0,
606613 })
@@ -678,9 +685,15 @@ impl Av1Encoder {
678685 (self.config.width, self.config.height)
679686 }
680687
681- /// Encodes one picture, key or inter by this stream's `gop` cadence, and
682- /// returns its packet — always exactly one, never held back for a later
683- /// call.
688+ /// Takes one picture and returns the PREVIOUS picture's packet, key or
689+ /// inter by this stream's `gop` cadence — the facade's one frame of
690+ /// latency (the picture just handed in is what the previous one is coded
691+ /// against as its lookahead). The FIRST call has no previous picture and
692+ /// returns a packet with an EMPTY `data` (its other fields are
693+ /// placeholders; test `data.is_empty()`), and the last picture's packet
694+ /// comes out of [`Av1Encoder::flush`] — so a caller that concatenates
695+ /// `data` in call order still gets the whole stream, provided it flushes
696+ /// at the end.
684697 ///
685698 /// # Errors
686699 /// Returns an error when `picture`'s size does not match
@@ -697,12 +710,19 @@ impl Av1Encoder {
697710 ));
698711 }
699712 let mut packets = self.encode_frames(picture)?;
700- Ok(packets.pop().expect("the flat path emits exactly one packet"))
713+ Ok(packets.pop().unwrap_or(Packet {
714+ data: Vec::new(),
715+ key: false,
716+ order: 0,
717+ dts: 0,
718+ level: Level::Leaf,
719+ }))
701720 }
702721
703- /// Encodes one picture and returns every packet it completed, in coding
704- /// order. Without a [`Pyramid`] that is always exactly one packet and
705- /// this is [`Av1Encoder::encode`] with a `Vec` around it; with one it is
722+ /// Takes one picture and returns every packet it completed, in coding
723+ /// order. Without a [`Pyramid`] that is one packet — the PREVIOUS
724+ /// picture's, since this one is its lookahead — and none at all on the
725+ /// first call; with one it is
706726 /// empty for most pictures and a whole mini-GOP's worth (the hidden
707727 /// frame, its leaves and the `show_existing_frame` that re-outputs it)
708728 /// for the picture that closes a group.
@@ -721,7 +741,13 @@ impl Av1Encoder {
721741 ));
722742 }
723743 let Some(pyramid) = self.pyramid else {
724- return Ok(vec![self.encode_flat(picture)?]);
744+ // The one-picture delay queue: this picture is the lookahead the
745+ // previous one is coded with, which is what makes the facade's
746+ // bytes identical to `encode_sequence`'s (lane-av1facade).
747+ return Ok(match self.held.replace(picture.clone()) {
748+ None => Vec::new(),
749+ Some(previous) => vec![self.encode_flat(&previous, Some(picture))?],
750+ });
725751 };
726752 let order = self.next_index;
727753 self.next_index += 1;
@@ -743,19 +769,26 @@ impl Av1Encoder {
743769 Ok(Vec::new())
744770 }
745771
746- /// Codes and returns every picture still held back — the tail of a stream
747- /// whose last mini-GOP never filled up. Empty (and cheap) for a stream
748- /// with no [`Pyramid`], which never holds a picture at all.
772+ /// Codes and returns every picture still held back — the last picture of
773+ /// a flat stream (which has no lookahead and is coded without one), or
774+ /// the tail of a pyramid stream whose last mini-GOP never filled up.
775+ /// Empty once there is nothing held.
749776 ///
750777 /// # Errors
751778 /// As [`Av1Encoder::encode_frames`].
752779 pub fn flush(&mut self) -> Result<Vec<Packet>> {
753780 crate::encode::arm_tiles(self.config.tile_cols_log2, self.config.tile_rows_log2);
781+ if let Some(previous) = self.held.take() {
782+ return Ok(vec![self.encode_flat(&previous, None)?]);
783+ }
754784 self.drain_pending()
755785 }
756786
757- /// The pre-pyramid path, byte for byte: one picture in, one packet out.
758- fn encode_flat(&mut self, picture: &Picture) -> Result<Packet> {
787+ /// The flat path: one picture and its lookahead (the next source picture,
788+ /// `None` at the end of the stream) in, one packet out — the same inputs
789+ /// [`crate::encode::encode_sequence`] gives each of its inter frames, so
790+ /// the bytes are identical.
791+ fn encode_flat(&mut self, picture: &Picture, lookahead: Option<&Picture>) -> Result<Packet> {
759792 let render = (self.config.width, self.config.height);
760793 let padded = picture.padded_to(SUPERBLOCK);
761794 let is_key = self.next_index.is_multiple_of(self.config.gop as u64);
@@ -803,9 +836,7 @@ impl Av1Encoder {
803836 self.prev2.as_ref(),
804837 &self.fctx,
805838 None,
806- // The streaming facade holds no lookahead buffer
807- // (lane-av1tpl).
808- None,
839+ lookahead.map(|n| n.padded_to(SUPERBLOCK)).as_ref(),
809840 )?
810841 };
811842
@@ -1098,17 +1129,34 @@ mod tests {
10981129 picture
10991130 }
11001131
1132+ /// Drives a whole stream through the facade the way a caller must since
1133+ /// it holds one picture of lookahead: every picture through
1134+ /// [`Av1Encoder::encode_frames`], then [`Av1Encoder::flush`].
1135+ fn encode_all(enc: &mut Av1Encoder, pictures: &[Picture]) -> Vec<Packet> {
1136+ let mut packets = Vec::with_capacity(pictures.len());
1137+ for (i, picture) in pictures.iter().enumerate() {
1138+ packets.extend(
1139+ enc.encode_frames(picture)
1140+ .unwrap_or_else(|e| panic!("picture {i}: {e}")),
1141+ );
1142+ }
1143+ packets.extend(enc.flush().unwrap_or_else(|e| panic!("flush: {e}")));
1144+ packets
1145+ }
1146+
11011147 /// Every OBU stream this test writes to `ffmpeg`/`ffprobe`, concatenated
11021148 /// in order.
11031149 fn concat(packets: &[Packet]) -> Vec<u8> {
11041150 packets.iter().flat_map(|p| p.data.clone()).collect()
11051151 }
11061152
1107- /// One call to [`Av1Encoder::encode`] returns exactly one packet, always
1108- /// — the facade's whole "nothing held back" contract, checked without
1109- /// ffmpeg since it is a property of the return type, not the bytes.
1153+ /// The facade's latency contract (lane-av1facade): the first
1154+ /// [`Av1Encoder::encode`] call returns an empty packet, every later call
1155+ /// returns the PREVIOUS picture's packet, and [`Av1Encoder::flush`]
1156+ /// yields the last one — so a caller still gets exactly one non-empty
1157+ /// packet per picture, one call later.
11101158 #[test]
1111- fn one_in_one_out() {
1159+ fn one_in_one_out_delayed_by_a_frame() {
11121160 let config = EncoderConfig {
11131161 width: 64,
11141162 height: 64,
@@ -1121,8 +1169,67 @@ mod tests {
11211169 let mut enc = Av1Encoder::new(config).unwrap();
11221170 for t in 0..5u64 {
11231171 let packet = enc.encode(&test_card(64, 64, t as usize)).unwrap();
1172+ if t == 0 {
1173+ assert!(packet.data.is_empty(), "the first call holds its picture back");
1174+ continue;
1175+ }
11241176 assert!(!packet.data.is_empty(), "picture {t}: empty packet");
1125- assert_eq!(packet.order, t, "picture {t}: order");
1177+ assert_eq!(packet.order, t - 1, "picture {t}: order");
1178+ }
1179+ let tail = enc.flush().unwrap();
1180+ assert_eq!(tail.len(), 1, "flush yields the last picture");
1181+ assert_eq!(tail[0].order, 4);
1182+ assert!(enc.flush().unwrap().is_empty(), "nothing is held twice");
1183+ }
1184+
1185+ /// THE ENTRY-SURFACE GATE (lane-av1facade): the streaming facade — what
1186+ /// the editor's export drives — codes byte for byte what
1187+ /// [`crate::encode::encode_sequence`] codes, which is the path the BD
1188+ /// gate measures. It did not before: the facade passed no lookahead, so
1189+ /// every inter frame missed the per-superblock temporal lambda map
1190+ /// (lane-av1tpl) the gate's numbers were measured with.
1191+ ///
1192+ /// Runs on the gate's own clip at the gate's own size when the fixture is
1193+ /// there, and on a synthetic card otherwise — never skipped, since a
1194+ /// skipped identity gate is the defect it is meant to catch.
1195+ #[test]
1196+ fn the_facade_codes_the_same_bytes_as_encode_sequence() {
1197+ let frames = 12usize;
1198+ let pictures = h264_clip_frames(640, 384, frames).unwrap_or_else(|| {
1199+ eprintln!("no h264 clip: the facade identity gate runs on a synthetic card");
1200+ (0..frames).map(|t| test_card(64, 64, t)).collect()
1201+ });
1202+ let (width, height) = (pictures[0].width, pictures[0].height);
1203+ for q in [150u8, 60] {
1204+ let config = EncoderConfig {
1205+ width,
1206+ height,
1207+ base_q_idx: q,
1208+ // One key frame then all inter, which is `encode_sequence`'s
1209+ // only shape, and the gate's recipe.
1210+ gop: frames,
1211+ // `encode_sequence` writes an unspecified colour config.
1212+ colour: Colour::Unspecified,
1213+ tile_cols_log2: 0,
1214+ tile_rows_log2: 0,
1215+ };
1216+ let mut enc = Av1Encoder::new(config).unwrap();
1217+ let packets = encode_all(&mut enc, &pictures);
1218+ let sequence = crate::encode::encode_sequence(&pictures, q, DEADZONE).unwrap();
1219+ assert_eq!(packets.len(), frames, "q={q}: one packet per picture");
1220+ for (i, (packet, coded)) in packets.iter().zip(&sequence.frames).enumerate() {
1221+ let cropped = crate::encode::crop_encoded(coded, width, height);
1222+ assert_eq!(
1223+ (packet.data.len(), packet.data.clone()),
1224+ (cropped.stream.len(), cropped.stream.clone()),
1225+ "q={q} frame {i}: the facade's bytes are not the sequence path's"
1226+ );
1227+ }
1228+ assert_eq!(
1229+ concat(&packets),
1230+ sequence.stream,
1231+ "q={q}: whole stream"
1232+ );
11261233 }
11271234 }
11281235
@@ -1141,8 +1248,10 @@ mod tests {
11411248 tile_rows_log2: 0,
11421249 };
11431250 let mut enc = Av1Encoder::new(config).unwrap();
1144- let keys: Vec<bool> = (0..7)
1145- .map(|t| enc.encode(&test_card(64, 64, t)).unwrap().key)
1251+ let pictures: Vec<Picture> = (0..7).map(|t| test_card(64, 64, t)).collect();
1252+ let keys: Vec<bool> = encode_all(&mut enc, &pictures)
1253+ .iter()
1254+ .map(|p| p.key)
11461255 .collect();
11471256 assert_eq!(keys, vec![true, false, false, true, false, false, true]);
11481257 }
@@ -1251,9 +1360,8 @@ mod tests {
12511360 )
12521361 );
12531362
1254- let packets: Vec<Packet> = (0..30)
1255- .map(|t| enc.encode(&test_card(width, height, t)).unwrap())
1256- .collect();
1363+ let pictures: Vec<Picture> = (0..30).map(|t| test_card(width, height, t)).collect();
1364+ let packets: Vec<Packet> = encode_all(&mut enc, &pictures);
12571365 let expect_key: Vec<bool> = (0..30).map(|t| t % 15 == 0).collect();
12581366 assert_eq!(
12591367 packets.iter().map(|p| p.key).collect::<Vec<_>>(),
@@ -1296,8 +1404,8 @@ mod tests {
12961404 tile_rows_log2: 0,
12971405 };
12981406 let mut enc = Av1Encoder::new(config).unwrap();
1299- let packet = enc.encode(&test_card(64, 64, 0)).unwrap();
1300- let colour = ffprobe_colour(&packet.data);
1407+ let packets = encode_all(&mut enc, &[test_card(64, 64, 0)]);
1408+ let colour = ffprobe_colour(&packets[0].data);
13011409 assert_eq!(colour, "tv,bt709,bt709,bt709", "ffprobe colour fields");
13021410 }
13031411
@@ -1320,8 +1428,8 @@ mod tests {
13201428 tile_rows_log2: 0,
13211429 };
13221430 let mut enc = Av1Encoder::new(config).unwrap();
1323- let packet = enc.encode(&test_card(64, 64, 0)).unwrap();
1324- let colour = ffprobe_colour(&packet.data);
1431+ let packets = encode_all(&mut enc, &[test_card(64, 64, 0)]);
1432+ let colour = ffprobe_colour(&packets[0].data);
13251433 assert_eq!(
13261434 colour, "tv,smpte170m,smpte170m,smpte170m",
13271435 "ffprobe colour fields"
@@ -1433,9 +1541,9 @@ mod tests {
14331541 };
14341542 let mut enc =
14351543 Av1Encoder::with_rate_target(config, RateTarget::BytesPerFrame(target_bytes)).unwrap();
1436- let sizes: Vec<usize> = pictures
1544+ let sizes: Vec<usize> = encode_all(&mut enc, &pictures)
14371545 .iter()
1438- .map(|p| enc.encode(p).unwrap().data.len())
1546+ .map(|p| p.data.len())
14391547 .collect();
14401548 // Discard the key frame (always far larger than an inter target) and
14411549 // the next 4 inter frames the loop needs to step toward it.
@@ -1535,7 +1643,7 @@ mod tests {
15351643 Av1Encoder::with_rate_target(config, RateTarget::BytesPerFrame(4_000)).unwrap();
15361644 let mut prev_q = enc.rate_loop.as_ref().unwrap().q_idx(Level::Leaf);
15371645 for picture in &pictures {
1538- enc.encode(picture).unwrap();
1646+ enc.encode_frames(picture).unwrap();
15391647 let q = enc.rate_loop.as_ref().unwrap().q_idx(Level::Leaf);
15401648 let step = (i32::from(q) - i32::from(prev_q)).abs();
15411649 assert!(
@@ -1723,10 +1831,7 @@ mod tests {
17231831 let layout = format!("{}x{} tiles", 1 << cols_log2, 1 << rows_log2);
17241832 let mut enc = Av1Encoder::new(config).unwrap();
17251833 let mut stream = Vec::new();
1726- for (i, picture) in sources.iter().enumerate() {
1727- let packet = enc
1728- .encode(picture)
1729- .unwrap_or_else(|e| panic!("{layout} frame {i}: {e}"));
1834+ for packet in encode_all(&mut enc, &sources) {
17301835 stream.extend_from_slice(&packet.data);
17311836 }
17321837 sizes.push((layout.clone(), stream.len()));
@@ -1819,8 +1924,8 @@ mod tests {
18191924 let mut enc = Av1Encoder::new(config).unwrap();
18201925 let start = std::time::Instant::now();
18211926 let mut bytes = 0usize;
1822- for picture in &sources {
1823- bytes += enc.encode(picture).unwrap().data.len();
1927+ for packet in encode_all(&mut enc, &sources) {
1928+ bytes += packet.data.len();
18241929 }
18251930 let wall = start.elapsed().as_secs_f64();
18261931 let name = format!("{}x{}", 1 << cols_log2, 1 << rows_log2);
@@ -1860,8 +1965,8 @@ mod tests {
18601965 };
18611966 let mut enc = Av1Encoder::new(config).unwrap();
18621967 let mut stream = Vec::new();
1863- for picture in &sources {
1864- stream.extend_from_slice(&enc.encode(picture).unwrap().data);
1968+ for packet in encode_all(&mut enc, &sources) {
1969+ stream.extend_from_slice(&packet.data);
18651970 }
18661971 stream
18671972 };
@@ -1928,8 +2033,8 @@ mod tests {
19282033 };
19292034 let mut enc = Av1Encoder::new(config).unwrap();
19302035 let mut stream = Vec::new();
1931- for picture in &sources {
1932- stream.extend_from_slice(&enc.encode(picture).unwrap().data);
2036+ for packet in encode_all(&mut enc, &sources) {
2037+ stream.extend_from_slice(&packet.data);
19332038 }
19342039 stream
19352040 };
@@ -1964,8 +2069,8 @@ mod tests {
19642069 };
19652070 let mut enc = Av1Encoder::new(config).unwrap();
19662071 let mut stream = Vec::new();
1967- for picture in &sources {
1968- stream.extend_from_slice(&enc.encode(picture).unwrap().data);
2072+ for packet in encode_all(&mut enc, &sources) {
2073+ stream.extend_from_slice(&packet.data);
19692074 }
19702075 crate::decode::set_filter_replay_disabled(false);
19712076 stream
@@ -2031,8 +2136,8 @@ mod tests {
20312136 let mut enc = Av1Encoder::new(config).unwrap();
20322137 let _ = crate::par::take_stage_ns();
20332138 let start = std::time::Instant::now();
2034- for picture in &sources {
2035- assert!(!enc.encode(picture).unwrap().data.is_empty());
2139+ for packet in encode_all(&mut enc, &sources) {
2140+ assert!(!packet.data.is_empty());
20362141 }
20372142 let wall = start.elapsed().as_secs_f64();
20382143 let ns = crate::par::take_stage_ns();
@@ -2102,8 +2207,8 @@ mod tests {
21022207 let mut enc = Av1Encoder::new(config).unwrap();
21032208 let start = std::time::Instant::now();
21042209 let mut bytes = 0usize;
2105- for picture in &sources {
2106- bytes += enc.encode(picture).unwrap().data.len();
2210+ for packet in encode_all(&mut enc, &sources) {
2211+ bytes += packet.data.len();
21072212 }
21082213 (start.elapsed(), bytes)
21092214 };
@@ -2243,10 +2348,7 @@ mod tests {
22432348 let layout = format!("{}x{} tiles", 1 << cols_log2, 1 << rows_log2);
22442349 let mut enc = Av1Encoder::new(config).unwrap();
22452350 let mut stream = Vec::new();
2246- for (i, picture) in sources.iter().enumerate() {
2247- let packet = enc
2248- .encode(picture)
2249- .unwrap_or_else(|e| panic!("{layout} frame {i}: {e}"));
2351+ for packet in encode_all(&mut enc, &sources) {
22502352 stream.extend_from_slice(&packet.data);
22512353 }
22522354 let ours = crate::stream::decode_stream(&stream).expect("our decoder");
@@ -2301,8 +2403,7 @@ mod tests {
23012403 Av1Encoder::with_rate_target(config, RateTarget::Quality(quality)).unwrap();
23022404 let mut stream = Vec::new();
23032405 let mut total_bytes = 0usize;
2304- for picture in &pictures {
2305- let packet = enc.encode(picture).unwrap();
2406+ for packet in encode_all(&mut enc, &pictures) {
23062407 total_bytes += packet.data.len();
23072408 stream.extend_from_slice(&packet.data);
23082409 }