blob: 688c651c09586f30bc34ab09147135b285226e3e [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 Vongmasa033975f2016-12-27 03:14:55 +070034#include <android/hardware/media/omx/1.0/IOmx.h>
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080035#include <hidl/HidlTransportSupport.h>
Pawin Vongmasa0d3a5ed2017-02-22 03:19:35 -080036#include <omx/hal/1.0/impl/Omx.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.
41static const char kSeccompPolicyPath[] = "/system/etc/seccomp_policy/mediacodec-seccomp.policy";
42
Marco Nelissen1900e772016-02-02 16:12:16 -080043int main(int argc __unused, char** argv)
44{
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050045 LOG(INFO) << "mediacodecservice starting";
Marco Nelissen1900e772016-02-02 16:12:16 -080046 signal(SIGPIPE, SIG_IGN);
Jorge Lucangeli Obes80959a72017-02-14 15:49:33 -050047 SetUpMinijail(kSeccompPolicyPath, std::string());
Marco Nelissen1900e772016-02-02 16:12:16 -080048
49 strcpy(argv[0], "media.codec");
Pawin Vongmasa033975f2016-12-27 03:14:55 +070050
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080051 ::android::hardware::configureRpcThreadpool(64, false);
52 sp<ProcessState> proc(ProcessState::self());
53
54 int32_t trebleOmx = property_get_int32("persist.media.treble_omx", -1);
55 if ((trebleOmx == 1) || ((trebleOmx == -1) &&
56 property_get_bool("persist.hal.binderization", 0))) {
Pawin Vongmasa033975f2016-12-27 03:14:55 +070057 using namespace ::android::hardware::media::omx::V1_0;
Pawin Vongmasa0d3a5ed2017-02-22 03:19:35 -080058 sp<IOmx> omx = new implementation::Omx();
Pawin Vongmasa033975f2016-12-27 03:14:55 +070059 if (omx == nullptr) {
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050060 LOG(ERROR) << "Cannot create a Treble IOmx service.";
Pawin Vongmasa0d3a5ed2017-02-22 03:19:35 -080061 } else if (omx->registerAsService() != OK) {
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050062 LOG(ERROR) << "Cannot register a Treble IOmx service.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070063 } else {
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080064 LOG(INFO) << "Treble IOmx service created.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070065 }
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080066 } else {
67 MediaCodecService::instantiate();
68 LOG(INFO) << "Non-Treble IOMX service created.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070069 }
70
Marco Nelissen1900e772016-02-02 16:12:16 -080071 ProcessState::self()->startThreadPool();
72 IPCThreadState::self()->joinThreadPool();
73}