blob: 983bbba0daefa13cb4da0ae801994c9f0692a8ff [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 Vongmasa033975f2016-12-27 03:14:55 +070036
Marco Nelissen1900e772016-02-02 16:12:16 -080037using namespace android;
38
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050039// Must match location in Android.mk.
40static const char kSeccompPolicyPath[] = "/system/etc/seccomp_policy/mediacodec-seccomp.policy";
41
Marco Nelissen1900e772016-02-02 16:12:16 -080042int main(int argc __unused, char** argv)
43{
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050044 LOG(INFO) << "mediacodecservice starting";
Marco Nelissen1900e772016-02-02 16:12:16 -080045 signal(SIGPIPE, SIG_IGN);
Jorge Lucangeli Obes80959a72017-02-14 15:49:33 -050046 SetUpMinijail(kSeccompPolicyPath, std::string());
Marco Nelissen1900e772016-02-02 16:12:16 -080047
48 strcpy(argv[0], "media.codec");
Pawin Vongmasa033975f2016-12-27 03:14:55 +070049
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080050 ::android::hardware::configureRpcThreadpool(64, false);
51 sp<ProcessState> proc(ProcessState::self());
52
53 int32_t trebleOmx = property_get_int32("persist.media.treble_omx", -1);
54 if ((trebleOmx == 1) || ((trebleOmx == -1) &&
Steven Moreland7e0c3c32017-02-22 21:15:02 -080055 property_get_bool("persist.hal.binderization", 0))) {
Pawin Vongmasa033975f2016-12-27 03:14:55 +070056 using namespace ::android::hardware::media::omx::V1_0;
57 sp<IOmx> omx = IOmx::getService(true);
58 if (omx == nullptr) {
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050059 LOG(ERROR) << "Cannot create a Treble IOmx service.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070060 } else if (omx->registerAsService("default") != OK) {
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050061 LOG(ERROR) << "Cannot register a Treble IOmx service.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070062 } else {
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080063 LOG(INFO) << "Treble IOmx service created.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070064 }
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080065 } else {
66 MediaCodecService::instantiate();
67 LOG(INFO) << "Non-Treble IOMX service created.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070068 }
69
Marco Nelissen1900e772016-02-02 16:12:16 -080070 ProcessState::self()->startThreadPool();
71 IPCThreadState::self()->joinThreadPool();
72}