xref: /aosp_15_r20/frameworks/av/services/mediacodec/main_codecservice.cpp (revision ec779b8e0859a360c3d303172224686826e6e0e1)
1*ec779b8eSAndroid Build Coastguard Worker /*
2*ec779b8eSAndroid Build Coastguard Worker **
3*ec779b8eSAndroid Build Coastguard Worker ** Copyright 2016, The Android Open Source Project
4*ec779b8eSAndroid Build Coastguard Worker **
5*ec779b8eSAndroid Build Coastguard Worker ** Licensed under the Apache License, Version 2.0 (the "License");
6*ec779b8eSAndroid Build Coastguard Worker ** you may not use this file except in compliance with the License.
7*ec779b8eSAndroid Build Coastguard Worker ** You may obtain a copy of the License at
8*ec779b8eSAndroid Build Coastguard Worker **
9*ec779b8eSAndroid Build Coastguard Worker **     http://www.apache.org/licenses/LICENSE-2.0
10*ec779b8eSAndroid Build Coastguard Worker **
11*ec779b8eSAndroid Build Coastguard Worker ** Unless required by applicable law or agreed to in writing, software
12*ec779b8eSAndroid Build Coastguard Worker ** distributed under the License is distributed on an "AS IS" BASIS,
13*ec779b8eSAndroid Build Coastguard Worker ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*ec779b8eSAndroid Build Coastguard Worker ** See the License for the specific language governing permissions and
15*ec779b8eSAndroid Build Coastguard Worker ** limitations under the License.
16*ec779b8eSAndroid Build Coastguard Worker */
17*ec779b8eSAndroid Build Coastguard Worker 
18*ec779b8eSAndroid Build Coastguard Worker #include <android-base/logging.h>
19*ec779b8eSAndroid Build Coastguard Worker 
20*ec779b8eSAndroid Build Coastguard Worker // from LOCAL_C_INCLUDES
21*ec779b8eSAndroid Build Coastguard Worker #include "minijail.h"
22*ec779b8eSAndroid Build Coastguard Worker 
23*ec779b8eSAndroid Build Coastguard Worker #include <binder/ProcessState.h>
24*ec779b8eSAndroid Build Coastguard Worker #include <cutils/properties.h>
25*ec779b8eSAndroid Build Coastguard Worker #include <hidl/HidlTransportSupport.h>
26*ec779b8eSAndroid Build Coastguard Worker #include <media/stagefright/omx/1.0/Omx.h>
27*ec779b8eSAndroid Build Coastguard Worker #include <media/stagefright/omx/1.0/OmxStore.h>
28*ec779b8eSAndroid Build Coastguard Worker 
29*ec779b8eSAndroid Build Coastguard Worker #include <dlfcn.h>
30*ec779b8eSAndroid Build Coastguard Worker 
31*ec779b8eSAndroid Build Coastguard Worker using namespace android;
32*ec779b8eSAndroid Build Coastguard Worker 
33*ec779b8eSAndroid Build Coastguard Worker // Must match location in Android.mk.
34*ec779b8eSAndroid Build Coastguard Worker static const char kSystemSeccompPolicyPath[] =
35*ec779b8eSAndroid Build Coastguard Worker         "/system/etc/seccomp_policy/mediacodec.policy";
36*ec779b8eSAndroid Build Coastguard Worker static const char kVendorSeccompPolicyPath[] =
37*ec779b8eSAndroid Build Coastguard Worker         "/vendor/etc/seccomp_policy/mediacodec.policy";
38*ec779b8eSAndroid Build Coastguard Worker 
main(int argc __unused,char ** argv)39*ec779b8eSAndroid Build Coastguard Worker int main(int argc __unused, char** argv)
40*ec779b8eSAndroid Build Coastguard Worker {
41*ec779b8eSAndroid Build Coastguard Worker     strcpy(argv[0], "media.codec");
42*ec779b8eSAndroid Build Coastguard Worker     LOG(INFO) << "mediacodecservice starting";
43*ec779b8eSAndroid Build Coastguard Worker     signal(SIGPIPE, SIG_IGN);
44*ec779b8eSAndroid Build Coastguard Worker     SetUpMinijail(kSystemSeccompPolicyPath, kVendorSeccompPolicyPath);
45*ec779b8eSAndroid Build Coastguard Worker 
46*ec779b8eSAndroid Build Coastguard Worker     android::ProcessState::initWithDriver("/dev/vndbinder");
47*ec779b8eSAndroid Build Coastguard Worker     android::ProcessState::self()->startThreadPool();
48*ec779b8eSAndroid Build Coastguard Worker 
49*ec779b8eSAndroid Build Coastguard Worker     ::android::hardware::configureRpcThreadpool(64, false);
50*ec779b8eSAndroid Build Coastguard Worker 
51*ec779b8eSAndroid Build Coastguard Worker     // Default codec services
52*ec779b8eSAndroid Build Coastguard Worker     using namespace ::android::hardware::media::omx::V1_0;
53*ec779b8eSAndroid Build Coastguard Worker     sp<IOmx> omx = new implementation::Omx();
54*ec779b8eSAndroid Build Coastguard Worker     if (omx == nullptr) {
55*ec779b8eSAndroid Build Coastguard Worker         LOG(ERROR) << "Cannot create IOmx HAL service.";
56*ec779b8eSAndroid Build Coastguard Worker     } else if (omx->registerAsService() != OK) {
57*ec779b8eSAndroid Build Coastguard Worker         LOG(ERROR) << "Cannot register IOmx HAL service.";
58*ec779b8eSAndroid Build Coastguard Worker     } else {
59*ec779b8eSAndroid Build Coastguard Worker         LOG(INFO) << "IOmx HAL service created.";
60*ec779b8eSAndroid Build Coastguard Worker     }
61*ec779b8eSAndroid Build Coastguard Worker     sp<IOmxStore> omxStore = new implementation::OmxStore(
62*ec779b8eSAndroid Build Coastguard Worker             property_get_int64("vendor.media.omx", 1) ? omx : nullptr);
63*ec779b8eSAndroid Build Coastguard Worker     if (omxStore == nullptr) {
64*ec779b8eSAndroid Build Coastguard Worker         LOG(ERROR) << "Cannot create IOmxStore HAL service.";
65*ec779b8eSAndroid Build Coastguard Worker     } else if (omxStore->registerAsService() != OK) {
66*ec779b8eSAndroid Build Coastguard Worker         LOG(ERROR) << "Cannot register IOmxStore HAL service.";
67*ec779b8eSAndroid Build Coastguard Worker     }
68*ec779b8eSAndroid Build Coastguard Worker 
69*ec779b8eSAndroid Build Coastguard Worker     ::android::hardware::joinRpcThreadpool();
70*ec779b8eSAndroid Build Coastguard Worker }
71