blob: 51619f625e7a60d409e8c65c8986373c813a4168 [file] [log] [blame]
Marco Nelissen1900e772016-02-02 16:12:16 -08001/*
2**
Jeff Vander Stoepc9ea2112016-02-17 10:52:20 -08003** Copyright 2016, The Android Open Source Project
Marco Nelissen1900e772016-02-02 16:12:16 -08004**
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
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050018#include <android-base/logging.h>
19
Marco Nelissen1900e772016-02-02 16:12:16 -080020// from LOCAL_C_INCLUDES
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050021#include "minijail.h"
Marco Nelissen1900e772016-02-02 16:12:16 -080022
Pawin Vongmasae7b89422017-11-16 19:33:39 -080023#include <binder/ProcessState.h>
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080024#include <hidl/HidlTransportSupport.h>
Pawin Vongmasa255735a2017-07-19 11:24:56 -070025#include <media/stagefright/omx/1.0/Omx.h>
26#include <media/stagefright/omx/1.0/OmxStore.h>
Pawin Vongmasa033975f2016-12-27 03:14:55 +070027
Pawin Vongmasaa66243a2018-04-18 01:38:29 -070028#include <media/CodecServiceRegistrant.h>
29#include <dlfcn.h>
30
Marco Nelissen1900e772016-02-02 16:12:16 -080031using namespace android;
32
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050033// Must match location in Android.mk.
Jeff Vander Stoep79234e42017-02-23 10:03:30 -080034static const char kSystemSeccompPolicyPath[] =
35 "/system/etc/seccomp_policy/mediacodec.policy";
36static const char kVendorSeccompPolicyPath[] =
37 "/vendor/etc/seccomp_policy/mediacodec.policy";
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050038
Marco Nelissen1900e772016-02-02 16:12:16 -080039int main(int argc __unused, char** argv)
40{
Pawin Vongmasae7b89422017-11-16 19:33:39 -080041 strcpy(argv[0], "media.codec");
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050042 LOG(INFO) << "mediacodecservice starting";
Marco Nelissen1900e772016-02-02 16:12:16 -080043 signal(SIGPIPE, SIG_IGN);
Jeff Vander Stoep79234e42017-02-23 10:03:30 -080044 SetUpMinijail(kSystemSeccompPolicyPath, kVendorSeccompPolicyPath);
Marco Nelissen1900e772016-02-02 16:12:16 -080045
Pawin Vongmasae7b89422017-11-16 19:33:39 -080046 android::ProcessState::initWithDriver("/dev/vndbinder");
47 android::ProcessState::self()->startThreadPool();
Pawin Vongmasa033975f2016-12-27 03:14:55 +070048
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080049 ::android::hardware::configureRpcThreadpool(64, false);
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080050
Pawin Vongmasaa66243a2018-04-18 01:38:29 -070051 // 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 }
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080065 } else {
Pawin Vongmasaa66243a2018-04-18 01:38:29 -070066 // 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 }
Pawin Vongmasa033975f2016-12-27 03:14:55 +070082 }
83
Pawin Vongmasae7b89422017-11-16 19:33:39 -080084 ::android::hardware::joinRpcThreadpool();
Marco Nelissen1900e772016-02-02 16:12:16 -080085}