components: Migrate V4L2 related code to a separate module

This CL extracts V4L2 related code to a separate build module in order
to move V4L2 dependency for R-container

Bug: 281818034
Bug: 267299128
Test: m
Change-Id: I1fc878b4a41625e61d27bde5a9dcb9d157882758
diff --git a/common/Android.bp b/common/Android.bp
index 0096ca3..5e8d647 100644
--- a/common/Android.bp
+++ b/common/Android.bp
@@ -23,10 +23,7 @@
         "H264NalParser.cpp",
         "HEVCNalParser.cpp",
         "NalParser.cpp",
-        "V4L2ComponentCommon.cpp",
         "VideoTypes.cpp",
-        "V4L2Device.cpp",
-        "V4L2DevicePoller.cpp",
         "VideoPixelFormat.cpp",
     ],
 
diff --git a/common/Common.cpp b/common/Common.cpp
index 47560ac..24bb975 100644
--- a/common/Common.cpp
+++ b/common/Common.cpp
@@ -6,8 +6,6 @@
 
 #include <base/numerics/safe_math.h>
 
-#include <v4l2_codec2/common/V4L2Device.h>
-
 namespace android {
 
 bool contains(const Rect& rect1, const Rect& rect2) {
@@ -52,28 +50,4 @@
     }
 }
 
-bool isValidPixFmtForCodec(VideoCodec codec, uint32_t pixFmt) {
-    switch (pixFmt) {
-    case V4L2_PIX_FMT_H264:
-    case V4L2_PIX_FMT_H264_SLICE:
-        return codec == VideoCodec::H264;
-        break;
-    case V4L2_PIX_FMT_VP8:
-    case V4L2_PIX_FMT_VP8_FRAME:
-        return codec == VideoCodec::VP8;
-        break;
-    case V4L2_PIX_FMT_VP9:
-    case V4L2_PIX_FMT_VP9_FRAME:
-        return codec == VideoCodec::VP9;
-        break;
-    case V4L2_PIX_FMT_HEVC:
-    case V4L2_PIX_FMT_HEVC_SLICE:
-        return codec == VideoCodec::HEVC;
-        break;
-    default:
-        ALOGE("Unhandled pixelformat %s", fourccToString(pixFmt).c_str());
-        return false;
-    }
-}
-
 }  // namespace android
diff --git a/common/include/v4l2_codec2/common/Common.h b/common/include/v4l2_codec2/common/Common.h
index dfd9ca2..ac55bd2 100644
--- a/common/include/v4l2_codec2/common/Common.h
+++ b/common/include/v4l2_codec2/common/Common.h
@@ -72,9 +72,6 @@
 // Check whether specified profile can be used with specified codec
 bool isValidProfileForCodec(VideoCodec codec, C2Config::profile_t profile);
 
-// Check whether specified pixel format can be used with specified codec
-bool isValidPixFmtForCodec(VideoCodec codec, uint32_t pixFmt);
-
 }  // namespace android
 
 #endif  // ANDROID_V4L2_CODEC2_COMMON_COMMON_H
