virtio: video: Only clear output resource after ProvidePictureBuffers()

At CL:2494322, we moved the clearing output resources logic from
handle_provide_picture_buffers() to clear_queue(). That CL only
considered the resolution change case, but didn't handle the flush
case correctly.

When the userspace flush the decoding, it streamoff the output queue.
But VDA doesn't request new set of buffers, ProvidePictureBuffers()
won't be called. In this case, crosvm shouldn't clear the output
resources. Crosvm only needs to clear the set of queued resource ids.

Also, when VDA sends ProvidePictureBuffers() the first time, V4L2
output queue at the userspace is not streaming. So the userspace won't
streamoff the output queue. In this case, we also don't need to clear
the output resources.

BUG=b:171860073
TEST=pass android.media.cts.MediaCodecTest#testDecodeAfterFlush
TEST=pass android.media.cts.AdaptivePlaybackTest

Change-Id: I2a425c1fd9e61322d92dc54930dd88242c964de3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2505284
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Alex Lau <alexlau@chromium.org>
This commit is contained in:
Chih-Yu Huang 2020-10-29 14:16:15 +09:00 committed by Commit Bot
parent d4ca29b5d9
commit bd27bd0eac

View file

@ -165,6 +165,9 @@ struct Context {
in_res: InputResources,
out_res: OutputResources,
// Set the flag if we need to clear output resource when the output queue is cleared next time.
is_clear_out_res_needed: bool,
}
impl Context {
@ -261,6 +264,12 @@ impl Context {
// No need to set `frame_rate`, as it's only for the encoder.
..Default::default()
};
// That eos_resource_id has value means there are previous output resources.
// Clear the output resources when the output queue is cleared next time.
if self.out_res.eos_resource_id.is_some() {
self.is_clear_out_res_needed = true;
}
}
fn handle_picture_ready(
@ -742,7 +751,11 @@ impl<'a> Decoder<'a> {
session.reset().map_err(VideoError::VdaError)?;
}
QueueType::Output => {
if std::mem::replace(&mut ctx.is_clear_out_res_needed, false) {
ctx.out_res = Default::default();
} else {
ctx.out_res.queued_res_ids.clear();
}
}
}
Ok(())