Pawin Vongmasa | 20c40b3 | 2018-02-26 16:27:02 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "vendor.google.media.c2@1.0-service" |
| 19 | |
| 20 | #include <C2PlatformSupport.h> |
| 21 | #include <C2V4l2Support.h> |
| 22 | #include <cutils/properties.h> |
| 23 | |
| 24 | #include <codec2/hidl/1.0/ComponentStore.h> |
| 25 | #include <hidl/HidlTransportSupport.h> |
| 26 | #include <minijail.h> |
| 27 | |
| 28 | // TODO: Remove this once "setenv()" call is removed. |
| 29 | #include <stdlib.h> |
| 30 | |
| 31 | // This is created by module "codec2.system.base.policy". This can be modified. |
| 32 | static constexpr char kBaseSeccompPolicyPath[] = |
| 33 | "/system/etc/seccomp_policy/codec2.system.base.policy"; |
| 34 | |
| 35 | // Additional device-specific seccomp permissions can be added in this file. |
| 36 | static constexpr char kExtSeccompPolicyPath[] = |
| 37 | "/system/etc/seccomp_policy/codec2.system.ext.policy"; |
| 38 | |
| 39 | int main(int /* argc */, char** /* argv */) { |
| 40 | ALOGD("vendor.google.media.c2@1.0-service-system starting..."); |
| 41 | |
| 42 | // TODO: Remove this when all the build settings and sepolicies are in place. |
| 43 | setenv("TREBLE_TESTING_OVERRIDE", "true", true); |
| 44 | |
| 45 | signal(SIGPIPE, SIG_IGN); |
| 46 | android::SetUpMinijail(kBaseSeccompPolicyPath, kExtSeccompPolicyPath); |
| 47 | |
| 48 | // Extra threads may be needed to handle a stacked IPC sequence that |
| 49 | // contains alternating binder and hwbinder calls. (See b/35283480.) |
| 50 | android::hardware::configureRpcThreadpool(8, true /* callerWillJoin */); |
| 51 | |
| 52 | // Create IComponentStore service. |
| 53 | { |
| 54 | using namespace ::vendor::google::media::c2::V1_0; |
| 55 | android::sp<IComponentStore> store = |
| 56 | new implementation::ComponentStore( |
| 57 | android::GetCodec2PlatformComponentStore()); |
| 58 | if (store == nullptr) { |
| 59 | ALOGE("Cannot create Codec2's IComponentStore system service."); |
| 60 | } else { |
| 61 | if (store->registerAsService("system") != android::OK) { |
| 62 | ALOGE("Cannot register Codec2's " |
| 63 | "IComponentStore system service."); |
| 64 | } else { |
| 65 | ALOGI("Codec2's IComponentStore system service created."); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | // To enable the v4l2 service, set this sysprop and add "v4l2" instance |
| 70 | // to the system manifest file. |
| 71 | if (property_get_bool("debug.stagefright.ccodec_v4l2", false)) { |
| 72 | store = new implementation::ComponentStore( |
| 73 | android::GetCodec2VDAComponentStore()); |
| 74 | if (store == nullptr) { |
| 75 | ALOGE("Cannot create Codec2's IComponentStore V4L2 service."); |
| 76 | } else { |
| 77 | if (store->registerAsService("v4l2") != android::OK) { |
| 78 | ALOGE("Cannot register Codec2's " |
| 79 | "IComponentStore V4L2 service."); |
| 80 | } else { |
| 81 | ALOGI("Codec2's IComponentStore V4L2 service created."); |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | android::hardware::joinRpcThreadpool(); |
| 88 | return 0; |
| 89 | } |
| 90 | |