blob: f5940965480dc545c37cf29d57b5fe24e9540e40 [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 Obesfbfb8e82017-02-14 10:33:41 -050026#include <android-base/logging.h>
27
Marco Nelissen1900e772016-02-02 16:12:16 -080028// from LOCAL_C_INCLUDES
29#include "MediaCodecService.h"
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050030#include "minijail.h"
Marco Nelissen1900e772016-02-02 16:12:16 -080031
Pawin Vongmasa033975f2016-12-27 03:14:55 +070032#include <android/hardware/media/omx/1.0/IOmx.h>
33
Marco Nelissen1900e772016-02-02 16:12:16 -080034using namespace android;
35
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050036// Must match location in Android.mk.
37static const char kSeccompPolicyPath[] = "/system/etc/seccomp_policy/mediacodec-seccomp.policy";
38
Marco Nelissen1900e772016-02-02 16:12:16 -080039int main(int argc __unused, char** argv)
40{
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);
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050043 SetUpMinijail(kSeccompPolicyPath);
Marco Nelissen1900e772016-02-02 16:12:16 -080044
45 strcpy(argv[0], "media.codec");
46 sp<ProcessState> proc(ProcessState::self());
47 sp<IServiceManager> sm = defaultServiceManager();
48 MediaCodecService::instantiate();
Pawin Vongmasa033975f2016-12-27 03:14:55 +070049
50 // Treble
51 bool useTrebleOmx = bool(property_get_bool("debug.treble_omx", 0));
52 if (useTrebleOmx) {
53 using namespace ::android::hardware::media::omx::V1_0;
54 sp<IOmx> omx = IOmx::getService(true);
55 if (omx == nullptr) {
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050056 LOG(ERROR) << "Cannot create a Treble IOmx service.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070057 } else if (omx->registerAsService("default") != OK) {
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050058 LOG(ERROR) << "Cannot register a Treble IOmx service.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070059 } else {
Jorge Lucangeli Obesfbfb8e82017-02-14 10:33:41 -050060 LOG(VERBOSE) << "Treble IOmx service created.";
Pawin Vongmasa033975f2016-12-27 03:14:55 +070061 }
62 }
63
Marco Nelissen1900e772016-02-02 16:12:16 -080064 ProcessState::self()->startThreadPool();
65 IPCThreadState::self()->joinThreadPool();
66}