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

Commit 6a9e943d authored by Hangyu Kuang's avatar Hangyu Kuang
Browse files

media: Add colorAspect support to SoftMPEG2 decoder.

Bug:27442922
Change-Id: Id78e104c31cd712cdfa546a5f79d7fe823688cf9
parent cecb30a2
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
@@ -460,6 +460,47 @@ void SoftMPEG2::onReset() {
    resetPlugin();
}

bool SoftMPEG2::getSeqInfo() {
    IV_API_CALL_STATUS_T status;
    impeg2d_ctl_get_seq_info_ip_t s_ctl_get_seq_info_ip;
    impeg2d_ctl_get_seq_info_op_t s_ctl_get_seq_info_op;

    s_ctl_get_seq_info_ip.e_cmd = IVD_CMD_VIDEO_CTL;
    s_ctl_get_seq_info_ip.e_sub_cmd =
        (IVD_CONTROL_API_COMMAND_TYPE_T)IMPEG2D_CMD_CTL_GET_SEQ_INFO;

    s_ctl_get_seq_info_ip.u4_size = sizeof(impeg2d_ctl_get_seq_info_ip_t);
    s_ctl_get_seq_info_op.u4_size = sizeof(impeg2d_ctl_get_seq_info_op_t);

    status = ivdec_api_function(
            (iv_obj_t *)mCodecCtx, (void *)&s_ctl_get_seq_info_ip,
            (void *)&s_ctl_get_seq_info_op);

    if (status != IV_SUCCESS) {
        ALOGW("Error in getting Sequence info: 0x%x",
                s_ctl_get_seq_info_op.u4_error_code);
        return false;
    }


    int32_t primaries = s_ctl_get_seq_info_op.u1_colour_primaries;
    int32_t transfer = s_ctl_get_seq_info_op.u1_transfer_characteristics;
    int32_t coeffs = s_ctl_get_seq_info_op.u1_matrix_coefficients;
    bool fullRange = false;  // mpeg2 video has limited range.

    ColorAspects colorAspects;
    ColorUtils::convertIsoColorAspectsToCodecAspects(
            primaries, transfer, coeffs, fullRange, colorAspects);

    // Update color aspects if necessary.
    if (colorAspectsDiffer(colorAspects, mBitstreamColorAspects)) {
        mBitstreamColorAspects = colorAspects;
        status_t err = handleColorAspectsChange();
        CHECK(err == OK);
    }
    return true;
}

OMX_ERRORTYPE SoftMPEG2::internalSetParameter(OMX_INDEXTYPE index, const OMX_PTR params) {
    const uint32_t oldWidth = mWidth;
    const uint32_t oldHeight = mHeight;
@@ -650,6 +691,8 @@ void SoftMPEG2::onQueueFilled(OMX_U32 portIndex) {
            bool unsupportedDimensions = (IMPEG2D_UNSUPPORTED_DIMENSIONS == s_dec_op.u4_error_code);
            bool resChanged = (IVD_RES_CHANGED == (s_dec_op.u4_error_code & 0xFF));

            getSeqInfo();

            GETTIME(&mTimeEnd, NULL);
            /* Compute time taken for decode() */
            TIME_DIFF(mTimeStart, mTimeEnd, timeTaken);
@@ -705,6 +748,8 @@ void SoftMPEG2::onQueueFilled(OMX_U32 portIndex) {
                continue;
            }

            // Combine the resolution change and coloraspects change in one PortSettingChange event
            // if necessary.
            if ((0 < s_dec_op.u4_pic_wd) && (0 < s_dec_op.u4_pic_ht)) {
                uint32_t width = s_dec_op.u4_pic_wd;
                uint32_t height = s_dec_op.u4_pic_ht;
@@ -715,6 +760,11 @@ void SoftMPEG2::onQueueFilled(OMX_U32 portIndex) {
                    resetDecoder();
                    return;
                }
            } else if (mUpdateColorAspects) {
                notify(OMX_EventPortSettingsChanged, kOutputPortIndex,
                    kDescribeColorAspectsIndex, NULL);
                mUpdateColorAspects = false;
                return;
            }

            if (s_dec_op.u4_output_present) {
@@ -783,6 +833,10 @@ void SoftMPEG2::onQueueFilled(OMX_U32 portIndex) {
    }
}

int SoftMPEG2::getColorAspectPreference() {
    return kPreferBitstream;
}

}  // namespace android

android::SoftOMXComponent *createSoftOMXComponent(
+3 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ protected:
    virtual void onQueueFilled(OMX_U32 portIndex);
    virtual void onPortFlushCompleted(OMX_U32 portIndex);
    virtual void onReset();
    virtual int getColorAspectPreference();
    virtual OMX_ERRORTYPE internalSetParameter(OMX_INDEXTYPE index, const OMX_PTR params);
private:
    // Number of input and output buffers
@@ -125,6 +126,8 @@ private:
            OMX_BUFFERHEADERTYPE *outHeader,
            size_t timeStampIx);

    bool getSeqInfo();

    DISALLOW_EVIL_CONSTRUCTORS(SoftMPEG2);
};