• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <codec2/hidl/1.0/ComponentStore.h>
21 #include <hidl/HidlTransportSupport.h>
22 #include <binder/ProcessState.h>
23 #include <minijail.h>
24 
25 #include <C2Component.h>
26 
27 // OmxStore is added for visibility by dumpstate.
28 #include <media/stagefright/omx/1.0/OmxStore.h>
29 
30 // This is created by module "codec2.vendor.base.policy". This can be modified.
31 static constexpr char kBaseSeccompPolicyPath[] =
32         "/vendor/etc/seccomp_policy/codec2.vendor.base.policy";
33 
34 // Additional device-specific seccomp permissions can be added in this file.
35 static constexpr char kExtSeccompPolicyPath[] =
36         "/vendor/etc/seccomp_policy/codec2.vendor.ext.policy";
37 
38 class DummyC2Store : public C2ComponentStore {
39 public:
40     DummyC2Store() = default;
41 
42     virtual ~DummyC2Store() override = default;
43 
getName() const44     virtual C2String getName() const override {
45         return "default";
46     }
47 
createComponent(C2String,std::shared_ptr<C2Component> * const)48     virtual c2_status_t createComponent(
49             C2String /*name*/,
50             std::shared_ptr<C2Component>* const /*component*/) override {
51         return C2_NOT_FOUND;
52     }
53 
createInterface(C2String,std::shared_ptr<C2ComponentInterface> * const)54     virtual c2_status_t createInterface(
55             C2String /* name */,
56             std::shared_ptr<C2ComponentInterface>* const /* interface */) override {
57         return C2_NOT_FOUND;
58     }
59 
60     virtual std::vector<std::shared_ptr<const C2Component::Traits>>
listComponents()61             listComponents() override {
62         return {};
63     }
64 
copyBuffer(std::shared_ptr<C2GraphicBuffer>,std::shared_ptr<C2GraphicBuffer>)65     virtual c2_status_t copyBuffer(
66             std::shared_ptr<C2GraphicBuffer> /* src */,
67             std::shared_ptr<C2GraphicBuffer> /* dst */) override {
68         return C2_OMITTED;
69     }
70 
query_sm(const std::vector<C2Param * > &,const std::vector<C2Param::Index> &,std::vector<std::unique_ptr<C2Param>> * const) const71     virtual c2_status_t query_sm(
72         const std::vector<C2Param*>& /* stackParams */,
73         const std::vector<C2Param::Index>& /* heapParamIndices */,
74         std::vector<std::unique_ptr<C2Param>>* const /* heapParams */) const override {
75         return C2_OMITTED;
76     }
77 
config_sm(const std::vector<C2Param * > &,std::vector<std::unique_ptr<C2SettingResult>> * const)78     virtual c2_status_t config_sm(
79             const std::vector<C2Param*>& /* params */,
80             std::vector<std::unique_ptr<C2SettingResult>>* const /* failures */) override {
81         return C2_OMITTED;
82     }
83 
getParamReflector() const84     virtual std::shared_ptr<C2ParamReflector> getParamReflector() const override {
85         return nullptr;
86     }
87 
querySupportedParams_nb(std::vector<std::shared_ptr<C2ParamDescriptor>> * const) const88     virtual c2_status_t querySupportedParams_nb(
89             std::vector<std::shared_ptr<C2ParamDescriptor>>* const /* params */) const override {
90         return C2_OMITTED;
91     }
92 
querySupportedValues_sm(std::vector<C2FieldSupportedValuesQuery> &) const93     virtual c2_status_t querySupportedValues_sm(
94             std::vector<C2FieldSupportedValuesQuery>& /* fields */) const override {
95         return C2_OMITTED;
96     }
97 };
98 
main(int,char **)99 int main(int /* argc */, char** /* argv */) {
100     ALOGD("hardware.google.media.c2@1.0-service starting...");
101 
102     signal(SIGPIPE, SIG_IGN);
103     android::SetUpMinijail(kBaseSeccompPolicyPath, kExtSeccompPolicyPath);
104 
105     // vndbinder is needed by BufferQueue.
106     android::ProcessState::initWithDriver("/dev/vndbinder");
107     android::ProcessState::self()->startThreadPool();
108 
109     // Extra threads may be needed to handle a stacked IPC sequence that
110     // contains alternating binder and hwbinder calls. (See b/35283480.)
111     android::hardware::configureRpcThreadpool(8, true /* callerWillJoin */);
112 
113     // Create IComponentStore service.
114     {
115         using namespace ::hardware::google::media::c2::V1_0;
116         android::sp<IComponentStore> store;
117 
118         // Vendor's TODO: Replace this with
119         // store = new utils::ComponentStore(
120         //         /* implementation of C2ComponentStore */);
121         ALOGD("Instantiating Codec2's dummy IComponentStore service...");
122         store = new utils::ComponentStore(
123                 std::make_shared<DummyC2Store>());
124 
125         if (store == nullptr) {
126             ALOGE("Cannot create Codec2's IComponentStore service.");
127         } else {
128             if (store->registerAsService("default") != android::OK) {
129                 ALOGE("Cannot register Codec2's "
130                         "IComponentStore service.");
131             } else {
132                 ALOGI("Codec2's IComponentStore service created.");
133             }
134         }
135     }
136 
137     // Register IOmxStore service.
138     {
139         using namespace ::android::hardware::media::omx::V1_0;
140         android::sp<IOmxStore> omxStore = new implementation::OmxStore();
141         if (omxStore == nullptr) {
142             ALOGE("Cannot create IOmxStore HAL service.");
143         } else if (omxStore->registerAsService() != android::OK) {
144             ALOGE("Cannot register IOmxStore HAL service.");
145         }
146     }
147 
148     android::hardware::joinRpcThreadpool();
149     return 0;
150 }
151