service: Make use of V4L2ComponentStore conditional
This change will allow in the future use of the service code to be
shared for R-container.
Bug: 281818034
Bug: 267299128
Test: m
Change-Id: Ia57802069e93b4702b582fbe0ed324c1d0f63029
diff --git a/service/Android.bp b/service/Android.bp
index a64cd1d..5361c3f 100644
--- a/service/Android.bp
+++ b/service/Android.bp
@@ -7,8 +7,8 @@
default_applicable_licenses: ["external_v4l2_codec2_license"],
}
-cc_binary {
- name: "[email protected]",
+cc_defaults {
+ name: "libv4l2_codec2_service",
defaults: [
"hidl_defaults",
@@ -33,6 +33,22 @@
],
required: ["[email protected]_policy"],
+}
+
+cc_binary {
+ name: "[email protected]",
+
+ defaults: [
+ "libv4l2_codec2_service",
+ ],
+
+ shared_libs: [
+ "libv4l2_codec2_v4l2",
+ ],
+
+ cflags: [
+ "-DV4L2_CODEC2_SERVICE_V4L2_STORE",
+ ],
compile_multilib: "both",
multilib: {
diff --git a/service/service.cpp b/service/service.cpp
index 123452b..0633fc3 100644
--- a/service/service.cpp
+++ b/service/service.cpp
@@ -3,7 +3,11 @@
// found in the LICENSE file.
//#define LOG_NDEBUG 0
+#ifdef V4L2_CODEC2_SERVICE_V4L2_STORE
#define LOG_TAG "[email protected]"
+#else
+#error "V4L2_CODEC2_SERVICE_V4L2_STORE has to be defined"
+#endif
#include <C2Component.h>
#include <base/logging.h>
@@ -12,7 +16,9 @@
#include <log/log.h>
#include <minijail.h>
+#ifdef V4L2_CODEC2_SERVICE_V4L2_STORE
#include <v4l2_codec2/v4l2/V4L2ComponentStore.h>
+#endif
// Default policy for codec2.0 service.
static constexpr char kBaseSeccompPolicyPath[] =
@@ -40,12 +46,15 @@
// Create IComponentStore service.
{
using namespace ::android::hardware::media::c2::V1_2;
+ android::sp<IComponentStore> store = nullptr;
+#ifdef V4L2_CODEC2_SERVICE_V4L2_STORE
ALOGD("Instantiating Codec2's V4L2 IComponentStore service...");
- android::sp<IComponentStore> store(
- new utils::ComponentStore(android::V4L2ComponentStore::Create()));
+ store = new utils::ComponentStore(android::V4L2ComponentStore::Create());
+#endif
+
if (store == nullptr) {
- ALOGE("Cannot create Codec2's V4L2 IComponentStore service.");
+ ALOGE("Cannot create Codec2's IComponentStore service.");
} else if (store->registerAsService("default") != android::OK) {
ALOGE("Cannot register Codec2's IComponentStore service.");
} else {