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

📄 encodevop.c

📁 adi bf533视频编码程序
💻 C
📖 第 1 页 / 共 5 页
字号:
        xhQuantIntra_MPEG4_16s_C1I(coeffMB+numBlock*64, quant, VOL.intra_quant_inv_mat, &nzCount); \
    else \
        xhQuantIntra_H263_C1I(coeffMB+numBlock*64, quant, &nzCount); \
    if (nzCount > 0) \
        pattern |= 1 << (5 - numBlock)

#else

#define mp4_DCT_Quant_Intra_MPEG4(p, step, numBlock) \
	convert_8u16s(p, coeffMB + numBlock*64, step); \
    fdct_int32(coeffMB+numBlock*64); \
    if (VOL.quant_type) \
        xhQuantIntra_MPEG4_16s_C1I(coeffMB+numBlock*64, quant, VOL.intra_quant_inv_mat, &nzCount); \
    else \
        xhQuantIntra_H263_C1I(coeffMB+numBlock*64, quant, &nzCount); \
    if (nzCount > 0) \
        pattern |= 1 << (5 - numBlock)
#endif


#define mp4_Inv_Quant_DCT_Intra_MPEG4(p, step, numBlock) \
    if ((pattern & (1 << (5 - numBlock))) == 0) { \
        mp4_Set8x8_asm(p, step, (MBDC[numBlock] + 4) >> 3); \
    } else { \
        coeffMB[numBlock*64] = MBDC[numBlock]; \
        if (VOL.quant_type) \
            xhQuantInvIntra_MPEG4_16s_C1I(coeffMB + numBlock*64, quant, VOL.intra_quant_mat); \
        else \
            xhQuantInvIntra_H263_C1I(coeffMB + numBlock*64, quant); \
        idct_int32(coeffMB+numBlock*64); \
        convert_16s8u(coeffMB+numBlock*64, p, step); \
    }

    
static void mp4_CheckPattern(Ipp16s *coeff, int *pattern)
{
    int  i, j, pat = *pattern;
    for (i = 0; i < 6; i ++) {
        for (j = 1; j < 64; j ++) {
            if (coeff[i*64+j] != 0)
                break;
        }
        pat &= ~(1 << (5-i));
        if (j < 64)
            pat |= (1 << (5-i));
    }
    *pattern = pat;
}

/*
inline  int CalcMSE_16x16(Ipp8u *pSrc1, int stepSrc1, Ipp8u *pSrc2, int stepSrc2)
{
    int  e;
	xhSqrDiff16x16_8u32s(pSrc1, stepSrc1, pSrc2, stepSrc2, 0, &e);
    //ippiSqrDiff16x16_8u32s(pSrc1, stepSrc1, pSrc2, stepSrc2, 0, &e);
    return e;
}


int CalcMSE_8x8(Ipp8u *pSrc1, int stepSrc1, Ipp8u *pSrc2, int stepSrc2)
{
    int  i, j, e, t;

    e = 0;
    for (i = 0; i < 8; i ++) {
        for (j = 0; j < 8; j ++) {
            t = (int)pSrc1[j] - pSrc2[j];
            e += t * t;
        }
        pSrc1 += stepSrc1;
        pSrc2 += stepSrc2;
    }
    return e;
}
*/
/*********************************************************************/
int mp4_MC_type(struct IppMotionVector *mv)
{
    return (((mv->dy & 1) << 2) + ((mv->dx & 1) << 3));
}


int mp4_MC_offs( struct IppMotionVector *mv, int step)
{
    return ((mv->dy >> 1) * step + (mv->dx >> 1));
}




#if 1
#define mp4_DCT_Quant_Inter_MPEG4(numBlock) \
    xhDCT8x8Fwd_16s_C1I(coeffMB+numBlock*64,coeff,temp); \
    if (VOL.quant_type) \
        xhQuant_MPEG4_16s_C1I(coeffMB+numBlock*64, quant, VOL.nonintra_quant_inv_mat, &nzCount); \
    else \
        xhQuant_H263_C1I(coeffMB+numBlock*64, quant, &nzCount); \
    if (nzCount >= 0) \
        pattern |= 1 << (5 - numBlock)

#else

