v4l2_codec2: Mark V4L2EncodeComponent buffers as BufferUsage::VIDEO_ENCODER.

This CL adds the BufferUsage::VIDEO_ENCODER flag to the
V4L2EncodeComponent's input and output buffers so they are properly
synced between the encoder and crosvm.

Bug: 162371919
Test: tast run $HOST arc.VideoEncodeAccel.h264_vm on hatch-arc-r
Change-Id: I9179c556e77718d2c9af7584bfa3540d82db07ac
diff --git a/components/V4L2EncodeComponent.cpp b/components/V4L2EncodeComponent.cpp
index b5ada11..f3a10a5 100644
--- a/components/V4L2EncodeComponent.cpp
+++ b/components/V4L2EncodeComponent.cpp
@@ -15,6 +15,7 @@
 #include <C2AllocatorGralloc.h>
 #include <C2PlatformSupport.h>
 #include <C2Work.h>
+#include <android/hardware/graphics/common/1.0/types.h>
 #include <base/bind.h>
 #include <base/bind_helpers.h>
 #include <log/log.h>
@@ -29,6 +30,8 @@
 #include <v4l2_device.h>
 #include <video_pixel_format.h>
 
+using android::hardware::graphics::common::V1_0::BufferUsage;
+
 namespace android {
 
 namespace {
@@ -1160,7 +1163,10 @@
     ALOGV("Fetching linear block (size: %u)", mOutputBufferSize);
     std::shared_ptr<C2LinearBlock> outputBlock;
     c2_status_t status = mOutputBlockPool->fetchLinearBlock(
-            mOutputBufferSize, {C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE}, &outputBlock);
+            mOutputBufferSize,
+            C2MemoryUsage(C2MemoryUsage::CPU_READ |
+                          static_cast<uint64_t>(BufferUsage::VIDEO_ENCODER)),
+            &outputBlock);
     if (status != C2_OK) {
         ALOGE("Failed to fetch linear block (error: %d)", status);
         reportError(status);
diff --git a/components/V4L2EncodeInterface.cpp b/components/V4L2EncodeInterface.cpp
index 50bc4aa..fb715b1 100644
--- a/components/V4L2EncodeInterface.cpp
+++ b/components/V4L2EncodeInterface.cpp
@@ -11,6 +11,7 @@
 
 #include <C2PlatformSupport.h>
 #include <SimpleC2Interface.h>
+#include <android/hardware/graphics/common/1.0/types.h>
 #include <media/stagefright/MediaDefs.h>
 #include <utils/Log.h>
 
@@ -18,6 +19,8 @@
 #include <v4l2_codec2/common/V4L2ComponentCommon.h>
 #include <video_codecs.h>
 
+using android::hardware::graphics::common::V1_0::BufferUsage;
+
 namespace android {
 
 namespace {
@@ -332,6 +335,10 @@
             DefineParam(mInputFormat, C2_PARAMKEY_INPUT_STREAM_BUFFER_TYPE)
                     .withConstValue(new C2StreamBufferTypeSetting::input(0u, C2BufferData::GRAPHIC))
                     .build());
+    addParameter(DefineParam(mInputMemoryUsage, C2_PARAMKEY_INPUT_STREAM_USAGE)
+                         .withConstValue(new C2StreamUsageTuning::input(
+                                 0u, static_cast<uint64_t>(BufferUsage::VIDEO_ENCODER)))
+                         .build());
 
     addParameter(
             DefineParam(mOutputFormat, C2_PARAMKEY_OUTPUT_STREAM_BUFFER_TYPE)
diff --git a/components/include/v4l2_codec2/components/V4L2EncodeInterface.h b/components/include/v4l2_codec2/components/V4L2EncodeInterface.h
index e41ddff..f480d25 100644
--- a/components/include/v4l2_codec2/components/V4L2EncodeInterface.h
+++ b/components/include/v4l2_codec2/components/V4L2EncodeInterface.h
@@ -60,6 +60,8 @@
 
     // The input format kind; should be C2FormatVideo.
     std::shared_ptr<C2StreamBufferTypeSetting::input> mInputFormat;
+    // The memory usage flag of input buffer; should be BufferUsage::VIDEO_ENCODER.
+    std::shared_ptr<C2StreamUsageTuning::input> mInputMemoryUsage;
     // The output format kind; should be C2FormatCompressed.
     std::shared_ptr<C2StreamBufferTypeSetting::output> mOutputFormat;
     // The MIME type of input port; should be MEDIA_MIMETYPE_VIDEO_RAW.