Pawin Vongmasa | 20c40b3 | 2018-02-26 16:27:02 -0800 | [diff] [blame] | 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 "vendor.google.media.c2@1.0-service" |
| 19 | |
| 20 | #include <codec2/hidl/1.0/ComponentStore.h> |
| 21 | #include <hidl/HidlTransportSupport.h> |
| 22 | #include <minijail.h> |
| 23 | |
| 24 | #include <C2Component.h> |
| 25 | |
| 26 | // TODO: Remove this once "setenv()" call is removed. |
| 27 | #include <stdlib.h> |
| 28 | |
| 29 | // This is created by module "codec2.vendor.base.policy". This can be modified. |
| 30 | static constexpr char kBaseSeccompPolicyPath[] = |
| 31 | "/vendor/etc/seccomp_policy/codec2.vendor.base.policy"; |
| 32 | |
| 33 | // Additional device-specific seccomp permissions can be added in this file. |
| 34 | static constexpr char kExtSeccompPolicyPath[] = |
| 35 | "/vendor/etc/seccomp_policy/codec2.vendor.ext.policy"; |
| 36 | |
| 37 | // TODO: Replace with a valid C2ComponentStore implementation. |
| 38 | class DummyC2Store : public C2ComponentStore { |
| 39 | public: |
| 40 | DummyC2Store() = default; |
| 41 | |
| 42 | virtual ~DummyC2Store() override = default; |
| 43 | |
| 44 | virtual C2String getName() const override { |
| 45 | return "default"; |
| 46 | } |
| 47 | |
| 48 | virtual c2_status_t createComponent( |
| 49 | C2String /*name*/, |
| 50 | std::shared_ptr<C2Component>* const /*component*/) override { |
| 51 | return C2_NOT_FOUND; |
| 52 | } |
| 53 | |
| 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>> |
| 61 | listComponents() override { |
| 62 | return {}; |
| 63 | } |
| 64 | |
| 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 | |
| 71 | 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 | |
| 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 | |
| 84 | virtual std::shared_ptr<C2ParamReflector> getParamReflector() const override { |
| 85 | return nullptr; |
| 86 | } |
| 87 | |
| 88 | virtual c2_status_t querySupportedParams_nb( |
| 89 | std::vector<std::shared_ptr<C2ParamDescriptor>>* const /* params */) const override { |
| 90 | return C2_OMITTED; |
| 91 | } |
| 92 | |
| 93 | virtual c2_status_t querySupportedValues_sm( |
| 94 | std::vector<C2FieldSupportedValuesQuery>& /* fields */) const override { |
| 95 | return C2_OMITTED; |
| 96 | } |
| 97 | }; |
| 98 | |
| 99 | int main(int /* argc */, char** /* argv */) { |
| 100 | ALOGD("vendor.google.media.c2@1.0-service starting..."); |
| 101 | |
| 102 | // TODO: Remove this when all the build settings and sepolicies are in place. |
| 103 | setenv("TREBLE_TESTING_OVERRIDE", "true", true); |
| 104 | |
| 105 | signal(SIGPIPE, SIG_IGN); |
| 106 | android::SetUpMinijail(kBaseSeccompPolicyPath, kExtSeccompPolicyPath); |
| 107 | |
| 108 | // Extra threads may be needed to handle a stacked IPC sequence that |
| 109 | // contains alternating binder and hwbinder calls. (See b/35283480.) |
| 110 | android::hardware::configureRpcThreadpool(8, true /* callerWillJoin */); |
| 111 | |
| 112 | // Create IComponentStore service. |
| 113 | { |
| 114 | using namespace ::vendor::google::media::c2::V1_0; |
| 115 | android::sp<IComponentStore> store = |
| 116 | new implementation::ComponentStore( |
| 117 | // TODO: Replace this with a valid C2ComponentStore |
| 118 | // implementation. |
| 119 | std::make_shared<DummyC2Store>()); |
| 120 | if (store == nullptr) { |
| 121 | ALOGE("Cannot create Codec2's IComponentStore service."); |
| 122 | } else { |
| 123 | if (store->registerAsService("default") != android::OK) { |
| 124 | ALOGE("Cannot register Codec2's " |
| 125 | "IComponentStore service."); |
| 126 | } else { |
| 127 | ALOGI("Codec2's IComponentStore service created."); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | android::hardware::joinRpcThreadpool(); |
| 133 | return 0; |
| 134 | } |
| 135 | |