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

Commit 09a62c6b authored by Wonsik Kim's avatar Wonsik Kim
Browse files

codec2: add filter plugin interface & wrapper implementation

Bug: 160259947
Test: manually run the logic with a sample plugin
Change-Id: I9e96695101262ecf0e8428574ecc56c0c6e17ae7
parent b62cce4a
Loading
Loading
Loading
Loading
+66 −0
Original line number Diff line number Diff line
cc_library_headers {
    name: "libcodec2_hidl_plugin_headers",
    vendor_available: true,
    export_include_dirs: [
        "include",
    ],
}

cc_library {
    name: "libcodec2_hidl_plugin_stub",

    srcs: [
        "DefaultFilterPlugin.cpp",
        "FilterWrapperStub.cpp",
    ],

    header_libs: [
        "libcodec2_internal", // private
    ],

    shared_libs: [
        "libbase",
        "libcodec2",
        "libcodec2_vndk",
        "liblog",
        "libutils",
    ],

    export_include_dirs: [
        "include",
        "internal",
    ],

    apex_available: [
        "//apex_available:platform",
        "com.android.media.swcodec",
    ],
    min_sdk_version: "29",
}

cc_library {
    name: "libcodec2_hidl_plugin",
    vendor: true,

    srcs: [
        "DefaultFilterPlugin.cpp",
        "FilterWrapper.cpp",
    ],

    header_libs: [
        "libcodec2_internal", // private
    ],

    shared_libs: [
        "libbase",
        "libcodec2",
        "libcodec2_vndk",
        "liblog",
        "libutils",
    ],

    export_include_dirs: [
        "include",
        "internal",
    ],
}
+108 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 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 "Codec2-DefaultFilterPlugin"
#include <android-base/logging.h>

#include <set>

#include <dlfcn.h>

#include <C2Config.h>
#include <C2Debug.h>
#include <C2ParamInternal.h>

#include <codec2/hidl/plugin/FilterPlugin.h>

#include <DefaultFilterPlugin.h>
#include <FilterWrapper.h>

namespace android {

DefaultFilterPlugin::DefaultFilterPlugin(const char *pluginPath)
    : mInit(NO_INIT),
      mHandle(nullptr),
      mDestroyPlugin(nullptr),
      mPlugin(nullptr) {
    mHandle = dlopen(pluginPath, RTLD_NOW | RTLD_NODELETE);
    if (!mHandle) {
        LOG(DEBUG) << "FilterPlugin: no plugin detected";
        return;
    }
    GetFilterPluginVersionFunc getVersion =
        (GetFilterPluginVersionFunc)dlsym(mHandle, "GetFilterPluginVersion");
    if (!getVersion) {
        LOG(WARNING) << "FilterPlugin: GetFilterPluginVersion undefined";
        return;
    }
    int32_t version = getVersion();
    if (version != FilterPlugin_V1::VERSION) {
        LOG(WARNING) << "FilterPlugin: unrecognized version (" << version << ")";
        return;
    }
    CreateFilterPluginFunc createPlugin =
        (CreateFilterPluginFunc)dlsym(mHandle, "CreateFilterPlugin");
    if (!createPlugin) {
        LOG(WARNING) << "FilterPlugin: CreateFilterPlugin undefined";
        return;
    }
    mDestroyPlugin =
        (DestroyFilterPluginFunc)dlsym(mHandle, "DestroyFilterPlugin");
    if (!mDestroyPlugin) {
        LOG(WARNING) << "FilterPlugin: DestroyFilterPlugin undefined";
        return;
    }
    mPlugin = (FilterPlugin_V1 *)createPlugin();
    if (!mPlugin) {
        LOG(WARNING) << "FilterPlugin: CreateFilterPlugin returned nullptr";
        return;
    }
    mStore = mPlugin->getComponentStore();
    if (!mStore) {
        LOG(WARNING) << "FilterPlugin: FilterPlugin_V1::getComponentStore returned nullptr";
        return;
    }
    mInit = OK;
}

DefaultFilterPlugin::~DefaultFilterPlugin() {
    if (mHandle) {
        if (mDestroyPlugin && mPlugin) {
            mDestroyPlugin(mPlugin);
            mPlugin = nullptr;
        }
        dlclose(mHandle);
        mHandle = nullptr;
        mDestroyPlugin = nullptr;
    }
}

bool DefaultFilterPlugin::describe(C2String name, FilterWrapper::Descriptor *desc) {
    if (mInit != OK) {
        return false;
    }
    return mPlugin->describe(name, desc);
}

bool DefaultFilterPlugin::isFilteringEnabled(const std::shared_ptr<C2ComponentInterface> &intf) {
    if (mInit != OK) {
        return false;
    }
    return mPlugin->isFilteringEnabled(intf);
}

}  // namespace android
+921 −0

