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

📄 umc_h264_reconstruct_templates.h

📁 audio-video-codecs.rar语音编解码器
💻 H
📖 第 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_defs.h"
#if defined (UMC_ENABLE_H264_VIDEO_DECODER)

#ifndef __UMC_H264_RECONSTRUCT_TEMPLATES_H
#define __UMC_H264_RECONSTRUCT_TEMPLATES_H

namespace UMC
{

#define NO_PADDING

// turn off the "conditional expression is constant" warning
#pragma warning(disable: 4127)

enum
{
    BI_DIR                      = 0,
    UNI_DIR                     = 1
};

template <typename PlaneY,
          typename PlaneUV,
          Ipp32s color_format,
          Ipp32s is_field,
          Ipp32s is_weight>
class ReconstructMB
{
public:
    typedef PlaneY * PlanePtrY;
    typedef PlaneUV * PlanePtrUV;

    STRUCT_DECLSPEC_ALIGN class ReconstructParams
    {
    public:
        PlanePtrY m_pDstY;                                      // (PlanePtrY) pointer to an Y plane
        PlanePtrUV m_pDstU;                                     // (PlanePtrUV) pointer to an U plane
        PlanePtrUV m_pDstV;                                     // (PlanePtrUV) pointer to an V plane
        Ipp32s m_iDstPitchLuma;                                     // (Ipp32s) pitch of planes
        Ipp32s m_iDstPitchChroma;                                     // (Ipp32s) pitch of planes
        // these variables used for optimized prediction
        PlanePtrY m_pSrcY[2];                                   // (PlanePtrY) pointer to an Y plane
        PlanePtrUV m_pSrcU[2];                                  // (PlanePtrUV) pointer to an U plane
        PlanePtrUV m_pSrcV[2];                                  // (PlanePtrUV) pointer to an V plane
        Ipp32s m_iSrcPitchLuma[2];                              // (Ipp32s) pitch of luminance planes
        Ipp32s m_iSrcPitchChroma[2];                            // (Ipp32s) pitch of chrominance planes

        // prediction pointers
        H264DecoderMotionVector *(m_pMV[2]);                    // (H264DecoderMotionVector * []) array of pointers to motion vectors
        Ipp32s m_iRefIndex[2];                                  // (Ipp32s) current reference index
        Ipp8s *(m_pRefIndex[2]);                                // (Ipp8s * []) pointer to array of reference indexes

        // current macroblock parameters
        Ipp32s m_iOffsetLuma;                                   // (Ipp32s) luminance offset
        Ipp32s m_iOffsetChroma;                                 // (Ipp32s) chrominance offset
        Ipp32s m_iLumaXPos;                                     // (Ipp32s) horizontal luminance position (for MV checking)
        Ipp32s m_iLumaYPos;                                     // (Ipp32s) vertical luminance position (for MV checking)
        Ipp32s m_iChromaXPos;                                   // (Ipp32s) horizontal chrominance position (for MV checking)
        Ipp32s m_iChromaYPos;                                   // (Ipp32s) vertical chrominance position (for MV checking)
        Ipp32s m_iIntraMBLumaOffset;
        Ipp32s m_iIntraMBChromaOffset;
        Ipp32s m_iIntraMBLumaOffsetTmp;
        Ipp32s m_iIntraMBChromaOffsetTmp;
        IppiSize roi;                                           // (Ipp32s) size of processed block
        IppiSize roi_chroma;                                    // (Ipp32s) size of processed block

        // weighting parameters
        Ipp32s luma_log2_weight_denom;                          // (Ipp32s)
        Ipp32s chroma_log2_weight_denom;                        // (Ipp32s)
        Ipp32s weighted_bipred_idc;                             // (Ipp32s)
        bool m_bBidirWeightMB;                                  // (bool) flag of bidirectional weighting
        bool m_bUnidirWeightMB;                                 // (bool) flag of unidirectional weighting
        Ipp32s bit_depth_luma;                                  // (Ipp32s) bits per pixel for luma plane
        Ipp32s bit_depth_chroma;                                // (Ipp32s) bits per pixel for chroma planes
        H264SegmentDecoder *m_pSegDec;                          // (H264SegmentDecoder *) pointer to segment decoder

        // current frame parameters
        IppiSize m_lumaSize;                                 // (sDimensions) size of luminance
        IppiSize m_chromaSize;                               // (sDimensions) size of chrominance

        bool is_mbaff;
        bool is_bottom_mb;
    };

