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

📄 umc_h264_deblocking_mbaff.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*
//
//              INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license  agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in  accordance  with the terms of that agreement.
//        Copyright (c) 2003-2007 Intel Corporation. All Rights Reserved.
//
//
*/

#include "umc_h264_deblocking.h"
#include "umc_h264_video_encoder.h"
#include "vm_types.h"
#include "vm_debug.h"
#include "umc_h264_to_ipp.h"
#include "umc_h264_bme.h"

namespace UMC_H264_ENCODER
{

inline IppStatus ippiFilterDeblockingLuma_VerEdge_MBAFF_H264(Ipp8u* pSrcDst,
                                                             Ipp32s srcdstStep,
                                                             Ipp32u nAlpha,
                                                             Ipp32u nBetha,
                                                             Ipp8u* pThresholds,
                                                             Ipp8u* pBs,
                                                             Ipp32s bitdepth)
{
    return(ippiFilterDeblockingLuma_VerEdge_MBAFF_H264_8u_C1IR(pSrcDst, srcdstStep, nAlpha, nBetha, pThresholds, pBs));
}

#if defined BITDEPTH_9_12
inline IppStatus ippiFilterDeblockingLuma_VerEdge_MBAFF_H264(Ipp16u* pSrcDst,
                                                             Ipp32s  srcdstStep,
                                                             Ipp32u  nAlpha,
                                                             Ipp32u  nBetha,
                                                             Ipp8u*  pThresholds,
                                                             Ipp8u*  pBs,
                                                             Ipp32s  bitdepth)
{
    Ipp16u a[2], b[2];

    a[0] = nAlpha;
    b[0] = nBetha;
    IppiFilterDeblock_16u d;
    d.pSrcDstPlane = pSrcDst;
    d.srcDstStep = srcdstStep;
    d.pAlpha = a;
    d.pBeta = b;
    d.pThresholds = (Ipp16u*)pThresholds;
    d.pBs = pBs;
    d.bitDepth = bitdepth;
    return(ippiFilterDeblockingLumaVerEdgeMBAFF_H264_16u_C1IR(&d));
}
#endif // BITDEPTH_9_12

inline IppStatus ippiFilterDeblockingChroma_VerEdge_MBAFF_H264(Ipp8u* pSrcDst,
                                                               Ipp32s srcdstStep,
                                                               Ipp32u nAlpha,
                                                               Ipp32u nBetha,
                                                               Ipp8u* pThresholds,
                                                               Ipp8u* pBs,
                                                               Ipp32s bitdepth)
{
    return(ippiFilterDeblockingChroma_VerEdge_MBAFF_H264_8u_C1IR(pSrcDst, srcdstStep, nAlpha, nBetha, pThresholds, pBs));
}

#if defined BITDEPTH_9_12
inline IppStatus ippiFilterDeblockingChroma_VerEdge_MBAFF_H264(Ipp16u* pSrcDst,
                                                               Ipp32s  srcdstStep,
                                                               Ipp32u  nAlpha,
                                                               Ipp32u  nBetha,
                                                               Ipp8u*  pThresholds,
                                                               Ipp8u*  pBs,
                                                               Ipp32s  bitdepth)
{
    Ipp16u a[2],b[2];

    a[0] = nAlpha;
    b[0] = nBetha;
    /// Should be corrected
    IppiFilterDeblock_16u d;
    d.pSrcDstPlane = pSrcDst;
    d.srcDstStep = srcdstStep;
    d.pAlpha = a;
    d.pBeta = b;
    d.pThresholds = (Ipp16u*)pThresholds;
    d.pBs = pBs;
    d.bitDepth = bitdepth;
    return(ippiFilterDeblockingChromaVerEdgeMBAFF_H264_16u_C1IR(&d));
}
#endif // BITDEPTH_9_12

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::DeblockMacroblockISliceMBAFF(Ipp32u MBAddr)
{
    __align(16)
    DeblockingParametersMBAFF<PixType> params;

    // prepare deblocking parameters
    params.nMBAddr = MBAddr;
    ResetDeblockingVariablesMBAFF(&params);
    PrepareDeblockingParametersISliceMBAFF(&params);

    // perform luma deblocking
    if (0 == params.UseComplexVerticalDeblocking)
        DeblockLuma(VERTICAL_DEBLOCKING, &params);
    else
        DeblockLumaVerticalMBAFF(&params);
    if (0 == params.ExtraHorizontalEdge)
        DeblockLuma(HORIZONTAL_DEBLOCKING, &params);
    else
        DeblockLumaHorizontalMBAFF(&params);

    // perform chroma deblocking
    if (0 == params.UseComplexVerticalDeblocking)
        DeblockChroma(VERTICAL_DEBLOCKING, &params);
    else
        DeblockChromaVerticalMBAFF(&params);
    if (0 == params.ExtraHorizontalEdge)
        DeblockChroma(HORIZONTAL_DEBLOCKING, &params);
    else
        DeblockChromaHorizontalMBAFF(&params);

} // void H264CoreEncoder::DeblockMacroblockISliceMBAFF(Ipp32u MBAddr)

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::DeblockMacroblockPSliceMBAFF(Ipp32u MBAddr)
{
    __align(16)
    DeblockingParametersMBAFF<PixType> params;

    // prepare deblocking parameters
    params.nMBAddr = MBAddr;
    ResetDeblockingVariablesMBAFF(&params);
    PrepareDeblockingParametersPSliceMBAFF(&params);

    // perform luma deblocking
    if (0 == params.UseComplexVerticalDeblocking)
        DeblockLuma(VERTICAL_DEBLOCKING, &params);
    else
        DeblockLumaVerticalMBAFF(&params);
    if (0 == params.ExtraHorizontalEdge)
        DeblockLuma(HORIZONTAL_DEBLOCKING, &params);
    else
        DeblockLumaHorizontalMBAFF(&params);

    // perform chroma deblocking
    if (0 == params.UseComplexVerticalDeblocking)
        DeblockChroma(VERTICAL_DEBLOCKING, &params);
    else
        DeblockChromaVerticalMBAFF(&params);
    if (0 == params.ExtraHorizontalEdge)
        DeblockChroma(HORIZONTAL_DEBLOCKING, &params);
    else
        DeblockChromaHorizontalMBAFF(&params);

} // void H264CoreEncoder::DeblockMacroblockPSliceMBAFF(Ipp32u MBAddr)

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::DeblockMacroblockBSliceMBAFF(Ipp32u MBAddr)
{
    __align(16)
    DeblockingParametersMBAFF<PixType> params;

    // prepare deblocking parameters
    params.nMBAddr = MBAddr;
    ResetDeblockingVariablesMBAFF(&params);
    PrepareDeblockingParametersBSliceMBAFF(&params);

    // perform luma deblocking
    if (0 == params.UseComplexVerticalDeblocking)
        DeblockLuma(VERTICAL_DEBLOCKING, &params);
    else
        DeblockLumaVerticalMBAFF(&params);
    if (0 == params.ExtraHorizontalEdge)
        DeblockLuma(HORIZONTAL_DEBLOCKING, &params);
    else
        DeblockLumaHorizontalMBAFF(&params);

    // perform chroma deblocking
    if (0 == params.UseComplexVerticalDeblocking)
        DeblockChroma(VERTICAL_DEBLOCKING, &params);
    else
        DeblockChromaVerticalMBAFF(&params);
    if (0 == params.ExtraHorizontalEdge)
        DeblockChroma(HORIZONTAL_DEBLOCKING, &params);
    else
        DeblockChromaHorizontalMBAFF(&params);

} // void H264CoreEncoder::DeblockMacroblockBSliceMBAFF(Ipp32u MBAddr)

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::ResetDeblockingVariablesMBAFF(DeblockingParametersMBAFF<PixType>*pParams)
{
    PixType *pY, *pU, *pV;
    Ipp32s offset;
    Ipp32s mbXOffset, mbYOffset;
    Ipp32s pic_pitchPixels = m_pCurrentFrame->pitchPixels();
    Ipp32s MBAddr = pParams->nMBAddr;
    Ipp32s nCurrMB_X, nCurrMB_Y;
    H264LimitedSliceHeader *pHeader;
    Ipp32s nFieldMacroblockMode;

/*    // from linear MB number to MBAFF MB number
    {
        Ipp32u nRemain;
        nRemain = MBAddr % (mb_width * 2);
        MBAddr = MBAddr - nRemain + nRemain / 2;
        if (nRemain & 1)
            MBAddr += mb_width;
    }
*/
    // load slice header
    pHeader = m_pLimitedSliceInfo + m_pCurrentFrame->m_mbinfo.mbs[MBAddr].slice_id;

    // load planes
    pY = (PixType*)m_pReconstructFrame->m_pYPlane;
    pU = (PixType*)m_pReconstructFrame->m_pUPlane;
    pV = (PixType*)m_pReconstructFrame->m_pVPlane;

    // prepare macroblock variables
    nCurrMB_X = ((MBAddr>>1) % m_WidthInMBs);
    nCurrMB_Y = ((MBAddr>>1) / m_WidthInMBs)*2 + (MBAddr&1);

    mbXOffset = nCurrMB_X * 16;
    mbYOffset = nCurrMB_Y * 16;

    // obtain macroblock mode
    nFieldMacroblockMode = pGetMBFieldDecodingFlag(m_pCurrentFrame->m_mbinfo.mbs + MBAddr);
    // calc plane's offsets
    offset = m_pMBOffsets[MBAddr].uLumaOffset[1][nFieldMacroblockMode];
    pY += offset;
    offset = m_pMBOffsets[MBAddr].uChromaOffset[1][nFieldMacroblockMode];
    pU += offset;
    pV += offset;
    // correct y, u & v offset
    if (nFieldMacroblockMode)
    {
        pic_pitchPixels *= 2;
    }

    // set external edge variables
    // there are only two values:
    // zero - do not deblocking
    // nonzero - do deblocking
    pParams->ExternalEdgeFlag[VERTICAL_DEBLOCKING] = nCurrMB_X;
    pParams->ExternalEdgeFlag[HORIZONTAL_DEBLOCKING] = (nFieldMacroblockMode) ? (1 < nCurrMB_Y) : (nCurrMB_Y);

    if (DEBLOCK_FILTER_ON_NO_SLICE_EDGES == pHeader->disable_deblocking_filter_idc)
    {
        // don't filter at slice boundaries
        if (pParams->ExternalEdgeFlag[VERTICAL_DEBLOCKING])
        {
            if (m_pCurrentFrame->m_mbinfo.mbs[MBAddr].slice_id !=
                m_pCurrentFrame->m_mbinfo.mbs[MBAddr - 2].slice_id)
                pParams->ExternalEdgeFlag[VERTICAL_DEBLOCKING] = 0;
        }

        if (pParams->ExternalEdgeFlag[HORIZONTAL_DEBLOCKING])
        {
            if (m_pCurrentFrame->m_mbinfo.mbs[MBAddr].slice_id !=
                m_pCurrentFrame->m_mbinfo.mbs[MBAddr - m_WidthInMBs * 2].slice_id)
                pParams->ExternalEdgeFlag[HORIZONTAL_DEBLOCKING] = 0;
        }
    }

    // set left MB couple adresses
    {
        Ipp32u nRemain;
        nRemain = pParams->nMBAddr % (m_WidthInMBs * 2);
        pParams->nLeft[0] = pParams->nMBAddr - nRemain + nRemain / 2 - 1;
        pParams->nLeft[1] = pParams->nLeft[0] + 1;
    }

    // set "complex deblocking" flag
    // when left & current macroblock are coded in different modes
    pParams->UseComplexVerticalDeblocking = 0;
    if (pParams->ExternalEdgeFlag[VERTICAL_DEBLOCKING])
    {
        if (nFieldMacroblockMode !=
            (Ipp32u) pGetMBFieldDecodingFlag(m_pCurrentFrame->m_mbinfo.mbs + MBAddr - 2))
        {
            // when left macroblocks aren't intra blocks
            // or have different QP
            if (IS_INTER_MBTYPE((m_pCurrentFrame->m_mbinfo.mbs + pParams->nLeft[0])->mbtype) ||
                IS_INTER_MBTYPE((m_pCurrentFrame->m_mbinfo.mbs + pParams->nLeft[1])->mbtype) ||
                (m_mbinfo.mbs[pParams->nLeft[0]].QP != m_mbinfo.mbs[pParams->nLeft[1]].QP))
            {
                pParams->ExternalEdgeFlag[VERTICAL_DEBLOCKING] = 0;
                pParams->UseComplexVerticalDeblocking = 1;
            }
        }
    }

    // obtain extra horizontal edge condition
    // when above macroblock is field coded and
    // current macroblock is frame coded
    pParams->ExtraHorizontalEdge = 0;
    if ((0 == (pParams->nMBAddr & 1)) &&
        (pParams->ExternalEdgeFlag[HORIZONTAL_DEBLOCKING]))
    {
        if ((0 == nFieldMacroblockMode) &&
            (0 != pGetMBFieldDecodingFlag(m_pCurrentFrame->m_mbinfo.mbs + MBAddr - m_WidthInMBs * 2)))
            pParams->ExtraHorizontalEdge = 1;
    }

    // reset external edges strength
    SetEdgeStrength(pParams->Strength[VERTICAL_DEBLOCKING], 0);
    SetEdgeStrength(pParams->Strength[HORIZONTAL_DEBLOCKING], 0);

⌨️ 快捷键说明

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