#define mp4_DCT_Quant_Inter_MPEG4(numBlock) \
    fdct_int32(coeffMB+numBlock*64); \
    if (VOL.quant_type) \
        xhQuant_MPEG4_16s_C1I(coeffMB+numBlock*64, quant, VOL.nonintra_quant_inv_mat, &nzCount); \
    else \
        xhQuant_H263_C1I(coeffMB+numBlock*64, quant, &nzCount); \
    if (nzCount >= 0) \
        pattern |= 1 << (5 - numBlock)
#endif


#define mp4_Inv_Quant_DCT_Inter_MPEG4(pc, pr, step, numBlock) \
    if (pattern & (1 << (5 - numBlock))) { \
        if (VOL.quant_type) \
            xhQuantInv_MPEG4_16s_C1I(coeffMB + numBlock*64, quant, VOL.nonintra_quant_mat); \
        else \
            xhQuantInv_H263_C1I(coeffMB + numBlock*64, quant); \
        idct_int32(coeffMB+numBlock*64); \
        xhReconBlockHalfpel_MPEG4_8u_MOD(pr, step, coeffMB+numBlock*64, pc, step, VOP.vop_rounding_type); \
    } else \
        xhCopyBlock_8x8_8u(pr, step, pc, step)


static inline void mp4_MV_CheckRange(struct IppMotionVector *mvD, int fMin, int fMax, int fRange)
{
    if (mvD->dx < fMin)
        mvD->dx = (Ipp16s)(mvD->dx + fRange);
    else if (mvD->dx > fMax)
        mvD->dx = (Ipp16s)(mvD->dx - fRange);
    if (mvD->dy < fMin)
        mvD->dy = (Ipp16s)(mvD->dy + fRange);
    else if (mvD->dy > fMax)
        mvD->dy = (Ipp16s)(mvD->dy - fRange);
}


static inline void init_refDC(short *refDC, short value, int num)
{
    int i;
    for (i=num; i>0; i--) {
        *refDC ++ = value;
    }
}


