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

Commit 32504e89 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Enable YUV420Flexible output in FrameDecoder" into udc-dev am: 68b3da47

parents 83f581d6 68b3da47
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -542,7 +542,7 @@ sp<AMessage> VideoFrameDecoder::onGetFormatAndSeekOptions(
    if (dstFormat() == COLOR_Format32bitABGR2101010) {
        videoFormat->setInt32("color-format", COLOR_FormatYUVP010);
    } else {
        videoFormat->setInt32("color-format", OMX_COLOR_FormatYUV420Planar);
        videoFormat->setInt32("color-format", COLOR_FormatYUV420Flexible);
    }

    // For the thumbnail extraction case, try to allocate single buffer in both
@@ -685,7 +685,6 @@ status_t VideoFrameDecoder::onOutputReceived(
    if (mCaptureLayer != nullptr) {
        return captureSurface();
    }

    ColorConverter converter((OMX_COLOR_FORMATTYPE)srcFormat, dstFormat());

    uint32_t standard, range, transfer;
@@ -698,8 +697,18 @@ status_t VideoFrameDecoder::onOutputReceived(
    if (!outputFormat->findInt32("color-transfer", (int32_t*)&transfer)) {
        transfer = 0;
    }
    sp<ABuffer> imgObj;
    if (videoFrameBuffer->meta()->findBuffer("image-data", &imgObj)) {
        MediaImage2 *imageData = nullptr;
        imageData = (MediaImage2 *)(imgObj.get()->data());
        if (imageData != nullptr) {
            converter.setSrcMediaImage2(*imageData);
        }
    }
    if (srcFormat == COLOR_FormatYUV420Flexible && imgObj.get() == nullptr) {
        return ERROR_UNSUPPORTED;
    }
    converter.setSrcColorSpace(standard, range, transfer);

    if (converter.isValid()) {
        converter.convert(
                (const uint8_t *)videoFrameBuffer->data(),
@@ -864,7 +873,7 @@ sp<AMessage> MediaImageDecoder::onGetFormatAndSeekOptions(
    if (dstFormat() == COLOR_Format32bitABGR2101010) {
        videoFormat->setInt32("color-format", COLOR_FormatYUVP010);
    } else {
        videoFormat->setInt32("color-format", OMX_COLOR_FormatYUV420Planar);
        videoFormat->setInt32("color-format", COLOR_FormatYUV420Flexible);
    }

    if ((mGridRows == 1) && (mGridCols == 1)) {
@@ -967,6 +976,17 @@ status_t MediaImageDecoder::onOutputReceived(
    if (!outputFormat->findInt32("color-transfer", (int32_t*)&transfer)) {
        transfer = 0;
    }
    sp<ABuffer> imgObj;
    if (videoFrameBuffer->meta()->findBuffer("image-data", &imgObj)) {
        MediaImage2 *imageData = nullptr;
        imageData = (MediaImage2 *)(imgObj.get()->data());
        if (imageData != nullptr) {
            converter.setSrcMediaImage2(*imageData);
        }
    }
    if (srcFormat == COLOR_FormatYUV420Flexible && imgObj.get() == nullptr) {
        return ERROR_UNSUPPORTED;
    }
    converter.setSrcColorSpace(standard, range, transfer);

    int32_t crop_left, crop_top, crop_right, crop_bottom;
+709 −225

File changed.

Preview size limit exceeded, changes collapsed.

+103 −20
Original line number Diff line number Diff line
@@ -23,7 +23,10 @@
#include <stdint.h>
#include <utils/Errors.h>

#include <optional>

#include <OMX_Video.h>
#include <media/hardware/VideoAPI.h>

namespace android {

@@ -35,6 +38,8 @@ struct ColorConverter {

    bool isDstRGB() const;

    void setSrcMediaImage2(MediaImage2 img);

    void setSrcColorSpace(uint32_t standard, uint32_t range, uint32_t transfer);

    status_t convert(
@@ -49,18 +54,91 @@ struct ColorConverter {

    struct Coeffs; // matrix coefficients

private:
    struct ColorSpace {
        uint32_t mStandard;
        uint32_t mRange;
        uint32_t mTransfer;

        bool isLimitedRange() const;
        // libyuv helper methods
        //   BT.2020 limited Range
        bool isBt2020() const;
        // BT.2020 full range
        bool isBtV2020() const;
        // 709 limited range
        bool isH709() const;
        // 709 full range
        bool isF709() const;
        // 601 limited range
        bool isI601() const;
        // 601 full range
        // also called "JPEG" in libyuv
        bool isJ601() const;
    };

        // libyuv helper methods
        bool isH420() const;
        bool isI420() const;
        bool isJ420() const;
private:

    typedef enum : uint8_t {
        ImageLayoutUnknown = 0x0,
        ImageLayout420SemiPlanar = 0x1,
        ImageLayout420Planar = 0x2
    } Layout_t;

    typedef enum : uint8_t {
        ImageSamplingUnknown = 0x0,
        ImageSamplingYUV420 = 0x1,
    } Sampling_t;

    //this is the actual usable bit
    typedef enum : uint8_t {
        ImageBitDepthInvalid = 0x0,
        ImageBitDepth8 = 0x1,
        ImageBitDepth10 = 0x2,
        ImageBitDepth12 = 0x3,
        ImageBitDepth16 = 0x4
    } BitDepth_t;

    struct BitmapParams;


    class Image {
    public:
        Image(const MediaImage2& img);
        virtual ~Image() {}

        const MediaImage2 getMediaImage2() const {
            return mImage;
        }

        Layout_t getLayout() const {
            return mLayout;
        }
        Sampling_t getSampling() const {
            return mSampling;
        }
        BitDepth_t getBitDepth() const {
            return mBitDepth;
        }

        // Returns the plane offset for this image
        // after accounting for the src Crop offsets
        status_t getYUVPlaneOffsetAndStride(
                const BitmapParams &src,
                uint32_t *y_offset,
                uint32_t *u_offset,
                uint32_t *v_offset,
                size_t *y_stride,
                size_t *u_stride,
                size_t *v_stride
                ) const;

        bool isNV21() const;

    private:
        MediaImage2 mImage;
        Layout_t mLayout;
        Sampling_t mSampling;
        BitDepth_t mBitDepth;
    };

    struct BitmapParams {
@@ -84,6 +162,7 @@ private:
    };

    OMX_COLOR_FORMATTYPE mSrcFormat, mDstFormat;
    std::optional<Image> mSrcImage;
    ColorSpace mSrcColorSpace;
    uint8_t *mClip;
    uint16_t *mClip10Bit;
@@ -91,14 +170,30 @@ private:
    uint8_t *initClip();
    uint16_t *initClip10Bit();

    // resolve YUVFormat from YUV420Flexible
    bool isValidForMediaImage2() const;

    // get plane offsets from Formats
    status_t getSrcYUVPlaneOffsetAndStride(
            const BitmapParams &src,
            uint32_t *y_offset,
            uint32_t *u_offset,
            uint32_t *v_offset,
            size_t *y_stride,
            size_t *u_stride,
            size_t *v_stride) const;

    status_t convertYUVMediaImage(
        const BitmapParams &src, const BitmapParams &dst);

    // returns the YUV2RGB matrix coefficients according to the color aspects and bit depth
    const struct Coeffs *getMatrix() const;

    status_t convertCbYCrY(
            const BitmapParams &src, const BitmapParams &dst);

    status_t convertYUV420Planar(
            const BitmapParams &src, const BitmapParams &dst);
    // status_t convertYUV420Planar(
    //        const BitmapParams &src, const BitmapParams &dst);

    status_t convertYUV420PlanarUseLibYUV(
            const BitmapParams &src, const BitmapParams &dst);
@@ -115,19 +210,6 @@ private:
    status_t convertYUV420Planar16ToRGB(
            const BitmapParams &src, const BitmapParams &dst);

    status_t convertQCOMYUV420SemiPlanar(
            const BitmapParams &src, const BitmapParams &dst);

    status_t convertYUV420SemiPlanar(
            const BitmapParams &src, const BitmapParams &dst);

    status_t convertYUV420SemiPlanarBase(
            const BitmapParams &src, const BitmapParams &dst,
            size_t row_inc, bool isNV21 = false);

    status_t convertTIYUV420PackedSemiPlanar(
            const BitmapParams &src, const BitmapParams &dst);

    status_t convertYUVP010(
                const BitmapParams &src, const BitmapParams &dst);

@@ -135,6 +217,7 @@ private:
                const BitmapParams &src, const BitmapParams &dst);

    ColorConverter(const ColorConverter &);

    ColorConverter &operator=(const ColorConverter &);
};