1 /*
2 * Copyright 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 //#define LOG_NDEBUG 0
18 #define LOG_TAG "hardware.google.media.c2@1.0-service"
19
20 // Vendor's TODO: Remove this when V4L2 service is removed. (See below.)
21 // The dependency on libv4l2_c2componentstore should be removed as well.
22 #include <C2V4l2Support.h>
23
24 // Vendor's TODO: Remove this if property_get_bool is removed. (See below.)
25 // The dependency on libcutils should be removed as well.
26 #include <cutils/properties.h>
27
28 #include <codec2/hidl/1.0/ComponentStore.h>
29 #include <hidl/HidlTransportSupport.h>
30 #include <binder/ProcessState.h>
31 #include <minijail.h>
32
33 #include <C2Component.h>
34
35 // OmxStore is added for visibility by dumpstate.
36 #include <media/stagefright/omx/1.0/OmxStore.h>
37
38 // This is created by module "codec2.vendor.base.policy". This can be modified.
39 static constexpr char kBaseSeccompPolicyPath[] =
40 "/vendor/etc/seccomp_policy/codec2.vendor.base.policy";
41
42 // Additional device-specific seccomp permissions can be added in this file.
43 static constexpr char kExtSeccompPolicyPath[] =
44 "/vendor/etc/seccomp_policy/codec2.vendor.ext.policy";
45
46 class DummyC2Store : public C2ComponentStore {
47 public:
48 DummyC2Store() = default;
49
50 virtual ~DummyC2Store() override = default;
51
getName() const52 virtual C2String getName() const override {
53 return "default";
54 }
55
createComponent(C2String,std::shared_ptr<C2Component> * const)56 virtual c2_status_t createComponent(
57 C2String /*name*/,
58 std::shared_ptr<C2Component>* const /*component*/) override {
59 return C2_NOT_FOUND;
60 }
61
createInterface(C2String,std::shared_ptr<C2ComponentInterface> * const)62 virtual c2_status_t createInterface(
63 C2String /* name */,
64 std::shared_ptr<C2ComponentInterface>* const /* interface */) override {
65 return C2_NOT_FOUND;
66 }
67
68 virtual std::vector<std::shared_ptr<const C2Component::Traits>>
listComponents()69 listComponents() override {
70 return {};
71 }
72
copyBuffer(std::shared_ptr<C2GraphicBuffer>,std::shared_ptr<C2GraphicBuffer>)73 virtual c2_status_t copyBuffer(
74 std::shared_ptr<C2GraphicBuffer> /* src */,
75 std::shared_ptr<C2GraphicBuffer> /* dst */) override {
76 return C2_OMITTED;
77 }
78
query_sm(const std::vector<C2Param * > &,const std::vector<C2Param::Index> &,std::vector<std::unique_ptr<C2Param>> * const) const79 virtual c2_status_t query_sm(
80 const std::vector<C2Param*>& /* stackParams */,
81 const std::vector<C2Param::Index>& /* heapParamIndices */,
82 std::vector<std::unique_ptr<C2Param>>* const /* heapParams */) const override {
83 return C2_OMITTED;
84 }
85
config_sm(const std::vector<C2Param * > &,std::vector<std::unique_ptr<C2SettingResult>> * const)86 virtual c2_status_t config_sm(
87 const std::vector<C2Param*>& /* params */,
88 std::vector<std::unique_ptr<C2SettingResult>>* const /* failures */) override {
89 return C2_OMITTED;
90 }
91
getParamReflector() const92 virtual std::shared_ptr<C2ParamReflector> getParamReflector() const override {
93 return nullptr;
94 }
95
querySupportedParams_nb(std::vector<std::shared_ptr<C2ParamDescriptor>> * const) const96 virtual c2_status_t querySupportedParams_nb(
97 std::vector<std::shared_ptr<C2ParamDescriptor>>* const /* params */) const override {
98 return C2_OMITTED;
99 }
100
querySupportedValues_sm(std::vector<C2FieldSupportedValuesQuery> &) const101 virtual c2_status_t querySupportedValues_sm(
102 std::vector<C2FieldSupportedValuesQuery>& /* fields */) const override {
103 return C2_OMITTED;
104 }
105 };
106
main(int,char **)107 int main(int /* argc */, char** /* argv */) {
108 ALOGD("hardware.google.media.c2@1.0-service starting...");
109
110 signal(SIGPIPE, SIG_IGN);
111 android::SetUpMinijail(kBaseSeccompPolicyPath, kExtSeccompPolicyPath);
112
113 // vndbinder is needed by BufferQueue.
114 android::ProcessState::initWithDriver("/dev/vndbinder");
115 android::ProcessState::self()->startThreadPool();
116
117 // Extra threads may be needed to handle a stacked IPC sequence that
118 // contains alternating binder and hwbinder calls. (See b/35283480.)
119 android::hardware::configureRpcThreadpool(8, true /* callerWillJoin */);
120
121 // Create IComponentStore service.
122 {
123 using namespace ::hardware::google::media::c2::V1_0;
124 android::sp<IComponentStore> store;
125
126 // Vendor's TODO: Replace this if...else block with
127 // store = new utils::ComponentStore(
128 // /* implementation of C2ComponentStore */);
129 if (property_get_bool("debug.stagefright.ccodec_v4l2", false)) {
130 ALOGD("Instantiating Codec2's V4L2 IComponentStore service...");
131 store = new utils::ComponentStore(
132 android::GetCodec2VDAComponentStore());
133 } else {
134 ALOGD("Instantiating Codec2's dummy IComponentStore service...");
135 store = new utils::ComponentStore(
136 std::make_shared<DummyC2Store>());
137 }
138
139 if (store == nullptr) {
140 ALOGE("Cannot create Codec2's IComponentStore service.");
141 } else {
142 if (store->registerAsService("default") != android::OK) {
143 ALOGE("Cannot register Codec2's "
144 "IComponentStore service.");
145 } else {
146 ALOGI("Codec2's IComponentStore service created.");
147 }
148 }
149 }
150
151 // Register IOmxStore service.
152 {
153 using namespace ::android::hardware::media::omx::V1_0;
154 android::sp<IOmxStore> omxStore = new implementation::OmxStore();
155 if (omxStore == nullptr) {
156 ALOGE("Cannot create IOmxStore HAL service.");
157 } else if (omxStore->registerAsService() != android::OK) {
158 ALOGE("Cannot register IOmxStore HAL service.");
159 }
160 }
161
162 android::hardware::joinRpcThreadpool();
163 return 0;
164 }
165
166