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

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

Merge "media.c2 aidl: Unwrap AHardwareBuffer based handle from existing APIs"...

Merge "media.c2 aidl: Unwrap AHardwareBuffer based handle from existing APIs" into main am: 9b1c4a98 am: 183e08ee

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



Change-Id: I285504b76edb5b705d89f33ba9fb26ebab972bfd
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents b6edb15d 183e08ee
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -1049,12 +1049,9 @@ public:
        // Unwrap raw buffer handle from the C2Handle
        native_handle_t *nh = UnwrapNativeCodec2GrallocHandle(handle);
        if (!nh) {
            nh = UnwrapNativeCodec2AhwbHandle(handle);
            if (!nh) {
                ALOGE("handle is not compatible to neither C2HandleGralloc nor C2HandleAhwb");
            ALOGE("handle is not compatible to any gralloc C2Handle types");
            return;
        }
        }
        // Import the raw handle so IMapper can use the buffer. The imported
        // handle must be freed when the client is done with the buffer.
        status_t status = mapper.importBufferNoValidate(
+62 −15
Original line number Diff line number Diff line
@@ -318,6 +318,14 @@ public:
        return reinterpret_cast<C2HandleAhwb *>(res);
    }

    static uint32_t getPixelFormat(const C2Handle *const handle) {
        if (handle == nullptr) {
            return 0;
        }
        const ExtraData *xd = GetExtraData(handle);
        return xd->format;
    }

    static C2HandleAhwb* WrapNativeHandle(
            const native_handle_t *const handle,
            uint32_t width, uint32_t height, uint32_t format, uint64_t usage,
@@ -899,8 +907,18 @@ static void HandleInterleavedPlanes(


native_handle_t *UnwrapNativeCodec2GrallocHandle(const C2Handle *const handle) {
    if (handle == nullptr) {
        return nullptr;
    }
    if (C2AllocatorGralloc::CheckHandle(handle)) {
        return C2HandleGralloc::UnwrapNativeHandle(handle);
    }
    if (C2AllocatorAhwb::CheckHandle(handle)) {
        return C2HandleAhwb::UnwrapNativeHandle(handle);
    }
    ALOGE("tried to unwrap non c2 compatible handle");
    return nullptr;
}

C2Handle *WrapNativeCodec2GrallocHandle(
        const native_handle_t *const handle,
@@ -911,8 +929,39 @@ C2Handle *WrapNativeCodec2GrallocHandle(
}

uint32_t ExtractFormatFromCodec2GrallocHandle(const C2Handle *const handle) {
    if (C2AllocatorGralloc::CheckHandle(handle)) {
        return C2HandleGralloc::getPixelFormat(handle);
    }
    if (C2AllocatorAhwb::CheckHandle(handle)) {
        return C2HandleAhwb::getPixelFormat(handle);
    }
    ALOGE("tried to extract pixelformat from non c2 compatible handle");
    return 0;
}

bool EXtractMetadataFromCodec2GrallocHandle(
        const C2Handle *const handle,
        uint32_t *width, uint32_t *height, uint32_t *format, uint64_t *usage, uint32_t *stride) {
    if (handle == nullptr) {
        ALOGE("ExtractMetadata from nullptr");
        return false;
    }
    if (C2AllocatorGralloc::CheckHandle(handle)) {
        uint32_t generation;
        uint64_t igbp_id;
        uint32_t igbp_slot;
        (void)C2HandleGralloc::Import(handle, width, height, format, usage, stride,
                                      &generation, &igbp_id, &igbp_slot);
        return true;
    }
    if (C2AllocatorAhwb::CheckHandle(handle)) {
        uint64_t origId;
        (void)C2HandleAhwb::Import(handle, width, height, format, usage, stride, &origId);
        return true;
    }
    ALOGE("EXtractMetadata from non compatible handle");
    return false;
}

bool MigrateNativeCodec2GrallocHandle(
        native_handle_t *handle,
@@ -1137,8 +1186,17 @@ void _UnwrapNativeCodec2GrallocMetadata(
        const C2Handle *const handle,
        uint32_t *width, uint32_t *height, uint32_t *format,uint64_t *usage, uint32_t *stride,
        uint32_t *generation, uint64_t *igbp_id, uint32_t *igbp_slot) {
    if (C2AllocatorGralloc::CheckHandle(handle)) {
        (void)C2HandleGralloc::Import(handle, width, height, format, usage, stride,
                                      generation, igbp_id, igbp_slot);
        return;
    }
    if (C2AllocatorAhwb::CheckHandle(handle)) {
        uint64_t origId;
        (void)C2HandleAhwb::Import(handle, width, height, format, usage, stride, &origId);
        return;
    }
    ALOGE("Tried to extract metadata from non c2 compatible handle");
}

C2AllocatorGralloc::Impl::Impl(id_t id, bool bufferQueue)
@@ -1250,10 +1308,6 @@ bool C2AllocatorGralloc::CheckHandle(const C2Handle* const o) {
}


native_handle_t *UnwrapNativeCodec2AhwbHandle(const C2Handle *const handle) {
    return C2HandleAhwb::UnwrapNativeHandle(handle);
}

C2Handle *WrapNativeCodec2AhwbHandle(
        const native_handle_t *const handle,
        uint32_t width, uint32_t height, uint32_t format, uint64_t usage, uint32_t stride,
@@ -1477,13 +1531,6 @@ private:
    c2_status_t mInit;
};

void _UnwrapNativeCodec2AhwbMetadata(
        const C2Handle *const handle,
        uint32_t *width, uint32_t *height, uint32_t *format,uint64_t *usage, uint32_t *stride,
        uint64_t *origId) {
    (void)C2HandleAhwb::Import(handle, width, height, format, usage, stride, origId);
}

C2AllocatorAhwb::Impl::Impl(id_t id)
    : mInit(C2_OK) {
    // TODO: get this from allocator
+17 −25
Original line number Diff line number Diff line
@@ -22,7 +22,24 @@
#include <C2Buffer.h>

namespace android {
// VNDK
/**
 * Extract pixel format from the extra data of gralloc handle.
 *
 * @return 0 when no valid pixel format exists.
 */
uint32_t ExtractFormatFromCodec2GrallocHandle(const C2Handle *const handle);

/**
 * Extract metadata from the extra data of gralloc handle.
 *
 * @return {@code false} if extraction was failed, {@code true} otherwise.
 */
bool ExtractMetadataFromCodec2GrallocHandle(
    const C2Handle *const handle,
    uint32_t *width, uint32_t *height, uint32_t *format, uint64_t *usage, uint32_t  *stride);

// Not for VNDK (system partition and inside vndk only)
/**
 * Unwrap the native handle from a Codec2 handle allocated by C2AllocatorGralloc.
 *
@@ -45,13 +62,6 @@ C2Handle *WrapNativeCodec2GrallocHandle(
        uint32_t width, uint32_t height, uint32_t format, uint64_t usage, uint32_t stride,
        uint32_t generation = 0, uint64_t igbp_id = 0, uint32_t igbp_slot = 0);

/**
 * Extract pixel format from the extra data of gralloc handle.
 *
 * @return 0 when no valid pixel format exists.
 */
uint32_t ExtractFormatFromCodec2GrallocHandle(const C2Handle *const handle);

/**
 * When the gralloc handle is migrated to another bufferqueue, update
 * bufferqueue information.
@@ -70,16 +80,6 @@ void _UnwrapNativeCodec2GrallocMetadata(
        uint32_t *width, uint32_t *height, uint32_t *format, uint64_t *usage, uint32_t *stride,
        uint32_t *generation, uint64_t *igbp_id, uint32_t *igbp_slot);

/**
 * Unwrap the native handle from a Codec2 handle allocated by C2AllocatorAhwb.
 *
 * @param handle a handle allocated by C2AllocatorAhwb. This includes handles returned for a
 * graphic block allocation handle based on an AHardwareBuffer.
 *
 * @return a new NON-OWNING native handle that must be deleted using native_handle_delete.
 */
native_handle_t *UnwrapNativeCodec2AhwbHandle(const C2Handle *const handle);

/**
 * Wrap the gralloc handle and metadata based on AHardwareBuffer into Codec2 handle
 * recognized by C2AllocatorAhwb.
@@ -92,14 +92,6 @@ C2Handle *WrapNativeCodec2AhwbHandle(
        uint32_t width, uint32_t height, uint32_t format, uint64_t usage, uint32_t stride,
        uint64_t origId);

/**
 * \todo Get this from the buffer
 */
void _UnwrapNativeCodec2AhwbMetadata(
        const C2Handle *const handle,
        uint32_t *width, uint32_t *height, uint32_t *format, uint64_t *usage, uint32_t *stride,
        uint64_t *origId);

class C2AllocatorGralloc : public C2Allocator {
public:
    virtual id_t getId() const override;