blob: 79fea25e15365f27fe90b0cf14b1d30e40e185a8 [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
Kostya Kortchinsky21f08542018-12-18 07:39:15 -080040// Disable Scudo's mismatch allocation check, as it is being triggered
41// by some third party code.
42extern "C" const char *__scudo_default_options() {
43 return "DeallocationTypeMismatch=false";
44}
45
Chong Zhang8f915432018-09-05 11:17:17 -070046int 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 Zhangea788f72018-10-12 14:44:24 -070052 std::string value = base::GetProperty("ro.build.type", "unknown");
53 if (value == "userdebug" || value == "eng") {
54 media::MediaCodecUpdateService::instantiate();
55 }
56
Chong Zhang8f915432018-09-05 11:17:17 -070057 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}