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

Commit b45af0d0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "codec2 hal: add the AIDL adaptation layer [step 2]" into main am: 16f07159 am: cd1a3abf

parents 75dcc749 cd1a3abf
Loading
Loading
Loading
Loading
+88 −94
Original line number Diff line number Diff line
@@ -50,100 +50,94 @@ cc_library {
}

// DO NOT DEPEND ON THIS DIRECTLY
// use libcodec2-hidl-defaults instead
//cc_library {
//    name: "libcodec2_hidl@1.0",
//    vendor_available: true,
//    min_sdk_version: "29",
//    apex_available: [
//        "//apex_available:platform",
//        "com.android.media.swcodec",
//    ],
//
//    defaults: ["hidl_defaults"],
//
//    srcs: [
//        "Component.cpp",
//        "ComponentInterface.cpp",
//        "ComponentStore.cpp",
//        "Configurable.cpp",
//        "InputBufferManager.cpp",
//        "InputSurface.cpp",
//        "InputSurfaceConnection.cpp",
//        "types.cpp",
//    ],
//
//    header_libs: [
//        "libbinder_headers",
//        "libcodec2_hal_common",
//        "libcodec2_internal", // private
//        "libsystem_headers",
//    ],
//
//    shared_libs: [
//        "android.hardware.graphics.bufferqueue@1.0",
//        "android.hardware.graphics.bufferqueue@2.0",
//        "android.hardware.graphics.common@1.0",
//        "android.hardware.media@1.0",
//        "android.hardware.media.bufferpool@2.0",
//        "android.hardware.media.c2@1.0",
//        "android.hardware.media.omx@1.0",
//        "libbase",
//        "libcodec2",
//        "libcodec2_vndk",
//        "libcodec2_hidl_plugin_stub",
//        "libcutils",
//        "libhidlbase",
//        "liblog",
//        "libstagefright_bufferpool@2.0.1",
//        "libstagefright_bufferqueue_helper_novndk",
//        "libui",
//        "libutils",
//    ],
//
//    target: {
//        vendor: {
//            exclude_shared_libs: [
//                "libstagefright_bufferqueue_helper_novndk",
//                "libcodec2_hidl_plugin_stub",
//            ],
//            shared_libs: [
//                "libstagefright_bufferqueue_helper",
//                "libcodec2_hidl_plugin",
//            ],
//        },
//        apex: {
//            exclude_shared_libs: [
//                "libcodec2_hidl_plugin",
//                "libcodec2_hidl_plugin_stub",
//            ],
//        },
//    },
//
//    export_include_dirs: [
//        "include",
//    ],
//
//    export_shared_lib_headers: [
//        "android.hardware.media.c2@1.0",
//        "libcodec2",
//        "libcodec2_vndk",
//        "libhidlbase",
//        "libstagefright_bufferpool@2.0.1",
//        "libui",
//    ],
//}
//
//// public dependency for Codec 2.0 HAL service implementations
//cc_defaults {
//    name: "libcodec2-hidl-defaults@1.0",
//    defaults: ["libcodec2-impl-defaults"],
//
//    shared_libs: [
//        "android.hardware.media.c2@1.0",
//        "libcodec2_hidl@1.0",
//    ],
//}
// use libcodec2-aidl-defaults instead
cc_library {
    name: "libcodec2_aidl",
    vendor_available: true,
    min_sdk_version: "34",
    apex_available: [
        "//apex_available:platform",
        "com.android.media.swcodec",
        "test_com.android.media.swcodec",
    ],

    srcs: [
        "BufferTypes.cpp",
        "Component.cpp",
        "ComponentInterface.cpp",
        "ComponentStore.cpp",
        "Configurable.cpp",
        "InputBufferManager.cpp",
        "ParamTypes.cpp",
    ],

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

    shared_libs: [
        "android.hardware.common-V2-ndk",
        "android.hardware.media.bufferpool2-V1-ndk",
        "android.hardware.media.c2-V1-ndk",
        "libbase",
        "libbinder_ndk",
        "libcodec2",
        "libcodec2_hal_common",
        "libcodec2_hidl_plugin_stub",
        "libcodec2_vndk",
        "libcutils",
        "libhidlbase",
        "liblog",
        "libstagefright_aidl_bufferpool2",
        "libstagefright_bufferpool@2.0.1",
        "libui",
        "libutils",
    ],

    static_libs: [
        "libaidlcommonsupport",
    ],

    target: {
        vendor: {
            exclude_shared_libs: [
                "libcodec2_hidl_plugin_stub",
            ],
            shared_libs: [
                "libcodec2_hidl_plugin",
            ],
        },
        apex: {
            exclude_shared_libs: [
                "libcodec2_hidl_plugin_stub",
                "libcodec2_hidl_plugin",
            ],
        },
    },

    export_include_dirs: [
        "include",
    ],

    export_shared_lib_headers: [
        "android.hardware.media.c2-V1-ndk",
        "libcodec2",
        "libstagefright_bufferpool@2.0.1",
        "libui",
    ],
}

