blob: 386abb236b3084c5861258c46b071efdff474882 [file] [log] [blame]
Chong Zhang8f915432018-09-05 11:17:17 -07001/*
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 Zhangea788f72018-10-12 14:44:24 -070023#include <android-base/properties.h>
Chong Zhang8f915432018-09-05 11:17:17 -070024#include <binder/ProcessState.h>
Chong Zhangea788f72018-10-12 14:44:24 -070025#include <dlfcn.h>
Chong Zhang8f915432018-09-05 11:17:17 -070026#include <hidl/HidlTransportSupport.h>
27#include <media/CodecServiceRegistrant.h>
Chong Zhangea788f72018-10-12 14:44:24 -070028
29#include "MediaCodecUpdateService.h"
Chong Zhang8f915432018-09-05 11:17:17 -070030
31using namespace android;
32
33// TODO: replace policy with software codec-only policies
34// Must match location in Android.mk.
35static const char kSystemSeccompPolicyPath[] =
36 "/system/etc/seccomp_policy/mediacodec.policy";
37static const char kVendorSeccompPolicyPath[] =
38 "/vendor/etc/seccomp_policy/mediacodec.policy";
39
40int 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 Zhangea788f72018-10-12 14:44:24 -070046 std::string value = base::GetProperty("ro.build.type", "unknown");
47 if (value == "userdebug" || value == "eng") {
48 media::MediaCodecUpdateService::instantiate();
49 }
50
Chong Zhang8f915432018-09-05 11:17:17 -070051 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}