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

📄 umc_h264_ermb.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                ippiCountCoeffs(pTransformResult, &iNumCoeffs, enc_single_scan[is_cur_mb_field], &iLastCoeff, 16);
            }

            cur_mb.MacroblockCoeffsInfo->lumaAC |= ((iNumCoeffs < -1) || (iNumCoeffs > 0));

            if (!iNumCoeffs){
                bCoded = 0;
            } else {
                cur_mb.MacroblockCoeffsInfo->numCoeff[uBlock] = (T_NumCoeffs)((iNumCoeffs < 0) ? -(iNumCoeffs+1) : iNumCoeffs);
                if (m_PicParamSet.entropy_coding_mode){
                    ScanSignificant_CABAC(pTransformResult,BLOCK_LUMA_AC_LEVELS,15, dec_single_scan[is_cur_mb_field], &curr_slice->Block_CABAC[uBlock]);
                    bCoded = curr_slice->Block_CABAC[uBlock].uNumSigCoeffs;
                } else {
                    ippiEncodeCoeffsCAVLC_H264(pTransformResult, 1, dec_single_scan[is_cur_mb_field], iLastCoeff,
                                               &curr_slice->Block_RLE[uBlock].uTrailing_Ones,
                                               &curr_slice->Block_RLE[uBlock].uTrailing_One_Signs,
                                               &curr_slice->Block_RLE[uBlock].uNumCoeffs,
                                               &curr_slice->Block_RLE[uBlock].uTotalZeros,
                                               curr_slice->Block_RLE[uBlock].iLevels,
                                               curr_slice->Block_RLE[uBlock].uRuns);
                    cur_mb.MacroblockCoeffsInfo->numCoeff[uBlock] = bCoded = curr_slice->Block_RLE[uBlock].uNumCoeffs;
                }
            }

            if (!bCoded) uCBPLuma &= ~CBP4x4Mask[uBlock];

            // If the block wasn't coded and the DC coefficient is zero
            if (!bCoded && !pDCBuf[block_subblock_mapping[uBlock]]){
                Copy4x4(pPredBuf, 16*sizeof(PixType), pReconBuf, pitchPix*sizeof(PixType));
            } else if(!transform_bypass) {
                ippiDequantTransformResidualAndAdd_H264( pPredBuf, pTransformResult, &pDCBuf[block_subblock_mapping[uBlock]], pReconBuf, 16, pitchPix, uMBQP, ((iNumCoeffs < -1) || (iNumCoeffs > 0)), m_PicParamSet.bit_depth_luma);
            }
        }
    }

    cur_mb.LocalMacroblockInfo->cbp_luma = uCBPLuma;
    if (cur_mb.MacroblockCoeffsInfo->lumaAC > 1)
        cur_mb.MacroblockCoeffsInfo->lumaAC = 1;

/*    cur_mb.intra_types[0] = cur_mb.LocalMacroblockInfo->intra_16x16_mode;
    for (Ipp32s i=1; i<16; i++)
    {
        cur_mb.intra_types[i] = 2;
    }
*/
}

inline void ippiCalcNonZero(const Ipp16s *coeffs, Ipp32s  m, Ipp32s *numCoeffs)
{
    Ipp32s n = 0;
    for (Ipp32s i = 0; i < m; i ++) {
        if (coeffs[i] != 0)
            n ++;
    }
    *numCoeffs = n; //(coeffs[0] != 0)? -n: n;
}

inline void ippiCalcNonZero(const Ipp32s *coeffs, Ipp32s  m, Ipp32s *numCoeffs)
{
    Ipp32s n = 0;
    for (Ipp32s i = 0; i < m; i ++) {
        if (coeffs[i] != 0)
            n ++;
    }
    *numCoeffs = n; //(coeffs[0] != 0)? -n: n;
}

inline void ippiCountCoeffs(const Ipp32s *coeffs, Ipp32s *numCoeffs, const Ipp16s *enc_scan, Ipp32s *lastCoeff, Ipp32s  m)
{
    // m can take the following values: 16, 64.
    Ipp32s l = 0;
    Ipp32s n = 0;
    for(Ipp32s i = 0; i < m; i++) {
        if (coeffs[i] != 0) {
            n ++;
            if (l < enc_scan[i])
                l = enc_scan[i];
        }
    }

    *numCoeffs = n;//(coeffs[0] != 0)? -n: n;
    *lastCoeff = l;
}

