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

Commit 6a867d53 authored by Chong Zhang's avatar Chong Zhang
Browse files

Separate buffer width and stride

bug:80105792

Test: Disable hw vp9 decoder, and modify SoftVPX to use
different stride and width, test VP9/VP9 profile2 streams
playback in Photos.
Test: HEIF decoding.

Change-Id: I97364accc5f610bb28c44f7da2e8ae57a30ab581
parent 1f90537e
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -498,9 +498,10 @@ status_t VideoFrameDecoder::onOutputReceived(
        return ERROR_MALFORMED;
    }

    int32_t width, height;
    int32_t width, height, stride;
    CHECK(outputFormat->findInt32("width", &width));
    CHECK(outputFormat->findInt32("height", &height));
    CHECK(outputFormat->findInt32("stride", &stride));

    int32_t crop_left, crop_top, crop_right, crop_bottom;
    if (!outputFormat->findRect("crop", &crop_left, &crop_top, &crop_right, &crop_bottom)) {
@@ -527,11 +528,10 @@ status_t VideoFrameDecoder::onOutputReceived(
    if (converter.isValid()) {
        converter.convert(
                (const uint8_t *)videoFrameBuffer->data(),
                width, height,
                width, height, stride,
                crop_left, crop_top, crop_right, crop_bottom,
                frame->getFlattenedData(),
                frame->mWidth,
                frame->mHeight,
                frame->mWidth, frame->mHeight, frame->mRowBytes,
                crop_left, crop_top, crop_right, crop_bottom);
        return OK;
    }
@@ -678,9 +678,10 @@ status_t ImageDecoder::onOutputReceived(
        return ERROR_MALFORMED;
    }

    int32_t width, height;
    int32_t width, height, stride;
    CHECK(outputFormat->findInt32("width", &width));
    CHECK(outputFormat->findInt32("height", &height));
    CHECK(outputFormat->findInt32("stride", &stride));

    if (mFrame == NULL) {
        sp<IMemory> frameMem = allocVideoFrame(
@@ -724,11 +725,10 @@ status_t ImageDecoder::onOutputReceived(
    if (converter.isValid()) {
        converter.convert(
                (const uint8_t *)videoFrameBuffer->data(),
                width, height,
                width, height, stride,
                crop_left, crop_top, crop_right, crop_bottom,
                mFrame->getFlattenedData(),
                mFrame->mWidth,
                mFrame->mHeight,
                mFrame->mWidth, mFrame->mHeight, mFrame->mRowBytes,
                dstLeft, dstTop, dstRight, dstBottom);
        return OK;
    }
+25 −19
Original line number Diff line number Diff line
@@ -85,9 +85,15 @@ bool ColorConverter::isDstRGB() const {
            || mDstFormat == OMX_COLOR_Format32bitBGRA8888;
}

/*
 * If stride is non-zero, client's stride will be used. For planar
 * or semi-planar YUV formats, stride must be even numbers.
 * If stride is zero, it will be calculated based on width and bpp
 * of the format, assuming no padding on the right edge.
 */
ColorConverter::BitmapParams::BitmapParams(
        void *bits,
        size_t width, size_t height,
        size_t width, size_t height, size_t stride,
        size_t cropLeft, size_t cropTop,
        size_t cropRight, size_t cropBottom,
        OMX_COLOR_FORMATTYPE colorFromat)
@@ -101,6 +107,8 @@ ColorConverter::BitmapParams::BitmapParams(
      mCropBottom(cropBottom) {
    switch(mColorFormat) {
    case OMX_COLOR_Format16bitRGB565:
    case OMX_COLOR_FormatYUV420Planar16:
    case OMX_COLOR_FormatCbYCrY:
        mBpp = 2;
        mStride = 2 * mWidth;
        break;
@@ -112,13 +120,7 @@ ColorConverter::BitmapParams::BitmapParams(
        mStride = 4 * mWidth;
        break;

    case OMX_COLOR_FormatYUV420Planar16:
        mBpp = 2;
        mStride = 2 * mWidth;
        break;

    case OMX_COLOR_FormatYUV420Planar:
    case OMX_COLOR_FormatCbYCrY:
    case OMX_QCOM_COLOR_FormatYVU420SemiPlanar:
    case OMX_COLOR_FormatYUV420SemiPlanar:
    case OMX_TI_COLOR_FormatYUV420PackedSemiPlanar:
@@ -132,6 +134,10 @@ ColorConverter::BitmapParams::BitmapParams(
        mStride = mWidth;
        break;
    }
    // use client's stride if it's specified.
    if (stride != 0) {
        mStride = stride;
    }
}

size_t ColorConverter::BitmapParams::cropWidth() const {
@@ -144,21 +150,21 @@ size_t ColorConverter::BitmapParams::cropHeight() const {

status_t ColorConverter::convert(
        const void *srcBits,
        size_t srcWidth, size_t srcHeight,
        size_t srcWidth, size_t srcHeight, size_t srcStride,
        size_t srcCropLeft, size_t srcCropTop,
        size_t srcCropRight, size_t srcCropBottom,
        void *dstBits,
        size_t dstWidth, size_t dstHeight,
        size_t dstWidth, size_t dstHeight, size_t dstStride,
        size_t dstCropLeft, size_t dstCropTop,
        size_t dstCropRight, size_t dstCropBottom) {
    BitmapParams src(
            const_cast<void *>(srcBits),
            srcWidth, srcHeight,
            srcWidth, srcHeight, srcStride,
            srcCropLeft, srcCropTop, srcCropRight, srcCropBottom, mSrcFormat);

    BitmapParams dst(
            dstBits,
            dstWidth, dstHeight,
            dstWidth, dstHeight, dstStride,
            dstCropLeft, dstCropTop, dstCropRight, dstCropBottom, mDstFormat);

    if (!((src.mCropLeft & 1) == 0
@@ -792,15 +798,15 @@ status_t ColorConverter::convertYUV420SemiPlanar(

    uint8_t *kAdjustedClip = initClip();

    uint16_t *dst_ptr = (uint16_t *)dst.mBits
        + dst.mCropTop * dst.mWidth + dst.mCropLeft;
    uint16_t *dst_ptr = (uint16_t *)((uint8_t *)
            dst.mBits + dst.mCropTop * dst.mStride + dst.mCropLeft * dst.mBpp);

    const uint8_t *src_y =
        (const uint8_t *)src.mBits + src.mCropTop * src.mWidth + src.mCropLeft;
        (const uint8_t *)src.mBits + src.mCropTop * src.mStride + src.mCropLeft;

    const uint8_t *src_u =
        (const uint8_t *)src_y + src.mWidth * src.mHeight
        + src.mCropTop * src.mWidth + src.mCropLeft;
        (const uint8_t *)src.mBits + src.mHeight * src.mStride +
        src.mCropTop * src.mStride / 2 + src.mCropLeft;

    for (size_t y = 0; y < src.cropHeight(); ++y) {
        for (size_t x = 0; x < src.cropWidth(); x += 2) {
@@ -842,13 +848,13 @@ status_t ColorConverter::convertYUV420SemiPlanar(
            }
        }

        src_y += src.mWidth;
        src_y += src.mStride;

        if (y & 1) {
            src_u += src.mWidth;
            src_u += src.mStride;
        }

        dst_ptr += dst.mWidth;
        dst_ptr = (uint16_t*)((uint8_t*)dst_ptr + dst.mStride);
    }

    return OK;
+22 −28
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ SoftwareRenderer::SoftwareRenderer(
      mNativeWindow(nativeWindow),
      mWidth(0),
      mHeight(0),
      mStride(0),
      mCropLeft(0),
      mCropTop(0),
      mCropRight(0),
@@ -67,9 +68,10 @@ void SoftwareRenderer::resetFormatIfChanged(
    int32_t colorFormatNew;
    CHECK(format->findInt32("color-format", &colorFormatNew));

    int32_t widthNew, heightNew;
    CHECK(format->findInt32("stride", &widthNew));
    int32_t widthNew, heightNew, strideNew;
    CHECK(format->findInt32("width", &widthNew));
    CHECK(format->findInt32("slice-height", &heightNew));
    CHECK(format->findInt32("stride", &strideNew));

    int32_t cropLeftNew, cropTopNew, cropRightNew, cropBottomNew;
    if (!format->findRect(
@@ -106,6 +108,7 @@ void SoftwareRenderer::resetFormatIfChanged(
    mColorFormat = static_cast<OMX_COLOR_FORMATTYPE>(colorFormatNew);
    mWidth = widthNew;
    mHeight = heightNew;
    mStride = strideNew;
    mCropLeft = cropLeftNew;
    mCropTop = cropTopNew;
    mCropRight = cropRightNew;
@@ -276,20 +279,15 @@ std::list<FrameRenderTracker::Info> SoftwareRenderer::render(
    if (mConverter) {
        mConverter->convert(
                data,
                mWidth, mHeight,
                mWidth, mHeight, mStride,
                mCropLeft, mCropTop, mCropRight, mCropBottom,
                dst,
                buf->stride, buf->height,
                buf->stride, buf->height, 0,
                0, 0, mCropWidth - 1, mCropHeight - 1);
    } else if (mColorFormat == OMX_COLOR_FormatYUV420Planar) {
        const uint8_t *src_y = (const uint8_t *)data;
        const uint8_t *src_u =
                (const uint8_t *)data + mWidth * mHeight;
        const uint8_t *src_v = src_u + (mWidth / 2 * mHeight / 2);

        src_y +=mCropLeft + mCropTop * mWidth;
        src_u +=(mCropLeft + mCropTop * mWidth / 2)/2;
        src_v +=(mCropLeft + mCropTop * mWidth / 2)/2;
        const uint8_t *src_y = (const uint8_t *)data + mCropTop * mStride + mCropLeft;
        const uint8_t *src_u = (const uint8_t *)data + mStride * mHeight + mCropTop * mStride / 4;
        const uint8_t *src_v = (const uint8_t *)src_u + mStride * mHeight / 4;

        uint8_t *dst_y = (uint8_t *)dst;
        size_t dst_y_size = buf->stride * buf->height;
@@ -305,7 +303,7 @@ std::list<FrameRenderTracker::Info> SoftwareRenderer::render(
        for (int y = 0; y < mCropHeight; ++y) {
            memcpy(dst_y, src_y, mCropWidth);

            src_y += mWidth;
            src_y += mStride;
            dst_y += buf->stride;
        }

@@ -313,19 +311,15 @@ std::list<FrameRenderTracker::Info> SoftwareRenderer::render(
            memcpy(dst_u, src_u, (mCropWidth + 1) / 2);
            memcpy(dst_v, src_v, (mCropWidth + 1) / 2);

            src_u += mWidth / 2;
            src_v += mWidth / 2;
            src_u += mStride / 2;
            src_v += mStride / 2;
            dst_u += dst_c_stride;
            dst_v += dst_c_stride;
        }
    } else if (mColorFormat == OMX_COLOR_FormatYUV420Planar16) {
        const uint16_t *src_y = (const uint16_t *)data;
        const uint16_t *src_u = (const uint16_t *)data + mWidth * mHeight;
        const uint16_t *src_v = src_u + (mWidth / 2 * mHeight / 2);

        src_y += mCropLeft + mCropTop * mWidth;
        src_u += (mCropLeft + mCropTop * mWidth / 2) / 2;
        src_v += (mCropLeft + mCropTop * mWidth / 2) / 2;
        const uint8_t *src_y = (const uint8_t *)data + mCropTop * mStride + mCropLeft * 2;
        const uint8_t *src_u = (const uint8_t *)data + mStride * mHeight + mCropTop * mStride / 4;
        const uint8_t *src_v = (const uint8_t *)src_u + mStride * mHeight / 4;

        uint8_t *dst_y = (uint8_t *)dst;
        size_t dst_y_size = buf->stride * buf->height;
@@ -340,21 +334,21 @@ std::list<FrameRenderTracker::Info> SoftwareRenderer::render(

        for (int y = 0; y < mCropHeight; ++y) {
            for (int x = 0; x < mCropWidth; ++x) {
                dst_y[x] = (uint8_t)(src_y[x] >> 2);
                dst_y[x] = (uint8_t)(((uint16_t *)src_y)[x] >> 2);
            }

            src_y += mWidth;
            src_y += mStride;
            dst_y += buf->stride;
        }

        for (int y = 0; y < (mCropHeight + 1) / 2; ++y) {
            for (int x = 0; x < (mCropWidth + 1) / 2; ++x) {
                dst_u[x] = (uint8_t)(src_u[x] >> 2);
                dst_v[x] = (uint8_t)(src_v[x] >> 2);
                dst_u[x] = (uint8_t)(((uint16_t *)src_u)[x] >> 2);
                dst_v[x] = (uint8_t)(((uint16_t *)src_v)[x] >> 2);
            }

            src_u += mWidth / 2;
            src_v += mWidth / 2;
            src_u += mStride / 2;
            src_v += mStride / 2;
            dst_u += dst_c_stride;
            dst_v += dst_c_stride;
        }
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ private:
    ColorConverter *mConverter;
    YUVMode mYUVMode;
    sp<ANativeWindow> mNativeWindow;
    int32_t mWidth, mHeight;
    int32_t mWidth, mHeight, mStride;
    int32_t mCropLeft, mCropTop, mCropRight, mCropBottom;
    int32_t mCropWidth, mCropHeight;
    int32_t mRotationDegrees;
+3 −3
Original line number Diff line number Diff line
@@ -37,11 +37,11 @@ struct ColorConverter {

    status_t convert(
            const void *srcBits,
            size_t srcWidth, size_t srcHeight,
            size_t srcWidth, size_t srcHeight, size_t srcStride,
            size_t srcCropLeft, size_t srcCropTop,
            size_t srcCropRight, size_t srcCropBottom,
            void *dstBits,
            size_t dstWidth, size_t dstHeight,
            size_t dstWidth, size_t dstHeight, size_t dstStride,
            size_t dstCropLeft, size_t dstCropTop,
            size_t dstCropRight, size_t dstCropBottom);

@@ -49,7 +49,7 @@ private:
    struct BitmapParams {
        BitmapParams(
                void *bits,
                size_t width, size_t height,
                size_t width, size_t height, size_t stride,
                size_t cropLeft, size_t cropTop,
                size_t cropRight, size_t cropBottom,
                OMX_COLOR_FORMATTYPE colorFromat);
Loading