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

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

Merge changes Ibb4dad3a,I6eb1ce89 am: 261eac80 am: b078796d am: 73d6a085 am: 6ccc50f5

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/1965761

Change-Id: If44cc71647e9311180a9d52e0cb4b25cef587053
parents cdd7a4c2 6ccc50f5
Loading
Loading
Loading
Loading
+1 −32
Original line number Diff line number Diff line
@@ -9,44 +9,13 @@ package {

cc_defaults {
    name: "C2SoftCodecTest-defaults",
    defaults: [ "libcodec2-static-defaults" ],
    gtest: true,
    host_supported: false,
    srcs: [
        "C2SoftCodecTest.cpp",
    ],

    static_libs: [
        "liblog",
        "libion",
        "libfmq",
        "libbase",
        "libutils",
        "libcutils",
        "libcodec2",
        "libhidlbase",
        "libdmabufheap",
        "libcodec2_vndk",
        "libnativewindow",
        "libcodec2_soft_common",
        "libsfplugin_ccodec_utils",
        "libstagefright_foundation",
        "libstagefright_bufferpool@2.0.1",
        "android.hardware.graphics.mapper@2.0",
        "android.hardware.graphics.mapper@3.0",
        "android.hardware.media.bufferpool@2.0",
        "android.hardware.graphics.allocator@2.0",
        "android.hardware.graphics.allocator@3.0",
        "android.hardware.graphics.bufferqueue@2.0",
    ],

    shared_libs: [
        "libui",
        "libdl",
        "libhardware",
        "libvndksupport",
        "libprocessgroup",
    ],

    cflags: [
        "-Wall",
        "-Werror",
+2 −33
Original line number Diff line number Diff line
@@ -28,43 +28,12 @@ package {
cc_defaults {
    name: "C2Fuzzer-defaults",

    defaults: [ "libcodec2-static-defaults" ],

    srcs: [
        "C2Fuzzer.cpp",
    ],

    static_libs: [
        "liblog",
        "libion",
        "libfmq",
        "libbase",
        "libutils",
        "libcutils",
        "libcodec2",
        "libhidlbase",
        "libdmabufheap",
        "libcodec2_vndk",
        "libnativewindow",
        "libcodec2_soft_common",
        "libsfplugin_ccodec_utils",
        "libstagefright_foundation",
        "libstagefright_bufferpool@2.0.1",
        "android.hardware.graphics.mapper@2.0",
        "android.hardware.graphics.mapper@3.0",
        "android.hardware.media.bufferpool@2.0",
        "android.hardware.graphics.allocator@2.0",
        "android.hardware.graphics.allocator@3.0",
        "android.hardware.graphics.bufferqueue@2.0",
    ],

    shared_libs: [
        "libui",
        "libdl",
        "libbinder",
        "libhardware",
        "libvndksupport",
        "libprocessgroup",
    ],

    cflags: [
        "-Wall",
        "-Werror",
+41 −2
Original line number Diff line number Diff line
@@ -73,11 +73,12 @@ cc_library {
        "libbase",
        "libcutils",
        "libdl",
        "libdmabufheap",
        "libfmq",
        "libgralloctypes",
        "libhardware",
        "libhidlbase",
        "libion",
        "libdmabufheap",
        "libfmq",
        "liblog",
        "libnativewindow",
        "libstagefright_foundation",
@@ -92,6 +93,44 @@ cc_library {
    ],
}

// public dependency for statically linking to libcodec2_vndk for unit tests
cc_defaults {
    name: "libcodec2-static-defaults",

    static_libs: [
        "liblog",
        "libion",
        "libfmq",
        "libbase",
        "libutils",
        "libcutils",
        "libcodec2",
        "libhidlbase",
        "libdmabufheap",
        "libcodec2_vndk",
        "libnativewindow",
        "libcodec2_soft_common",
        "libsfplugin_ccodec_utils",
        "libstagefright_foundation",
        "libstagefright_bufferpool@2.0.1",
        "libgralloctypes",
        "android.hardware.graphics.mapper@2.0",
        "android.hardware.graphics.mapper@3.0",
        "android.hardware.media.bufferpool@2.0",
        "android.hardware.graphics.allocator@2.0",
        "android.hardware.graphics.allocator@3.0",
        "android.hardware.graphics.bufferqueue@2.0",
    ],

    shared_libs: [
        "libui",
        "libdl",
        "libhardware",
        "libvndksupport",
        "libprocessgroup",
    ],
}

// public dependency for implementing Codec 2 components
cc_defaults {
    name: "libcodec2-impl-defaults",
+98 −4
Original line number Diff line number Diff line
@@ -20,8 +20,10 @@

#include <mutex>

#include <aidl/android/hardware/graphics/common/PlaneLayoutComponentType.h>
#include <android/hardware/graphics/common/1.2/types.h>
#include <cutils/native_handle.h>
#include <gralloctypes/Gralloc4.h>
#include <hardware/gralloc.h>
#include <ui/GraphicBufferAllocator.h>
#include <ui/GraphicBufferMapper.h>
@@ -29,6 +31,7 @@

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

using ::android::hardware::hidl_handle;
@@ -230,8 +233,89 @@ public:
    }
};

static
c2_status_t Gralloc4Mapper_lock(native_handle_t *handle, uint64_t usage, const Rect& bounds,
        C2PlanarLayout *layout, uint8_t **addr) {
    GraphicBufferMapper &mapper = GraphicBufferMapper::get();

    std::vector<ui::PlaneLayout> planes;
    // this method is only supported on Gralloc 4 or later
    status_t err = mapper.getPlaneLayouts(handle, &planes);
    if (err != NO_ERROR || planes.empty()) {
        return C2_CANNOT_DO;
    }

    uint8_t *pointer = nullptr;
    err = mapper.lock(handle, usage, bounds, (void **)&pointer, nullptr, nullptr);
    if (err != NO_ERROR || pointer == nullptr) {
        return C2_CORRUPTED;
    }

    using aidl::android::hardware::graphics::common::PlaneLayoutComponentType;
    using aidl::android::hardware::graphics::common::PlaneLayoutComponent;

    layout->type = C2PlanarLayout::TYPE_YUV;
    layout->numPlanes = 0;
    layout->rootPlanes = 0;

    for (const ui::PlaneLayout &plane : planes) {
        layout->rootPlanes++;
        uint32_t lastOffsetInBits = 0;
        uint32_t rootIx = 0;

        for (const PlaneLayoutComponent &component : plane.components) {
            if (!gralloc4::isStandardPlaneLayoutComponentType(component.type)) {
                return C2_CANNOT_DO;
            }

            uint32_t rightShiftBits = component.offsetInBits - lastOffsetInBits;
            uint32_t allocatedDepthInBits = component.sizeInBits + rightShiftBits;
            C2PlanarLayout::plane_index_t planeId;
            C2PlaneInfo::channel_t channel;

            switch (static_cast<PlaneLayoutComponentType>(component.type.value)) {
                case PlaneLayoutComponentType::Y:
                    planeId = C2PlanarLayout::PLANE_Y;
                    channel = C2PlaneInfo::CHANNEL_Y;
                    break;
                case PlaneLayoutComponentType::CB:
                    planeId = C2PlanarLayout::PLANE_U;
                    channel = C2PlaneInfo::CHANNEL_CB;
                    break;
                case PlaneLayoutComponentType::CR:
                    planeId = C2PlanarLayout::PLANE_V;
                    channel = C2PlaneInfo::CHANNEL_CR;
                    break;
                default:
                    return C2_CORRUPTED;
            }

            addr[planeId] = pointer + plane.offsetInBytes + (component.offsetInBits / 8);
            layout->planes[planeId] = {
                channel,                                                // channel
                static_cast<int32_t>(plane.sampleIncrementInBits / 8),  // colInc
                static_cast<int32_t>(plane.strideInBytes),              // rowInc
                static_cast<uint32_t>(plane.horizontalSubsampling),     // mColSampling
                static_cast<uint32_t>(plane.verticalSubsampling),       // mRowSampling
                allocatedDepthInBits,                                   // allocatedDepth (bits)
                static_cast<uint32_t>(component.sizeInBits),            // bitDepth (bits)
                rightShiftBits,                                         // rightShift (bits)
                C2PlaneInfo::NATIVE,                                    // endianness
                rootIx,                                                 // rootIx
                static_cast<uint32_t>(component.offsetInBits / 8),      // offset (bytes)
            };

            layout->numPlanes++;
            lastOffsetInBits = component.offsetInBits + component.sizeInBits;
            rootIx++;
        }
    }
    return C2_OK;
}

} // unnamed namespace


native_handle_t *UnwrapNativeCodec2GrallocHandle(const C2Handle *const handle) {
    return C2HandleGralloc::UnwrapNativeHandle(handle);
}
@@ -385,6 +469,10 @@ c2_status_t C2AllocationGralloc::map(
                mBuffer, mWidth, mHeight, mFormat, mGrallocUsage,
                mStride, generation, igbp_id, igbp_slot);
    }

    // 'NATIVE' on Android means LITTLE_ENDIAN
    constexpr C2PlaneInfo::endianness_t kEndianness = C2PlaneInfo::NATIVE;

    switch (mFormat) {
        case static_cast<uint32_t>(PixelFormat4::RGBA_1010102): {
            // TRICKY: this is used for media as YUV444 in the case when it is queued directly to a
@@ -646,7 +734,7 @@ c2_status_t C2AllocationGralloc::map(
                16,                             // allocatedDepth
                10,                             // bitDepth
                6,                              // rightShift
                C2PlaneInfo::LITTLE_END,        // endianness
                kEndianness,                    // endianness
                C2PlanarLayout::PLANE_Y,        // rootIx
                0,                              // offset
            };
@@ -659,7 +747,7 @@ c2_status_t C2AllocationGralloc::map(
                16,                             // allocatedDepth
                10,                             // bitDepth
                6,                              // rightShift
                C2PlaneInfo::LITTLE_END,        // endianness
                kEndianness,                    // endianness
                C2PlanarLayout::PLANE_U,        // rootIx
                0,                              // offset
            };
@@ -672,7 +760,7 @@ c2_status_t C2AllocationGralloc::map(
                16,                             // allocatedDepth
                10,                             // bitDepth
                6,                              // rightShift
                C2PlaneInfo::LITTLE_END,        // endianness
                kEndianness,                    // endianness
                C2PlanarLayout::PLANE_U,        // rootIx
                2,                              // offset
            };
@@ -680,9 +768,15 @@ c2_status_t C2AllocationGralloc::map(
        }

        default: {
            // We don't know what it is, but let's try to lock it.
            // We don't know what it is, let's try to lock it with gralloc4
            android_ycbcr ycbcrLayout;
            c2_status_t status = Gralloc4Mapper_lock(
                    const_cast<native_handle_t*>(mBuffer), grallocUsage, rect, layout, addr);
            if (status == C2_OK) {
                break;
            }

            // fallback to lockYCbCr
            status_t err = GraphicBufferMapper::get().lockYCbCr(
                    const_cast<native_handle_t*>(mBuffer), grallocUsage, rect, &ycbcrLayout);
            if (err == OK && ycbcrLayout.y && ycbcrLayout.cb && ycbcrLayout.cr