blob: 6ffbd268a3c8ffd1bd65037d9c401d277d77ddda [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
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050018#include <android-base/logging.h>
19
Marco Nelissen1900e772016-02-02 16:12:16 -080020// from LOCAL_C_INCLUDES
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050021#include "minijail.h"
Marco Nelissen1900e772016-02-02 16:12:16 -080022
Pawin Vongmasae7b89422017-11-16 19:33:39 -080023#include <binder/ProcessState.h>
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080024#include <hidl/HidlTransportSupport.h>
Pawin Vongmasa255735a2017-07-19 11:24:56 -070025#include <media/stagefright/omx/1.0/Omx.h>
26#include <media/stagefright/omx/1.0/OmxStore.h>
Pawin Vongmasa033975f2016-12-27 03:14:55 +070027
Pawin Vongmasaa66243a2018-04-18 01:38:29 -070028#include <dlfcn.h>
29
Marco Nelissen1900e772016-02-02 16:12:16 -080030using namespace android;
31
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050032// Must match location in Android.mk.
Jeff Vander Stoep79234e42017-02-23 10:03:30 -080033static const char kSystemSeccompPolicyPath[] =
34 "/system/etc/seccomp_policy/mediacodec.policy";
35static const char kVendorSeccompPolicyPath[] =
36 "/vendor/etc/seccomp_policy/mediacodec.policy";
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050037
Marco Nelissen1900e772016-02-02 16:12:16 -080038int main(int argc __unused, char** argv)
39{
Pawin Vongmasae7b89422017-11-16 19:33:39 -080040 strcpy(argv[0], "media.codec");
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050041 LOG(INFO) << "mediacodecservice starting";
Marco Nelissen1900e772016-02-02 16:12:16 -080042 signal(SIGPIPE, SIG_IGN);
Jeff Vander Stoep79234e42017-02-23 10:03:30 -080043 SetUpMinijail(kSystemSeccompPolicyPath, kVendorSeccompPolicyPath);
Marco Nelissen1900e772016-02-02 16:12:16 -080044
Pawin Vongmasae7b89422017-11-16 19:33:39 -080045 android::ProcessState::initWithDriver("/dev/vndbinder");
46 android::ProcessState::self()->startThreadPool();
Pawin Vongmasa033975f2016-12-27 03:14:55 +070047
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080048 ::android::hardware::configureRpcThreadpool(64, false);
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080049
Chong Zhang8f915432018-09-05 11:17:17 -070050 // Default codec services
51 using namespace ::android::hardware::media::omx::V1_0;
52 sp<IOmxStore> omxStore = new implementation::OmxStore();
53 if (omxStore == nullptr) {
54 LOG(ERROR) << "Cannot create IOmxStore HAL service.";
55 } else if (omxStore->registerAsService() != OK) {
56 LOG(ERROR) << "Cannot register IOmxStore HAL service.";
57 }
58 sp<IOmx> omx = new implementation::Omx();
59 if (omx == nullptr) {
60 LOG(ERROR) << "Cannot create IOmx HAL service.";
61 } else if (omx->registerAsService() != OK) {
62 LOG(ERROR) << "Cannot register IOmx HAL service.";
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080063 } else {
Chong Zhang8f915432018-09-05 11:17:17 -070064 LOG(INFO) << "IOmx HAL service created.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070065 }
66
Pawin Vongmasae7b89422017-11-16 19:33:39 -080067 ::android::hardware::joinRpcThreadpool();
Marco Nelissen1900e772016-02-02 16:12:16 -080068}