    inline
    Ipp32s ChromaOffset(Ipp32s x, Ipp32s y, Ipp32s pitch)
    {
        return (x >> (Ipp32s)(color_format < 3)) + (y >> (Ipp32s)(color_format < 2)) * pitch;

    } // Ipp32s ChromaOffset(Ipp32s x, Ipp32s y, Ipp32s pitch)

    // we can't use template instead implicit parameter's passing
    // couse we use slightly different types
    void CompensateMotionLumaBlock(ReconstructParams *pParams,
                                   Ipp32s iDir,
                                   Ipp32s iBlockNumber,
                                   Ipp32s iUniDir,
                                   Ipp8u *)
    {
        IppVCInterpolateBlock_8u interpolateInfo;
        Ipp32s iRefIndex;
        Ipp32s iRefFieldTop;

        // get reference index
        iRefIndex =
        (pParams->m_iRefIndex[iDir] = pParams->m_pRefIndex[iDir][iBlockNumber]);
        if (is_field && pParams->is_mbaff)
            iRefIndex >>= 1;
        VM_ASSERT(iRefIndex >= 0);

        // get reference frame & pitch
        interpolateInfo.pSrc[0] = (Ipp8u *) pParams->m_pSegDec->m_pRefPicList[iDir][iRefIndex]->m_pYPlane;
        VM_ASSERT(interpolateInfo.pSrc[0]);
        interpolateInfo.srcStep = pParams->m_pSegDec->m_pRefPicList[iDir][iRefIndex]->pitch_luma();

        if (is_field)
        {
            if (pParams->is_mbaff)
            {
                iRefFieldTop = pParams->is_bottom_mb ^ (pParams->m_iRefIndex[iDir] & 1);
                pParams->m_iRefIndex[iDir] = iRefIndex;
            }
            else
                iRefFieldTop = GetReferenceField(pParams->m_pSegDec->m_pFields[iDir], iRefIndex);

            if (iRefFieldTop)
                interpolateInfo.pSrc[0] += interpolateInfo.srcStep;

            interpolateInfo.srcStep *= 2;
        }

        // create vectors & factors
        interpolateInfo.pointVector.x = pParams->m_pMV[iDir][iBlockNumber].mvx;
        interpolateInfo.pointVector.y = pParams->m_pMV[iDir][iBlockNumber].mvy;

        // we should do interpolation if vertical or horizontal vector isn't zero
        if (interpolateInfo.pointVector.x | interpolateInfo.pointVector.y)
        {
            // fill parameters
            interpolateInfo.pDst[0] = pParams->m_pDstY;
            interpolateInfo.dstStep = pParams->m_iDstPitchLuma;
            interpolateInfo.sizeFrame = pParams->m_lumaSize;
            interpolateInfo.sizeBlock = pParams->roi;
            interpolateInfo.pointBlockPos.x = pParams->m_iLumaXPos;
            interpolateInfo.pointBlockPos.y = pParams->m_iLumaYPos;

            ippiInterpolateLumaBlock_H264_8u_P1R(&interpolateInfo);

            // save pointers for optimized interpolation
            pParams->m_pSrcY[iDir] = pParams->m_pDstY;
            pParams->m_iSrcPitchLuma[iDir] = pParams->m_iDstPitchLuma;
        }
        else
        {
            Ipp32s iOffset = pParams->m_iOffsetLuma +
                             pParams->m_iIntraMBLumaOffset;

            // save pointers for optimized interpolation
            if (0 == iUniDir)
            {
                pParams->m_pSrcY[iDir] = (PlanePtrY) interpolateInfo.pSrc[0] + iOffset;
                pParams->m_iSrcPitchLuma[iDir] = interpolateInfo.srcStep;
            }
            // we have to do interpolation for uni-direction motion
            else
            {
                ippiInterpolateLuma_H264_8u_C1R((PlanePtrY) (interpolateInfo.pSrc[0] + iOffset),
                                                interpolateInfo.srcStep,
                                                pParams->m_pDstY,
                                                pParams->m_iDstPitchLuma,
                                                0,
                                                0,
                                                pParams->roi);

                // save pointers for optimized interpolation
                pParams->m_pSrcY[iDir] = pParams->m_pDstY;
                pParams->m_iSrcPitchLuma[iDir] = pParams->m_iDstPitchLuma;
            }
        }

    } // void CompensateMotionLumaBlock(ReconstructParams *pParams,

