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

Commit 5eb7259c authored by Wonsik Kim's avatar Wonsik Kim Committed by Android (Google) Code Review
Browse files

Merge changes I590426f6,I7be88587 into sc-dev

* changes:
  codec2 hidl plugin samples: implement queryParamsForPreviousComponent
  codec2 hidl plugin: define queryParamsForPreviousComponent
parents cc2e2089 6eec57fb
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -105,4 +105,13 @@ bool DefaultFilterPlugin::isFilteringEnabled(const std::shared_ptr<C2ComponentIn
    return mPlugin->isFilteringEnabled(intf);
}

c2_status_t DefaultFilterPlugin::queryParamsForPreviousComponent(
        const std::shared_ptr<C2ComponentInterface> &intf,
        std::vector<std::unique_ptr<C2Param>> *params) {
    if (mInit != OK) {
        return C2_NO_INIT;
    }
    return mPlugin->queryParamsForPreviousComponent(intf, params);
}

}  // namespace android
+66 −4
Original line number Diff line number Diff line
@@ -45,8 +45,9 @@ class WrappedDecoderInterface : public C2ComponentInterface {
public:
    WrappedDecoderInterface(
            std::shared_ptr<C2ComponentInterface> intf,
            std::vector<FilterWrapper::Component> &&filters)
        : mIntf(intf) {
            std::vector<FilterWrapper::Component> &&filters,
            std::weak_ptr<FilterWrapper> filterWrapper)
        : mIntf(intf), mFilterWrapper(filterWrapper) {
        takeFilters(std::move(filters));
    }

@@ -101,6 +102,13 @@ public:
                mTypeToIndexForQuery[type.type()] = i;
            }
        }
        for (size_t i = mFilters.size(); i > 0; --i) {
            if (i == 1) {
                backPropagateParams_l(mIntf, mFilters[0].intf, C2_MAY_BLOCK);
            } else {
                backPropagateParams_l(mFilters[i - 2].intf, mFilters[i - 1].intf, C2_MAY_BLOCK);
            }
        }
        if (!mFilters.empty()) {
            for (uint32_t type : kTypesForLastFilter) {
                mTypeToIndexForQuery[type] = mFilters.size() - 1;
@@ -256,6 +264,13 @@ public:
                result = err;
            }
        }
        for (size_t i = mFilters.size(); i > 0; --i) {
            if (i == 1) {
                backPropagateParams_l(mIntf, mFilters[0].intf, mayBlock);
            } else {
                backPropagateParams_l(mFilters[i - 2].intf, mFilters[i - 1].intf, mayBlock);
            }
        }

        return result;
    }
@@ -338,6 +353,7 @@ private:
    mutable std::mutex mMutex;
    std::shared_ptr<C2ComponentInterface> mIntf;
    std::vector<FilterWrapper::Component> mFilters;
    std::weak_ptr<FilterWrapper> mFilterWrapper;
    std::map<uint32_t, size_t> mTypeToIndexForQuery;
    std::map<uint32_t, size_t> mTypeToIndexForConfig;

@@ -402,6 +418,41 @@ private:
        }
        return C2_OK;
    }

    c2_status_t backPropagateParams_l(
            const std::shared_ptr<C2ComponentInterface> &curr,
            const std::shared_ptr<C2ComponentInterface> &next,
            c2_blocking_t mayBlock) {
        // NOTE: this implementation is preliminary --- it could change once
        // we define what parameters needs to be propagated in component chaining.
        std::shared_ptr<FilterWrapper> filterWrapper = mFilterWrapper.lock();
        if (!filterWrapper) {
            LOG(DEBUG) << "WrappedDecoderInterface: FilterWrapper not found";
            return C2_OK;
        }
        std::vector<std::unique_ptr<C2Param>> params;
        c2_status_t err = filterWrapper->queryParamsForPreviousComponent(next, &params);
        if (err != C2_OK) {
            LOG(DEBUG) << "WrappedDecoderInterface: FilterWrapper returned error for "
                << "queryParamsForPreviousComponent; intf=" << next->getName() << " err=" << err;
            return C2_OK;
        }
        std::vector<C2Param *> configParams;
        for (size_t i = 0; i < params.size(); ++i) {
            if (!params[i]) {
                continue;
            }
            configParams.push_back(params[i].get());
        }
        std::vector<std::unique_ptr<C2SettingResult>> failures;
        curr->config_vb(configParams, mayBlock, &failures);
        if (err != C2_OK && err != C2_BAD_INDEX) {
            LOG(DEBUG) << "WrappedDecoderInterface: " << next->getName()
                    << " returned error for config_vb; err=" << err;
            return err;
        }
        return C2_OK;
    }
};

