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

Commit 6a7e93d1 authored by Harish Mahendrakar's avatar Harish Mahendrakar Committed by Wonsik Kim
Browse files

C2SoftDec: Use stride returned by graphic view in avc, hevc and mpeg2

Instead of assuming stride to be a multiple of 64, use the value
returned by graphic view.
These codecs require chroma stride to be half of luma, hence the luma stride
should be a multiple of 32. Hence request for stride that is multiple of
32, then use returned stride.
This is needed where allcoated buffer has a stride that is multiple of
128.

Test: atest android.media.cts.DecoderTest
Test: Test decoding clips with dimensions that are not multiples of 16

Bug: 144190181
Change-Id: I08912396e495326fca787e8ae0b47256505210ca
Merged-In: I08912396e495326fca787e8ae0b47256505210ca
parent 95ec1b8e
Loading
Loading
Loading
Loading
+17 −9
Original line number Diff line number Diff line
@@ -501,7 +501,7 @@ void C2SoftAvcDec::getVersion() {
status_t C2SoftAvcDec::initDecoder() {
    if (OK != createDecoder()) return UNKNOWN_ERROR;
    mNumCores = MIN(getCpuCoreCount(), MAX_NUM_CORES);
    mStride = ALIGN128(mWidth);
    mStride = ALIGN32(mWidth);
    mSignalledError = false;
    resetPlugin();
    (void) setNumCores();
@@ -519,10 +519,20 @@ bool C2SoftAvcDec::setDecodeArgs(ivd_video_decode_ip_t *ps_decode_ip,
                                 size_t inSize,
                                 uint32_t tsMarker) {
    uint32_t displayStride = mStride;
    if (outBuffer) {
        C2PlanarLayout layout;
        layout = outBuffer->layout();
        displayStride = layout.planes[C2PlanarLayout::PLANE_Y].rowInc;
    }
    uint32_t displayHeight = mHeight;
    size_t lumaSize = displayStride * displayHeight;
    size_t chromaSize = lumaSize >> 2;

    if (mStride != displayStride) {
        mStride = displayStride;
        if (OK != setParams(mStride, IVD_DECODE_FRAME)) return false;
    }

    ps_decode_ip->u4_size = sizeof(ivd_video_decode_ip_t);
    ps_decode_ip->e_cmd = IVD_CMD_VIDEO_DECODE;
    if (inBuffer) {
@@ -756,24 +766,21 @@ c2_status_t C2SoftAvcDec::ensureDecoderState(const std::shared_ptr<C2BlockPool>
        ALOGE("not supposed to be here, invalid decoder context");
        return C2_CORRUPTED;
    }
    if (mStride != ALIGN128(mWidth)) {
        mStride = ALIGN128(mWidth);
        if (OK != setParams(mStride, IVD_DECODE_FRAME)) return C2_CORRUPTED;
    }
    if (mOutBlock &&
            (mOutBlock->width() != mStride || mOutBlock->height() != mHeight)) {
            (mOutBlock->width() != ALIGN32(mWidth) || mOutBlock->height() != mHeight)) {
        mOutBlock.reset();
    }
    if (!mOutBlock) {
        uint32_t format = HAL_PIXEL_FORMAT_YV12;
        C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE };
        c2_status_t err = pool->fetchGraphicBlock(mStride, mHeight, format, usage, &mOutBlock);
        c2_status_t err =
            pool->fetchGraphicBlock(ALIGN32(mWidth), mHeight, format, usage, &mOutBlock);
        if (err != C2_OK) {
            ALOGE("fetchGraphicBlock for Output failed with status %d", err);
            return err;
        }
        ALOGV("provided (%dx%d) required (%dx%d)",
              mOutBlock->width(), mOutBlock->height(), mStride, mHeight);
              mOutBlock->width(), mOutBlock->height(), ALIGN32(mWidth), mHeight);
    }

    return C2_OK;
@@ -909,7 +916,8 @@ void C2SoftAvcDec::process(
        if (0 < s_decode_op.u4_pic_wd && 0 < s_decode_op.u4_pic_ht) {
            if (mHeaderDecoded == false) {
                mHeaderDecoded = true;
                setParams(ALIGN128(s_decode_op.u4_pic_wd), IVD_DECODE_FRAME);
                mStride = ALIGN32(s_decode_op.u4_pic_wd);
                setParams(mStride, IVD_DECODE_FRAME);
            }
            if (s_decode_op.u4_pic_wd != mWidth || s_decode_op.u4_pic_ht != mHeight) {
                mWidth = s_decode_op.u4_pic_wd;
+1 −2
Original line number Diff line number Diff line
@@ -39,8 +39,7 @@ namespace android {
#define ivdext_ctl_set_num_cores_op_t   ih264d_ctl_set_num_cores_op_t
#define ivdext_ctl_get_vui_params_ip_t  ih264d_ctl_get_vui_params_ip_t
#define ivdext_ctl_get_vui_params_op_t  ih264d_ctl_get_vui_params_op_t
#define ALIGN64(x)                      ((((x) + 63) >> 6) << 6)
#define ALIGN128(x)                     ((((x) + 127) >> 7) << 7)
#define ALIGN32(x)                      ((((x) + 31) >> 5) << 5)
#define MAX_NUM_CORES                   4
#define IVDEXT_CMD_CTL_SET_NUM_CORES    \
        (IVD_CONTROL_API_COMMAND_TYPE_T)IH264D_CMD_CTL_SET_NUM_CORES
+16 −9
Original line number Diff line number Diff line
@@ -497,7 +497,7 @@ status_t C2SoftHevcDec::getVersion() {
status_t C2SoftHevcDec::initDecoder() {
    if (OK != createDecoder()) return UNKNOWN_ERROR;
    mNumCores = MIN(getCpuCoreCount(), MAX_NUM_CORES);
    mStride = ALIGN128(mWidth);
    mStride = ALIGN32(mWidth);
    mSignalledError = false;
    resetPlugin();
    (void) setNumCores();
@@ -515,10 +515,20 @@ bool C2SoftHevcDec::setDecodeArgs(ivd_video_decode_ip_t *ps_decode_ip,
                                  size_t inSize,
                                  uint32_t tsMarker) {
    uint32_t displayStride = mStride;
    if (outBuffer) {
        C2PlanarLayout layout;
        layout = outBuffer->layout();
        displayStride = layout.planes[C2PlanarLayout::PLANE_Y].rowInc;
    }
    uint32_t displayHeight = mHeight;
    size_t lumaSize = displayStride * displayHeight;
    size_t chromaSize = lumaSize >> 2;

    if (mStride != displayStride) {
        mStride = displayStride;
        if (OK != setParams(mStride, IVD_DECODE_FRAME)) return false;
    }

    ps_decode_ip->u4_size = sizeof(ivd_video_decode_ip_t);
    ps_decode_ip->e_cmd = IVD_CMD_VIDEO_DECODE;
    if (inBuffer) {
@@ -752,24 +762,21 @@ c2_status_t C2SoftHevcDec::ensureDecoderState(const std::shared_ptr<C2BlockPool>
        ALOGE("not supposed to be here, invalid decoder context");
        return C2_CORRUPTED;
    }
    if (mStride != ALIGN128(mWidth)) {
        mStride = ALIGN128(mWidth);
        if (OK != setParams(mStride, IVD_DECODE_FRAME)) return C2_CORRUPTED;
    }
    if (mOutBlock &&
            (mOutBlock->width() != mStride || mOutBlock->height() != mHeight)) {
            (mOutBlock->width() != ALIGN32(mWidth) || mOutBlock->height() != mHeight)) {
        mOutBlock.reset();
    }
    if (!mOutBlock) {
        uint32_t format = HAL_PIXEL_FORMAT_YV12;
        C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE };
        c2_status_t err = pool->fetchGraphicBlock(mStride, mHeight, format, usage, &mOutBlock);
        c2_status_t err =
            pool->fetchGraphicBlock(ALIGN32(mWidth), mHeight, format, usage, &mOutBlock);
        if (err != C2_OK) {
            ALOGE("fetchGraphicBlock for Output failed with status %d", err);
            return err;
        }
        ALOGV("provided (%dx%d) required (%dx%d)",
              mOutBlock->width(), mOutBlock->height(), mStride, mHeight);
              mOutBlock->width(), mOutBlock->height(), ALIGN32(mWidth), mHeight);
    }

    return C2_OK;
@@ -904,7 +911,7 @@ void C2SoftHevcDec::process(
        if (0 < s_decode_op.u4_pic_wd && 0 < s_decode_op.u4_pic_ht) {
            if (mHeaderDecoded == false) {
                mHeaderDecoded = true;
                setParams(ALIGN128(s_decode_op.u4_pic_wd), IVD_DECODE_FRAME);
                setParams(ALIGN32(s_decode_op.u4_pic_wd), IVD_DECODE_FRAME);
            }
            if (s_decode_op.u4_pic_wd != mWidth ||  s_decode_op.u4_pic_ht != mHeight) {
                mWidth = s_decode_op.u4_pic_wd;
+1 −2
Original line number Diff line number Diff line
@@ -37,8 +37,7 @@ namespace android {
#define ivdext_ctl_set_num_cores_op_t   ihevcd_cxa_ctl_set_num_cores_op_t
#define ivdext_ctl_get_vui_params_ip_t  ihevcd_cxa_ctl_get_vui_params_ip_t
#define ivdext_ctl_get_vui_params_op_t  ihevcd_cxa_ctl_get_vui_params_op_t
#define ALIGN64(x)                      ((((x) + 63) >> 6) << 6)
#define ALIGN128(x)                     ((((x) + 127) >> 7) << 7)
#define ALIGN32(x)                      ((((x) + 31) >> 5) << 5)
#define MAX_NUM_CORES                   4
#define IVDEXT_CMD_CTL_SET_NUM_CORES    \
        (IVD_CONTROL_API_COMMAND_TYPE_T)IHEVCD_CXA_CMD_CTL_SET_NUM_CORES
+15 −8
Original line number Diff line number Diff line
@@ -571,7 +571,7 @@ status_t C2SoftMpeg2Dec::initDecoder() {
    if (OK != createDecoder()) return UNKNOWN_ERROR;

    mNumCores = MIN(getCpuCoreCount(), MAX_NUM_CORES);
    mStride = ALIGN64(mWidth);
    mStride = ALIGN32(mWidth);
    mSignalledError = false;
    resetPlugin();
    (void) setNumCores();
@@ -589,10 +589,20 @@ bool C2SoftMpeg2Dec::setDecodeArgs(ivd_video_decode_ip_t *ps_decode_ip,
                                   size_t inSize,
                                   uint32_t tsMarker) {
    uint32_t displayStride = mStride;
    if (outBuffer) {
        C2PlanarLayout layout;
        layout = outBuffer->layout();
        displayStride = layout.planes[C2PlanarLayout::PLANE_Y].rowInc;
    }
    uint32_t displayHeight = mHeight;
    size_t lumaSize = displayStride * displayHeight;
    size_t chromaSize = lumaSize >> 2;

    if (mStride != displayStride) {
        mStride = displayStride;
        if (OK != setParams(mStride)) return false;
    }

    ps_decode_ip->u4_size = sizeof(ivd_video_decode_ip_t);
    ps_decode_ip->e_cmd = IVD_CMD_VIDEO_DECODE;
    if (inBuffer) {
@@ -833,24 +843,21 @@ c2_status_t C2SoftMpeg2Dec::ensureDecoderState(const std::shared_ptr<C2BlockPool
        ALOGE("not supposed to be here, invalid decoder context");
        return C2_CORRUPTED;
    }
    if (mStride != ALIGN64(mWidth)) {
        mStride = ALIGN64(mWidth);
        if (OK != setParams(mStride)) return C2_CORRUPTED;
    }
    if (mOutBlock &&
            (mOutBlock->width() != mStride || mOutBlock->height() != mHeight)) {
            (mOutBlock->width() != ALIGN32(mWidth) || mOutBlock->height() != mHeight)) {
        mOutBlock.reset();
    }
    if (!mOutBlock) {
        uint32_t format = HAL_PIXEL_FORMAT_YV12;
        C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE };
        c2_status_t err = pool->fetchGraphicBlock(mStride, mHeight, format, usage, &mOutBlock);
        c2_status_t err =
            pool->fetchGraphicBlock(ALIGN32(mWidth), mHeight, format, usage, &mOutBlock);
        if (err != C2_OK) {
            ALOGE("fetchGraphicBlock for Output failed with status %d", err);
            return err;
        }
        ALOGV("provided (%dx%d) required (%dx%d)",
              mOutBlock->width(), mOutBlock->height(), mStride, mHeight);
              mOutBlock->width(), mOutBlock->height(), ALIGN32(mWidth), mHeight);
    }

    return C2_OK;
Loading