diff --git a/video/dav1d/src/dav1ddec/imp.rs b/video/dav1d/src/dav1ddec/imp.rs index 62ed9196..b65e5a5b 100644 --- a/video/dav1d/src/dav1ddec/imp.rs +++ b/video/dav1d/src/dav1ddec/imp.rs @@ -430,11 +430,23 @@ impl Dav1dDec { mut state_guard: MutexGuard<'s, Option>, drain: bool, ) -> Result>, gst::FlowError> { - while let Some(pic) = self.pending_picture(&mut state_guard)? { - state_guard = self.handle_picture(state_guard, &pic)?; - if !drain { + // dav1d wants to have get_picture() called a second time after it return EAGAIN to + // actually drain all pending pictures. + let mut call_twice = drain; + + loop { + while let Some(pic) = self.pending_picture(&mut state_guard)? { + state_guard = self.handle_picture(state_guard, &pic)?; + call_twice = false; + if !drain { + break; + } + } + + if !call_twice { break; } + call_twice = false; } Ok(state_guard)