V4L2VDA: Execute NotifyFlushDone for Flush if there is no info enough to decode.

If input buffers previously given before Flush request don't contain a header
information which is required to decode frames, Flush will never completed.
This becomes a problem if a client waits until NotifyFlushDone() is invoked.
This CL changes in order to handle the problem, by executing NotifyFlushDone in
such a case.
Concretely, when V4L2_DEC_CMD_STOP will be about to be executed and V4L2VDA
doesn't know detect the resolution change event by that time, NotifyFlushDone
is executed.
This is possible because all the driver with V4L2VDA used on ChromeOS issue
resolution change events until VIDIOC_DQBUF is successful for the buffer which
contains the header.

TEST=CtsSecurityTestCases android.security.cts.StagefrightTest
TEST=VDA unittest on hana

Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I23c94bdf7e0ec7b92ed9cf184be0503ccca3b2b0
Reviewed-on: https://chromium-review.googlesource.com/906090
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Pawel Osciak <posciak@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#538413}(cherry picked from commit b2223975f45caefa796cc276ce5ddbe6d5469fb9)
Reviewed-on: https://chromium-review.googlesource.com/936946
Reviewed-by: Kazuhiro Inaba <kinaba@chromium.org>
Cr-Commit-Position: refs/branch-heads/3325@{#622}
Cr-Branched-From: bc084a8b5afa3744a74927344e304c02ae54189f-refs/heads/master@{#530369}
diff --git a/media/gpu/v4l2/v4l2_video_decode_accelerator.cc b/media/gpu/v4l2/v4l2_video_decode_accelerator.cc
index 58bc7bf..b6b912e 100644
--- a/media/gpu/v4l2/v4l2_video_decode_accelerator.cc
+++ b/media/gpu/v4l2/v4l2_video_decode_accelerator.cc
@@ -1270,11 +1270,18 @@
       // change. They implicitly send a V4L2_DEC_CMD_STOP and V4L2_DEC_CMD_START
       // to the decoder.
       if (input_buffer_queued_count_ == 0) {
-        if (!SendDecoderCmdStop())
-          return;
         input_record.input_id = -1;
+        if (coded_size_.IsEmpty()) {
+          // If coded_size_.IsEmpty(), no output buffer could have been
+          // allocated and there is nothing to flush. We can NotifyFlushDone()
+          // immediately, without requesting flush to the driver via
+          // SendDecoderCmdStop().
+          NotifyFlushDoneIfNeeded();
+        } else if (!SendDecoderCmdStop()) {
+          return;
+        }
       } else {