blob: c59944ac4ca20301a90e826be578ab55a2ed63e9 [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
Marco Nelissen1900e772016-02-02 16:12:16 -080018#include <fcntl.h>
19#include <sys/prctl.h>
20#include <sys/wait.h>
21#include <binder/IPCThreadState.h>
22#include <binder/ProcessState.h>
23#include <binder/IServiceManager.h>
Pawin Vongmasa033975f2016-12-27 03:14:55 +070024#include <cutils/properties.h>
Marco Nelissen1900e772016-02-02 16:12:16 -080025
Jorge Lucangeli Obes80959a72017-02-14 15:49:33 -050026#include <string>
27
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050028#include <android-base/logging.h>
29
Marco Nelissen1900e772016-02-02 16:12:16 -080030// from LOCAL_C_INCLUDES
31#include "MediaCodecService.h"
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050032#include "minijail.h"
Marco Nelissen1900e772016-02-02 16:12:16 -080033
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080034#include <hidl/HidlTransportSupport.h>
Pawin Vongmasa04563aa2017-03-09 07:02:01 -080035#include <omx/1.0/Omx.h>
Pawin Vongmasa52257b72017-04-25 05:06:20 -070036#include <omx/1.0/OmxStore.h>
Pawin Vongmasa033975f2016-12-27 03:14:55 +070037
Marco Nelissen1900e772016-02-02 16:12:16 -080038using namespace android;
39
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050040// Must match location in Android.mk.
Jeff Vander Stoep79234e42017-02-23 10:03:30 -080041static const char kSystemSeccompPolicyPath[] =
42 "/system/etc/seccomp_policy/mediacodec.policy";
43static const char kVendorSeccompPolicyPath[] =
44 "/vendor/etc/seccomp_policy/mediacodec.policy";
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050045
Marco Nelissen1900e772016-02-02 16:12:16 -080046int main(int argc __unused, char** argv)
47{
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050048 LOG(INFO) << "mediacodecservice starting";
Iliyan Malchev6772cfb2017-04-11 20:19:36 -070049 bool treble = property_get_bool("persist.media.treble_omx", true);
50 if (treble) {
51 android::ProcessState::initWithDriver("/dev/vndbinder");
52 }
53
Marco Nelissen1900e772016-02-02 16:12:16 -080054 signal(SIGPIPE, SIG_IGN);
Jeff Vander Stoep79234e42017-02-23 10:03:30 -080055 SetUpMinijail(kSystemSeccompPolicyPath, kVendorSeccompPolicyPath);
Marco Nelissen1900e772016-02-02 16:12:16 -080056
57 strcpy(argv[0], "media.codec");
Pawin Vongmasa033975f2016-12-27 03:14:55 +070058
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080059 ::android::hardware::configureRpcThreadpool(64, false);
60 sp<ProcessState> proc(ProcessState::self());
61
Iliyan Malchev6772cfb2017-04-11 20:19:36 -070062 if (treble) {
Pawin Vongmasa033975f2016-12-27 03:14:55 +070063 using namespace ::android::hardware::media::omx::V1_0;
Pawin Vongmasa52257b72017-04-25 05:06:20 -070064 sp<IOmxStore> omxStore = new implementation::OmxStore();
65 if (omxStore == nullptr) {
66 LOG(ERROR) << "Cannot create IOmxStore HAL service.";
67 } else if (omxStore->registerAsService() != OK) {
68 LOG(ERROR) << "Cannot register IOmxStore HAL service.";
Pawin Vongmasa4271c822017-04-26 21:24:30 -070069 }
70 sp<IOmx> omx = new implementation::Omx();
71 if (omx == nullptr) {
72 LOG(ERROR) << "Cannot create IOmx HAL service.";
73 } else if (omx->registerAsService() != OK) {
74 LOG(ERROR) << "Cannot register IOmx HAL service.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070075 } else {
Pawin Vongmasa4271c822017-04-26 21:24:30 -070076 LOG(INFO) << "Treble OMX service created.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070077 }
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080078 } else {
79 MediaCodecService::instantiate();
Pawin Vongmasa52257b72017-04-25 05:06:20 -070080 LOG(INFO) << "Non-Treble OMX service created.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070081 }
82
Marco Nelissen1900e772016-02-02 16:12:16 -080083 ProcessState::self()->startThreadPool();
84 IPCThreadState::self()->joinThreadPool();
85}