void EncodeIVOP()
{   
	Ipp8u  *pY, *pU, *pV, *p656;
    int     i, j, cbpy, cbpc, quant, pattern, acPredSum0, acPredSum1;
    Ipp16s  _coeffMB[64*6+31], *coeffMB = (Ipp16s*)_PTR_ALIGN32(_coeffMB);
//    Ipp8u   _pDec[64*6+31], *pDec = (Ipp8u*)_PTR_ALIGN32(_pDec);
    Ipp32s  nzCount;
//    struct mp4_MacroBlock *MBcurr=MBinfo ;
	int type;
	int not_coded;
//	short MBYDC[4]={mDefDC};
//	short MBUDC = mDefDC;
//	short MBVDC = mDefDC;
	short MBDC[6];
	short leftUDC;
	short leftVDC;
	short MBAC_A[6][8];
	short MBAC_C[6][8];
	short leftYAC[2][8];
	short leftUAC[8];
	short leftVAC[8];
	
    int j2;
    short tmp_uvdc;

	int iCur_MB = 0;	
    Ipp8u          *pCur_MB;
    
	Ipp8u *pPreY, *pPreU, *pPreV;

    int dcScalerLuma, dcScalerChroma, predDir[6], ac_pred_flag, use_intra_dc_vlc;
    
    init_refDC(_refYDC, mDefDC, REFYDC_NUM);
    init_refDC(_refUDC, mDefDC, REFUVDC_NUM);
    init_refDC(_refVDC, mDefDC, REFUVDC_NUM);
	
    memset(&refYAC[0][0], 0, REFYAC_NUM*8*sizeof(short));
    memset(&refUAC[0][0], 0, REFUVAC_NUM*8*sizeof(short));
    memset(&refVAC[0][0], 0, REFUVAC_NUM*8*sizeof(short));
//    memset(&MBY_AC_A[0][0], 0, 4*8*sizeof(MBY_AC_A[0][0]));
//    memset(&MBY_AC_C[0][0], 0, 4*8*sizeof(MBY_AC_C[0][0]));
//    memset(&MBUV_AC_A[0], 0, 8*sizeof(MBUV_AC_A[0]));
//    memset(&MBUV_AC_C[0], 0, 8*sizeof(MBUV_AC_C[0]));
    
    quant = VOP.vop_quant;
    use_intra_dc_vlc = quant < mDC_VLC_Threshold[VOP.intra_dc_vlc_thr];
        
//qp在编码整个VOP的过程中保持不变,所以可以在这里初始化 dcScalerLuma 和dcScalerChroma;
	dcScalerLuma = mp4_GetDCscaler(quant, 0);
	dcScalerChroma = mp4_GetDCscaler(quant, 4);

	pPreY = mCurrPtrY-16;
	pPreU = mCurrPtrU-8;
	pPreV = mCurrPtrV-8;
	
    for (i = 0; i < mNumMacroBlockPerCol; i ++) {
        pY = mCurrPtrY + i * 16 * mStepLuma;
        pU = mCurrPtrU + i * 8 * mStepChroma;
        pV = mCurrPtrV + i * 8 * mStepChroma;
        p656 = mCurrPtr656 + i * MB_row_step * YUV656_BUF_WIDTH;
        
        MBDC[1]=MBDC[3] = mDefDC;
        leftUDC = mDefDC;
        leftVDC = mDefDC;
        
	    memset(&leftYAC[0][0], 0, 2*8*sizeof(short));
	    memset(&leftUAC[0], 0, 8*sizeof(short));
	    memset(&leftVAC[0], 0, 8*sizeof(short));
        
        for (j = 0; j < mNumMacroBlockPerRow; j ++) {
            j2 = j<<1;
//            MBcurr->quant = quant;
//            MBcurr->type = IPP_VIDEO_INTRA;
//            MBcurr->not_coded = 0;
            type = IPP_VIDEO_INTRA;
            not_coded = 0;
            
//            MBcurr->mv[0].dx = MBcurr->mv[0].dy = MBcurr->mv[1].dx = MBcurr->mv[1].dy = MBcurr->mv[2].dx = MBcurr->mv[2].dy = MBcurr->mv[3].dx = MBcurr->mv[3].dy = 0;
//            MBcurr->mv.dx = MBcurr->mv.dy = 0;
            
//            dcScalerLuma = mp4_GetDCscaler(quant, 0);
//            dcScalerChroma = mp4_GetDCscaler(quant, 4);
            pattern = 0;
            
//                get_CurMB(Current_MB,pY,pU,pV,mStepLuma,0);
//                pCur_MB=Current_MB;
	        pCur_MB = MB_buffer[iCur_MB];
    		iCur_MB ^= 0x01;

			while(!dma_done);
//				while(!((*pMDMA_D0_IRQ_STATUS)&0x01));
//				*pMDMA_D0_IRQ_STATUS = 0x01;
//	        get_MB((j==mNumMacroBlockPerRow-1) ? 
//	        			(mCurrPtr656+(i+1)*MB_row_step*YUV656_BUF_WIDTH):
//	        			(p656+MB_byte_step),
//	        			MB_buffer[iCur_MB]);
			restore_MB_get_MB_refwin(
				MB_buffer[iCur_MB], pPreY, pPreU, pPreV,
				(j==mNumMacroBlockPerRow-1) ? 
    			(mCurrPtr656+(i+1)*MB_row_step*YUV656_BUF_WIDTH):
    			(p656+MB_byte_step),
    			MB_buffer[iCur_MB],
    			NULL, NULL, NULL, 
    			NULL, NULL, NULL,
    			0x02
    			);
    			
			pPreY = pY;
			pPreU = pU;
			pPreV = pV;
			
			MB_preprocess(pCur_MB, 24);
			
//                mp4_DCT_Quant_Intra_MPEG4(pY, mStepLuma, 0);
//                mp4_DCT_Quant_Intra_MPEG4(pY+8, mStepLuma, 1);
//                mp4_DCT_Quant_Intra_MPEG4(pY+8*mStepLuma, mStepLuma, 2);
//                mp4_DCT_Quant_Intra_MPEG4(pY+8*mStepLuma+8, mStepLuma, 3);
//                mp4_DCT_Quant_Intra_MPEG4(pU, mStepChroma, 4);
//                mp4_DCT_Quant_Intra_MPEG4(pV, mStepChroma, 5);
            mp4_DCT_Quant_Intra_MPEG4(pCur_MB, 16, 0);
            mp4_DCT_Quant_Intra_MPEG4(pCur_MB+8, 16, 1);
            mp4_DCT_Quant_Intra_MPEG4(pCur_MB+8*16, 16, 2);
            mp4_DCT_Quant_Intra_MPEG4(pCur_MB+8*16+8, 16, 3);
            mp4_DCT_Quant_Intra_MPEG4(pCur_MB+24*18, 8, 4);
            mp4_DCT_Quant_Intra_MPEG4(pCur_MB+24*18+64, 8, 5);
                
            ac_pred_flag = pattern ? 1 : 0;
            acPredSum0 = acPredSum1 = 0;
            
//			mp4_PredictIntraDCAC(MBcurr, coeffMB+0*64, dcScalerLuma,   0, &predDir[0], ac_pred_flag, &acPredSum0, &acPredSum1);
//			mp4_PredictIntraDCAC(MBcurr, coeffMB+1*64, dcScalerLuma,   1, &predDir[1], ac_pred_flag, &acPredSum0, &acPredSum1);
//			mp4_PredictIntraDCAC(MBcurr, coeffMB+2*64, dcScalerLuma,   2, &predDir[2], ac_pred_flag, &acPredSum0, &acPredSum1);
//			mp4_PredictIntraDCAC(MBcurr, coeffMB+3*64, dcScalerLuma,   3, &predDir[3], ac_pred_flag, &acPredSum0, &acPredSum1);
//			mp4_PredictIntraDCAC(MBcurr, coeffMB+4*64, dcScalerChroma, 4, &predDir[4], ac_pred_flag, &acPredSum0, &acPredSum1);
//			mp4_PredictIntraDCAC(MBcurr, coeffMB+5*64, dcScalerChroma, 5, &predDir[5], ac_pred_flag, &acPredSum0, &acPredSum1);
//			mp4_PredictIntraDCAC(MBcurr, MBDC[1], refYDC[j2-1], refYDC[j2], MBDC, coeffMB+0*64, dcScalerLuma,   0, &predDir[0], ac_pred_flag, &acPredSum0, &acPredSum1);
//			refYDC[j2-1] = MBDC[3];
//			mp4_PredictIntraDCAC(MBcurr, MBDC[3], MBDC[1], 	  MBDC[0], 		MBDC, coeffMB+2*64, dcScalerLuma,   2, &predDir[2], ac_pred_flag, &acPredSum0, &acPredSum1);
//			mp4_PredictIntraDCAC(MBcurr, MBDC[0], refYDC[j2], refYDC[j2+1], MBDC, coeffMB+1*64, dcScalerLuma,   1, &predDir[1], ac_pred_flag, &acPredSum0, &acPredSum1);
//			refYDC[j2] = MBDC[2];
//			mp4_PredictIntraDCAC(MBcurr, MBDC[2], MBDC[0], 	  MBDC[1],		MBDC, coeffMB+3*64, dcScalerLuma,   3, &predDir[3], ac_pred_flag, &acPredSum0, &acPredSum1);
//			tmp_uvdc = MBDC[4];
//			mp4_PredictIntraDCAC(MBcurr, MBDC[4], refUDC[j-1], refUDC[j], 	MBDC, coeffMB+4*64, dcScalerChroma, 4, &predDir[4], ac_pred_flag, &acPredSum0, &acPredSum1);
//			refUDC[j-1] = tmp_uvdc;
//			tmp_uvdc = MBDC[5];
//			mp4_PredictIntraDCAC(MBcurr, MBDC[5], refVDC[j-1], refVDC[j],	MBDC, coeffMB+5*64, dcScalerChroma, 5, &predDir[5], ac_pred_flag, &acPredSum0, &acPredSum1);
//			refVDC[j-1] = tmp_uvdc;
			
			mp4_PredictIntraDCAC1(MBDC[1],		refYDC[j2-1],	refYDC[j2], 	&MBDC[0],
									leftYAC[0],	refYAC[j2], 	MBAC_A[0], 		MBAC_C[0],
									coeffMB+0*64, dcScalerLuma, &predDir[0], ac_pred_flag, &acPredSum0, &acPredSum1);
			refYDC[j2-1] = MBDC[3];
			
			mp4_PredictIntraDCAC1(MBDC[3], 		MBDC[1],		MBDC[0], 		&MBDC[2],
									leftYAC[1],	MBAC_C[0],		MBAC_A[2], 		MBAC_C[2],
									coeffMB+2*64, 	dcScalerLuma, &predDir[2], ac_pred_flag, &acPredSum0, &acPredSum1);
//			memcpy(refYAC[j2], MBY_AC_C[2], 8*sizeof(short));
			

⌨️ 快捷键说明

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