// public dependency for Codec 2.0 HAL service implementations
cc_defaults {
    name: "libcodec2-aidl-defaults",
    min_sdk_version: "34",
    defaults: ["libcodec2-impl-defaults"],

    shared_libs: [
        "android.hardware.media.c2-V1-ndk",
        "libcodec2_aidl",
    ],
}

// public dependency for Codec 2.0 HAL client
cc_defaults {
+163 −280

File changed.

Preview size limit exceeded, changes collapsed.

+12 −11
Original line number Diff line number Diff line
@@ -18,28 +18,26 @@
#define LOG_TAG "Codec2-ComponentInterface"
#include <android-base/logging.h>

#include <codec2/hidl/1.0/Component.h>
#include <codec2/hidl/1.0/ComponentInterface.h>
#include <codec2/hidl/1.0/ComponentStore.h>
#include <android/binder_auto_utils.h>
#include <codec2/aidl/ComponentInterface.h>
#include <codec2/aidl/Configurable.h>

#include <hidl/HidlBinderSupport.h>
#include <utils/Timers.h>

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

#include <chrono>
#include <thread>

namespace aidl {
namespace android {
namespace hardware {
namespace media {
namespace c2 {
namespace V1_0 {
namespace utils {

using namespace ::android;
using ::ndk::ScopedAStatus;

namespace /* unnamed */ {

@@ -89,7 +87,8 @@ ComponentInterface::ComponentInterface(
        const std::shared_ptr<C2ComponentInterface>& intf,
        const std::shared_ptr<ParameterCache>& cache)
      : mInterface{intf},
        mConfigurable{new CachedConfigurable(std::make_unique<CompIntf>(intf))} {
        mConfigurable{SharedRefBase::make<CachedConfigurable>(
                std::make_unique<CompIntf>(intf))} {
    mInit = mConfigurable->init(cache);
}

@@ -97,14 +96,16 @@ c2_status_t ComponentInterface::status() const {
    return mInit;
}

Return<sp<IConfigurable>> ComponentInterface::getConfigurable() {
    return mConfigurable;
ScopedAStatus ComponentInterface::getConfigurable(
        std::shared_ptr<IConfigurable> *configurable) {
    *configurable = mConfigurable;
    return ScopedAStatus::ok();
}

}  // namespace utils
}  // namespace V1_0
}  // namespace c2
}  // namespace media
}  // namespace hardware
}  // namespace android
}  // namespace aidl
+79 −163
Original line number Diff line number Diff line
@@ -15,15 +15,16 @@
 */

//#define LOG_NDEBUG 0
#define LOG_TAG "Codec2-ComponentStore@1.2"
#define LOG_TAG "Codec2-ComponentStore-Aidl"
#include <android-base/logging.h>

#include <codec2/hidl/1.2/ComponentStore.h>
#include <codec2/hidl/1.2/InputSurface.h>
#include <codec2/hidl/1.2/types.h>
#include <bufferpool2/ClientManager.h>
#include <codec2/aidl/Component.h>
#include <codec2/aidl/ComponentInterface.h>
#include <codec2/aidl/ComponentStore.h>
#include <codec2/aidl/ParamTypes.h>

#include <android-base/file.h>
#include <media/stagefright/bqhelper/GraphicBufferSource.h>
#include <utils/Errors.h>

#include <C2PlatformSupport.h>
@@ -43,16 +44,16 @@
#include <FilterWrapper.h>
#endif

namespace aidl {
namespace android {
namespace hardware {
namespace media {
namespace c2 {
namespace V1_2 {
namespace utils {

using namespace ::android;
using ::android::GraphicBufferSource;
using namespace ::android::hardware::media::bufferpool::V2_0::implementation;
using ::android::DefaultFilterPlugin;
using ::android::FilterWrapper;
using ::ndk::ScopedAStatus;

namespace /* unnamed */ {

@@ -131,12 +132,13 @@ struct ComponentStore::StoreParameterCache : public ParameterCache {
};

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

    std::shared_ptr<C2ComponentStore> platformStore = android::GetCodec2PlatformComponentStore();
    SetPreferredCodec2ComponentStore(store);
    std::shared_ptr<C2ComponentStore> platformStore =
        ::android::GetCodec2PlatformComponentStore();
    ::android::SetPreferredCodec2ComponentStore(store);

    // Retrieve struct descriptors
    mParamReflector = mStore->getParamReflector();
@@ -194,93 +196,78 @@ std::shared_ptr<FilterWrapper> ComponentStore::GetFilterWrapper() {
}
#endif

// Methods from ::android::hardware::media::c2::V1_0::IComponentStore
Return<void> ComponentStore::createComponent(
        const hidl_string& name,
        const sp<IComponentListener>& listener,
        const sp<IClientManager>& pool,
        createComponent_cb _hidl_cb) {
// Methods from ::aidl::android::hardware::media::c2::IComponentStore
ScopedAStatus ComponentStore::createComponent(
        const std::string& name,
        const std::shared_ptr<IComponentListener>& listener,
        const std::shared_ptr<IClientManager>& pool,
        std::shared_ptr<IComponent> *component) {

    sp<Component> component;
    std::shared_ptr<C2Component> c2component;
    Status status = static_cast<Status>(
            mStore->createComponent(name, &c2component));
    c2_status_t status =
            mStore->createComponent(name, &c2component);

    if (status == Status::OK) {
    if (status == C2_OK) {
#ifndef __ANDROID_APEX__
        c2component = GetFilterWrapper()->maybeWrapComponent(c2component);
#endif
        onInterfaceLoaded(c2component->intf());
        component = new Component(c2component, listener, this, pool);
        std::shared_ptr<Component> comp =
            SharedRefBase::make<Component>(c2component, listener, shared_from_this(), pool);
        *component = comp;
        if (!component) {
            status = Status::CORRUPTED;
            status = C2_CORRUPTED;
        } else {
            reportComponentBirth(component.get());
            if (component->status() != C2_OK) {
                status = static_cast<Status>(component->status());
            reportComponentBirth(comp.get());
            if (comp->status() != C2_OK) {
                status = comp->status();
            } else {
                component->initListener(component);
                if (component->status() != C2_OK) {
                    status = static_cast<Status>(component->status());
                comp->initListener(comp);
                if (comp->status() != C2_OK) {
                    status = comp->status();
                }
            }
        }
    }
    _hidl_cb(status, component);
    return Void();
    if (status == C2_OK) {
        return ScopedAStatus::ok();
    }
    return ScopedAStatus::fromServiceSpecificError(status);
}

Return<void> ComponentStore::createInterface(
        const hidl_string& name,
        createInterface_cb _hidl_cb) {
ScopedAStatus ComponentStore::createInterface(
        const std::string& name,
        std::shared_ptr<IComponentInterface> *intf) {
    std::shared_ptr<C2ComponentInterface> c2interface;
    c2_status_t res = mStore->createInterface(name, &c2interface);
    sp<IComponentInterface> interface;
    if (res == C2_OK) {
#ifndef __ANDROID_APEX__
        c2interface = GetFilterWrapper()->maybeWrapInterface(c2interface);
#endif
        onInterfaceLoaded(c2interface);
        interface = new ComponentInterface(c2interface, mParameterCache);
        *intf = SharedRefBase::make<ComponentInterface>(c2interface, mParameterCache);
        return ScopedAStatus::ok();
    }
    _hidl_cb(static_cast<Status>(res), interface);
    return Void();
    return ScopedAStatus::fromServiceSpecificError(res);
}

Return<void> ComponentStore::listComponents(listComponents_cb _hidl_cb) {
ScopedAStatus ComponentStore::listComponents(
        std::vector<IComponentStore::ComponentTraits> *traits) {
    std::vector<std::shared_ptr<const C2Component::Traits>> c2traits =
            mStore->listComponents();
    hidl_vec<IComponentStore::ComponentTraits> traits(c2traits.size());
    traits->resize(c2traits.size());
    size_t ix = 0;
    for (const std::shared_ptr<const C2Component::Traits> &c2trait : c2traits) {
        if (c2trait) {
            if (objcpy(&traits[ix], *c2trait)) {
            if (ToAidl(&traits->at(ix), *c2trait)) {
                ++ix;
            } else {
                break;
            }
        }
    }
    traits.resize(ix);
    _hidl_cb(Status::OK, traits);
    return Void();
}

Return<void> ComponentStore::createInputSurface(createInputSurface_cb _hidl_cb) {
    sp<GraphicBufferSource> source = new GraphicBufferSource();
    if (source->initCheck() != OK) {
        _hidl_cb(Status::CORRUPTED, nullptr);
        return Void();
    }
    using namespace std::placeholders;
    sp<InputSurface> inputSurface = new InputSurface(
            mParameterCache,
            std::make_shared<C2ReflectorHelper>(),
            source->getHGraphicBufferProducer(),
            source);
    _hidl_cb(inputSurface ? Status::OK : Status::NO_MEMORY,
             inputSurface);
    return Void();
    traits->resize(ix);
    return ScopedAStatus::ok();
}

void ComponentStore::onInterfaceLoaded(const std::shared_ptr<C2ComponentInterface> &intf) {
@@ -293,15 +280,16 @@ void ComponentStore::onInterfaceLoaded(const std::shared_ptr<C2ComponentInterfac
    }
}

Return<void> ComponentStore::getStructDescriptors(
        const hidl_vec<uint32_t>& indices,
        getStructDescriptors_cb _hidl_cb) {
    hidl_vec<StructDescriptor> descriptors(indices.size());
ScopedAStatus ComponentStore::getStructDescriptors(
        const std::vector<int32_t>& indices,
        std::vector<StructDescriptor> *descriptors) {
    descriptors->resize(indices.size());
    size_t dstIx = 0;
    Status res = Status::OK;
    int32_t res = Status::OK;
    for (size_t srcIx = 0; srcIx < indices.size(); ++srcIx) {
        std::lock_guard<std::mutex> lock(mStructDescriptorsMutex);
        const C2Param::CoreIndex coreIndex = C2Param::CoreIndex(indices[srcIx]).coreIndex();
        const C2Param::CoreIndex coreIndex =
            C2Param::CoreIndex(uint32_t(indices[srcIx])).coreIndex();
        const auto item = mStructDescriptors.find(coreIndex);
        if (item == mStructDescriptors.end()) {
            // not in the cache, and not known to be unsupported, query local reflector
@@ -312,7 +300,7 @@ Return<void> ComponentStore::getStructDescriptors(
                    mUnsupportedStructDescriptors.emplace(coreIndex);
                } else {
                    mStructDescriptors.insert({ coreIndex, structDesc });
                    if (objcpy(&descriptors[dstIx], *structDesc)) {
                    if (ToAidl(&descriptors->at(dstIx), *structDesc)) {
                        ++dstIx;
                        continue;
                    }
@@ -322,7 +310,7 @@ Return<void> ComponentStore::getStructDescriptors(
            }
            res = Status::NOT_FOUND;
        } else if (item->second) {
            if (objcpy(&descriptors[dstIx], *item->second)) {
            if (ToAidl(&descriptors->at(dstIx), *item->second)) {
                ++dstIx;
                continue;
            }
@@ -333,96 +321,31 @@ Return<void> ComponentStore::getStructDescriptors(
            break;
        }
    }
    descriptors.resize(dstIx);
    _hidl_cb(res, descriptors);
    return Void();
    descriptors->resize(dstIx);
    if (res == Status::OK) {
        return ScopedAStatus::ok();
    }
    return ScopedAStatus::fromServiceSpecificError(res);
}

Return<sp<IClientManager>> ComponentStore::getPoolClientManager() {
    return ClientManager::getInstance();
ScopedAStatus ComponentStore::getPoolClientManager(
        std::shared_ptr<IClientManager> *manager) {
    using ::aidl::android::hardware::media::bufferpool2::implementation::ClientManager;
    *manager = ClientManager::getInstance();
    return ScopedAStatus::ok();
}

Return<Status> ComponentStore::copyBuffer(const Buffer& src, const Buffer& dst) {
ScopedAStatus ComponentStore::copyBuffer(const Buffer& src, const Buffer& dst) {
    // TODO implement
    (void)src;
    (void)dst;
    return Status::OMITTED;
    return ScopedAStatus::fromServiceSpecificError(Status::OMITTED);
}

Return<sp<IConfigurable>> ComponentStore::getConfigurable() {
    return mConfigurable;
}

// Methods from ::android::hardware::media::c2::V1_1::IComponentStore
Return<void> ComponentStore::createComponent_1_1(
        const hidl_string& name,
        const sp<IComponentListener>& listener,
        const sp<IClientManager>& pool,
        createComponent_1_1_cb _hidl_cb) {

    sp<Component> component;
    std::shared_ptr<C2Component> c2component;
    Status status = static_cast<Status>(
            mStore->createComponent(name, &c2component));

    if (status == Status::OK) {
#ifndef __ANDROID_APEX__
        c2component = GetFilterWrapper()->maybeWrapComponent(c2component);
#endif
        onInterfaceLoaded(c2component->intf());
        component = new Component(c2component, listener, this, pool);
        if (!component) {
            status = Status::CORRUPTED;
        } else {
            reportComponentBirth(component.get());
            if (component->status() != C2_OK) {
                status = static_cast<Status>(component->status());
            } else {
                component->initListener(component);
                if (component->status() != C2_OK) {
                    status = static_cast<Status>(component->status());
                }
            }
        }
    }
    _hidl_cb(status, component);
    return Void();
}

// Methods from ::android::hardware::media::c2::V1_2::IComponentStore
Return<void> ComponentStore::createComponent_1_2(
        const hidl_string& name,
        const sp<IComponentListener>& listener,
        const sp<IClientManager>& pool,
        createComponent_1_2_cb _hidl_cb) {

    sp<Component> component;
    std::shared_ptr<C2Component> c2component;
    Status status = static_cast<Status>(
            mStore->createComponent(name, &c2component));

    if (status == Status::OK) {
#ifndef __ANDROID_APEX__
        c2component = GetFilterWrapper()->maybeWrapComponent(c2component);
#endif
        onInterfaceLoaded(c2component->intf());
        component = new Component(c2component, listener, this, pool);
        if (!component) {
            status = Status::CORRUPTED;
        } else {
            reportComponentBirth(component.get());
            if (component->status() != C2_OK) {
                status = static_cast<Status>(component->status());
            } else {
                component->initListener(component);
                if (component->status() != C2_OK) {
                    status = static_cast<Status>(component->status());
                }
            }
        }
    }
    _hidl_cb(status, component);
    return Void();
ScopedAStatus ComponentStore::getConfigurable(
        std::shared_ptr<IConfigurable> *configurable) {
    *configurable = mConfigurable;
    return ScopedAStatus::ok();
}

// Called from createComponent() after a successful creation of `component`.
@@ -495,16 +418,9 @@ std::ostream& ComponentStore::dump(
}

// Dumps information when lshal is called.
Return<void> ComponentStore::debug(
        const hidl_handle& handle,
        const hidl_vec<hidl_string>& /* args */) {
binder_status_t ComponentStore::dump(
        int fd, [[maybe_unused]] const char** args, [[maybe_unused]] uint32_t numArgs) {
    LOG(INFO) << "debug -- dumping...";
    const native_handle_t *h = handle.getNativeHandle();
    if (!h || h->numFds != 1) {
       LOG(ERROR) << "debug -- dumping failed -- "
               "invalid file descriptor to dump to";
       return Void();
    }
    std::ostringstream out;

    { // Populate "out".
@@ -546,17 +462,17 @@ Return<void> ComponentStore::debug(
                << mStore->getName() << std::endl;
    }

    if (!android::base::WriteStringToFd(out.str(), h->data[0])) {
    if (!::android::base::WriteStringToFd(out.str(), fd)) {
        PLOG(WARNING) << "debug -- dumping failed -- write()";
    } else {
        LOG(INFO) << "debug -- dumping succeeded";
    }
    return Void();
    return STATUS_OK;
}

} // namespace utils
} // namespace V1_2
} // namespace c2
} // namespace media
} // namespace hardware
} // namespace android
} // namespace aidl
+61 −57

File changed.

Preview size limit exceeded, changes collapsed.

Loading