| 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 |  | 
|  | 40 | int main(int argc __unused, char** /*argv*/) | 
|  | 41 | { | 
|  | 42 | LOG(INFO) << "media swcodec service starting"; | 
|  | 43 | signal(SIGPIPE, SIG_IGN); | 
|  | 44 | SetUpMinijail(kSystemSeccompPolicyPath, kVendorSeccompPolicyPath); | 
|  | 45 |  | 
| Chong Zhang | ea788f7 | 2018-10-12 14:44:24 -0700 | [diff] [blame^] | 46 | std::string value = base::GetProperty("ro.build.type", "unknown"); | 
|  | 47 | if (value == "userdebug" || value == "eng") { | 
|  | 48 | media::MediaCodecUpdateService::instantiate(); | 
|  | 49 | } | 
|  | 50 |  | 
| Chong Zhang | 8f91543 | 2018-09-05 11:17:17 -0700 | [diff] [blame] | 51 | android::ProcessState::self()->startThreadPool(); | 
|  | 52 |  | 
|  | 53 | ::android::hardware::configureRpcThreadpool(64, false); | 
|  | 54 |  | 
|  | 55 | // Registration of customized codec services | 
|  | 56 | void *registrantLib = dlopen( | 
|  | 57 | "libmedia_codecserviceregistrant.so", | 
|  | 58 | RTLD_NOW | RTLD_LOCAL); | 
|  | 59 | if (registrantLib) { | 
|  | 60 | RegisterCodecServicesFunc registerCodecServices = | 
|  | 61 | reinterpret_cast<RegisterCodecServicesFunc>( | 
|  | 62 | dlsym(registrantLib, "RegisterCodecServices")); | 
|  | 63 | if (registerCodecServices) { | 
|  | 64 | registerCodecServices(); | 
|  | 65 | } else { | 
|  | 66 | LOG(WARNING) << "Cannot register codec services " | 
|  | 67 | "-- corrupted library."; | 
|  | 68 | } | 
|  | 69 | } else { | 
|  | 70 | LOG(ERROR) << "Cannot find codec service registrant."; | 
|  | 71 | } | 
|  | 72 |  | 
|  | 73 | ::android::hardware::joinRpcThreadpool(); | 
|  | 74 | } |