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: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1080>
This commit is contained in:
Sebastian Dröge 2023-02-08 11:24:27 +02:00
parent 0ed74d0aa4
commit 44405e0cd7

View file

@ -430,13 +430,25 @@ impl Dav1dDec {
mut state_guard: MutexGuard<'s, Option<State>>, mut state_guard: MutexGuard<'s, Option<State>>,
drain: bool, drain: bool,
) -> Result<MutexGuard<Option<State>>, gst::FlowError> { ) -> Result<MutexGuard<Option<State>>, gst::FlowError> {
// 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)? { while let Some(pic) = self.pending_picture(&mut state_guard)? {
state_guard = self.handle_picture(state_guard, &pic)?; state_guard = self.handle_picture(state_guard, &pic)?;
call_twice = false;
if !drain { if !drain {
break; break;
} }
} }
if !call_twice {
break;
}
call_twice = false;
}
Ok(state_guard) Ok(state_guard)
} }
} }