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

Commit dfa3f5ac authored by Harish Mahendrakar's avatar Harish Mahendrakar Committed by Lajos Molnar
Browse files

codec2: Update stride calculations in mpeg4, vpx and aom decoder plugins

Bug: 131844219
Test: atest android.media.cts.DecoderTest
Test: Play HDR videos on YouTube

Change-Id: Iec4823cf6e061b10a9fd8d7d4429fd0b6d6f6bf6
parent 00ffd9e0
Loading
Loading
Loading
Loading
+16 −13
Original line number Diff line number Diff line
@@ -501,15 +501,13 @@ void C2SoftAomDec::process(const std::unique_ptr<C2Work>& work,
    }
}

static void copyOutputBufferToYV12Frame(uint8_t *dst,
        const uint8_t *srcY, const uint8_t *srcU, const uint8_t *srcV,
static void copyOutputBufferToYuvPlanarFrame(
        uint8_t *dst, const uint8_t *srcY, const uint8_t *srcU, const uint8_t *srcV,
        size_t srcYStride, size_t srcUStride, size_t srcVStride,
        size_t dstYStride, size_t dstUVStride,
        uint32_t width, uint32_t height) {
    size_t dstYStride = align(width, 16);
    size_t dstUVStride = align(dstYStride / 2, 16);
    uint8_t* dstStart = dst;


    for (size_t i = 0; i < height; ++i) {
        memcpy(dst, srcY, width);
        srcY += srcYStride;
@@ -597,11 +595,10 @@ static void convertYUV420Planar16ToY410(uint32_t *dst,
static void convertYUV420Planar16ToYUV420Planar(uint8_t *dst,
        const uint16_t *srcY, const uint16_t *srcU, const uint16_t *srcV,
        size_t srcYStride, size_t srcUStride, size_t srcVStride,
        size_t dstStride, size_t width, size_t height) {
        size_t dstYStride, size_t dstUVStride, size_t width, size_t height) {

    uint8_t *dstY = (uint8_t *)dst;
    size_t dstYSize = dstStride * height;
    size_t dstUVStride = align(dstStride / 2, 16);
    size_t dstYSize = dstYStride * height;
    size_t dstUVSize = dstUVStride * height / 2;
    uint8_t *dstV = dstY + dstYSize;
    uint8_t *dstU = dstV + dstUVSize;
@@ -612,7 +609,7 @@ static void convertYUV420Planar16ToYUV420Planar(uint8_t *dst,
        }

        srcY += srcYStride;
        dstY += dstStride;
        dstY += dstYStride;
    }

    for (size_t y = 0; y < (height + 1) / 2; ++y) {
@@ -699,6 +696,9 @@ bool C2SoftAomDec::outputBuffer(
    size_t srcYStride = img->stride[AOM_PLANE_Y];
    size_t srcUStride = img->stride[AOM_PLANE_U];
    size_t srcVStride = img->stride[AOM_PLANE_V];
    C2PlanarLayout layout = wView.layout();
    size_t dstYStride = layout.planes[C2PlanarLayout::PLANE_Y].rowInc;
    size_t dstUVStride = layout.planes[C2PlanarLayout::PLANE_U].rowInc;

    if (img->fmt == AOM_IMG_FMT_I42016) {
        const uint16_t *srcY = (const uint16_t *)img->planes[AOM_PLANE_Y];
@@ -708,20 +708,23 @@ bool C2SoftAomDec::outputBuffer(
        if (format == HAL_PIXEL_FORMAT_RGBA_1010102) {
            convertYUV420Planar16ToY410((uint32_t *)dst, srcY, srcU, srcV, srcYStride / 2,
                                    srcUStride / 2, srcVStride / 2,
                                    align(mWidth, 16),
                                    dstYStride / sizeof(uint32_t),
                                    mWidth, mHeight);
        } else {
            convertYUV420Planar16ToYUV420Planar(dst, srcY, srcU, srcV, srcYStride / 2,
                                    srcUStride / 2, srcVStride / 2,
                                    align(mWidth, 16),
                                    dstYStride, dstUVStride,
                                    mWidth, mHeight);
        }
    } else {
        const uint8_t *srcY = (const uint8_t *)img->planes[AOM_PLANE_Y];
        const uint8_t *srcU = (const uint8_t *)img->planes[AOM_PLANE_U];
        const uint8_t *srcV = (const uint8_t *)img->planes[AOM_PLANE_V];
        copyOutputBufferToYV12Frame(dst, srcY, srcU, srcV,
                                srcYStride, srcUStride, srcVStride, mWidth, mHeight);
        copyOutputBufferToYuvPlanarFrame(
                dst, srcY, srcU, srcV,
                srcYStride, srcUStride, srcVStride,
                dstYStride, dstUVStride,
                mWidth, mHeight);
    }
    finishWork(*(int64_t*)img->user_priv, work, std::move(block));
    block = nullptr;
+13 −5
Original line number Diff line number Diff line
@@ -466,9 +466,11 @@ bool C2SoftMpeg4Dec::handleResChange(const std::unique_ptr<C2Work> &work) {

/* TODO: can remove temporary copy after library supports writing to display
 * buffer Y, U and V plane pointers using stride info. */
static void copyOutputBufferToYV12Frame(uint8_t *dst, uint8_t *src, size_t dstYStride,
                                        size_t srcYStride, uint32_t width, uint32_t height) {
    size_t dstUVStride = align(dstYStride / 2, 16);
static void copyOutputBufferToYuvPlanarFrame(
        uint8_t *dst, uint8_t *src,
        size_t dstYStride, size_t dstUVStride,
        size_t srcYStride, uint32_t width,
        uint32_t height) {
    size_t srcUVStride = srcYStride / 2;
    uint8_t *srcStart = src;
    uint8_t *dstStart = dst;
@@ -673,8 +675,14 @@ void C2SoftMpeg4Dec::process(
        }

        uint8_t *outputBufferY = wView.data()[C2PlanarLayout::PLANE_Y];
        (void)copyOutputBufferToYV12Frame(outputBufferY, mOutputBuffer[mNumSamplesOutput & 1],
                                          wView.width(), align(mWidth, 16), mWidth, mHeight);
        C2PlanarLayout layout = wView.layout();
        size_t dstYStride = layout.planes[C2PlanarLayout::PLANE_Y].rowInc;
        size_t dstUVStride = layout.planes[C2PlanarLayout::PLANE_U].rowInc;
        (void)copyOutputBufferToYuvPlanarFrame(
                outputBufferY,
                mOutputBuffer[mNumSamplesOutput & 1],
                dstYStride, dstUVStride,
                align(mWidth, 16), mWidth, mHeight);

        inPos += inSize - (size_t)tmpInSize;
        finishWork(workIndex, work);
+16 −12
Original line number Diff line number Diff line
@@ -559,12 +559,11 @@ void C2SoftVpxDec::process(
    }
}

static void copyOutputBufferToYV12Frame(uint8_t *dst,
        const uint8_t *srcY, const uint8_t *srcU, const uint8_t *srcV,
static void copyOutputBufferToYuvPlanarFrame(
        uint8_t *dst, const uint8_t *srcY, const uint8_t *srcU, const uint8_t *srcV,
        size_t srcYStride, size_t srcUStride, size_t srcVStride,
        size_t dstYStride, size_t dstUVStride,
        uint32_t width, uint32_t height) {
    size_t dstYStride = align(width, 16);
    size_t dstUVStride = align(dstYStride / 2, 16);
    uint8_t *dstStart = dst;

    for (size_t i = 0; i < height; ++i) {
@@ -654,11 +653,10 @@ static void convertYUV420Planar16ToY410(uint32_t *dst,
static void convertYUV420Planar16ToYUV420Planar(uint8_t *dst,
        const uint16_t *srcY, const uint16_t *srcU, const uint16_t *srcV,
        size_t srcYStride, size_t srcUStride, size_t srcVStride,
        size_t dstStride, size_t width, size_t height) {
        size_t dstYStride, size_t dstUVStride, size_t width, size_t height) {

    uint8_t *dstY = (uint8_t *)dst;
    size_t dstYSize = dstStride * height;
    size_t dstUVStride = align(dstStride / 2, 16);
    size_t dstYSize = dstYStride * height;
    size_t dstUVSize = dstUVStride * height / 2;
    uint8_t *dstV = dstY + dstYSize;
    uint8_t *dstU = dstV + dstUVSize;
@@ -669,7 +667,7 @@ static void convertYUV420Planar16ToYUV420Planar(uint8_t *dst,
        }

        srcY += srcYStride;
        dstY += dstStride;
        dstY += dstYStride;
    }

    for (size_t y = 0; y < (height + 1) / 2; ++y) {
@@ -751,6 +749,9 @@ bool C2SoftVpxDec::outputBuffer(
    size_t srcYStride = img->stride[VPX_PLANE_Y];
    size_t srcUStride = img->stride[VPX_PLANE_U];
    size_t srcVStride = img->stride[VPX_PLANE_V];
    C2PlanarLayout layout = wView.layout();
    size_t dstYStride = layout.planes[C2PlanarLayout::PLANE_Y].rowInc;
    size_t dstUVStride = layout.planes[C2PlanarLayout::PLANE_U].rowInc;

    if (img->fmt == VPX_IMG_FMT_I42016) {
        const uint16_t *srcY = (const uint16_t *)img->planes[VPX_PLANE_Y];
@@ -760,20 +761,23 @@ bool C2SoftVpxDec::outputBuffer(
        if (format == HAL_PIXEL_FORMAT_RGBA_1010102) {
            convertYUV420Planar16ToY410((uint32_t *)dst, srcY, srcU, srcV, srcYStride / 2,
                                    srcUStride / 2, srcVStride / 2,
                                    align(mWidth, 16),
                                    dstYStride / sizeof(uint32_t),
                                    mWidth, mHeight);
        } else {
            convertYUV420Planar16ToYUV420Planar(dst, srcY, srcU, srcV, srcYStride / 2,
                                    srcUStride / 2, srcVStride / 2,
                                    align(mWidth, 16),
                                    dstYStride, dstUVStride,
                                    mWidth, mHeight);
        }
    } else {
        const uint8_t *srcY = (const uint8_t *)img->planes[VPX_PLANE_Y];
        const uint8_t *srcU = (const uint8_t *)img->planes[VPX_PLANE_U];
        const uint8_t *srcV = (const uint8_t *)img->planes[VPX_PLANE_V];
        copyOutputBufferToYV12Frame(dst, srcY, srcU, srcV,
                                srcYStride, srcUStride, srcVStride, mWidth, mHeight);
        copyOutputBufferToYuvPlanarFrame(
                dst, srcY, srcU, srcV,
                srcYStride, srcUStride, srcVStride,
                dstYStride, dstUVStride,
                mWidth, mHeight);
    }
    finishWork(*(int64_t *)img->user_priv, work, std::move(block));
    return true;