diff --git a/components/Android.bp b/components/Android.bp
index b4e35e6..73efcf2 100644
--- a/components/Android.bp
+++ b/components/Android.bp
@@ -18,15 +18,9 @@
     srcs: [
         "VideoFrame.cpp",
         "VideoFramePool.cpp",
-        "V4L2ComponentFactory.cpp",
-        "V4L2ComponentStore.cpp",
         "ComponentStore.cpp",
-        "V4L2Decoder.cpp",
         "DecodeComponent.cpp",
         "DecodeInterface.cpp",
-        "V4L2DecodeComponent.cpp",
-        "V4L2Encoder.cpp",
-        "V4L2EncodeComponent.cpp",
         "EncodeComponent.cpp",
         "EncodeInterface.cpp",
         "VideoDecoder.cpp",
diff --git a/components/ComponentStore.cpp b/components/ComponentStore.cpp
index 6b20f2a..aa4eba8 100644
--- a/components/ComponentStore.cpp
+++ b/components/ComponentStore.cpp
@@ -17,8 +17,7 @@
 #include <log/log.h>
 #include <media/stagefright/foundation/MediaDefs.h>
 
-#include <v4l2_codec2/common/V4L2ComponentCommon.h>
-#include <v4l2_codec2/components/V4L2ComponentFactory.h>
+#include <v4l2_codec2/common/VideoTypes.h>
 
 namespace android {
 namespace {
diff --git a/components/DecodeInterface.cpp b/components/DecodeInterface.cpp
index d140e4c..20d13fe 100644
--- a/components/DecodeInterface.cpp
+++ b/components/DecodeInterface.cpp
@@ -14,7 +14,6 @@
 #include <media/stagefright/foundation/MediaDefs.h>
 
 #include <v4l2_codec2/common/Common.h>
-#include <v4l2_codec2/common/V4L2ComponentCommon.h>
 #include <v4l2_codec2/plugin_store/V4L2AllocatorId.h>
 
 namespace android {
diff --git a/components/EncodeInterface.cpp b/components/EncodeInterface.cpp
index 902ebb8..9d7d81f 100644
--- a/components/EncodeInterface.cpp
+++ b/components/EncodeInterface.cpp
@@ -17,7 +17,6 @@
 #include <utils/Log.h>
 
 #include <v4l2_codec2/common/Common.h>
-#include <v4l2_codec2/common/V4L2ComponentCommon.h>
 #include <v4l2_codec2/common/VideoTypes.h>
 
 using android::hardware::graphics::common::V1_0::BufferUsage;
diff --git a/service/Android.bp b/service/Android.bp
index a690f08..a64cd1d 100644
--- a/service/Android.bp
+++ b/service/Android.bp
@@ -22,6 +22,7 @@
     ],
 
     shared_libs: [
+        "libv4l2_codec2_v4l2",
         "libv4l2_codec2_components",
         "libavservices_minijail",
         "libchrome",
diff --git a/service/service.cpp b/service/service.cpp
index e76e583..123452b 100644
--- a/service/service.cpp
+++ b/service/service.cpp
@@ -12,7 +12,7 @@
 #include <log/log.h>
 #include <minijail.h>
 
-#include <v4l2_codec2/components/V4L2ComponentStore.h>
+#include <v4l2_codec2/v4l2/V4L2ComponentStore.h>
 
 // Default policy for codec2.0 service.
 static constexpr char kBaseSeccompPolicyPath[] =
diff --git a/v4l2/Android.bp b/v4l2/Android.bp
new file mode 100644
index 0000000..fe8043b
--- /dev/null
+++ b/v4l2/Android.bp
@@ -0,0 +1,57 @@
+package {
+    // See: http://go/android-license-faq
+    // A large-scale-change added 'default_applicable_licenses' to import
+    // all of the 'license_kinds' from "external_v4l2_codec2_license"
+    // to get the below license kinds:
+    //   SPDX-license-identifier-BSD
+    default_applicable_licenses: ["external_v4l2_codec2_license"],
+}
+
+cc_library {
+    name: "libv4l2_codec2_v4l2",
+    vendor: true,
+
+    defaults: [
+        "libcodec2-hidl-defaults",
+    ],
+
+    srcs: [
+        "V4L2ComponentCommon.cpp",
+        "V4L2ComponentFactory.cpp",
+        "V4L2ComponentStore.cpp",
+        "V4L2Decoder.cpp",
+        "V4L2DecodeComponent.cpp",
+        "V4L2Device.cpp",
+        "V4L2DevicePoller.cpp",
+        "V4L2Encoder.cpp",
+        "V4L2EncodeComponent.cpp",
+    ],
+    export_include_dirs: [
+        "include",
+    ],
+
+    header_libs: [
+        "libcodec2_internal",
+    ],
+    shared_libs: [
+        "[email protected]",
+        "libc2plugin_store",
+        "libchrome",
+        "libcodec2_soft_common",
+        "libcutils",
+        "liblog",
+        "libsfplugin_ccodec_utils",
+        "libstagefright_bufferqueue_helper",
+        "libstagefright_foundation",
+        "libui",
+        "libv4l2_codec2_common",
+        "libv4l2_codec2_components",
+    ],
+
+    cflags: [
+      "-Werror",
+      "-Wall",
+      "-Wno-unused-parameter",  // needed for libchrome/base codes
+      "-Wthread-safety",
+    ],
+}
diff --git a/common/V4L2ComponentCommon.cpp b/v4l2/V4L2ComponentCommon.cpp
similarity index 97%
rename from common/V4L2ComponentCommon.cpp
rename to v4l2/V4L2ComponentCommon.cpp
index 0e70b29..7bdc6de 100644
--- a/common/V4L2ComponentCommon.cpp
+++ b/v4l2/V4L2ComponentCommon.cpp
@@ -5,7 +5,7 @@
 //#define LOG_NDEBUG 0
 #define LOG_TAG "V4L2ComponentCommon"
 
-#include <v4l2_codec2/common/V4L2ComponentCommon.h>
+#include <v4l2_codec2/v4l2/V4L2ComponentCommon.h>
 
 #include <log/log.h>
 #include <set>
diff --git a/components/V4L2ComponentFactory.cpp b/v4l2/V4L2ComponentFactory.cpp
similarity index 95%
rename from components/V4L2ComponentFactory.cpp
rename to v4l2/V4L2ComponentFactory.cpp
index 7fae344..4493a22 100644
--- a/components/V4L2ComponentFactory.cpp
+++ b/v4l2/V4L2ComponentFactory.cpp
@@ -5,18 +5,18 @@
 //#define LOG_NDEBUG 0
 #define LOG_TAG "V4L2ComponentFactory"
 
-#include <v4l2_codec2/components/V4L2ComponentFactory.h>
+#include <v4l2_codec2/v4l2/V4L2ComponentFactory.h>
 
 #include <codec2/hidl/1.0/InputBufferManager.h>
 #include <log/log.h>
 
 #include <v4l2_codec2/common/Common.h>
-#include <v4l2_codec2/common/V4L2ComponentCommon.h>
-#include <v4l2_codec2/common/V4L2Device.h>
 #include <v4l2_codec2/components/DecodeInterface.h>
 #include <v4l2_codec2/components/EncodeInterface.h>
-#include <v4l2_codec2/components/V4L2DecodeComponent.h>
-#include <v4l2_codec2/components/V4L2EncodeComponent.h>
+#include <v4l2_codec2/v4l2/V4L2ComponentCommon.h>
+#include <v4l2_codec2/v4l2/V4L2DecodeComponent.h>
+#include <v4l2_codec2/v4l2/V4L2Device.h>
+#include <v4l2_codec2/v4l2/V4L2EncodeComponent.h>
 
 namespace android {
 
diff --git a/components/V4L2ComponentStore.cpp b/v4l2/V4L2ComponentStore.cpp
similarity index 92%
rename from components/V4L2ComponentStore.cpp
rename to v4l2/V4L2ComponentStore.cpp
index 33dedf5..927a4c0 100644
--- a/components/V4L2ComponentStore.cpp
+++ b/v4l2/V4L2ComponentStore.cpp
@@ -5,7 +5,7 @@
 //#define LOG_NDEBUG 0
 #define LOG_TAG "V4L2ComponentStore"
 
-#include <v4l2_codec2/components/V4L2ComponentStore.h>
+#include <v4l2_codec2/v4l2/V4L2ComponentStore.h>
 
 #include <stdint.h>
 
@@ -17,9 +17,9 @@
 #include <log/log.h>
 #include <media/stagefright/foundation/MediaDefs.h>
 
-#include <v4l2_codec2/common/V4L2ComponentCommon.h>
 #include <v4l2_codec2/components/ComponentStore.h>
-#include <v4l2_codec2/components/V4L2ComponentFactory.h>
+#include <v4l2_codec2/v4l2/V4L2ComponentCommon.h>
+#include <v4l2_codec2/v4l2/V4L2ComponentFactory.h>
 
 namespace android {
 
diff --git a/components/V4L2DecodeComponent.cpp b/v4l2/V4L2DecodeComponent.cpp
similarity index 97%
rename from components/V4L2DecodeComponent.cpp
rename to v4l2/V4L2DecodeComponent.cpp
index 1ad0842..e13a72c 100644
--- a/components/V4L2DecodeComponent.cpp
+++ b/v4l2/V4L2DecodeComponent.cpp
@@ -5,8 +5,8 @@
 //#define LOG_NDEBUG 0
 #define LOG_TAG "V4L2DecodeComponent"
 
-#include <v4l2_codec2/components/V4L2DecodeComponent.h>
-#include <v4l2_codec2/components/V4L2Decoder.h>
+#include <v4l2_codec2/v4l2/V4L2DecodeComponent.h>
+#include <v4l2_codec2/v4l2/V4L2Decoder.h>
 
 #include <base/bind.h>
 #include <base/callback_helpers.h>
diff --git a/components/V4L2Decoder.cpp b/v4l2/V4L2Decoder.cpp
similarity index 99%
rename from components/V4L2Decoder.cpp
rename to v4l2/V4L2Decoder.cpp
index 582a0e4..a09a488 100644
--- a/components/V4L2Decoder.cpp
+++ b/v4l2/V4L2Decoder.cpp
@@ -6,7 +6,7 @@
 #define ATRACE_TAG ATRACE_TAG_VIDEO
 #define LOG_TAG "V4L2Decoder"
 
-#include <v4l2_codec2/components/V4L2Decoder.h>
+#include <v4l2_codec2/v4l2/V4L2Decoder.h>
 
 #include <stdint.h>
 
diff --git a/common/V4L2Device.cpp b/v4l2/V4L2Device.cpp
similarity index 98%
rename from common/V4L2Device.cpp
rename to v4l2/V4L2Device.cpp
index 6d669ee..0190deb 100644
--- a/common/V4L2Device.cpp
+++ b/v4l2/V4L2Device.cpp
@@ -10,7 +10,7 @@
 #define LOG_TAG "V4L2Device"
 
 #include <linux/v4l2-controls.h>
-#include <v4l2_codec2/common/V4L2Device.h>
+#include <v4l2_codec2/v4l2/V4L2Device.h>
 
 #include <fcntl.h>
 #include <inttypes.h>
@@ -40,6 +40,30 @@
 
 namespace android {
 
+bool isValidPixFmtForCodec(VideoCodec codec, uint32_t pixFmt) {
+    switch (pixFmt) {
+    case V4L2_PIX_FMT_H264:
+    case V4L2_PIX_FMT_H264_SLICE:
+        return codec == VideoCodec::H264;
+        break;
+    case V4L2_PIX_FMT_VP8:
+    case V4L2_PIX_FMT_VP8_FRAME:
+        return codec == VideoCodec::VP8;
+        break;
+    case V4L2_PIX_FMT_VP9:
+    case V4L2_PIX_FMT_VP9_FRAME:
+        return codec == VideoCodec::VP9;
+        break;
+    case V4L2_PIX_FMT_HEVC:
+    case V4L2_PIX_FMT_HEVC_SLICE:
+        return codec == VideoCodec::HEVC;
+        break;
+    default:
+        ALOGE("Unhandled pixelformat %s", fourccToString(pixFmt).c_str());
+        return false;
+    }
+}
+
 struct v4l2_format buildV4L2Format(const enum v4l2_buf_type type, uint32_t fourcc,
                                    const ui::Size& size, size_t buffer_size, uint32_t stride) {
     struct v4l2_format format;
diff --git a/common/V4L2DevicePoller.cpp b/v4l2/V4L2DevicePoller.cpp
similarity index 97%
rename from common/V4L2DevicePoller.cpp
rename to v4l2/V4L2DevicePoller.cpp
index fa2b491..b4add7d 100644
--- a/common/V4L2DevicePoller.cpp
+++ b/v4l2/V4L2DevicePoller.cpp
@@ -6,7 +6,7 @@
 //#define LOG_NDEBUG 0
 #define LOG_TAG "V4L2DevicePoller"
 
-#include <v4l2_codec2/common/V4L2DevicePoller.h>
+#include <v4l2_codec2/v4l2/V4L2DevicePoller.h>
 
 #include <string>
 
@@ -15,7 +15,7 @@
 #include <base/threading/thread_checker.h>
 #include <log/log.h>
 
-#include <v4l2_codec2/common/V4L2Device.h>
+#include <v4l2_codec2/v4l2/V4L2Device.h>
 
 namespace android {
 
diff --git a/components/V4L2EncodeComponent.cpp b/v4l2/V4L2EncodeComponent.cpp
similarity index 97%
rename from components/V4L2EncodeComponent.cpp
rename to v4l2/V4L2EncodeComponent.cpp
index 03b732c..6d8f037 100644
--- a/components/V4L2EncodeComponent.cpp
+++ b/v4l2/V4L2EncodeComponent.cpp
@@ -5,7 +5,7 @@
 //#define LOG_NDEBUG 0
 #define LOG_TAG "V4L2EncodeComponent"
 
-#include <v4l2_codec2/components/V4L2EncodeComponent.h>
+#include <v4l2_codec2/v4l2/V4L2EncodeComponent.h>
 
 #include <base/bind_helpers.h>
 
@@ -13,7 +13,7 @@
 
 #include <v4l2_codec2/components/BitstreamBuffer.h>
 #include <v4l2_codec2/components/EncodeInterface.h>
-#include <v4l2_codec2/components/V4L2Encoder.h>
+#include <v4l2_codec2/v4l2/V4L2Encoder.h>
 
 namespace android {
 
diff --git a/components/V4L2Encoder.cpp b/v4l2/V4L2Encoder.cpp
similarity index 99%
rename from components/V4L2Encoder.cpp
rename to v4l2/V4L2Encoder.cpp
index 2901348..730827c 100644
--- a/components/V4L2Encoder.cpp
+++ b/v4l2/V4L2Encoder.cpp
@@ -5,7 +5,7 @@
 //#define LOG_NDEBUG 0
 #define LOG_TAG "V4L2Encoder"
 
-#include <v4l2_codec2/components/V4L2Encoder.h>
+#include <v4l2_codec2/v4l2/V4L2Encoder.h>
 
 #include <stdint.h>
 #include <optional>
@@ -19,8 +19,8 @@
 
 #include <v4l2_codec2/common/EncodeHelpers.h>
 #include <v4l2_codec2/common/Fourcc.h>
-#include <v4l2_codec2/common/V4L2Device.h>
 #include <v4l2_codec2/components/BitstreamBuffer.h>
+#include <v4l2_codec2/v4l2/V4L2Device.h>
 
 namespace android {
 
diff --git a/common/include/v4l2_codec2/common/V4L2ComponentCommon.h b/v4l2/include/v4l2_codec2/v4l2/V4L2ComponentCommon.h
similarity index 88%
rename from common/include/v4l2_codec2/common/V4L2ComponentCommon.h
rename to v4l2/include/v4l2_codec2/v4l2/V4L2ComponentCommon.h
index 7e2ad8e..525d462 100644
--- a/common/include/v4l2_codec2/common/V4L2ComponentCommon.h
+++ b/v4l2/include/v4l2_codec2/v4l2/V4L2ComponentCommon.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef ANDROID_V4L2_CODEC2_COMMON_V4L2_COMPONENT_COMMON_H
-#define ANDROID_V4L2_CODEC2_COMMON_V4L2_COMPONENT_COMMON_H
+#ifndef ANDROID_V4L2_CODEC2_V4L2_V4L2_COMPONENT_COMMON_H
+#define ANDROID_V4L2_CODEC2_V4L2_V4L2_COMPONENT_COMMON_H
 
 #include <v4l2_codec2/common/VideoTypes.h>
 #include <optional>
@@ -43,4 +43,4 @@
 
 }  // namespace android
 
-#endif  // ANDROID_V4L2_CODEC2_COMMON_V4L2_COMPONENT_COMMON_H
+#endif  // ANDROID_V4L2_CODEC2_V4L2_V4L2_COMPONENT_COMMON_H
diff --git a/components/include/v4l2_codec2/components/V4L2ComponentFactory.h b/v4l2/include/v4l2_codec2/v4l2/V4L2ComponentFactory.h
similarity index 88%
rename from components/include/v4l2_codec2/components/V4L2ComponentFactory.h
rename to v4l2/include/v4l2_codec2/v4l2/V4L2ComponentFactory.h
index 9f47922..2c25628 100644
--- a/components/include/v4l2_codec2/components/V4L2ComponentFactory.h
+++ b/v4l2/include/v4l2_codec2/v4l2/V4L2ComponentFactory.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_COMPONENT_FACTORY_H
-#define ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_COMPONENT_FACTORY_H
+#ifndef ANDROID_V4L2_CODEC2_V4L2_V4L2_COMPONENT_FACTORY_H
+#define ANDROID_V4L2_CODEC2_V4L2_V4L2_COMPONENT_FACTORY_H
 
 #include <memory>
 #include <string>
@@ -45,4 +45,4 @@
 
 }  // namespace android
 
-#endif  // ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_COMPONENT_FACTORY_H
+#endif  // ANDROID_V4L2_CODEC2_V4L2_V4L2_COMPONENT_FACTORY_H
diff --git a/components/include/v4l2_codec2/components/V4L2ComponentStore.h b/v4l2/include/v4l2_codec2/v4l2/V4L2ComponentStore.h
similarity index 63%
rename from components/include/v4l2_codec2/components/V4L2ComponentStore.h
rename to v4l2/include/v4l2_codec2/v4l2/V4L2ComponentStore.h
index 6dcfbcd..4033b79 100644
--- a/components/include/v4l2_codec2/components/V4L2ComponentStore.h
+++ b/v4l2/include/v4l2_codec2/v4l2/V4L2ComponentStore.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_COMPONENT_STORE_H
-#define ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_COMPONENT_STORE_H
+#ifndef ANDROID_V4L2_CODEC2_V4L2_V4L2_COMPONENT_STORE_H
+#define ANDROID_V4L2_CODEC2_V4L2_V4L2_COMPONENT_STORE_H
 
 #include <C2Component.h>
 
@@ -15,4 +15,4 @@
 
 }  // namespace android
 
-#endif  // ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_COMPONENT_STORE_H
+#endif  // ANDROID_V4L2_CODEC2_V4L2_V4L2_COMPONENT_STORE_H
diff --git a/components/include/v4l2_codec2/components/V4L2DecodeComponent.h b/v4l2/include/v4l2_codec2/v4l2/V4L2DecodeComponent.h
similarity index 81%
rename from components/include/v4l2_codec2/components/V4L2DecodeComponent.h
rename to v4l2/include/v4l2_codec2/v4l2/V4L2DecodeComponent.h
index 4869c83..dbb607f 100644
--- a/components/include/v4l2_codec2/components/V4L2DecodeComponent.h
+++ b/v4l2/include/v4l2_codec2/v4l2/V4L2DecodeComponent.h
@@ -1,6 +1,6 @@
 
-#ifndef ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_DECODE_COMPONENT_H
-#define ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_DECODE_COMPONENT_H
+#ifndef ANDROID_V4L2_CODEC2_V4L2_V4L2_DECODE_COMPONENT_H
+#define ANDROID_V4L2_CODEC2_V4L2_V4L2_DECODE_COMPONENT_H
 
 #include <v4l2_codec2/components/DecodeComponent.h>
 
@@ -25,4 +25,4 @@
 
 };  // namespace android
 
-#endif  // ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_DECODE_COMPONENT_H
\ No newline at end of file
+#endif  // ANDROID_V4L2_CODEC2_V4L2_V4L2_DECODE_COMPONENT_H
\ No newline at end of file
diff --git a/components/include/v4l2_codec2/components/V4L2Decoder.h b/v4l2/include/v4l2_codec2/v4l2/V4L2Decoder.h
similarity index 95%
rename from components/include/v4l2_codec2/components/V4L2Decoder.h
rename to v4l2/include/v4l2_codec2/v4l2/V4L2Decoder.h
index 1848b1e..e77cf77 100644
--- a/components/include/v4l2_codec2/components/V4L2Decoder.h
+++ b/v4l2/include/v4l2_codec2/v4l2/V4L2Decoder.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_DECODER_H
-#define ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_DECODER_H
+#ifndef ANDROID_V4L2_CODEC2_V4L2_V4L2_DECODER_H
+#define ANDROID_V4L2_CODEC2_V4L2_V4L2_DECODER_H
 
 #include <stdint.h>
 
@@ -18,12 +18,12 @@
 #include <ui/Rect.h>
 #include <ui/Size.h>
 #include <v4l2_codec2/common/Fourcc.h>
-#include <v4l2_codec2/common/V4L2Device.h>
 #include <v4l2_codec2/common/VideoTypes.h>
 #include <v4l2_codec2/components/VideoDecoder.h>
 #include <v4l2_codec2/components/VideoFrame.h>
 #include <v4l2_codec2/components/VideoFramePool.h>
 #include <v4l2_codec2/plugin_store/DmabufHelpers.h>
+#include <v4l2_codec2/v4l2/V4L2Device.h>
 
 namespace android {
 
@@ -147,4 +147,4 @@
 
 }  // namespace android
 
-#endif  // ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_DECODER_H
+#endif  // ANDROID_V4L2_CODEC2_V4L2_V4L2_DECODER_H
diff --git a/common/include/v4l2_codec2/common/V4L2Device.h b/v4l2/include/v4l2_codec2/v4l2/V4L2Device.h
similarity index 98%
rename from common/include/v4l2_codec2/common/V4L2Device.h
rename to v4l2/include/v4l2_codec2/v4l2/V4L2Device.h
index 1c45735..143aec9 100644
--- a/common/include/v4l2_codec2/common/V4L2Device.h
+++ b/v4l2/include/v4l2_codec2/v4l2/V4L2Device.h
@@ -6,8 +6,8 @@
 // delegate/pass the device specific handling of any of the functionalities.
 // Note: ported from Chromium commit head: 2f13d62f0c0d, but some parts have been removed.
 
-#ifndef ANDROID_V4L2_CODEC2_COMMON_V4L2_DEVICE_H
-#define ANDROID_V4L2_CODEC2_COMMON_V4L2_DEVICE_H
+#ifndef ANDROID_V4L2_CODEC2_V4L2_V4L2_DEVICE_H
+#define ANDROID_V4L2_CODEC2_V4L2_V4L2_DEVICE_H
 
 #include <linux/videodev2.h>
 #include <stddef.h>
@@ -24,8 +24,8 @@
 
 #include <ui/Size.h>
 #include <v4l2_codec2/common/Common.h>
-#include <v4l2_codec2/common/V4L2DevicePoller.h>
 #include <v4l2_codec2/common/VideoTypes.h>
+#include <v4l2_codec2/v4l2/V4L2DevicePoller.h>
 
 // VP8 parsed frames
 #ifndef V4L2_PIX_FMT_VP8_FRAME
@@ -61,6 +61,8 @@
     struct v4l2_ext_control ctrl;
 };
 
+bool isValidPixFmtForCodec(VideoCodec codec, uint32_t pixFmt);
+
 // A unique reference to a buffer for clients to prepare and submit.
 //
 // Clients can prepare a buffer for queuing using the methods of this class, and then either queue
@@ -545,4 +547,4 @@
 
 }  // namespace android
 
-#endif  // ANDROID_V4L2_CODEC2_COMMON_V4L2_DEVICE_H
+#endif  // ANDROID_V4L2_CODEC2_V4L2_V4L2_DEVICE_H
diff --git a/common/include/v4l2_codec2/common/V4L2DevicePoller.h b/v4l2/include/v4l2_codec2/v4l2/V4L2DevicePoller.h
similarity index 95%
rename from common/include/v4l2_codec2/common/V4L2DevicePoller.h
rename to v4l2/include/v4l2_codec2/v4l2/V4L2DevicePoller.h
index 260a331..65887bf 100644
--- a/common/include/v4l2_codec2/common/V4L2DevicePoller.h
+++ b/v4l2/include/v4l2_codec2/v4l2/V4L2DevicePoller.h
@@ -3,8 +3,8 @@
 // found in the LICENSE file.
 // Note: ported from Chromium commit head: f65c38dcdac2
 
-#ifndef ANDROID_V4L2_CODEC2_COMMON_V4L2_DEVICE_POLLER_H
-#define ANDROID_V4L2_CODEC2_COMMON_V4L2_DEVICE_POLLER_H
+#ifndef ANDROID_V4L2_CODEC2_V4L2_V4L2_DEVICE_POLLER_H
+#define ANDROID_V4L2_CODEC2_V4L2_V4L2_DEVICE_POLLER_H
 
 #include <atomic>
 
@@ -83,4 +83,4 @@
 
 }  // namespace android
 
-#endif  // ANDROID_V4L2_CODEC2_COMMON_V4L2_DEVICE_POLLER_H
+#endif  // ANDROID_V4L2_CODEC2_V4L2_V4L2_DEVICE_POLLER_H
diff --git a/components/include/v4l2_codec2/components/V4L2EncodeComponent.h b/v4l2/include/v4l2_codec2/v4l2/V4L2EncodeComponent.h
similarity index 83%
rename from components/include/v4l2_codec2/components/V4L2EncodeComponent.h
rename to v4l2/include/v4l2_codec2/v4l2/V4L2EncodeComponent.h
index 007e3ab..79d99d0 100644
--- a/components/include/v4l2_codec2/components/V4L2EncodeComponent.h
+++ b/v4l2/include/v4l2_codec2/v4l2/V4L2EncodeComponent.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_ENCODE_COMPONENT_H
-#define ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_ENCODE_COMPONENT_H
+#ifndef ANDROID_V4L2_CODEC2_V4L2_V4L2_ENCODE_COMPONENT_H
+#define ANDROID_V4L2_CODEC2_V4L2_V4L2_ENCODE_COMPONENT_H
 
 #include <v4l2_codec2/components/EncodeComponent.h>
 
@@ -30,4 +30,4 @@
 
 }  // namespace android
 
-#endif  // ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_ENCODE_COMPONENT_H
\ No newline at end of file
+#endif  // ANDROID_V4L2_CODEC2_V4L2_V4L2_ENCODE_COMPONENT_H
\ No newline at end of file
diff --git a/components/include/v4l2_codec2/components/V4L2Encoder.h b/v4l2/include/v4l2_codec2/v4l2/V4L2Encoder.h
similarity index 97%
rename from components/include/v4l2_codec2/components/V4L2Encoder.h
rename to v4l2/include/v4l2_codec2/v4l2/V4L2Encoder.h
index a042974..d1eb656 100644
--- a/components/include/v4l2_codec2/components/V4L2Encoder.h
+++ b/v4l2/include/v4l2_codec2/v4l2/V4L2Encoder.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_ENCODER_H
-#define ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_ENCODER_H
+#ifndef ANDROID_V4L2_CODEC2_V4L2_V4L2_ENCODER_H
+#define ANDROID_V4L2_CODEC2_V4L2_V4L2_ENCODER_H
 
 #include <stdint.h>
 #include <memory>
@@ -194,4 +194,4 @@
 
 }  // namespace android
 
-#endif  // ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_ENCODER_H
+#endif  // ANDROID_V4L2_CODEC2_V4L2_V4L2_ENCODER_H