class WrappedDecoder : public C2Component, public std::enable_shared_from_this<WrappedDecoder> {
@@ -413,7 +464,7 @@ public:
        : mComp(comp), mFilters(std::move(filters)), mFilterWrapper(filterWrapper) {
        std::vector<FilterWrapper::Component> filtersDup(mFilters);
        mIntf = std::make_shared<WrappedDecoderInterface>(
                comp->intf(), std::move(filtersDup));
                comp->intf(), std::move(filtersDup), filterWrapper);
    }

    ~WrappedDecoder() override = default;
@@ -844,7 +895,8 @@ std::shared_ptr<C2ComponentInterface> FilterWrapper::maybeWrapInterface(
                << " is not video/image decoder; not wrapping the interface";
        return intf;
    }
    return std::make_shared<WrappedDecoderInterface>(intf, createFilters());
    return std::make_shared<WrappedDecoderInterface>(
            intf, createFilters(), weak_from_this());
}

std::shared_ptr<C2Component> FilterWrapper::maybeWrapComponent(
@@ -917,4 +969,14 @@ c2_status_t FilterWrapper::createBlockPool(
    return CreateCodec2BlockPool(allocatorId, component, pool);
}

c2_status_t FilterWrapper::queryParamsForPreviousComponent(
        const std::shared_ptr<C2ComponentInterface> &intf,
        std::vector<std::unique_ptr<C2Param>> *params) {
    if (mInit != OK) {
        LOG(WARNING) << "queryParamsForPreviousComponent: Wrapper not initialized: ";
        return C2_NO_INIT;
    }
    return mPlugin->queryParamsForPreviousComponent(intf, params);
}

}  // namespace android
+9 −0
Original line number Diff line number Diff line
@@ -57,6 +57,15 @@ public:
     * current configuration; false if it will be no-op.
     */
    virtual bool isFilteringEnabled(const std::shared_ptr<C2ComponentInterface> &intf) = 0;

    /**
     * Query parameters to |intf|, which the component wants applied to
     * the previous component in the chain. For example, an image/video filter
     * may require specific usage or pixel format from the previous component.
     */
    virtual c2_status_t queryParamsForPreviousComponent(
            const std::shared_ptr<C2ComponentInterface> &intf,
            std::vector<std::unique_ptr<C2Param>> *params) = 0;
};

}  // namespace android
+3 −0
Original line number Diff line number Diff line
@@ -35,6 +35,9 @@ public:
    std::shared_ptr<C2ComponentStore> getStore() override { return mStore; }
    bool describe(C2String name, FilterWrapper::Descriptor *desc) override;
    bool isFilteringEnabled(const std::shared_ptr<C2ComponentInterface> &intf) override;
    c2_status_t queryParamsForPreviousComponent(
            const std::shared_ptr<C2ComponentInterface> &intf,
            std::vector<std::unique_ptr<C2Param>> *params) override;

private:
    status_t mInit;
+13 −0
Original line number Diff line number Diff line
@@ -43,6 +43,9 @@ public:
        virtual std::shared_ptr<C2ComponentStore> getStore() = 0;
        virtual bool describe(C2String name, Descriptor *desc) = 0;
        virtual bool isFilteringEnabled(const std::shared_ptr<C2ComponentInterface> &intf) = 0;
        virtual c2_status_t queryParamsForPreviousComponent(
                const std::shared_ptr<C2ComponentInterface> &intf,
                std::vector<std::unique_ptr<C2Param>> *params) = 0;
        C2_DO_NOT_COPY(Plugin);
    };

@@ -78,11 +81,21 @@ public:
     */
    bool isFilteringEnabled(const std::shared_ptr<C2ComponentInterface> &intf);

    /**
     * Create a C2BlockPool object with |allocatorId| for |component|.
     */
    c2_status_t createBlockPool(
            C2PlatformAllocatorStore::id_t allocatorId,
            std::shared_ptr<const C2Component> component,
            std::shared_ptr<C2BlockPool> *pool);

    /**
     * Query parameters that |intf| wants from the previous component.
     */
    c2_status_t queryParamsForPreviousComponent(
            const std::shared_ptr<C2ComponentInterface> &intf,
            std::vector<std::unique_ptr<C2Param>> *params);

private:
    status_t mInit;
    std::unique_ptr<Plugin> mPlugin;
Loading