inline void ippiCountCoeffs(const Ipp16s *coeffs, Ipp32s *numCoeffs, const Ipp16s *enc_scan, Ipp32s *lastCoeff, Ipp32s  m)
{
    // m can take the following values: 16, 64.
    Ipp32s l = 0;
    Ipp32s n = 0;
    for(Ipp32s i = 0; i < m; i++) {
        if (coeffs[i] != 0) {
            n ++;
            if (l < enc_scan[i])
                l = enc_scan[i];
        }
    }
    *numCoeffs = n;//(coeffs[0] != 0)? -n: n;
    *lastCoeff = l;
}

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType, CoeffsType>::EncodeChroma(H264EncoderThreadPrivateSlice<PixType, CoeffsType> *curr_slice )
{
    Ipp32u  uBlock;         // block number, 0 to 23
    Ipp32u  uOffset;        // to upper left corner of block from start of plane
    Ipp32u  uMBQP;          // QP of current MB
    Ipp32u  uMB;
    PixType*  pSrcPlane;    // start of plane to encode
    Ipp32s    pitchPixels;  // buffer pitch
    CoeffsType *pDCBuf;     // chroma & luma dc coeffs pointer
    PixType*  pPredBuf;     // prediction block pointer
    PixType*  pReconBuf;     // prediction block pointer
    PixType*  pPredBuf_copy;     // prediction block pointer
    PixType*  pReconBuf_copy;     // prediction block pointer
    CoeffsType* pQBuf;      // quantized block pointer
    Ipp16s* pMassDiffBuf;   // difference block pointer

    Ipp32u   uCBPChroma;    // coded flags for all chroma blocks
    Ipp32s   bCoded;        // coded block flag
    Ipp32s   iNumCoeffs;    // Number of nonzero coeffs after quant (negative if DC is nonzero)
    Ipp32s   iLastCoeff;    // Number of nonzero coeffs after quant (negative if DC is nonzero)
    Ipp32s   RLE_Offset;    // Index into BlockRLE array

    H264CurrentMacroblockDescriptor<PixType, CoeffsType> &cur_mb = curr_slice->m_cur_mb;
    Ipp32s is_cur_mb_field = curr_slice->m_is_cur_mb_field;
    EnumSliceType slice_type = curr_slice->m_slice_type;
    CoeffsType *pTransformResult;
    CoeffsType *pTransform;
    Ipp32s QPy = getLumaQP(cur_mb.LocalMacroblockInfo->QP, m_PicParamSet.bit_depth_luma);

    pitchPixels = cur_mb.mbPitchPixels;
    uMBQP       = getChromaQP(cur_mb.LocalMacroblockInfo->QP, m_PicParamSet.chroma_qp_index_offset, m_SeqParamSet.bit_depth_chroma);
    pTransform = (CoeffsType*)curr_slice->m_pMBEncodeBuffer;
    pQBuf       = (CoeffsType*) (pTransform + 64*2);
    pDCBuf      = (CoeffsType*) (pQBuf + 16);   // Used for both luma and chroma DC blocks
    pMassDiffBuf= (Ipp16s*) (pDCBuf+ 16);
    Ipp16s*  pTempDiffBuf;
    bool    intra;
    uMB = cur_mb.uMB;
    Ipp32s  pitchPix;

#ifdef H264_RD_OPT
    pitchPix = 16;
#else
    pitchPix = pitchPixels;
#endif
    // initialize pointers and offset
    uOffset = m_pMBOffsets[uMB].uChromaOffset[m_is_cur_pic_afrm][is_cur_mb_field];
    bool transform_bypass = m_SeqParamSet.qpprime_y_zero_transform_bypass_flag && QPy == 0;
    uCBPChroma  = cur_mb.LocalMacroblockInfo->cbp_chroma;

    cur_mb.MacroblockCoeffsInfo->chromaNC = 0;

    if( cur_mb.GlobalMacroblockInfo->mbtype == MBTYPE_INTRA ||
        cur_mb.GlobalMacroblockInfo->mbtype == MBTYPE_INTRA_16x16 ) intra = true;
    else intra = false;

        // Because JVT jointly codes the Intra prediction type for both
        // U and V MBs (they use the same type), we need to jointly determine
        // the best type, and save the predictor values for both in the
        // pPredBuf to be used below.  This is OK, since this is typically used
        // as a 16x16 buffer and the U and V predictions are each 8x8 blocks.
        // The 16x16 blocks are stored U above V, and the buffer pitch is 16.
    if( intra ){
        pPredBuf = cur_mb.mbChromaIntra.prediction;
        pReconBuf = cur_mb.mbChromaIntra.reconstruct;
        AIModeSelectChromaMBs_8x8(curr_slice,
                                  m_pCurrentFrame->m_pUPlane + uOffset,
                                  m_pReconstructFrame->m_pUPlane + uOffset,
                                  m_pCurrentFrame->m_pVPlane + uOffset,
                                  m_pReconstructFrame->m_pVPlane + uOffset,
                                  pitchPixels,
                                  &cur_mb.LocalMacroblockInfo->intra_chroma_mode,
                                  pPredBuf,
                                  pPredBuf+8);  //up to 422 only
    }else{
        pPredBuf = cur_mb.mbChromaInter.prediction;
        pReconBuf = cur_mb.mbChromaInter.reconstruct;
    }

        // initialize pointers for the U plane blocks
        Ipp32s num_blocks = 2<<m_PicParamSet.chroma_format_idc;
        Ipp32s startBlock;
        startBlock = uBlock = 16;
        Ipp32u uLastBlock = uBlock+num_blocks;
        Ipp32u uFinalBlock = uBlock+2*num_blocks;

        // encode first chroma U plane then V plane
        do
        {
            // Adjust the pPredBuf to point at the V plane predictor when appropriate:
            // (blocks and an INTRA Y plane mode...)
            if (uBlock == uLastBlock) {
                startBlock = uBlock;
                uOffset = m_pMBOffsets[uMB].uChromaOffset[m_is_cur_pic_afrm][is_cur_mb_field];
                pSrcPlane = m_pCurrentFrame->m_pVPlane;
                pPredBuf -= 60;
#ifdef H264_RD_OPT
                pReconBuf -= 60;
#else
                pReconBuf = m_pReconstructFrame->m_pVPlane+uOffset;
#endif
                RLE_Offset = V_DC_RLE;
                // initialize pointers for the V plane blocks
                uLastBlock += num_blocks;
                if( !intra )
                    MCOneMBChroma(curr_slice,
                                  uMB, pitchPixels,
                                  cur_mb.MVs[LIST_0]->MotionVectors,
                                  cur_mb.MVs[LIST_1]->MotionVectors,
                                  pPredBuf,
                                  true);
            } else {
                RLE_Offset = U_DC_RLE;
                pSrcPlane = m_pCurrentFrame->m_pUPlane;
#ifndef H264_RD_OPT
                pReconBuf = m_pReconstructFrame->m_pUPlane+uOffset;
#endif
                if( !intra )
                    MCOneMBChroma(curr_slice,
                                  uMB, pitchPixels,
                                  cur_mb.MVs[LIST_0]->MotionVectors,
                                  cur_mb.MVs[LIST_1]->MotionVectors,
                                  pPredBuf,
                                  false);
            }

            ippiSumsDiff8x8Blocks4x4(pSrcPlane + uOffset,    // source pels
                                     pitchPixels,                 // source pitch
                                     pPredBuf,               // predictor pels
                                     16,
                                     pDCBuf,                 // result buffer
                                     pMassDiffBuf);
            if( m_PicParamSet.chroma_format_idc == 2 ){
                // Process second part of 2x4 block for DC coeffs
                 ippiSumsDiff8x8Blocks4x4(pSrcPlane + uOffset+8*pitchPixels,    // source pels
                                          pitchPixels,                 // source pitch
                                          pPredBuf+8*16,               // predictor pels
                                          16,
                                          pDCBuf+4,                 // result buffer
                                          pMassDiffBuf+64);   //+Offset for second path
            }

            // Code chromaDC
            if( !transform_bypass ){
                switch( m_PicParamSet.chroma_format_idc ){
                    case 1:
                        ippiTransformQuantChromaDC_H264(pDCBuf, pQBuf,uMBQP,&iNumCoeffs,(slice_type == INTRASLICE),1);
                        break;
                    case 2:
                        ippiTransformQuantChroma422DC_H264(pDCBuf, pQBuf,uMBQP,&iNumCoeffs,(slice_type == INTRASLICE),1);
                        break;
                }
            }else{
                Ipp32s i,j;
                Ipp32s num_rows, num_cols;
                Ipp32s bPitch;
                num_cols = ( (m_PicParamSet.chroma_format_idc-1) & 0x2 )? 4 : 2;
                num_rows = ( m_PicParamSet.chroma_format_idc & 0x2 )? 4 : 2;
                bPitch = num_cols*16;

                for(i = 0; i < num_rows; i++) {
                    for(j = 0; j < num_cols; j++) {

⌨️ 快捷键说明

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