blob: 3a4546b5df3ed1e88ba13726c05f747cb9017e6c [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 Vongmasa04563aa2017-03-09 07:02:01 -080036#include <omx/1.0/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.
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";
Marco Nelissen1900e772016-02-02 16:12:16 -080049 signal(SIGPIPE, SIG_IGN);
Jeff Vander Stoep79234e42017-02-23 10:03:30 -080050 SetUpMinijail(kSystemSeccompPolicyPath, kVendorSeccompPolicyPath);
Marco Nelissen1900e772016-02-02 16:12:16 -080051
52 strcpy(argv[0], "media.codec");
Pawin Vongmasa033975f2016-12-27 03:14:55 +070053
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080054 ::android::hardware::configureRpcThreadpool(64, false);
55 sp<ProcessState> proc(ProcessState::self());
56
Pawin Vongmasad4e9ca42017-03-29 17:24:56 -070057 if (property_get_bool("persist.media.treble_omx", true)) {
Pawin Vongmasa033975f2016-12-27 03:14:55 +070058 using namespace ::android::hardware::media::omx::V1_0;
Pawin Vongmasa0d3a5ed2017-02-22 03:19:35 -080059 sp<IOmx> omx = new implementation::Omx();
Pawin Vongmasa033975f2016-12-27 03:14:55 +070060 if (omx == nullptr) {
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050061 LOG(ERROR) << "Cannot create a Treble IOmx service.";
Pawin Vongmasa0d3a5ed2017-02-22 03:19:35 -080062 } else if (omx->registerAsService() != OK) {
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050063 LOG(ERROR) << "Cannot register a Treble IOmx service.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070064 } else {
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080065 LOG(INFO) << "Treble IOmx service created.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070066 }
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080067 } else {
68 MediaCodecService::instantiate();
69 LOG(INFO) << "Non-Treble IOMX service created.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070070 }
71
Marco Nelissen1900e772016-02-02 16:12:16 -080072 ProcessState::self()->startThreadPool();
73 IPCThreadState::self()->joinThreadPool();
74}