/* * Copyright 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ //#define LOG_NDEBUG 0 #define LOG_TAG "android.hardware.media.c2@1.1-service" #include #include #include #include #include #include #include #include #include // This is the absolute on-device path of the prebuild_etc module // "android.hardware.media.c2@1.1-default-seccomp_policy" in Android.bp. static constexpr char kBaseSeccompPolicyPath[] = "/vendor/etc/seccomp_policy/" "android.hardware.media.c2@1.1-seccomp_policy"; // Additional seccomp permissions can be added in this file. // This file does not exist by default. static constexpr char kExtSeccompPolicyPath[] = "/vendor/etc/seccomp_policy/" "android.hardware.media.c2@1.1-extended-seccomp-policy"; class StoreImpl : public C2ComponentStore { public: StoreImpl() : mReflectorHelper(std::make_shared()), mInterface(mReflectorHelper) { } virtual ~StoreImpl() override = default; virtual C2String getName() const override { return "default"; } virtual c2_status_t createComponent( C2String /*name*/, std::shared_ptr* const /*component*/) override { return C2_NOT_FOUND; } virtual c2_status_t createInterface( C2String /* name */, std::shared_ptr* const /* interface */) override { return C2_NOT_FOUND; } virtual std::vector> listComponents() override { return {}; } virtual c2_status_t copyBuffer( std::shared_ptr /* src */, std::shared_ptr /* dst */) override { return C2_OMITTED; } virtual c2_status_t query_sm( const std::vector& stackParams, const std::vector& heapParamIndices, std::vector>* const heapParams) const override { return mInterface.query(stackParams, heapParamIndices, C2_MAY_BLOCK, heapParams); } virtual c2_status_t config_sm( const std::vector& params, std::vector>* const failures) override { return mInterface.config(params, C2_MAY_BLOCK, failures); } virtual std::shared_ptr getParamReflector() const override { return mReflectorHelper; } virtual c2_status_t querySupportedParams_nb( std::vector>* const params) const override { return mInterface.querySupportedParams(params); } virtual c2_status_t querySupportedValues_sm( std::vector& fields) const override { return mInterface.querySupportedValues(fields, C2_MAY_BLOCK); } private: class Interface : public C2InterfaceHelper { public: Interface(const std::shared_ptr &helper) : C2InterfaceHelper(helper) { setDerivedInstance(this); } virtual ~Interface() = default; private: std::shared_ptr mIonUsageInfo; std::shared_ptr mDmaBufUsageInfo; }; std::shared_ptr mReflectorHelper; Interface mInterface; }; int main(int /* argc */, char** /* argv */) { using namespace ::android; LOG(DEBUG) << "android.hardware.media.c2@1.1-service starting..."; // Set up minijail to limit system calls. signal(SIGPIPE, SIG_IGN); SetUpMinijail(kBaseSeccompPolicyPath, kExtSeccompPolicyPath); // Enable vndbinder to allow vendor-to-vendor binder calls. ProcessState::initWithDriver("/dev/vndbinder"); ProcessState::self()->startThreadPool(); // Extra threads may be needed to handle a stacked IPC sequence that // contains alternating binder and hwbinder calls. (See b/35283480.) hardware::configureRpcThreadpool(8, true /* callerWillJoin */); // Create IComponentStore service. { using namespace ::android::hardware::media::c2::V1_1; sp store; // TODO: Replace this with // store = new utils::ComponentStore( // /* implementation of C2ComponentStore */); LOG(DEBUG) << "Instantiating Codec2's IComponentStore service..."; store = new utils::ComponentStore( android::GetCodec2PlatformComponentStore()); if (store == nullptr) { LOG(ERROR) << "Cannot create Codec2's IComponentStore service."; } else { constexpr char const* serviceName = "default"; if (store->registerAsService(serviceName) != OK) { LOG(ERROR) << "Cannot register Codec2's IComponentStore service" " with instance name << \"" << serviceName << "\"."; } else { LOG(DEBUG) << "Codec2's IComponentStore service registered. " "Instance name: \"" << serviceName << "\"."; } } } hardware::joinRpcThreadpool(); return 0; }