blob: c4e4cffdf7def31f4927bd56f592fc3d4dfbcb24 [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";
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 Vongmasa0d3a5ed2017-02-22 03:19:35 -080064 sp<IOmx> omx = new implementation::Omx();
Pawin Vongmasa033975f2016-12-27 03:14:55 +070065 if (omx == nullptr) {
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050066 LOG(ERROR) << "Cannot create a Treble IOmx service.";
Pawin Vongmasa0d3a5ed2017-02-22 03:19:35 -080067 } else if (omx->registerAsService() != OK) {
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050068 LOG(ERROR) << "Cannot register a Treble IOmx service.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070069 } else {
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080070 LOG(INFO) << "Treble IOmx service created.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070071 }
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080072 } else {
73 MediaCodecService::instantiate();
74 LOG(INFO) << "Non-Treble IOMX service created.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070075 }
76
Marco Nelissen1900e772016-02-02 16:12:16 -080077 ProcessState::self()->startThreadPool();
78 IPCThreadState::self()->joinThreadPool();
79}