xref: /aosp_15_r20/external/v4l2_codec2/service/service.cpp (revision 0ec5a0ec62797f775085659156625e7f1bdb369f)
1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 //#define LOG_NDEBUG 0
6 #ifdef V4L2_CODEC2_SERVICE_V4L2_STORE
7 #define LOG_TAG "[email protected]"
8 #else
9 #error "V4L2_CODEC2_SERVICE_V4L2_STORE has to be defined"
10 #endif
11 
12 #include <C2Component.h>
13 #include <base/logging.h>
14 #include <codec2/hidl/1.2/ComponentStore.h>
15 #include <hidl/HidlTransportSupport.h>
16 #include <log/log.h>
17 #include <minijail.h>
18 
19 #ifdef V4L2_CODEC2_SERVICE_V4L2_STORE
20 #include <v4l2_codec2/v4l2/V4L2ComponentStore.h>
21 #endif
22 
23 // This is the absolute on-device path of the prebuild_etc module
24 // "android.hardware.media.c2-default-seccomp_policy" in Android.bp.
25 static constexpr char kBaseSeccompPolicyPath[] =
26         "/vendor/etc/seccomp_policy/"
27         "android.hardware.media.c2-default-seccomp_policy";
28 
29 // Additional seccomp permissions can be added in this file.
30 // This file does not exist by default.
31 static constexpr char kExtSeccompPolicyPath[] =
32         "/vendor/etc/seccomp_policy/"
33         "android.hardware.media.c2-extended-seccomp_policy";
34 
main(int,char **)35 int main(int /* argc */, char** /* argv */) {
36     ALOGD("Service starting...");
37 
38     signal(SIGPIPE, SIG_IGN);
39     android::SetUpMinijail(kBaseSeccompPolicyPath, kExtSeccompPolicyPath);
40 
41     // Extra threads may be needed to handle a stacked IPC sequence that
42     // contains alternating binder and hwbinder calls. (See b/35283480.)
43     android::hardware::configureRpcThreadpool(16, true /* callerWillJoin */);
44 
45 #if LOG_NDEBUG == 0
46     ALOGD("Enable all verbose logging of libchrome");
47     logging::SetMinLogLevel(-5);
48 #endif
49 
50     // Create IComponentStore service.
51     {
52         using namespace ::android::hardware::media::c2::V1_2;
53         android::sp<IComponentStore> store = nullptr;
54 
55 #ifdef V4L2_CODEC2_SERVICE_V4L2_STORE
56         ALOGD("Instantiating Codec2's V4L2 IComponentStore service...");
57         store = new utils::ComponentStore(android::V4L2ComponentStore::Create());
58 #endif
59 
60         if (store == nullptr) {
61             ALOGE("Cannot create Codec2's IComponentStore service.");
62         } else if (store->registerAsService("default") != android::OK) {
63             ALOGE("Cannot register Codec2's IComponentStore service.");
64         } else {
65             ALOGI("Codec2's IComponentStore service created.");
66         }
67     }
68 
69     android::hardware::joinRpcThreadpool();
70     ALOGD("Service shutdown.");
71     return 0;
72 }
73