Chong Zhang | 8f91543 | 2018-09-05 11:17:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2018, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <android-base/logging.h> |
| 19 | |
| 20 | // from LOCAL_C_INCLUDES |
| 21 | #include "minijail.h" |
| 22 | |
Chong Zhang | ea788f7 | 2018-10-12 14:44:24 -0700 | [diff] [blame] | 23 | #include <android-base/properties.h> |
Chong Zhang | 8f91543 | 2018-09-05 11:17:17 -0700 | [diff] [blame] | 24 | #include <binder/ProcessState.h> |
Chong Zhang | ea788f7 | 2018-10-12 14:44:24 -0700 | [diff] [blame] | 25 | #include <dlfcn.h> |
Chong Zhang | 8f91543 | 2018-09-05 11:17:17 -0700 | [diff] [blame] | 26 | #include <hidl/HidlTransportSupport.h> |
| 27 | #include <media/CodecServiceRegistrant.h> |
Chong Zhang | ea788f7 | 2018-10-12 14:44:24 -0700 | [diff] [blame] | 28 | |
| 29 | #include "MediaCodecUpdateService.h" |
Chong Zhang | 8f91543 | 2018-09-05 11:17:17 -0700 | [diff] [blame] | 30 | |
| 31 | using namespace android; |
| 32 | |
| 33 | // TODO: replace policy with software codec-only policies |
| 34 | // Must match location in Android.mk. |
| 35 | static const char kSystemSeccompPolicyPath[] = |
| 36 | "/system/etc/seccomp_policy/mediacodec.policy"; |
| 37 | static const char kVendorSeccompPolicyPath[] = |
| 38 | "/vendor/etc/seccomp_policy/mediacodec.policy"; |
| 39 | |
Kostya Kortchinsky | 21f0854 | 2018-12-18 07:39:15 -0800 | [diff] [blame^] | 40 | // Disable Scudo's mismatch allocation check, as it is being triggered |
| 41 | // by some third party code. |
| 42 | extern "C" const char *__scudo_default_options() { |
| 43 | return "DeallocationTypeMismatch=false"; |
| 44 | } |
| 45 | |
Chong Zhang | 8f91543 | 2018-09-05 11:17:17 -0700 | [diff] [blame] | 46 | int main(int argc __unused, char** /*argv*/) |
| 47 | { |
| 48 | LOG(INFO) << "media swcodec service starting"; |
| 49 | signal(SIGPIPE, SIG_IGN); |
| 50 | SetUpMinijail(kSystemSeccompPolicyPath, kVendorSeccompPolicyPath); |
| 51 | |
Chong Zhang | ea788f7 | 2018-10-12 14:44:24 -0700 | [diff] [blame] | 52 | std::string value = base::GetProperty("ro.build.type", "unknown"); |
| 53 | if (value == "userdebug" || value == "eng") { |
| 54 | media::MediaCodecUpdateService::instantiate(); |
| 55 | } |
| 56 | |
Chong Zhang | 8f91543 | 2018-09-05 11:17:17 -0700 | [diff] [blame] | 57 | android::ProcessState::self()->startThreadPool(); |
| 58 | |
| 59 | ::android::hardware::configureRpcThreadpool(64, false); |
| 60 | |
| 61 | // Registration of customized codec services |
| 62 | void *registrantLib = dlopen( |
| 63 | "libmedia_codecserviceregistrant.so", |
| 64 | RTLD_NOW | RTLD_LOCAL); |
| 65 | if (registrantLib) { |
| 66 | RegisterCodecServicesFunc registerCodecServices = |
| 67 | reinterpret_cast<RegisterCodecServicesFunc>( |
| 68 | dlsym(registrantLib, "RegisterCodecServices")); |
| 69 | if (registerCodecServices) { |
| 70 | registerCodecServices(); |
| 71 | } else { |
| 72 | LOG(WARNING) << "Cannot register codec services " |
| 73 | "-- corrupted library."; |
| 74 | } |
| 75 | } else { |
| 76 | LOG(ERROR) << "Cannot find codec service registrant."; |
| 77 | } |
| 78 | |
| 79 | ::android::hardware::joinRpcThreadpool(); |
| 80 | } |