avtest_label_detect: detect VAAPI VP9 decode acceleration

BUG=chromium:534975
TEST=run avtest_label_detect on supported and not-supported machines

Change-Id: I987cd5615334a452e1dbf8456a0715bb0d1a19a5
Reviewed-on: https://chromium-review.googlesource.com/306963
Commit-Ready: Kuang-che Wu <kcwu@chromium.org>
Tested-by: Kuang-che Wu <kcwu@chromium.org>
Reviewed-by: Pawel Osciak <posciak@chromium.org>
diff --git a/avtest_label_detect/detect_hw_video_acc.c b/avtest_label_detect/detect_hw_video_acc.c
index e8b35fc..df0a128 100644
--- a/avtest_label_detect/detect_hw_video_acc.c
+++ b/avtest_label_detect/detect_hw_video_acc.c
@@ -114,6 +114,26 @@
 }
 
 /* Helper function for detect_video_acc_vp9.
+ * Determine given |fd| is a VAAPI device supports VP9 decoding, i.e. it
+ * supports VP9 profile, has decoding entry point, and output YUV420
+ * formats.
+ */
+static bool is_vaapi_dec_vp9_device(int fd) {
+#ifdef HAS_VAAPI
+#if VA_CHECK_VERSION(0, 37, 1)
+  VAProfile va_profiles[] = {
+    VAProfileVP9Profile0,
+    VAProfileNone
+  };
+  if (is_vaapi_support_formats(fd, va_profiles, VAEntrypointVLD,
+        VA_RT_FORMAT_YUV420))
+    return true;
+#endif
+#endif
+  return false;
+}
+
+/* Helper function for detect_video_acc_vp9.
  * A V4L2 device supports VP9 decoding, if it's a mem-to-mem V4L2 device,
  * i.e. it provides V4L2_CAP_VIDEO_CAPTURE_*, V4L2_CAP_VIDEO_OUTPUT_* and
  * V4L2_CAP_STREAMING capabilities and it supports V4L2_PIX_FMT_VP9 as it's
@@ -130,7 +150,12 @@
  * formats. Or there is a /dev/video* device supporting VP9 decoding.
  */
 bool detect_video_acc_vp9(void) {
-  return is_any_device(kVideoDevicePattern, is_v4l2_dec_vp9_device);
+  if (is_any_device(kDRMDevicePattern, is_vaapi_dec_vp9_device))
+    return true;
+
+  if (is_any_device(kVideoDevicePattern, is_v4l2_dec_vp9_device))
+    return true;
+  return false;
 }
 
 /* Helper function for detect_video_acc_enc_h264.