blob: 62c3dac2b6a6543a8e3c6709bd7790fe0753a51b [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
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050031#include "minijail.h"
Marco Nelissen1900e772016-02-02 16:12:16 -080032
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080033#include <hidl/HidlTransportSupport.h>
Pawin Vongmasa255735a2017-07-19 11:24:56 -070034#include <media/stagefright/omx/1.0/Omx.h>
35#include <media/stagefright/omx/1.0/OmxStore.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.
Jeff Vander Stoep79234e42017-02-23 10:03:30 -080040static const char kSystemSeccompPolicyPath[] =
41 "/system/etc/seccomp_policy/mediacodec.policy";
42static const char kVendorSeccompPolicyPath[] =
43 "/vendor/etc/seccomp_policy/mediacodec.policy";
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050044
Marco Nelissen1900e772016-02-02 16:12:16 -080045int main(int argc __unused, char** argv)
46{
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050047 LOG(INFO) << "mediacodecservice starting";
Pawin Vongmasa37c79ff2017-10-21 05:31:38 -070048 android::ProcessState::initWithDriver("/dev/vndbinder");
Iliyan Malchev6772cfb2017-04-11 20:19:36 -070049
Marco Nelissen1900e772016-02-02 16:12:16 -080050 signal(SIGPIPE, SIG_IGN);
Jeff Vander Stoep79234e42017-02-23 10:03:30 -080051 SetUpMinijail(kSystemSeccompPolicyPath, kVendorSeccompPolicyPath);
Marco Nelissen1900e772016-02-02 16:12:16 -080052
53 strcpy(argv[0], "media.codec");
Pawin Vongmasa033975f2016-12-27 03:14:55 +070054
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080055 ::android::hardware::configureRpcThreadpool(64, false);
56 sp<ProcessState> proc(ProcessState::self());
57
Pawin Vongmasa37c79ff2017-10-21 05:31:38 -070058 using namespace ::android::hardware::media::omx::V1_0;
59 sp<IOmxStore> omxStore = new implementation::OmxStore();
60 if (omxStore == nullptr) {
61 LOG(ERROR) << "Cannot create IOmxStore HAL service.";
62 } else if (omxStore->registerAsService() != OK) {
63 LOG(ERROR) << "Cannot register IOmxStore HAL service.";
64 }
65 sp<IOmx> omx = new implementation::Omx();
66 if (omx == nullptr) {
67 LOG(ERROR) << "Cannot create IOmx HAL service.";
68 } else if (omx->registerAsService() != OK) {
69 LOG(ERROR) << "Cannot register IOmx HAL service.";
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080070 } else {
Pawin Vongmasa37c79ff2017-10-21 05:31:38 -070071 LOG(INFO) << "IOmx HAL service created.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070072 }
73
Marco Nelissen1900e772016-02-02 16:12:16 -080074 ProcessState::self()->startThreadPool();
75 IPCThreadState::self()->joinThreadPool();
76}