⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umc_h264_segment_decoder_deblocking_prepare.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            else \
                pStrength[block_num1] = 0; \
        } \
        else \
        { \
            pStrength[block_num1] = 2; \
            iDeblockingFlag = 1; \
        } \
    } \
    else \
    { \
        pStrength[block_num0] = (Ipp8u) (1 + ((HORIZONTAL_OUTER_EDGE_BLOCK_##block_num0 & uMask) ? (1) : (0))); \
        pStrength[block_num1] = (Ipp8u) (1 + ((HORIZONTAL_OUTER_EDGE_BLOCK_##block_num1 & uMask) ? (1) : (0))); \
        iDeblockingFlag = 1; \
    } \
}

#define IsVectorDifferenceBig(one, two, iMaxDiff) \
    /* the original code is \
    ((4 <= abs(one.mvx - two.mvx)) || \
     (iMaxDiff <= abs(one.mvy - two.mvy))); \
    but the current code is equal and uses less comparisons */ \
    ((7 <= (Ipp32u)(one.mvx - two.mvx + 3)) || \
     ((Ipp32u)(iMaxDiff * 2 - 1) <= (Ipp32u)(one.mvy - two.mvy + iMaxDiff - 1)))

inline
Ipp32s H264SegmentDecoder::GetReferencePSlice(Ipp32s iMBNum, Ipp32s iBlockNum)
{
    Ipp32s index, ref;

    // select reference index for current block
    index = m_gmbinfo->RefIdxs[0][iMBNum].RefIdxs[iBlockNum];
    if (0 <= index)
    {
        H264DecoderFrame **pRefPicList;
        H264DecoderMacroblockGlobalInfo *pMBInfo;
        Ipp32s iNum = 0;

        // obtain reference list
        pMBInfo = m_gmbinfo->mbs + iMBNum;
        pRefPicList = m_pCurrentFrame->GetRefPicList(pMBInfo->slice_id, 0)->m_RefPicList;
        if (FRM_STRUCTURE > m_pCurrentFrame->m_PictureStructureForDec)
        {
            ReferenceFlags *pFields;

            pFields = m_pCurrentFrame->GetRefPicList(pMBInfo->slice_id, 0)->m_Flags;
            iNum = pRefPicList[index]->GetNumberByParity(GetReferenceField(pFields, index));
        }
        ref = pRefPicList[index]->DeblockPicID(iNum);
    }
    else
        ref = -1;

    return ref;

} // Ipp32s H264SegmentDecoder::GetReferencePSlice(Ipp32s iMBNum, Ipp32s iBlockNum)

inline
Ipp32s H264SegmentDecoder::GetReferencesBSlice(Ipp32s iMBNum, Ipp32s iBlockNum, Ipp32s *pReferences)
{
    Ipp32s index, ref, num = 0;

    // select forward reference index
    index = m_gmbinfo->RefIdxs[0][iMBNum].RefIdxs[iBlockNum];
    if (0 <= index)
    {
        H264DecoderFrame **pRefPicList;
        H264DecoderMacroblockGlobalInfo *pMBInfo;
        Ipp32s iNum = 0;

        // obtain reference list
        pMBInfo = m_gmbinfo->mbs + iMBNum;
        pRefPicList = m_pCurrentFrame->GetRefPicList(pMBInfo->slice_id, 0)->m_RefPicList;
        if (FRM_STRUCTURE > m_pCurrentFrame->m_PictureStructureForDec)
        {
            ReferenceFlags *pFields;

            pFields = m_pCurrentFrame->GetRefPicList(pMBInfo->slice_id, 0)->m_Flags;
            iNum = pRefPicList[index]->GetNumberByParity(GetReferenceField(pFields, index));
        }
        ref = pRefPicList[index]->DeblockPicID(iNum);

        // increment number of valid references
        num += 1;
    }
    else
        ref = -1;
    pReferences[0] = ref;

    // select backward reference index
    index = m_gmbinfo->RefIdxs[1][iMBNum].RefIdxs[iBlockNum];
    if (0 <= index)
    {
        H264DecoderFrame **pRefPicList;
        H264DecoderMacroblockGlobalInfo *pMBInfo;
        Ipp32s iNum = 0;

        // obtain reference list
        pMBInfo = m_gmbinfo->mbs + iMBNum;
        pRefPicList = m_pCurrentFrame->GetRefPicList(pMBInfo->slice_id, 1)->m_RefPicList;
        if (FRM_STRUCTURE > m_pCurrentFrame->m_PictureStructureForDec)
        {
            ReferenceFlags *pFields;

            pFields = m_pCurrentFrame->GetRefPicList(pMBInfo->slice_id, 1)->m_Flags;
            iNum = pRefPicList[index]->GetNumberByParity(GetReferenceField(pFields, index));
        }
        ref = pRefPicList[index]->DeblockPicID(iNum);

        // increment number of valid references
        num += 1;
    }
    else
        ref = -1;
    pReferences[1] = ref;

    return num;

} // Ipp32s H264SegmentDecoder::GetReferencesBSlice(Ipp32s iMBNum, Ipp32s iBlockNum, Ipp32s *pReferences)

void H264SegmentDecoder::PrepareDeblockingParametersPSlice16x16Vert(DeblockingParameters *pParams)
{
    Ipp32s MBAddr = pParams->nMBAddr;
    Ipp32u cbp4x4_luma = (m_mbinfo.mbs + MBAddr)->cbp4x4_luma;
    Ipp8u *pStrength = pParams->Strength[VERTICAL_DEBLOCKING];
    Ipp32s iDeblockingFlag = 0;

    //
    // precalculating of reference numbers of current macroblock.
    // it is more likely we have to compare reference numbers.
    // we will use it also in horizontal deblocking
    //
    pParams->iReferences[0][0] = GetReferencePSlice(MBAddr, 0);

    //
    // external edge
    //
    if (pParams->ExternalEdgeFlag[VERTICAL_DEBLOCKING])
    {
        Ipp32s nNeighbour;

        // select neighbour addres
        nNeighbour = pParams->nNeighbour[VERTICAL_DEBLOCKING];

        // when neighbour macroblock isn't intra
        if (!IS_INTRA_MBTYPE((m_gmbinfo->mbs + nNeighbour)->mbtype))
        {
            H264DecoderMacroblockLocalInfo *pNeighbour;
            Ipp32u uMask;

            // select neighbour
            pNeighbour = m_mbinfo.mbs + nNeighbour;

            // create special mask
            uMask = cbp4x4_luma | (pNeighbour->cbp4x4_luma >> 5);

            // when at least one from a couple of blocks has coeffs
            if (VERTICAL_OUTER_EDGE_MASK != (uMask & VERTICAL_OUTER_EDGE_MASK))
            {
                Ipp32s refCur;
                H264DecoderMotionVector mvCur;
                H264DecoderMotionVector *pMVPrev;

                // obtain current block parameters
                refCur = pParams->iReferences[0][0];
                mvCur = m_gmbinfo->MV[0][MBAddr].MotionVectors[0];

                // obtain previous block parameters
                pMVPrev = m_gmbinfo->MV[0][nNeighbour].MotionVectors;

                SET_DEBLOCKING_STRENGTH_P_SLICE_VERTICAL(0, 1)

                SET_DEBLOCKING_STRENGTH_P_SLICE_VERTICAL(2, 3)
            }
            else
            {
                SetEdgeStrength(pStrength + 0, 2);
                iDeblockingFlag = 1;
            }
        }
        else
        {
            SetEdgeStrength(pStrength + 0, 4);
            iDeblockingFlag = 1;
        }
    }

    pParams->DeblockingFlag[VERTICAL_DEBLOCKING] = iDeblockingFlag;

    //
    // internal edge(s)
    //
    PrepareDeblockingParametersIntern16x16Vert(pParams);

} // void H264SegmentDecoder::PrepareDeblockingParametersPSlice16x16Vert(DeblockingParameters *pParams)

void H264SegmentDecoder::PrepareDeblockingParametersPSlice16x16Horz(DeblockingParameters *pParams)
{
    Ipp32s MBAddr = pParams->nMBAddr;
    Ipp32u cbp4x4_luma = (m_mbinfo.mbs + MBAddr)->cbp4x4_luma;
    Ipp8u *pStrength = pParams->Strength[HORIZONTAL_DEBLOCKING];
    Ipp32s iDeblockingFlag = 0;

    //
    // external edge
    //
    if (pParams->ExternalEdgeFlag[HORIZONTAL_DEBLOCKING])
    {
        Ipp32s nNeighbour;

        // select neighbour addres
        nNeighbour = pParams->nNeighbour[HORIZONTAL_DEBLOCKING];

        // when neighbour macroblock isn't intra
        if (!IS_INTRA_MBTYPE((m_gmbinfo->mbs + nNeighbour)->mbtype))
        {
            H264DecoderMacroblockLocalInfo *pNeighbour;
            Ipp32u uMask;

            // select neighbour
            pNeighbour = m_mbinfo.mbs + nNeighbour;

            // create special mask
            uMask = cbp4x4_luma | (pNeighbour->cbp4x4_luma >> 10);

            // when at least one from a couple of blocks has coeffs
            if (HORIZONTAL_OUTER_EDGE_MASK != (uMask & HORIZONTAL_OUTER_EDGE_MASK))
            {
                Ipp32s refCur;
                H264DecoderMotionVector mvCur;
                H264DecoderMotionVector *pMVPrev;

                // obtain current block parameters
                refCur = pParams->iReferences[0][0];
                mvCur = m_gmbinfo->MV[0][MBAddr].MotionVectors[0];

                // obtain neighbour block parameters
                pMVPrev = m_gmbinfo->MV[0][nNeighbour].MotionVectors;

                SET_DEBLOCKING_STRENGTH_P_SLICE_HORIZONTAL(0, 1)

                SET_DEBLOCKING_STRENGTH_P_SLICE_HORIZONTAL(2, 3)
            }
            // when at least one from a couple of blocks has coeffs
            else
            {
                SetEdgeStrength(pStrength + 0, 2);
                iDeblockingFlag = 1;
            }
        }
        else
        {
            if (pParams->MBFieldCoded)
                SetEdgeStrength(pStrength + 0, 3);
            else
                SetEdgeStrength(pStrength + 0, 4);
            iDeblockingFlag = 1;
        }
    }

    pParams->DeblockingFlag[HORIZONTAL_DEBLOCKING] = iDeblockingFlag;

    //
    // internal edge(s)
    //
    PrepareDeblockingParametersIntern16x16Horz(pParams);

} // void H264SegmentDecoder::PrepareDeblockingParametersPSlice16x16Horz(DeblockingParameters *pParams)

void H264SegmentDecoder::PrepareDeblockingParametersBSlice4(Ipp32u dir, DeblockingParameters *pParams)
{
    Ipp32s MBAddr = pParams->nMBAddr;
    Ipp32u cbp4x4_luma = (m_mbinfo.mbs + MBAddr)->cbp4x4_luma;
    Ipp8u *pStrength = pParams->Strength[dir];
    Ipp32s *pDeblockingFlag = &(pParams->DeblockingFlag[dir]);

    //
    // external edge
    //
    if (pParams->ExternalEdgeFlag[dir])
    {
        Ipp32s nNeighbour;

        // select neighbour addres
        nNeighbour = pParams->nNeighbour[dir];

        // when neighbour macroblock isn't intra
        if (!IS_INTRA_MBTYPE((m_gmbinfo->mbs + nNeighbour)->mbtype))
        {
            H264DecoderMacroblockLocalInfo *pNeighbour;
            Ipp32s idx;

            // select neighbour
            pNeighbour = m_mbinfo.mbs + nNeighbour;

            // cicle on blocks
            for (idx = 0;idx < 4;idx += 1)
            {
                Ipp32s blkQ, blkP;

                blkQ = EXTERNAL_BLOCK_MASK[dir][CURRENT_BLOCK][idx];
                blkP = EXTERNAL_BLOCK_MASK[dir][NEIGHBOUR_BLOCK][idx];

                // when one of couple of blocks has coeffs
                if ((cbp4x4_luma & blkQ) ||
                    (pNeighbour->cbp4x4_luma & blkP))
                {
                    pStrength[idx] = 2;
                    *pDeblockingFlag = 1;
                }
                // compare motion vectors & reference indexes
                else
                {
                    Ipp32s nBlock, nNeighbourBlock;
                    Ipp32s iRefQFrw, iRefPFrw, iRefQBck, iRefPBck;
                    Ipp32s nVectorDiffLimit = pParams->nMaxMVector;

                    // calc block and neighbour block number
                    if (VERTICAL_DEBLOCKING == dir)
                    {
                        nBlock = idx * 4;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -