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

📄 motion_est_core_2_optimized.c

📁 基于Linux的ffmepg decoder
💻 C
📖 第 1 页 / 共 5 页
字号:
int32_t
MotionEstimation_block0_4MV(MACROBLOCK *const pMB,Encoder *pEnc)
{
    FTMCP100_CODEC *pCodec=(FTMCP100_CODEC *)pEnc->pCodec;
    FRAMEINFO * const current1=pEnc->current1;
    FRAMEINFO * const reference=pEnc->reference;

	MACROBLOCK *prevMB = &reference->mbs[0];
	int32_t MOTION_ACTIVITY;
	int32_t  X, d_type;
	uint32_t lam_16;
	volatile MDMA *pmdma = MDMA1;
	DECLARE_MP4_PTR
	
	unsigned int *pDMA1,*pDMA2;
	unsigned int XDIM=pEnc->mEncParam.u32FrameWidth;
	pDMA1=pCodec->DMA_COMMAND_local;
	pDMA2=pCodec->DMA_COMMAND_local+DMA_COMMAND_QUEUE_STRIDE;

	// to set the VOP size (including VOP width and VOP height)
    // the VOPSIZE register is at address 0x10080.    
    SET_VOPSIZE((pEnc->mEncParam.u32FrameWidth)<<16 | (pEnc->mEncParam.u32FrameHeight))
	
	// to set the prediction MV buffer start address
    // the PMVBUF register is at address 0x10084.
	SET_PMVBUF(PMV_BUF)
	
	// to set Horizontal Offset Register 
    // the VOPSIZE register is at address 0x10018.
	SET_HOFFSET(0)

    //----------------------------------------------------------------------------
	// start to set the ME commands	for 1MV motion estimation	
	// to set horizontal prediction vector,BSIZE=1 (for 1MV),BK_BUM=0 (this bit should be 0 when BSIZE==1)
	pCodec->ME_command_queue0[16] = (0<<29) | (1<<25) | (0<<23);
	// to set vertical prediction vector,BSIZE=1 (for 1MV),BK_BUM=0 (this bit should be 0 when BSIZE==1)
	pCodec->ME_command_queue0[17] = (1<<29) | (1<<25) | (0<<23);
	
	// to set SAD command ,last=0 (not last SAD command), MPMV=1 (use median predictor) --- we select the median predictor as a candidate
	// SRC=0 (not meaningful since MPMV=1) ,MVX and MVY (not meaningful since MPMV=1) , RADD=Raddr (reference block start address)	
	pCodec->ME_command_queue0[18] = (2<<29) | (1<<27) | pCodec->Raddr;				//	median result
	
	// to set SAD command ,last=0 (not last SAD command), MPMV=0 (not use median predictor)
	// SRC=0 (specify the source for motion vector MVX and MVY and RADD , use these fields defined in this command)
	// MVX=0 and MVY=0 (used as horizontal motion vector and vertical motion vector since SRC==0)
	// because it is the first macroblock in whole frame, so the left,top and top-right neighbors' motion vector are zero
	// RADD=Raddr (start address of the first row of reference block in words since SRC==0)
	pCodec->ME_command_queue0[19] = (2<<29) | pCodec->Raddr;
	pCodec->ME_command_queue0[20] = (2<<29) | pCodec->Raddr;
	pCodec->ME_command_queue0[21] = (2<<29) | pCodec->Raddr;
	

	// to set SAD command ,last=1 (it's last SAD command), MPMV=0 (not use median predictor)
	// SRC=0 (specify the source for motion vector MVX and MVY and RADD , use these fields defined in this command)
	// MVX=((prevMB->mv16x_3 & 0x7f) << 19) and MVY=((prevMB->mv16y_3 & 0x7f) (used as horizontal motion vector and vertical motion vector since SRC==0)
	// RADD=Raddr + (prevMB->mv16y_3 < 0 ? 0 : (prevMB->mv16y_3 >> 1)*16) (start address of the first row of reference block in words since SRC==0)
	pCodec->ME_command_queue0[22] = (1<<28) | (2<<29) | ((prevMB->mv16x_3 & 0x7f) << 19) | ((prevMB->mv16y_3 & 0x7f) << 12) 
							| pCodec->Raddr + (prevMB->mv16y_3 < 0 ? 0 : (prevMB->mv16y_3 >> 1)*16);
	

	// to set diamond command , dsize=0 (choose small diamond) , 
	// maxloop= (Diamond_search_limit << 16) , MinSADth= ThEES (Threshold for minimim SAD for diamond stop)
	// according to the C model program, since it's the very first block , d_type will be 0 (small diamond)
	// so we search the diamond from small diamond
	pCodec->ME_command_queue0[23] = (3<<29) | (Diamond_search_limit << 16) | ThEES;		// dsize is always small
	

	// to set Half-Pel-Refine command , 4MV=1 (4MV mode is used), 
	// SAD8th = 0 (1MV/4MV threshold) , MinSADth= ThEES1 (Threshold for minimim SAD for skipping Half-Pel-Refine search)
	pCodec->ME_command_queue0[24] = ((unsigned int)4<<29) | (1<<28) | ThEES1; // add unsigned int to avoid warning... half pixel refine
	
    //----------------------------------------------------------------------------

	// start to set the ME commands	for 4MV motion estimation for block 0

	// to set horizontal prediction vector,BSIZE=0 (for 4MV),BK_BUM=0 (block number 0)
	pCodec->ME_command_queue0[25] = (0<<29) | (0<<25) | (0<<23);

	// to set vertical prediction vector,BSIZE=0 (for 4MV),BK_BUM=0 (block number 0)
	pCodec->ME_command_queue0[26] = (1<<29) | (0<<25) | (0<<23);
	

	// to set SAD command ,last=0 (not last SAD command), MPMV=1 (use median predictor) --- we select the median predictor as a candidate
	// SRC=0 (not meaningful since MPMV=1) ,MVX and MVY (not meaningful since MPMV=1) , RADD=Raddr (reference block start address)
	pCodec->ME_command_queue0[27] = (2<<29) | (1<<27) | pCodec->Raddr;							//	median result
	

	// to set SAD command ,last=0 (not last SAD command), MPMV=0 (not use median predictor)
	// SRC=0 (specify the source for motion vector MVX and MVY and RADD , use these fields defined in this command)
	// MVX=0 and MVY=0 (used as horizontal motion vector and vertical motion vector since SRC==0)
	// because it is the first macroblock in whole frame, so the left,top and top-right neighbors' motion vector are zero
	// RADD=Raddr (start address of the first row of reference block in words since SRC==0)
	pCodec->ME_command_queue0[28] = (2<<29) | pCodec->Raddr;
	pCodec->ME_command_queue0[29] = (2<<29) | pCodec->Raddr;
	pCodec->ME_command_queue0[30] = (2<<29) | pCodec->Raddr;
	

	// to set SAD command ,last=1 (it's last SAD command), MPMV=0 (not use median predictor)
	// SRC=0 (specify the source for motion vector MVX and MVY and RADD , use these fields defined in this command)
	// MVX=(prevMB->mv16x_0 & 0x7f) and MVY=(prevMB->mv16y_0 & 0x7f) (used as horizontal motion vector and vertical motion vector since SRC==0)
	// RADD=Raddr + (prevMB->mv16y_0 < 0 ? 0 : (prevMB->mv16y_0 >> 1)*16) (start address of the first row of reference block in words since SRC==0)
	pCodec->ME_command_queue0[31] = (1<<28) | (2<<29) | ((prevMB->mv16x_0 & 0x7f) << 19) | ((prevMB->mv16y_0 & 0x7f) << 12) 
							| pCodec->Raddr + (prevMB->mv16y_0 < 0 ? 0 : (prevMB->mv16y_0 >> 1)*16);
							

	// to set diamond command , dsize=0 (choose small diamond) , 
	// maxloop= (Diamond_search_limit << 16) , MinSADth= ThEES_4 (Threshold for minimim SAD for diamond stop)
	// according to the C model program, we always search the diamond from small diamond in 1MV macroblock search
	pCodec->ME_command_queue0[32] = ((unsigned int)3<<29) | (Diamond_search_limit << 16) | ThEES_4; // add unsigned int to avoid warning ... dsize is always small
	

	// to set Half-Pel-Refine command , 4MV=1 (4MV mode is used), 
	// SAD8th = 0 (1MV/4MV threshold) , MinSADth= ThEES1 (Threshold for minimim SAD for skipping Half-Pel-Refine search)
	pCodec->ME_command_queue0[33] = ((unsigned int)4<<29) | (1<<28) | ThEES1;	// to add unsigned int to avoid warning ... half pixel refine
    //-------------------------------------

	// to set horizontal prediction vector,BSIZE=0 (for 4MV),BK_BUM=1 (block number 1)
	pCodec->ME_command_queue0[34] = (0<<29) | (0<<25) | (1<<23);

	// to set vertical prediction vector,BSIZE=0 (for 4MV),BK_BUM=1 (block number 1)
	pCodec->ME_command_queue0[35] = (1<<29) | (0<<25) | (1<<23);
	

	// to set SAD command (median predictor) ,last=0 (not last SAD command), MPMV=1 (use median predictor) --- we select the median predictor as a candidate
	// SRC=0 (not meaningful since MPMV=1) ,MVX and MVY (not meaningful since MPMV=1)
	// RADD=Raddr (reference block start address)
	pCodec->ME_command_queue0[36] = (2<<29) | (1<<27) | pCodec->Raddr;							//	median result

	// to set SAD command (top neighbor),last=0 (not last SAD command), MPMV=0 (not use median predictor)
	// SRC=1 (the source is from MV buffer)
	// MVX=0 (get motion vector and reference start address from index 0 of MV buffer)
	// MVY and RADD is not used since SRC==1 
	pCodec->ME_command_queue0[37] = (2<<29) | (1<<26) | (0<<19);
	

	// to set SAD command (top and top-left neighbor),last=0 (not last SAD command), MPMV=0 (not use median predictor)
	// SRC=0 (specify the source for motion vector MVX and MVY and RADD , use these fields defined in this command)
	// MVX=0 and MVY=0 (used as horizontal motion vector and vertical motion vector since SRC==0)
	// because it is the first macroblock in whole frame, so the left,top and top-right neighbors' motion vector are zero
	// RADD=Raddr (start address of the first row of reference block in words since SRC==0)
	pCodec->ME_command_queue0[38] = (2<<29) | pCodec->Raddr;
	pCodec->ME_command_queue0[39] = (2<<29) | pCodec->Raddr;

	// to set SAD command (previous MB) ,last=1 (it's last SAD command), MPMV=0 (not use median predictor)
	// SRC=0 (specify the source for motion vector MVX and MVY and RADD , use these fields defined in this command)
	// MVX=(prevMB->mv16x_1 & 0x7f) and MVY=(prevMB->mv16y_1 & 0x7f) (used as horizontal motion vector and vertical motion vector since SRC==0)
	// RADD=Raddr + (prevMB->mv16y_1 < 0 ? 0 : (prevMB->mv16y_1 >> 1)*16) (start address of the first row of reference block in words since SRC==0)
	pCodec->ME_command_queue0[40] = (1<<28) | (2<<29) | ((prevMB->mv16x_1 & 0x7f) << 19) | ((prevMB->mv16y_1 & 0x7f) << 12) 
							| pCodec->Raddr + (prevMB->mv16y_1 < 0 ? 0 : (prevMB->mv16y_1 >> 1)*16);
	

	// to set diamond command , dsize=0 (choose small diamond) , 
	// maxloop= (Diamond_search_limit << 16) , MinSADth= ThEES_4 (Threshold for minimim SAD for diamond stop)
	pCodec->ME_command_queue0[41] = (3<<29) | (Diamond_search_limit << 16) | ThEES_4;		// dsize is always small

	// to set Half-Pel-Refine command , 4MV=1 (4MV mode is used), 
	// SAD8th = 0 (1MV/4MV threshold) , MinSADth= ThEES1 (Threshold for minimim SAD for skipping Half-Pel-Refine search)
	pCodec->ME_command_queue0[42] = ((unsigned int)4<<29) | (1<<28) | ThEES1;	// to add unsigned int to avoid warning ... half pixel refine
    //-------------------------------------

	// to set horizontal prediction vector,BSIZE=0 (for 4MV),BK_BUM=2 (block number 2)
	pCodec->ME_command_queue0[43] = (0<<29) | (0<<25) | (2<<23);

	// to set vertical prediction vector,BSIZE=0 (for 4MV),BK_BUM=2 (block number 2)
	pCodec->ME_command_queue0[44] = (1<<29) | (0<<25) | (2<<23);
	

	// to set SAD command (median predictor) ,last=0 (not last SAD command), MPMV=1 (use median predictor) --- we select the median predictor as a candidate
	// SRC=0 (not meaningful since MPMV=1) ,MVX and MVY (not meaningful since MPMV=1)
	// RADD=Raddr23 (reference block start address)
	pCodec->ME_command_queue0[45] = (2<<29) | (1<<27) | pCodec->Raddr23;							//	median result
	

	// to set SAD command (left neighbor),last=0 (not last SAD command), MPMV=0 (not use median predictor)
	// SRC=0 (specify the source for motion vector MVX and MVY and RADD , use these fields defined in this command)
	// MVX=0 and MVY=0 (used as horizontal motion vector and vertical motion vector since SRC==0)
	// RADD=Raddr23 (start address of the first row of reference block in words since SRC==0)
	pCodec->ME_command_queue0[46] = (2<<29) | pCodec->Raddr23;
	

	// to set SAD command (top neighbor),last=0 (not last SAD command), MPMV=0 (not use median predictor)
	// SRC=1 (the source is from MV buffer)
	// MVX=0 (get motion vector and reference start address from index 0 of MV buffer)
	// MVY and RADD is not used since SRC==1
	pCodec->ME_command_queue0[47] = (2<<29) | (1<<26) | (0<<19);

	// to set SAD command (top-right neighbor),last=0 (not last SAD command), MPMV=0 (not use median predictor)
	// SRC=1 (the source is from MV buffer)
	// MVX=0 (get motion vector and reference start address from index 1 of MV buffer)
	// MVY and RADD is not used since SRC==1
	pCodec->ME_command_queue0[48] = (2<<29) | (1<<26) | (1<<19);

	// to set SAD command (previous MB) ,last=1 (it's last SAD command), MPMV=0 (not use median predictor)
	// SRC=0 (specify the source for motion vector MVX and MVY and RADD , use these fields defined in this command)
	// MVX=(prevMB->mv16x_2 & 0x7f) and MVY=(prevMB->mv16y_2 & 0x7f) (used as horizontal motion vector and vertical motion vector since SRC==0)
	// Raddr23 + (prevMB->mv16y_2 < -16 ? ((-16>>1) * 16) : (prevMB->mv16y_2 >> 1)*16) (start address of the first row of reference block in words since SRC==0)
	pCodec->ME_command_queue0[49] = (1<<28) | (2<<29) | ((prevMB->mv16x_2 & 0x7f) << 19) | ((prevMB->mv16y_2 & 0x7f) << 12) 
							| pCodec->Raddr23 + (prevMB->mv16y_2 < -16 ? ((-16>>1) * 16) : (prevMB->mv16y_2 >> 1)*16);
							

	// to set diamond command , dsize=0 (choose small diamond) , 
	// maxloop= (Diamond_search_limit << 16) , MinSADth= ThEES_4 (Threshold for minimim SAD for diamond stop)
	pCodec->ME_command_queue0[50] = (3<<29) | (Diamond_search_limit << 16) | ThEES_4;		// dsize is always small

	// to set Half-Pel-Refine command , 4MV=1 (4MV mode is used), 
	// SAD8th = 0 (1MV/4MV threshold) , MinSADth= ThEES1 (Threshold for minimim SAD for skipping Half-Pel-Refine search)
	pCodec->ME_command_queue0[51] = ((unsigned int)4<<29) | (1<<28) | ThEES1; // to add unsigned int to avoid warning ... half pixel refine
    //-------------------------------------

	// to set horizontal prediction vector,BSIZE=0 (for 4MV),BK_BUM=3 (block number 3)
	pCodec->ME_command_queue0[52] = (0<<29) | (0<<25) | (3<<23);

	// to set vertical prediction vector,BSIZE=0 (for 4MV),BK_BUM=3 (block number 3)
	pCodec->ME_command_queue0[53] = (1<<29) | (0<<25) | (3<<23);

	// to set SAD command (median predictor) ,last=0 (not last SAD command), MPMV=1 (use median predictor) --- we select the median predictor as a candidate
	// SRC=0 (not meaningful since MPMV=1) ,MVX and MVY (not meaningful since MPMV=1)
	// RADD=Raddr23 (reference block start address)
	pCodec->ME_command_queue0[54] = (2<<29) | (1<<27) | pCodec->Raddr23;							//	median result
	

	// to set SAD command (left neighbor),last=0 (not last SAD command), MPMV=0 (not use median predictor)
	// SRC=1 (the source is from MV buffer)
	// MVX=2 (get motion vector and reference start address from index 2 of MV buffer)
	// MVY and RADD is not used since SRC==1
	pCodec->ME_command_queue0[55] = (2<<29) | (1<<26) | (2<<19);

	// to set SAD command (top neighbor),last=0 (not last SAD command), MPMV=0 (not use median predictor)
	// SRC=1 (the source is from MV buffer)
	// MVX=0 (get motion vector and reference start address from index 0 of MV buffer)
	// MVY and RADD is not used since SRC==1
	pCodec->ME_command_queue0[56] = (2<<29) | (1<<26) | (0<<19);

	// to set SAD command (top-right neighbor),last=0 (not last SAD command), MPMV=0 (not use median predictor)
	// SRC=1 (the source is from MV buffer)
	// MVX=1 (get motion vector and reference start address from index 1 of MV buffer)
	// MVY and RADD is not used since SRC==1
	pCodec->ME_command_queue0[57] = (2<<29) | (1<<26) | (1<<19);

	// to set SAD command (previous MB) ,last=1 (it's last SAD command), MPMV=0 (not use median predictor)
	// SRC=0 (specify the source for motion vector MVX and MVY and RADD , use these fields defined in this command)
	// MVX=(prevMB->mv16x_3 & 0x7f) and MVY=(prevMB->mv16y_3 & 0x7f) (used as horizontal motion vector and vertical motion vector since SRC==0)
	// Raddr23 + (prevMB->mv16y_3 < -16 ? ((-16>>1) * 16) : (prevMB->mv16y_3 >> 1)*16) (start address of the first row of reference block in words since SRC==0)
	pCodec->ME_command_queue0[58] = (1<<28) | (2<<29) | ((prevMB->mv16x_3 & 0x7f) << 19) | ((prevMB->mv16y_3 & 0x7f) << 12) 
							| pCodec->Raddr23 + (prevMB->mv16y_3 < -16 ? ((-16>>1) * 16) : (prevMB->mv16y_3 >> 1)*16);

	// to set diamond command , dsize=0 (choose small diamond) , 
	// maxloop= (Diamond_search_limit << 16) , MinSADth= ThEES_4 (Threshold for minimim SAD for diamond stop)
	pCodec->ME_command_queue0[59] = (3<<29) | (Diamond_search_limit << 16) | ThEES_4;		// dsize is always small

	// to set Half-Pel-Refine command , 4MV=1 (4MV mode is used), 
	// SAD8th = 0 (1MV/4MV threshold) , MinSADth= ThEES1 (Threshold for minimim SAD for skipping Half-Pel-Refine search)
	pCodec->ME_command_queue0[60] = ((unsigned int)4<<29) | (1<<28) | ThEES1;	// to add unsigned int to avoid warning ... half pixel refine
	//----------------------------------------------------------------------------

	// to set Intra/Inter Mode Decision command , MODEN=1 (enable mode decision command), 
	// intraSADth= MV16_INTER_BIAS (threshold for intra/inter mode)
	pCodec->ME_command_queue0[61] = ((unsigned int)5<<29) | (1<<28) | MV16_INTER_BIAS; // to add unsigned int to avoid warning ... P-I switch
	

	// to set pixel interpolation command , last=0 (not last pixel interpolation command), 
	// Chroma= 0 (select Y component)
	// RADD =0 (not used since Chroma==0)
	pCodec->ME_command_queue0[62] = ((unsigned int)6<<29); // add unsigned int to avoid warning ... Y interpolation

	// to set pixel interpolation command , last=0 (not last pixel interpolation command), 
	// Chroma= 1 (select chrominance (Cb & Cr) component)
	// RADD =(((uint32_t) (REF_U + 32*8)) >> 2) (reference block start address)
	pCodec->ME_command_queue0[63] = ((unsigned int)6<<29) | (((uint32_t) (REF_U + 32*8)) >> 2) | (1<<27); // add unsigned int to avoid warning

⌨️ 快捷键说明

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