Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 01594f2d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Codec2Utils: Separate parameter cache from store"

parents 68026f75 0594f29e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -204,7 +204,8 @@ Component::Component(
        const sp<::android::hardware::media::bufferpool::V2_0::
        IClientManager>& clientPoolManager)
      : mComponent{component},
        mInterface{new ComponentInterface(component->intf(), store.get())},
        mInterface{new ComponentInterface(component->intf(),
                                          store->getParameterCache())},
        mListener{listener},
        mStore{store},
        mBufferPoolSender{clientPoolManager} {
+2 −2
Original line number Diff line number Diff line
@@ -87,10 +87,10 @@ protected:
// ComponentInterface
ComponentInterface::ComponentInterface(
        const std::shared_ptr<C2ComponentInterface>& intf,
        ComponentStore* store)
        const std::shared_ptr<ParameterCache>& cache)
      : mInterface{intf},
        mConfigurable{new CachedConfigurable(std::make_unique<CompIntf>(intf))} {
    mInit = mConfigurable->init(store);
    mInit = mConfigurable->init(cache);
}

c2_status_t ComponentInterface::status() const {
+34 −3
Original line number Diff line number Diff line
@@ -102,8 +102,29 @@ protected:

} // unnamed namespace

struct ComponentStore::StoreParameterCache : public ParameterCache {
    std::mutex mStoreMutex;
    ComponentStore* mStore;

    StoreParameterCache(ComponentStore* store): mStore{store} {
    }

    virtual c2_status_t validate(
            const std::vector<std::shared_ptr<C2ParamDescriptor>>& params
            ) override {
        std::scoped_lock _lock(mStoreMutex);
        return mStore ? mStore->validateSupportedParams(params) : C2_NO_INIT;
    }

    void onStoreDestroyed() {
        std::scoped_lock _lock(mStoreMutex);
        mStore = nullptr;
    }
};

ComponentStore::ComponentStore(const std::shared_ptr<C2ComponentStore>& store)
      : mConfigurable{new CachedConfigurable(std::make_unique<StoreIntf>(store))},
        mParameterCache{std::make_shared<StoreParameterCache>(this)},
        mStore{store} {

    std::shared_ptr<C2ComponentStore> platformStore = android::GetCodec2PlatformComponentStore();
@@ -113,7 +134,12 @@ ComponentStore::ComponentStore(const std::shared_ptr<C2ComponentStore>& store)
    mParamReflector = mStore->getParamReflector();

    // Retrieve supported parameters from store
    mInit = mConfigurable->init(this);
    using namespace std::placeholders;
    mInit = mConfigurable->init(mParameterCache);
}

ComponentStore::~ComponentStore() {
    mParameterCache->onStoreDestroyed();
}

c2_status_t ComponentStore::status() const {
@@ -146,6 +172,10 @@ c2_status_t ComponentStore::validateSupportedParams(
    return res;
}

std::shared_ptr<ParameterCache> ComponentStore::getParameterCache() const {
    return mParameterCache;
}

// Methods from ::android::hardware::media::c2::V1_0::IComponentStore
Return<void> ComponentStore::createComponent(
        const hidl_string& name,
@@ -187,7 +217,7 @@ Return<void> ComponentStore::createInterface(
    sp<IComponentInterface> interface;
    if (res == C2_OK) {
        onInterfaceLoaded(c2interface);
        interface = new ComponentInterface(c2interface, this);
        interface = new ComponentInterface(c2interface, mParameterCache);
    }
    _hidl_cb(static_cast<Status>(res), interface);
    return Void();
@@ -218,8 +248,9 @@ Return<void> ComponentStore::createInputSurface(createInputSurface_cb _hidl_cb)
        _hidl_cb(Status::CORRUPTED, nullptr);
        return Void();
    }
    using namespace std::placeholders;
    sp<InputSurface> inputSurface = new InputSurface(
            this,
            mParameterCache,
            std::make_shared<C2ReflectorHelper>(),
            source->getHGraphicBufferProducer(),
            source);
+3 −2
Original line number Diff line number Diff line
@@ -38,10 +38,11 @@ CachedConfigurable::CachedConfigurable(
      : mIntf{std::move(intf)} {
}

c2_status_t CachedConfigurable::init(ComponentStore* store) {
c2_status_t CachedConfigurable::init(
        const std::shared_ptr<ParameterCache>& cache) {
    // Retrieve supported parameters from store
    c2_status_t init = mIntf->querySupportedParams(&mSupportedParams);
    c2_status_t validate = store->validateSupportedParams(mSupportedParams);
    c2_status_t validate = cache->validate(mSupportedParams);
    return init == C2_OK ? C2_OK : validate;
}

+5 −5
Original line number Diff line number Diff line
@@ -137,9 +137,9 @@ Return<void> InputSurface::connect(
    }
    std::shared_ptr<C2Component> comp = Component::findLocalComponent(sink);
    if (comp) {
        connection = new InputSurfaceConnection(mSource, comp, mStore);
        connection = new InputSurfaceConnection(mSource, comp, mParameterCache);
    } else {
        connection = new InputSurfaceConnection(mSource, sink, mStore);
        connection = new InputSurfaceConnection(mSource, sink, mParameterCache);
    }
    if (!connection->init()) {
        connection = nullptr;
@@ -153,11 +153,11 @@ Return<void> InputSurface::connect(

// Constructor is exclusive to ComponentStore.
InputSurface::InputSurface(
        const sp<ComponentStore>& store,
        const std::shared_ptr<ParameterCache>& cache,
        const std::shared_ptr<C2ReflectorHelper>& reflector,
        const sp<HGraphicBufferProducer>& producer,
        const sp<GraphicBufferSource>& source)
      : mStore{store},
      : mParameterCache{cache},
        mProducer{producer},
        mSource{source},
        mIntf{std::make_shared<Interface>(reflector)},
@@ -165,7 +165,7 @@ InputSurface::InputSurface(
                std::make_unique<ConfigurableIntf>(
                    mIntf, source))} {

    mConfigurable->init(store.get());
    mConfigurable->init(mParameterCache);
}

}  // namespace utils
Loading