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 <android-base/logging.h>
19
20 // from LOCAL_C_INCLUDES
21 #include "minijail.h"
22
23 #include <binder/ProcessState.h>
24 #include <hidl/HidlTransportSupport.h>
25 #include <media/stagefright/omx/1.0/Omx.h>
26 #include <media/stagefright/omx/1.0/OmxStore.h>
27
28 #include <dlfcn.h>
29
30 using namespace android;
31
32 // Must match location in Android.mk.
33 static const char kSystemSeccompPolicyPath[] =
34 "/system/etc/seccomp_policy/mediacodec.policy";
35 static const char kVendorSeccompPolicyPath[] =
36 "/vendor/etc/seccomp_policy/mediacodec.policy";
37
main(int argc __unused,char ** argv)38 int main(int argc __unused, char** argv)
39 {
40 strcpy(argv[0], "media.codec");
41 LOG(INFO) << "mediacodecservice starting";
42 signal(SIGPIPE, SIG_IGN);
43 SetUpMinijail(kSystemSeccompPolicyPath, kVendorSeccompPolicyPath);
44
45 android::ProcessState::initWithDriver("/dev/vndbinder");
46 android::ProcessState::self()->startThreadPool();
47
48 ::android::hardware::configureRpcThreadpool(64, false);
49
50 // Default codec services
51 using namespace ::android::hardware::media::omx::V1_0;
52 sp<IOmx> omx = new implementation::Omx();
53 if (omx == nullptr) {
54 LOG(ERROR) << "Cannot create IOmx HAL service.";
55 } else if (omx->registerAsService() != OK) {
56 LOG(ERROR) << "Cannot register IOmx HAL service.";
57 } else {
58 LOG(INFO) << "IOmx HAL service created.";
59 }
60 sp<IOmxStore> omxStore = new implementation::OmxStore(omx);
61 if (omxStore == nullptr) {
62 LOG(ERROR) << "Cannot create IOmxStore HAL service.";
63 } else if (omxStore->registerAsService() != OK) {
64 LOG(ERROR) << "Cannot register IOmxStore HAL service.";
65 }
66
67 ::android::hardware::joinRpcThreadpool();
68 }
69