From 44405e0cd7a68da89c65ee2b2c76be8883b18f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 8 Feb 2023 11:24:27 +0200 Subject: [PATCH] dav1ddec: Make sure to call `get_picture()` twice in a row when draining The first time might return `EAGAIN` if there are pending frames but there is no decoded frame available yet. The second time it will actually wait for frames to become available and only start returning `EAGAIN` again once no more frames are left. Part-of: --- video/dav1d/src/dav1ddec/imp.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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)