File added.

Preview size limit exceeded, changes collapsed.

+51 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 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 "Codec2-FilterWrapperStub"

#include <FilterWrapper.h>

namespace android {

FilterWrapper::FilterWrapper(std::unique_ptr<Plugin> &&) {
}

FilterWrapper::~FilterWrapper() {
}

std::shared_ptr<C2ComponentInterface> FilterWrapper::maybeWrapInterface(
        const std::shared_ptr<C2ComponentInterface> intf) {
    return intf;
}

std::shared_ptr<C2Component> FilterWrapper::maybeWrapComponent(
        const std::shared_ptr<C2Component> comp) {
    return comp;
}

bool FilterWrapper::isFilteringEnabled(const std::shared_ptr<C2ComponentInterface> &) {
    return false;
}

c2_status_t FilterWrapper::createBlockPool(
        C2PlatformAllocatorStore::id_t,
        std::shared_ptr<const C2Component>,
        std::shared_ptr<C2BlockPool> *) {
    return C2_OMITTED;
}

}  // namespace android
+77 −0
Original line number Diff line number Diff line
/*
 * 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.
 */

#ifndef CODEC2_HIDL_PLUGIN_FILTER_PLUGIN_H

#define CODEC2_HIDL_PLUGIN_FILTER_PLUGIN_H

#include <memory>

#include <C2Component.h>

namespace android {

class FilterPlugin_V1 {
public:
    static constexpr int32_t VERSION = 1;

    virtual ~FilterPlugin_V1() = default;

    /**
     * Returns a C2ComponentStore object with which clients can create
     * filter components / interfaces.
     */
    virtual std::shared_ptr<C2ComponentStore> getComponentStore() = 0;
    struct Descriptor {
        // Parameters that client sets for filter control.
        std::initializer_list<C2Param::Type> controlParams;
        // Parameters that the component changes after filtering.
        std::initializer_list<C2Param::Type> affectedParams;
    };

    /**
     * Describe a filter component.
     *
     * @param name[in]  filter's name
     * @param desc[out] pointer to filter descriptor to be populated
     * @return  true if |name| is in the store and |desc| is populated;
     *          false if |name| is not recognized
     */
    virtual bool describe(C2String name, Descriptor *desc) = 0;

    /**
     * Returns true if a component will apply filtering after all given the
     * current configuration; false if it will be no-op.
     */
    virtual bool isFilteringEnabled(const std::shared_ptr<C2ComponentInterface> &intf) = 0;
};

}  // namespace android

extern "C" {

typedef int32_t (*GetFilterPluginVersionFunc)();
int32_t GetFilterPluginVersion();

typedef void* (*CreateFilterPluginFunc)();
void *CreateFilterPlugin();

typedef void (*DestroyFilterPluginFunc)(void *);
void DestroyFilterPlugin(void *plugin);

}  // extern "C"

#endif  // CODEC2_HIDL_PLUGIN_FILTER_PLUGIN_H
Loading