forge
Explore
Log in

Don't you dare go Hollow

S6: Decoder::with_threads; one refresh_refs for key, intra-only and inter frames (same slots, same planes; recycled buffers are refilled)

Browse files at this commit

440f6aca5ae0707f0e63facb252a46ffd69f67f1Ahmet Kaan GümüşParent: 4fd4ed4
crates/ec-vp9/src/decode.rsmodified+19 -27
@@ -261,6 +261,11 @@ struct InterWalk {
261 impl Decoder {261 impl Decoder {
262 /// Create an empty decoder; the first key frame sets the size.262 /// Create an empty decoder; the first key frame sets the size.
263 pub fn new() -> Self {263 pub fn new() -> Self {
264+ Self::with_threads(default_threads())
265+ }
266+
267+ /// Create an empty decoder that walks tile columns on `threads` workers.
268+ pub fn with_threads(threads: usize) -> Self {
264 Decoder {269 Decoder {
265 parser: Vp9Parser::new(),270 parser: Vp9Parser::new(),
266 ctx: Box::new(FrameContext::new(true)),271 ctx: Box::new(FrameContext::new(true)),
@@ -277,7 +282,7 @@ impl Decoder {
277 iw: InterWalk::default(),282 iw: InterWalk::default(),
278 mc_scratch: Vec::new(),283 mc_scratch: Vec::new(),
279 mc_temp: vec![0; 64 * 135 + 64 * 64],284 mc_temp: vec![0; 64 * 135 + 64 * 64],
280- threads: default_threads(),285+ threads: threads.clamp(1, 64),
281 }286 }
282 }287 }
283 288
@@ -344,14 +349,7 @@ impl Decoder {
344 self.frame_ctxs[hdr.frame_context_idx as usize] = self.ctx.as_ref().clone();349 self.frame_ctxs[hdr.frame_context_idx as usize] = self.ctx.as_ref().clone();
345 }350 }
346 // Reference refresh (spec 8.10): a keyframe updates all slots.351 // Reference refresh (spec 8.10): a keyframe updates all slots.
347- let frame = RefFrame {352+ self.refresh_refs(&hdr, 0xff);
348- planes: std::sync::Arc::new(self.planes.take().expect("frame scratch")),
349- width: hdr.width as u16,
350- height: hdr.height as u16,
351- };
352- for slot in self.refs.iter_mut() {
353- *slot = Some(frame.clone());
354- }
355 Ok(if hdr.show_frame { Some(pic) } else { None })353 Ok(if hdr.show_frame { Some(pic) } else { None })
356 }354 }
357 355
@@ -411,17 +409,7 @@ impl Decoder {
411 self.frame_ctxs[0] = self.ctx.as_ref().clone();409 self.frame_ctxs[0] = self.ctx.as_ref().clone();
412 }410 }
413 // Reference refresh (spec 8.10): only `refresh_frame_flags` slots.411 // Reference refresh (spec 8.10): only `refresh_frame_flags` slots.
414- let frame = RefFrame {412+ self.refresh_refs(&hdr, hdr.refresh_frame_flags);
415- planes: std::sync::Arc::new(self.planes.take().expect("frame scratch")),
416- width: hdr.width as u16,
417- height: hdr.height as u16,
418- };
419- for slot in 0..8 {
420- if hdr.refresh_frame_flags & (1 << slot) != 0 {
421- let old = self.refs[slot].replace(frame.clone());
422- self.recycle(old);
423- }
424- }
425 Ok(if hdr.show_frame { Some(pic) } else { None })413 Ok(if hdr.show_frame { Some(pic) } else { None })
426 }414 }
427 415
@@ -597,23 +585,27 @@ impl Decoder {
597 }585 }
598 586
599 let pic = self.take_picture(hdr);587 let pic = self.take_picture(hdr);
588+ // Reference refresh (spec 8.10 / `swap_frame_buffers`): bit i of
589+ // `refresh_frame_flags` replaces slot i with the frame just decoded —
590+ // the LOOP-FILTERED frame, which is what a later frame's prediction
591+ // reads.
592+ self.refresh_refs(hdr, hdr.refresh_frame_flags);
593+ Ok(if hdr.show_frame { Some(pic) } else { None })
594+ }
595+
596+ /// Move the frame scratch into every slot whose bit is set in `flags`.
597+ fn refresh_refs(&mut self, hdr: &FrameHeader, flags: u8) {
600 let frame = RefFrame {598 let frame = RefFrame {
601 planes: std::sync::Arc::new(self.planes.take().expect("frame scratch")),599 planes: std::sync::Arc::new(self.planes.take().expect("frame scratch")),
602 width: hdr.width as u16,600 width: hdr.width as u16,
603 height: hdr.height as u16,601 height: hdr.height as u16,
604 };602 };
605-
606- // Reference refresh (spec 8.10 / `swap_frame_buffers`): bit i of
607- // `refresh_frame_flags` replaces slot i with the frame just decoded —
608- // the LOOP-FILTERED frame, which is what a later frame's prediction
609- // reads.
610 for slot in 0..8 {603 for slot in 0..8 {
611- if hdr.refresh_frame_flags & (1 << slot) != 0 {604+ if flags & (1 << slot) != 0 {
612 let old = self.refs[slot].replace(frame.clone());605 let old = self.refs[slot].replace(frame.clone());
613 self.recycle(old);606 self.recycle(old);
614 }607 }
615 }608 }
616- Ok(if hdr.show_frame { Some(pic) } else { None })
617 }609 }
618 610
619 /// Crop the frame scratch to a [`Picture`].611 /// Crop the frame scratch to a [`Picture`].