• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define LOG_TAG "android.hardware.media.c2@1.0-service-v4l2"
7 
8 #include <base/logging.h>
9 #include <C2Component.h>
10 #include <codec2/hidl/1.0/ComponentStore.h>
11 #include <hidl/HidlTransportSupport.h>
12 #include <log/log.h>
13 #include <minijail.h>
14 
15 #include <v4l2_codec2/store/V4L2ComponentStore.h>
16 
17 // Default policy for codec2.0 service.
18 static constexpr char kBaseSeccompPolicyPath[] =
19         "/vendor/etc/seccomp_policy/android.hardware.media.c2@1.1-default-seccomp_policy";
20 
21 // Additional device-specific seccomp permissions can be added in this file.
22 static constexpr char kExtSeccompPolicyPath[] =
23         "/vendor/etc/seccomp_policy/codec2.vendor.ext.policy";
24 
main(int,char **)25 int main(int /* argc */, char** /* argv */) {
26     ALOGD("Service starting...");
27 
28     signal(SIGPIPE, SIG_IGN);
29     android::SetUpMinijail(kBaseSeccompPolicyPath, kExtSeccompPolicyPath);
30 
31     // Extra threads may be needed to handle a stacked IPC sequence that
32     // contains alternating binder and hwbinder calls. (See b/35283480.)
33     android::hardware::configureRpcThreadpool(8, true /* callerWillJoin */);
34 
35 #if LOG_NDEBUG == 0
36     ALOGD("Enable all verbose logging of libchrome");
37     logging::SetMinLogLevel(-5);
38 #endif
39 
40     // Create IComponentStore service.
41     {
42         using namespace ::android::hardware::media::c2::V1_0;
43 
44         ALOGD("Instantiating Codec2's V4L2 IComponentStore service...");
45         android::sp<IComponentStore> store(
46                 new utils::ComponentStore(android::V4L2ComponentStore::Create()));
47         if (store == nullptr) {
48             ALOGE("Cannot create Codec2's V4L2 IComponentStore service.");
49         } else if (store->registerAsService("default") != android::OK) {
50             ALOGE("Cannot register Codec2's IComponentStore service.");
51         } else {
52             ALOGI("Codec2's IComponentStore service created.");
53         }
54     }
55 
56     android::hardware::joinRpcThreadpool();
57     ALOGD("Service shutdown.");
58     return 0;
59 }
60