1/*
2**
3** Copyright 2016, The Android Open Source Project
4**
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
18#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>
24#include <cutils/properties.h>
25
26#include <string>
27
28#include <android-base/logging.h>
29
30// from LOCAL_C_INCLUDES
31#include "MediaCodecService.h"
32#include "minijail.h"
33
34#include <hidl/HidlTransportSupport.h>
35#include <omx/1.0/Omx.h>
36#include <omx/1.0/OmxStore.h>
37
38using namespace android;
39
40// Must match location in Android.mk.
41static const char kSystemSeccompPolicyPath[] =
42        "/system/etc/seccomp_policy/mediacodec.policy";
43static const char kVendorSeccompPolicyPath[] =
44        "/vendor/etc/seccomp_policy/mediacodec.policy";
45
46int main(int argc __unused, char** argv)
47{
48    LOG(INFO) << "mediacodecservice starting";
49    bool treble = property_get_bool("persist.media.treble_omx", true);
50    if (treble) {
51      android::ProcessState::initWithDriver("/dev/vndbinder");
52    }
53
54    signal(SIGPIPE, SIG_IGN);
55    SetUpMinijail(kSystemSeccompPolicyPath, kVendorSeccompPolicyPath);
56
57    strcpy(argv[0], "media.codec");
58
59    ::android::hardware::configureRpcThreadpool(64, false);
60    sp<ProcessState> proc(ProcessState::self());
61
62    if (treble) {
63        using namespace ::android::hardware::media::omx::V1_0;
64        sp<IOmxStore> omxStore = new implementation::OmxStore();
65        if (omxStore == nullptr) {
66            LOG(ERROR) << "Cannot create IOmxStore HAL service.";
67        } else if (omxStore->registerAsService() != OK) {
68            LOG(ERROR) << "Cannot register IOmxStore HAL service.";
69        }
70        sp<IOmx> omx = new implementation::Omx();
71        if (omx == nullptr) {
72            LOG(ERROR) << "Cannot create IOmx HAL service.";
73        } else if (omx->registerAsService() != OK) {
74            LOG(ERROR) << "Cannot register IOmx HAL service.";
75        } else {
76            LOG(INFO) << "Treble OMX service created.";
77        }
78    } else {
79        MediaCodecService::instantiate();
80        LOG(INFO) << "Non-Treble OMX service created.";
81    }
82
83    ProcessState::self()->startThreadPool();
84    IPCThreadState::self()->joinThreadPool();
85}
86