    void CompensateMotionLumaBlock(ReconstructParams *pParams,
                                   Ipp32s iDir,
                                   Ipp32s iBlockNumber,
                                   Ipp32s iUniDir,
                                   Ipp16u *)
    {
        IppVCInterpolateBlock_16u interpolateInfo;
        Ipp32s iRefIndex;
        Ipp32s iRefFieldTop;

        // get reference index
        iRefIndex =
        (pParams->m_iRefIndex[iDir] = pParams->m_pRefIndex[iDir][iBlockNumber]);
        if (is_field && pParams->is_mbaff)
            iRefIndex >>= 1;
        VM_ASSERT(iRefIndex >= 0);

        // get reference frame & pitch
        interpolateInfo.pSrc[0] = (Ipp16u *) pParams->m_pSegDec->m_pRefPicList[iDir][iRefIndex]->m_pYPlane;
        VM_ASSERT(interpolateInfo.pSrc[0]);
        interpolateInfo.srcStep = pParams->m_pSegDec->m_pRefPicList[iDir][iRefIndex]->pitch_luma();

        if (is_field)
        {
            if (pParams->is_mbaff)
            {
                iRefFieldTop = pParams->is_bottom_mb ^ (pParams->m_iRefIndex[iDir] & 1);
                pParams->m_iRefIndex[iDir] = iRefIndex;
            }
            else
                iRefFieldTop = GetReferenceField(pParams->m_pSegDec->m_pFields[iDir], iRefIndex);

            if (iRefFieldTop)
                interpolateInfo.pSrc[0] += interpolateInfo.srcStep;

            interpolateInfo.srcStep *= 2;
        }

        // save vector
        interpolateInfo.pointVector.x = pParams->m_pMV[iDir][iBlockNumber].mvx;
        interpolateInfo.pointVector.y = pParams->m_pMV[iDir][iBlockNumber].mvy;

        // we should do interpolation if vertical or horizontal vector isn't zero
        if (interpolateInfo.pointVector.x | interpolateInfo.pointVector.y)
        {
            // fill parameters
            interpolateInfo.pDst[0] = pParams->m_pDstY;
            interpolateInfo.dstStep = pParams->m_iDstPitchLuma;
            interpolateInfo.sizeFrame = pParams->m_lumaSize;
            interpolateInfo.sizeBlock = pParams->roi;
            interpolateInfo.pointBlockPos.x = pParams->m_iLumaXPos;
            interpolateInfo.pointBlockPos.y = pParams->m_iLumaYPos;
            interpolateInfo.bitDepth = pParams->bit_depth_luma;

            ippiInterpolateLumaBlock_H264_16u_P1R(&interpolateInfo);

            // save pointers for optimized interpolation
            pParams->m_pSrcY[iDir] = pParams->m_pDstY;
            pParams->m_iSrcPitchLuma[iDir] = pParams->m_iDstPitchLuma;
        }
        else
        {
            Ipp32s iOffset = pParams->m_iOffsetLuma +
                             pParams->m_iIntraMBLumaOffset;

            // save pointers for optimized interpolation
            if (0 == iUniDir)
            {
                pParams->m_pSrcY[iDir] = (PlanePtrY) interpolateInfo.pSrc[0] + iOffset;
                pParams->m_iSrcPitchLuma[iDir] = interpolateInfo.srcStep;
            }
            // we have to do interpolation for uni-direction motion
            else
            {
                IppVCInterpolate_16u info;

                info.pSrc = (PlanePtrY) (interpolateInfo.pSrc[0] + iOffset);
                info.srcStep = interpolateInfo.srcStep;
                info.pDst = pParams->m_pDstY;
                info.dstStep = pParams->m_iDstPitchLuma;
                info.dx = 0;
                info.dy = 0;
                info.roiSize = pParams->roi;
                info.bitDepth = pParams->bit_depth_luma;

                ippiInterpolateLuma_H264_16u_C1R(&info);

                // save pointers for optimized interpolation
                pParams->m_pSrcY[iDir] = pParams->m_pDstY;
                pParams->m_iSrcPitchLuma[iDir] = pParams->m_iDstPitchLuma;
            }

⌨️ 快捷键说明

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