1 /*
2 **
3 ** Copyright 2016, 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
23 #include <binder/ProcessState.h>
24 #include <hidl/HidlTransportSupport.h>
25 #include <media/stagefright/omx/1.0/Omx.h>
26 #include <media/stagefright/omx/1.0/OmxStore.h>
27
28 #include <media/CodecServiceRegistrant.h>
29 #include <dlfcn.h>
30
31 using namespace android;
32
33 // Must match location in Android.mk.
34 static const char kSystemSeccompPolicyPath[] =
35 "/system/etc/seccomp_policy/mediacodec.policy";
36 static const char kVendorSeccompPolicyPath[] =
37 "/vendor/etc/seccomp_policy/mediacodec.policy";
38
main(int argc __unused,char ** argv)39 int main(int argc __unused, char** argv)
40 {
41 strcpy(argv[0], "media.codec");
42 LOG(INFO) << "mediacodecservice starting";
43 signal(SIGPIPE, SIG_IGN);
44 SetUpMinijail(kSystemSeccompPolicyPath, kVendorSeccompPolicyPath);
45
46 android::ProcessState::initWithDriver("/dev/vndbinder");
47 android::ProcessState::self()->startThreadPool();
48
49 ::android::hardware::configureRpcThreadpool(64, false);
50
51 // Registration of customized codec services
52 void *registrantLib = dlopen(
53 "libmedia_codecserviceregistrant.so",
54 RTLD_NOW | RTLD_LOCAL);
55 if (registrantLib) {
56 RegisterCodecServicesFunc registerCodecServices =
57 reinterpret_cast<RegisterCodecServicesFunc>(
58 dlsym(registrantLib, "RegisterCodecServices"));
59 if (registerCodecServices) {
60 registerCodecServices();
61 } else {
62 LOG(WARNING) << "Cannot register additional services "
63 "-- corrupted library.";
64 }
65 } else {
66 // Default codec services
67 using namespace ::android::hardware::media::omx::V1_0;
68 sp<IOmxStore> omxStore = new implementation::OmxStore();
69 if (omxStore == nullptr) {
70 LOG(ERROR) << "Cannot create IOmxStore HAL service.";
71 } else if (omxStore->registerAsService() != OK) {
72 LOG(ERROR) << "Cannot register IOmxStore HAL service.";
73 }
74 sp<IOmx> omx = new implementation::Omx();
75 if (omx == nullptr) {
76 LOG(ERROR) << "Cannot create IOmx HAL service.";
77 } else if (omx->registerAsService() != OK) {
78 LOG(ERROR) << "Cannot register IOmx HAL service.";
79 } else {
80 LOG(INFO) << "IOmx HAL service created.";
81 }
82 }
83
84 ::android::hardware::joinRpcThreadpool();
85 }
86