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

Commit b773bae2 authored by Arun Johnson's avatar Arun Johnson Committed by Gerrit Code Review
Browse files

Merge changes from topic "largeAudioBuffer" into main

* changes:
  Enabling large audio for BLOCK_MODEL
  Support for multi access-unit output in codec framework
  Large audio frames in MediaCodec
parents 06a2373a 72349dcf
Loading
Loading
Loading
Loading
+103 −5
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ namespace utils {
using ::aidl::android::hardware::common::NativeHandle;
using ::aidl::android::hardware::media::bufferpool2::IClientManager;
using ::ndk::ScopedAStatus;
using ::android::MultiAccessUnitInterface;
using ::android::MultiAccessUnitHelper;

// ComponentListener wrapper
struct Component::Listener : public C2Component::Listener {
@@ -139,6 +141,52 @@ protected:
    std::weak_ptr<IComponentListener> mListener;
};

// Component listener for handle multiple access-units
struct MultiAccessUnitListener : public Component::Listener {
    MultiAccessUnitListener(const std::shared_ptr<Component>& component,
            const std::shared_ptr<MultiAccessUnitHelper> &helper):
        Listener(component), mHelper(helper) {
    }

    virtual void onError_nb(
            std::weak_ptr<C2Component> c2component,
            uint32_t errorCode) override {
        if (mHelper) {
            std::list<std::unique_ptr<C2Work>> worklist;
            mHelper->error(&worklist);
            if (!worklist.empty()) {
                Listener::onWorkDone_nb(c2component, std::move(worklist));
            }
        }
        Listener::onError_nb(c2component, errorCode);
    }

    virtual void onTripped_nb(
            std::weak_ptr<C2Component> c2component,
            std::vector<std::shared_ptr<C2SettingResult>> c2settingResult
            ) override {
        Listener::onTripped_nb(c2component,
                c2settingResult);
    }

    virtual void onWorkDone_nb(
            std::weak_ptr<C2Component> c2component,
            std::list<std::unique_ptr<C2Work>> c2workItems) override {
        if (mHelper) {
            std::list<std::unique_ptr<C2Work>> processedWork;
            mHelper->gather(c2workItems, &processedWork);
            if (!processedWork.empty()) {
                Listener::onWorkDone_nb(c2component, std::move(processedWork));
            }
        } else {
            Listener::onWorkDone_nb(c2component, std::move(c2workItems));
        }
    }

    protected:
        std::shared_ptr<MultiAccessUnitHelper> mHelper;
};

// Component::DeathContext
struct Component::DeathContext {
    std::weak_ptr<Component> mWeakComp;
@@ -151,14 +199,38 @@ Component::Component(
        const std::shared_ptr<ComponentStore>& store,
        const std::shared_ptr<IClientManager>& clientPoolManager)
      : mComponent{component},
        mInterface{SharedRefBase::make<ComponentInterface>(
                component->intf(), store->getParameterCache())},
        mListener{listener},
        mStore{store},
        mBufferPoolSender{clientPoolManager},
        mDeathContext(nullptr) {
    // Retrieve supported parameters from store
    // TODO: We could cache this per component/interface type
    if (MultiAccessUnitHelper::isEnabledOnPlatform()) {
        c2_status_t err = C2_OK;
        C2ComponentDomainSetting domain;
        std::vector<std::unique_ptr<C2Param>> heapParams;
        err = component->intf()->query_vb({&domain}, {}, C2_MAY_BLOCK, &heapParams);
        if (err == C2_OK && (domain.value == C2Component::DOMAIN_AUDIO)) {
            std::vector<std::shared_ptr<C2ParamDescriptor>> params;
            bool isComponentSupportsLargeAudioFrame = false;
            component->intf()->querySupportedParams_nb(&params);
            for (const auto &paramDesc : params) {
                if (paramDesc->name().compare(C2_PARAMKEY_OUTPUT_LARGE_FRAME) == 0) {
                    isComponentSupportsLargeAudioFrame = true;
                    LOG(VERBOSE) << "Underlying component supports large frame audio";
                    break;
                }
            }
            if (!isComponentSupportsLargeAudioFrame) {
                mMultiAccessUnitIntf = std::make_shared<MultiAccessUnitInterface>(
                        component->intf(),
                        std::static_pointer_cast<C2ReflectorHelper>(
                                ::android::GetCodec2PlatformComponentStore()->getParamReflector()));
            }
        }
    }
    mInterface = SharedRefBase::make<ComponentInterface>(
            component->intf(), mMultiAccessUnitIntf, store->getParameterCache());
    mInit = mInterface->status();
}

@@ -181,8 +253,21 @@ ScopedAStatus Component::queue(const WorkBundle& workBundle) {
                    registerFrameData(mListener, work->input);
        }
    }
    c2_status_t err = C2_OK;
    if (mMultiAccessUnitHelper) {
        std::list<std::list<std::unique_ptr<C2Work>>> c2worklists;
        mMultiAccessUnitHelper->scatter(c2works, &c2worklists);
        for (auto &c2worklist : c2worklists) {
            err = mComponent->queue_nb(&c2worklist);
            if (err != C2_OK) {
                LOG(ERROR) << "Error Queuing to component.";
                return ScopedAStatus::fromServiceSpecificError(err);
            }
        }
        return ScopedAStatus::ok();
    }

    c2_status_t err = mComponent->queue_nb(&c2works);
    err = mComponent->queue_nb(&c2works);
    if (err == C2_OK) {
        return ScopedAStatus::ok();
    }
@@ -194,7 +279,9 @@ ScopedAStatus Component::flush(WorkBundle *flushedWorkBundle) {
    c2_status_t c2res = mComponent->flush_sm(
            C2Component::FLUSH_COMPONENT,
            &c2flushedWorks);

    if (mMultiAccessUnitHelper) {
        c2res = mMultiAccessUnitHelper->flush(&c2flushedWorks);
    }
    // Unregister input buffers.
    for (const std::unique_ptr<C2Work>& work : c2flushedWorks) {
        if (work) {
@@ -364,6 +451,9 @@ ScopedAStatus Component::reset() {
        std::lock_guard<std::mutex> lock(mBlockPoolsMutex);
        mBlockPools.clear();
    }
    if (mMultiAccessUnitHelper) {
        mMultiAccessUnitHelper->reset();
    }
    InputBufferManager::unregisterFrameData(mListener);
    if (status == C2_OK) {
        return ScopedAStatus::ok();
@@ -377,6 +467,9 @@ ScopedAStatus Component::release() {
        std::lock_guard<std::mutex> lock(mBlockPoolsMutex);
        mBlockPools.clear();
    }
    if (mMultiAccessUnitHelper) {
        mMultiAccessUnitHelper->reset();
    }
    InputBufferManager::unregisterFrameData(mListener);
    if (status == C2_OK) {
        return ScopedAStatus::ok();
@@ -415,7 +508,12 @@ ScopedAStatus Component::asInputSink(

void Component::initListener(const std::shared_ptr<Component>& self) {
    if (__builtin_available(android __ANDROID_API_T__, *)) {
        std::shared_ptr<C2Component::Listener> c2listener =
        std::shared_ptr<C2Component::Listener> c2listener;
        if (mMultiAccessUnitIntf) {
            mMultiAccessUnitHelper = std::make_shared<MultiAccessUnitHelper>(mMultiAccessUnitIntf);
        }
        c2listener = mMultiAccessUnitHelper ?
                std::make_shared<MultiAccessUnitListener>(self, mMultiAccessUnitHelper) :
                std::make_shared<Listener>(self);
        c2_status_t res = mComponent->setListener_vb(c2listener, C2_DONT_BLOCK);
        if (res != C2_OK) {
+76 −7
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@

#include <utils/Timers.h>

#include <codec2/common/MultiAccessUnitHelper.h>

#include <C2Debug.h>
#include <C2PlatformSupport.h>

@@ -43,9 +45,10 @@ namespace /* unnamed */ {

// Implementation of ConfigurableC2Intf based on C2ComponentInterface
struct CompIntf : public ConfigurableC2Intf {
    CompIntf(const std::shared_ptr<C2ComponentInterface>& intf) :
    CompIntf(const std::shared_ptr<C2ComponentInterface>& intf,
        const std::shared_ptr<MultiAccessUnitInterface>& multiAccessUnitIntf):
        ConfigurableC2Intf{intf->getName(), intf->getId()},
        mIntf{intf} {
        mIntf{intf}, mMultiAccessUnitIntf{multiAccessUnitIntf} {
    }

    virtual c2_status_t config(
@@ -53,7 +56,34 @@ struct CompIntf : public ConfigurableC2Intf {
            c2_blocking_t mayBlock,
            std::vector<std::unique_ptr<C2SettingResult>>* const failures
            ) override {
        return mIntf->config_vb(params, mayBlock, failures);
        std::vector<C2Param*> paramsToIntf;
        std::vector<C2Param*> paramsToLargeFrameIntf;
        c2_status_t err = C2_OK;
        if (mMultiAccessUnitIntf == nullptr) {
            err = mIntf->config_vb(params, mayBlock, failures);
            return err;
        }
        for (auto &p : params) {
            if (mMultiAccessUnitIntf->isParamSupported(p->index())) {
                paramsToLargeFrameIntf.push_back(p);
            } else {
                paramsToIntf.push_back(p);
            }
        }
        c2_status_t err1 = C2_OK;
        if (paramsToIntf.size() > 0) {
            err1 = mIntf->config_vb(paramsToIntf, mayBlock, failures);
        }
        if (err1 != C2_OK) {
            LOG(ERROR) << "We have a failed config";
        }
        c2_status_t err2 = C2_OK;
        if (paramsToLargeFrameIntf.size() > 0) {
            err2 = mMultiAccessUnitIntf->config(
                    paramsToLargeFrameIntf, mayBlock, failures);
        }
        // TODO: correct failure vector
        return err1 != C2_OK ? err1 : err2;
    }

    virtual c2_status_t query(
@@ -61,23 +91,56 @@ struct CompIntf : public ConfigurableC2Intf {
            c2_blocking_t mayBlock,
            std::vector<std::unique_ptr<C2Param>>* const params
            ) const override {
        return mIntf->query_vb({}, indices, mayBlock, params);
        c2_status_t err = C2_OK;
        if (mMultiAccessUnitIntf == nullptr) {
            err = mIntf->query_vb({}, indices, mayBlock, params);
            return err;
        }
        std::vector<C2Param::Index> paramsToIntf;
        std::vector<C2Param::Index> paramsToLargeFrameIntf;
        for (auto &i : indices) {
            if (mMultiAccessUnitIntf->isParamSupported(i)) {
                paramsToLargeFrameIntf.push_back(i);
            } else {
                paramsToIntf.push_back(i);
            }
        }
        c2_status_t err1 = C2_OK;
        if (paramsToIntf.size() > 0) {
            err1 = mIntf->query_vb({}, paramsToIntf, mayBlock, params);
        }
        c2_status_t err2 = C2_OK;
        if (paramsToLargeFrameIntf.size() > 0) {
            err2 = mMultiAccessUnitIntf->query(
                    {}, paramsToLargeFrameIntf, mayBlock, params);
        }
        // TODO: correct failure vector
        return err1 != C2_OK ? err1 : err2;
    }

    virtual c2_status_t querySupportedParams(
            std::vector<std::shared_ptr<C2ParamDescriptor>>* const params
            ) const override {
        return mIntf->querySupportedParams_nb(params);
        c2_status_t err = mIntf->querySupportedParams_nb(params);
        if (mMultiAccessUnitIntf != nullptr) {
            err =  mMultiAccessUnitIntf->querySupportedParams(params);
        }
        return err;
    }

    virtual c2_status_t querySupportedValues(
            std::vector<C2FieldSupportedValuesQuery>& fields,
            c2_blocking_t mayBlock) const override {
        return mIntf->querySupportedValues_vb(fields, mayBlock);
        c2_status_t err = mIntf->querySupportedValues_vb(fields, mayBlock);
        if (mMultiAccessUnitIntf != nullptr) {
            err = mMultiAccessUnitIntf->querySupportedValues(fields, mayBlock);
        }
        return err;
    }

protected:
    std::shared_ptr<C2ComponentInterface> mIntf;
    std::shared_ptr<MultiAccessUnitInterface> mMultiAccessUnitIntf;
};

} // unnamed namespace
@@ -85,10 +148,16 @@ protected:
// ComponentInterface
ComponentInterface::ComponentInterface(
        const std::shared_ptr<C2ComponentInterface>& intf,
        const std::shared_ptr<ParameterCache>& cache):ComponentInterface(intf, nullptr, cache) {
}

ComponentInterface::ComponentInterface(
        const std::shared_ptr<C2ComponentInterface>& intf,
        const std::shared_ptr<MultiAccessUnitInterface>& multiAccessUnitIntf,
        const std::shared_ptr<ParameterCache>& cache)
      : mInterface{intf},
        mConfigurable{SharedRefBase::make<CachedConfigurable>(
                std::make_unique<CompIntf>(intf))} {
                std::make_unique<CompIntf>(intf, multiAccessUnitIntf))} {
    mInit = mConfigurable->init(cache);
}

+8 −0
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@
#include <aidl/android/hardware/media/c2/IInputSurface.h>
#include <aidl/android/hardware/media/c2/IInputSurfaceConnection.h>

#include <codec2/common/MultiAccessUnitHelper.h>

#include <C2Component.h>
#include <C2Buffer.h>
#include <C2.h>
@@ -46,6 +48,8 @@ namespace media {
namespace c2 {
namespace utils {

using ::android::MultiAccessUnitInterface;
using ::android::MultiAccessUnitHelper;

struct ComponentStore;

@@ -85,6 +89,8 @@ protected:
    std::shared_ptr<C2Component> mComponent;
    std::shared_ptr<ComponentInterface> mInterface;
    std::shared_ptr<IComponentListener> mListener;
    std::shared_ptr<MultiAccessUnitInterface> mMultiAccessUnitIntf;
    std::shared_ptr<MultiAccessUnitHelper> mMultiAccessUnitHelper;
    std::shared_ptr<ComponentStore> mStore;
    DefaultBufferPoolSender mBufferPoolSender;

@@ -102,6 +108,8 @@ protected:

    struct Listener;

    friend struct MultiAccessUnitListener;

    ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient;
    static void OnBinderDied(void *cookie);
    static void OnBinderUnlinked(void *cookie);
+8 −2
Original line number Diff line number Diff line
@@ -22,11 +22,14 @@

#include <aidl/android/hardware/media/c2/BnComponentInterface.h>

#include <codec2/common/MultiAccessUnitHelper.h>

#include <C2Component.h>
#include <C2Buffer.h>
#include <C2.h>

#include <memory>
#include <set>

namespace aidl {
namespace android {
@@ -35,12 +38,16 @@ namespace media {
namespace c2 {
namespace utils {

struct ComponentStore;
using ::android::MultiAccessUnitInterface;

struct ComponentInterface : public BnComponentInterface {
    ComponentInterface(
            const std::shared_ptr<C2ComponentInterface>& interface,
            const std::shared_ptr<ParameterCache>& cache);
    ComponentInterface(
        const std::shared_ptr<C2ComponentInterface>& interface,
        const std::shared_ptr<MultiAccessUnitInterface>& largeBufferIntf,
        const std::shared_ptr<ParameterCache>& cache);
    c2_status_t status() const;
    ::ndk::ScopedAStatus getConfigurable(
            std::shared_ptr<IConfigurable> *intf) override;
@@ -51,7 +58,6 @@ protected:
    c2_status_t mInit;
};


}  // namespace utils
}  // namespace c2
}  // namespace media
+4 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ cc_library {

    srcs: [
        "BufferTypes.cpp",
        "MultiAccessUnitHelper.cpp",
    ],

    export_include_dirs: ["include/"],
@@ -26,7 +27,10 @@ cc_library {
        "libcodec2_vndk",
        "liblog",
        "libstagefright_foundation",
        "server_configurable_flags",
    ],

    static_libs: ["aconfig_mediacodec_flags_c_lib"],
}

cc_library_static {
Loading