blob: 6a82b1b6b818a74d0b2767e7aa999445900441a7 [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 Vongmasa847eaf42019-08-14 10:28:29 -070024#include <cutils/properties.h>
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080025#include <hidl/HidlTransportSupport.h>
Pawin Vongmasa255735a2017-07-19 11:24:56 -070026#include <media/stagefright/omx/1.0/Omx.h>
27#include <media/stagefright/omx/1.0/OmxStore.h>
Pawin Vongmasa033975f2016-12-27 03:14:55 +070028
Pawin Vongmasaa66243a2018-04-18 01:38:29 -070029#include <dlfcn.h>
30
Marco Nelissen1900e772016-02-02 16:12:16 -080031using namespace android;
32
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050033// Must match location in Android.mk.
Jeff Vander Stoep79234e42017-02-23 10:03:30 -080034static const char kSystemSeccompPolicyPath[] =
35 "/system/etc/seccomp_policy/mediacodec.policy";
36static const char kVendorSeccompPolicyPath[] =
37 "/vendor/etc/seccomp_policy/mediacodec.policy";
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050038
Marco Nelissen1900e772016-02-02 16:12:16 -080039int main(int argc __unused, char** argv)
40{
Pawin Vongmasae7b89422017-11-16 19:33:39 -080041 strcpy(argv[0], "media.codec");
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050042 LOG(INFO) << "mediacodecservice starting";
Marco Nelissen1900e772016-02-02 16:12:16 -080043 signal(SIGPIPE, SIG_IGN);
Jeff Vander Stoep79234e42017-02-23 10:03:30 -080044 SetUpMinijail(kSystemSeccompPolicyPath, kVendorSeccompPolicyPath);
Marco Nelissen1900e772016-02-02 16:12:16 -080045
Pawin Vongmasae7b89422017-11-16 19:33:39 -080046 android::ProcessState::initWithDriver("/dev/vndbinder");
47 android::ProcessState::self()->startThreadPool();
Pawin Vongmasa033975f2016-12-27 03:14:55 +070048
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080049 ::android::hardware::configureRpcThreadpool(64, false);
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080050
Chong Zhang8f915432018-09-05 11:17:17 -070051 // Default codec services
52 using namespace ::android::hardware::media::omx::V1_0;
Chong Zhang8f915432018-09-05 11:17:17 -070053 sp<IOmx> omx = new implementation::Omx();
54 if (omx == nullptr) {
55 LOG(ERROR) << "Cannot create IOmx HAL service.";
56 } else if (omx->registerAsService() != OK) {
57 LOG(ERROR) << "Cannot register IOmx HAL service.";
Pawin Vongmasa9c47c972017-02-08 04:09:38 -080058 } else {
Chong Zhang8f915432018-09-05 11:17:17 -070059 LOG(INFO) << "IOmx HAL service created.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070060 }
Pawin Vongmasa847eaf42019-08-14 10:28:29 -070061 sp<IOmxStore> omxStore = new implementation::OmxStore(
62 property_get_int64("vendor.media.omx", 1) ? omx : nullptr);
Lajos Molnar3c3d1d22019-04-08 17:22:26 -070063 if (omxStore == nullptr) {
64 LOG(ERROR) << "Cannot create IOmxStore HAL service.";
65 } else if (omxStore->registerAsService() != OK) {
66 LOG(ERROR) << "Cannot register IOmxStore HAL service.";
67 }
Pawin Vongmasa033975f2016-12-27 03:14:55 +070068
Pawin Vongmasae7b89422017-11-16 19:33:39 -080069 ::android::hardware::joinRpcThreadpool();
Marco Nelissen1900e772016-02-02 16:12:16 -080070}