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

Commit a3df8616 authored by Wonsik Kim's avatar Wonsik Kim Committed by Automerger Merge Worker
Browse files

Merge "FilterWrapper: propagate ParamReflectors to the wrapper component" into main am: 5a5ab97b

parents b799e9d5 5a5ab97b
Loading
Loading
Loading
Loading
+32 −11
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@
#include <ostream>
#include <sstream>

#ifndef __ANDROID_APEX__
#ifndef __ANDROID_APEX__  // Filters are not supported for APEX modules
#include <codec2/hidl/plugin/FilterPlugin.h>
#include <dlfcn.h>
#include <C2Config.h>
@@ -51,7 +51,7 @@ namespace media {
namespace c2 {
namespace utils {

#ifndef __ANDROID_APEX__
#ifndef __ANDROID_APEX__  // Filters are not supported for APEX modules
using ::android::DefaultFilterPlugin;
using ::android::FilterWrapper;
#endif
@@ -144,7 +144,15 @@ ComponentStore::ComponentStore(const std::shared_ptr<C2ComponentStore>& store)
    ::android::SetPreferredCodec2ComponentStore(store);

    // Retrieve struct descriptors
    mParamReflector = mStore->getParamReflector();
    mParamReflectors.push_back(mStore->getParamReflector());
#ifndef __ANDROID_APEX__  // Filters are not supported for APEX modules
    std::shared_ptr<C2ParamReflector> paramReflector =
        GetFilterWrapper()->getParamReflector();
    if (paramReflector != nullptr) {
        ALOGD("[%s] added param reflector from filter wrapper", mStore->getName().c_str());
        mParamReflectors.push_back(paramReflector);
    }
#endif

    // Retrieve supported parameters from store
    using namespace std::placeholders;
@@ -173,8 +181,7 @@ c2_status_t ComponentStore::validateSupportedParams(
        std::lock_guard<std::mutex> lock(mStructDescriptorsMutex);
        auto it = mStructDescriptors.find(coreIndex);
        if (it == mStructDescriptors.end()) {
            std::shared_ptr<C2StructDescriptor> structDesc =
                    mParamReflector->describe(coreIndex);
            std::shared_ptr<C2StructDescriptor> structDesc = describe(coreIndex);
            if (!structDesc) {
                // All supported params must be described
                res = C2_BAD_INDEX;
@@ -189,7 +196,7 @@ std::shared_ptr<ParameterCache> ComponentStore::getParameterCache() const {
    return mParameterCache;
}

#ifndef __ANDROID_APEX__
#ifndef __ANDROID_APEX__  // Filters are not supported for APEX modules
// static
std::shared_ptr<FilterWrapper> ComponentStore::GetFilterWrapper() {
    constexpr const char kPluginPath[] = "libc2filterplugin.so";
@@ -221,8 +228,13 @@ std::shared_ptr<MultiAccessUnitInterface> ComponentStore::tryCreateMultiAccessUn
                }
            }
            if (!isComponentSupportsLargeAudioFrame) {
                // TODO - b/342269852: MultiAccessUnitInterface also needs to take multiple
                // param reflectors. Currently filters work on video domain only,
                // and the MultiAccessUnitHelper is only enabled on audio domain;
                // thus we pass the component's param reflector, which is mParamReflectors[0].
                multiAccessUnitIntf = std::make_shared<MultiAccessUnitInterface>(
                        c2interface, std::static_pointer_cast<C2ReflectorHelper>(mParamReflector));
                        c2interface,
                        std::static_pointer_cast<C2ReflectorHelper>(mParamReflectors[0]));
            }
        }
    }
@@ -250,7 +262,7 @@ ScopedAStatus ComponentStore::createComponent(
            mStore->createComponent(name, &c2component);

    if (status == C2_OK) {
#ifndef __ANDROID_APEX__
#ifndef __ANDROID_APEX__  // Filters are not supported for APEX modules
        c2component = GetFilterWrapper()->maybeWrapComponent(c2component);
#endif
        onInterfaceLoaded(c2component->intf());
@@ -284,7 +296,7 @@ ScopedAStatus ComponentStore::createInterface(
    std::shared_ptr<C2ComponentInterface> c2interface;
    c2_status_t res = mStore->createInterface(name, &c2interface);
    if (res == C2_OK) {
#ifndef __ANDROID_APEX__
#ifndef __ANDROID_APEX__  // Filters are not supported for APEX modules
        c2interface = GetFilterWrapper()->maybeWrapInterface(c2interface);
#endif
        onInterfaceLoaded(c2interface);
@@ -347,8 +359,7 @@ ScopedAStatus ComponentStore::getStructDescriptors(
        if (item == mStructDescriptors.end()) {
            // not in the cache, and not known to be unsupported, query local reflector
            if (!mUnsupportedStructDescriptors.count(coreIndex)) {
                std::shared_ptr<C2StructDescriptor> structDesc =
                    mParamReflector->describe(coreIndex);
                std::shared_ptr<C2StructDescriptor> structDesc = describe(coreIndex);
                if (!structDesc) {
                    mUnsupportedStructDescriptors.emplace(coreIndex);
                } else {
@@ -401,6 +412,16 @@ ScopedAStatus ComponentStore::getConfigurable(
    return ScopedAStatus::ok();
}

std::shared_ptr<C2StructDescriptor> ComponentStore::describe(const C2Param::CoreIndex &index) {
    for (const std::shared_ptr<C2ParamReflector> &reflector : mParamReflectors) {
        std::shared_ptr<C2StructDescriptor> desc = reflector->describe(index);
        if (desc) {
            return desc;
        }
    }
    return nullptr;
}

// Called from createComponent() after a successful creation of `component`.
void ComponentStore::reportComponentBirth(Component* component) {
    ComponentStatus componentStatus;
+4 −1
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ protected:

    c2_status_t mInit;
    std::shared_ptr<C2ComponentStore> mStore;
    std::shared_ptr<C2ParamReflector> mParamReflector;
    std::vector<std::shared_ptr<C2ParamReflector>> mParamReflectors;

    std::map<C2Param::CoreIndex, std::shared_ptr<C2StructDescriptor>> mStructDescriptors;
    std::set<C2Param::CoreIndex> mUnsupportedStructDescriptors;
@@ -135,6 +135,9 @@ protected:
    mutable std::mutex mComponentRosterMutex;
    std::map<Component*, ComponentStatus> mComponentRoster;

    // describe from mParamReflectors
    std::shared_ptr<C2StructDescriptor> describe(const C2Param::CoreIndex &index);

    // Called whenever Component is created.
    void reportComponentBirth(Component* component);
    // Called only from the destructor of Component.
+23 −6
Original line number Diff line number Diff line
@@ -139,7 +139,15 @@ ComponentStore::ComponentStore(const std::shared_ptr<C2ComponentStore>& store)
    SetPreferredCodec2ComponentStore(store);

    // Retrieve struct descriptors
    mParamReflector = mStore->getParamReflector();
    mParamReflectors.push_back(mStore->getParamReflector());
#ifndef __ANDROID_APEX__
    std::shared_ptr<C2ParamReflector> paramReflector =
        GetFilterWrapper()->getParamReflector();
    if (paramReflector != nullptr) {
        ALOGD("[%s] added param reflector from filter wrapper", mStore->getName().c_str());
        mParamReflectors.push_back(paramReflector);
    }
#endif

    // Retrieve supported parameters from store
    using namespace std::placeholders;
@@ -168,8 +176,7 @@ c2_status_t ComponentStore::validateSupportedParams(
        std::lock_guard<std::mutex> lock(mStructDescriptorsMutex);
        auto it = mStructDescriptors.find(coreIndex);
        if (it == mStructDescriptors.end()) {
            std::shared_ptr<C2StructDescriptor> structDesc =
                    mParamReflector->describe(coreIndex);
            std::shared_ptr<C2StructDescriptor> structDesc = describe(coreIndex);
            if (!structDesc) {
                // All supported params must be described
                res = C2_BAD_INDEX;
@@ -217,7 +224,8 @@ std::shared_ptr<MultiAccessUnitInterface> ComponentStore::tryCreateMultiAccessUn
            }
            if (!isComponentSupportsLargeAudioFrame) {
                multiAccessUnitIntf = std::make_shared<MultiAccessUnitInterface>(
                        c2interface, std::static_pointer_cast<C2ReflectorHelper>(mParamReflector));
                        c2interface,
                        std::static_pointer_cast<C2ReflectorHelper>(mParamReflectors[0]));
            }
        }
    }
@@ -339,8 +347,7 @@ Return<void> ComponentStore::getStructDescriptors(
        if (item == mStructDescriptors.end()) {
            // not in the cache, and not known to be unsupported, query local reflector
            if (!mUnsupportedStructDescriptors.count(coreIndex)) {
                std::shared_ptr<C2StructDescriptor> structDesc =
                    mParamReflector->describe(coreIndex);
                std::shared_ptr<C2StructDescriptor> structDesc = describe(coreIndex);
                if (!structDesc) {
                    mUnsupportedStructDescriptors.emplace(coreIndex);
                } else {
@@ -386,6 +393,16 @@ Return<sp<IConfigurable>> ComponentStore::getConfigurable() {
    return mConfigurable;
}

std::shared_ptr<C2StructDescriptor> ComponentStore::describe(const C2Param::CoreIndex &index) {
    for (const std::shared_ptr<C2ParamReflector> &reflector : mParamReflectors) {
        std::shared_ptr<C2StructDescriptor> desc = reflector->describe(index);
        if (desc) {
            return desc;
        }
    }
    return nullptr;
}

// Called from createComponent() after a successful creation of `component`.
void ComponentStore::reportComponentBirth(Component* component) {
    ComponentStatus componentStatus;
+4 −1
Original line number Diff line number Diff line
@@ -117,9 +117,12 @@ protected:
    // Does bookkeeping for an interface that has been loaded.
    void onInterfaceLoaded(const std::shared_ptr<C2ComponentInterface> &intf);

    // describe from mParamReflectors
    std::shared_ptr<C2StructDescriptor> describe(const C2Param::CoreIndex &index);

    c2_status_t mInit;
    std::shared_ptr<C2ComponentStore> mStore;
    std::shared_ptr<C2ParamReflector> mParamReflector;
    std::vector<std::shared_ptr<C2ParamReflector>> mParamReflectors;

    std::map<C2Param::CoreIndex, std::shared_ptr<C2StructDescriptor>> mStructDescriptors;
    std::set<C2Param::CoreIndex> mUnsupportedStructDescriptors;
+23 −6
Original line number Diff line number Diff line
@@ -139,7 +139,15 @@ ComponentStore::ComponentStore(const std::shared_ptr<C2ComponentStore>& store)
    SetPreferredCodec2ComponentStore(store);

    // Retrieve struct descriptors
    mParamReflector = mStore->getParamReflector();
    mParamReflectors.push_back(mStore->getParamReflector());
#ifndef __ANDROID_APEX__
    std::shared_ptr<C2ParamReflector> paramReflector =
        GetFilterWrapper()->getParamReflector();
    if (paramReflector != nullptr) {
        ALOGD("[%s] added param reflector from filter wrapper", mStore->getName().c_str());
        mParamReflectors.push_back(paramReflector);
    }
#endif

    // Retrieve supported parameters from store
    using namespace std::placeholders;
@@ -168,8 +176,7 @@ c2_status_t ComponentStore::validateSupportedParams(
        std::lock_guard<std::mutex> lock(mStructDescriptorsMutex);
        auto it = mStructDescriptors.find(coreIndex);
        if (it == mStructDescriptors.end()) {
            std::shared_ptr<C2StructDescriptor> structDesc =
                    mParamReflector->describe(coreIndex);
            std::shared_ptr<C2StructDescriptor> structDesc = describe(coreIndex);
            if (!structDesc) {
                // All supported params must be described
                res = C2_BAD_INDEX;
@@ -218,7 +225,8 @@ std::shared_ptr<MultiAccessUnitInterface> ComponentStore::tryCreateMultiAccessUn

            if (!isComponentSupportsLargeAudioFrame) {
                multiAccessUnitIntf = std::make_shared<MultiAccessUnitInterface>(
                        c2interface, std::static_pointer_cast<C2ReflectorHelper>(mParamReflector));
                        c2interface,
                        std::static_pointer_cast<C2ReflectorHelper>(mParamReflectors[0]));
            }
        }
    }
@@ -340,8 +348,7 @@ Return<void> ComponentStore::getStructDescriptors(
        if (item == mStructDescriptors.end()) {
            // not in the cache, and not known to be unsupported, query local reflector
            if (!mUnsupportedStructDescriptors.count(coreIndex)) {
                std::shared_ptr<C2StructDescriptor> structDesc =
                    mParamReflector->describe(coreIndex);
                std::shared_ptr<C2StructDescriptor> structDesc = describe(coreIndex);
                if (!structDesc) {
                    mUnsupportedStructDescriptors.emplace(coreIndex);
                } else {
@@ -423,6 +430,16 @@ Return<void> ComponentStore::createComponent_1_1(
    return Void();
}

std::shared_ptr<C2StructDescriptor> ComponentStore::describe(const C2Param::CoreIndex &index) {
    for (const std::shared_ptr<C2ParamReflector> &reflector : mParamReflectors) {
        std::shared_ptr<C2StructDescriptor> desc = reflector->describe(index);
        if (desc) {
            return desc;
        }
    }
    return nullptr;
}

// Called from createComponent() after a successful creation of `component`.
void ComponentStore::reportComponentBirth(Component* component) {
    ComponentStatus componentStatus;
Loading