You are on page 1of 10

XVID

xvidcore-0.9.2

static int enc_init(int use_assembler)

XVID_INIT_PARAM xinit;
XVID_ENC_PARAM xparam;
1 use_assembler xinit.cpu_flags
2xvid_init(NULL, 0, &xinit, NULL)
a.xinit cpu_flagsapi_versioncore_build
b.idct_int32_init()
static short *iclpstatic short iclip[1024]
c.init_VLC_tables()

static REVERSE_EVENT DCT3D[2][4096];


if BIGLUT
static VLC coeff_VLC[2][2][4096][64];
static VLC *intra_table, *inter_table;
else
static VLC coeff_VLC[2][2][64][64];

static uint8_t const max_level[2][2][64];


static uint8_t const max_run[2][2][64];
static short const dc_threshold[64];
d.colorspace_init()


int32_t RGB_Y_tab[256]int32_t B_U_tab[256]int32_t G_U_tab[256]int32_t
G_V_tab[256] int32_t R_V_tab[256]
e. CPU
3xparam
4xvid_encore(NULL, XVID_ENC_CREATE, &xparam, NULL)
encoder_create((XVID_ENC_PARA *) pParam);
a.pParam
b. Encoder * pEnc
c. pEnc
pEnc->current pEnc->reference MACROBLOCK *mbs
pEnc->current->image, pEnc->reference->image, pEnc->vInterHpEnc->vInterV pEnc->vInterHV
yuv
d.pParam->handle = (void *)pEnc
e.RateControlInit()
5static void *enc_handle = xparam.handle
XVID

xvidcore-0.9.2

xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats)


encoder_encode(enc_handle,xframe, xstats)

1)
SWAP(enc_handle ->current, enc_handle ->reference) enc_handle
->current xframe->image enc_handle ->current image yv12


2) BitstreamInit(&bs, xframe ->bitstream, 0);
3) xframe ->quant enc_handle->current->quant; enc_handle->current->global_flags
XVID_LUMIMASKING adaptive_quantization() enc_handle->current->quant
4)
5)FrameCodeI() FrameCodeP()
6)BitstreamPadAlways(&bs);
7) xstats
8) xframe ->quant=0 RateControlUpdate()
9)inc_frame_num(enc_handle)
XVID

xvidcore-0.9.2

static int FrameCodeI(Encoder * pEnc,Bitstream * bs,uint32_t * pBits)

int16_t dct_codes[6*64]
int16_t qcoeff [6*64]

1) I_VOP
2) VOL VOP
BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
3)
a. MACROBLOCK *pMB
b. pMB CodeIntraMB(pEnc, pMB)

c.MBTransQuantIntra(&pEnc->mbParam, pEnc->current, pMB, x, y,dct_codes, qcoeff);


dct_codesqcoeff DCT+++IDCT
pEnc->current->imagepMB dct_codes

d.MBPrediction(pEnc->current, x, y, pEnc->mbParam.mb_width, qcoeff);


pMB->cbp AC

e. MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat)


bs VLC
4) XVID_HINTEDME_GET HintedMEGet(pEnc, 1)
5)return 1 I
XVID

xvidcore-0.9.2

static int FrameCodeP(Encoder *pEnc,Bitstream *bs,uint32_t *pBits,bool force_inter,bool


vol_header)

int16_t dct_codes[6*64]
int16_t qcoeff [6*64]

1),
image_setedges(pRef, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
pEnc->mbParam.width, pEnc->mbParam.height);
IMAGE *pRef = &pEnc->reference->image
2) I
3)

image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV,&pEnc->vInterHV,


pEnc->mbParam.edged_width,pEnc->mbParam.edged_height,
pEnc->current->rounding_type);
4)
int bIntra = MotionEstimation(&pEnc->mbParam, pEnc->current,,pEnc->reference,&pEnc->vInterH,
&pEnc->vInterV, &pEnc->vInterHV,iLimit);
5) bIntra 1 I
6) vol_header VOL VOP
BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
7)
MACROBLOCK *pMB pMB->mode
a.:

MBMotionCompensation(pMB, x, y, &pEnc->reference->image,&pEnc->vInterH,&pEnc->vInterV,
&pEnc->vInterHV, &pEnc->current->image,
dct_codes, pEnc->mbParam.width, pEnc->mbParam.height,pEnc->mbParam.edged_width,
pEnc->current->rounding_type);
DCT qcoeff
MBTransQuantInter(&pEnc->mbParam, pEnc->current, pMB, x, y, dct_codes, qcoeff);
b.:
CodeIntraMB(pEnc, pMB);
MBTransQuantIntra(&pEnc->mbParam, pEnc->current, pMB, x, y,dct_codes, qcoeff);
MBPrediction(pEnc->current, x, y, pEnc->mbParam.mb_width, qcoeff);
c.MBSkip() MBCoding()

8) XVID_HINTEDME_GET HintedMEGet(pEnc, 0)
9)return 0 P
xvidcore-0.9.2

bool MotionEstimation(MBParam * const pParam,FRAMEINFO * const current,


FRAMEINFO * const reference,const IMAGE * const pRefH,
const IMAGE * const pRefV,const IMAGE * const pRefHV,
const uint32_t iLimit)

1 MACROBLOCK * pMB
2
VECTOR predMV=
get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0);
3 16*16 SAD
16*16 pMB->pmvs[0]
pMB->sad16 =SEARCH16(pRef->y, pRefH->y, pRefV->y, pRefHV->y,
pCurrent, x, y,predMV.x, predMV.y, predMV.x, predMV.y,
current->motion_flags,current->quant,current->fcode,
pParam, pMBs, prevMBs, &pMB->mv16,&pMB->pmvs[0]);
4 pMB->sad16 > MV16_INTER_BIASMV16_INTER_BIAS=512
a. 16*16 SUM(abs(i-Mean))
deviation =dev16(pCurrent->y + x * 16 + y * 16 * pParam->edged_width,pParam->edged_width);
b. deviation < (pMB->sad16 - MV16_INTER_BIAS) 0
MODE_INTRA iIntra iIntra>=iLimit 1 I

5 XVID_INTER4V 4

a. 4 8*8 sad8
sad8 += SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y,
pCurrent,2 * x, 2 * y, pMB->mv16.x, pMB->mv16.y,
predMV.x, predMV.y, current->motion_flags,current->quant,
current->fcode, pParam,pMBs, prevMBs, &pMB->mvs[0],&pMB->pmvs[0]);
b.if (sad8 < pMB->sad16) MODE_INTER4V pMB->sad8[i]
4
6 MODE_INTER4
xvidcore-0.9.2

void MBMotionCompensation(MACROBLOCK * const mb,const uint32_t i,const uint32_t j,


const IMAGE * const ref,const IMAGE * const refh,const IMAGE * const refv,
const IMAGE * const refhv,IMAGE * const cur,int16_t * dct_codes,
const uint32_t width,const uint32_t height,
const uint32_t edged_width,const uint32_t rounding)

1if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)


a. dct_codes
compensate8x8_halfpel(...)
b.

dx = (dx&3)?(dx>>1)|1:dx/2;
dy = (dy&3)?(dy>>1)|1:dy/2;
c.( u )
interpolate8x8_switch(refv->u,ref->u,8*i,8*j,dx,dy,edged_width/2, rounding);
refv->u

d.
transfer_8to16sub(&dct_codes[4 * 64],cur->u+8*j*edged_width/2+8*i,
refv->u+8*j*edged_width/2+8*i,edged_width/2);
dct_codes
2else mb->mode == MODE_INTER4V
a.4 dct_codes
compensate8x8_halfpel(...);
b. 4
sum = mb->mvs[0].x+mb->mvs[1].x+mb->mvs[2].x+mb->mvs[3].x;
dx = (sum?SIGN(sum)*(roundtab[ABS(sum)%16]+(ABS(sum)/16)*2):0);
sum = mb->mvs[0].y+mb->mvs[1].y+mb->mvs[2].y+mb->mvs[3].y;
dy = (sum?SIGN(sum)*(roundtab[ABS(sum)%16]+(ABS(sum)/16)*2):0);
c. dct_codes
interpolate8x8_switch(refv->u,ref->u,8*i,8*j,dx,dy,edged_width/2,rounding);
transfer_8to16sub(&dct_codes[4*64],cur->u+8*j*edged_width/2+8*i,
refv->u+8*j*edged_width/2+8*i,edged_width/2);
XVID

xvidcore-0.9.2

int32_t PMVfastSearch16(const uint8_t * const pRef,


const uint8_t * const pRefH,
const uint8_t * const pRefV,
const uint8_t * const pRefHV,
const IMAGE * const pCur,
const int32_t x,const int32_t y,

const int32_t start_x,const int32_t start_y,


const int32_t center_x, const int32_t center_y,
const uint32_t MotionFlags,
const uint32_t iQuant,
const uint32_t iFcode,
const MBParam * const pParam,
const MACROBLOCK * const pMBs,
const MACROBLOCK * const prevMBs,
VECTOR * const currMV,
VECTOR * const currPMV)

VEVTOR pmv[4]; //
int32_t psad[4]; // SAD
currMV Center
Currpmv->x

currMV->x - Center->x;

Currpmv->x

currMV-> x- Center->x;

1
a. iFcode min_dx,max_dx,min_dy,max_dy
get_range(&min_dx, &max_dx, &min_dy, &max_dy, x, y,
16, iWidth, iHeight,iFcode);
b. MotionFlags & PMV_HALFPEL16 0
2 pmv psad
bPredEq = get_pmvdata2(pMBs, iWcount, 0, x, y, 0, pmv, psad)
1 0

3 SAD16
iMinSAD =sad16(cur,get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 16,
currMV,iEdgedWidth),iEdgedWidth, MV_MAX_ERROR)
a.get_ref_mv() currMV
b.sad16() SAD
c.
iMinSAD += calc_delta_16(currMV->x - center_x, currMV->y - center_y,(uint8_t) iFcode, iQuant)
d. SAD
SAD < 2* iQuant
MotionFlags
4 iDiamondSize
5 0 5 SAD
iMinSAD currMV
6 SAD
7
a. MotionFlags iMinSAD currMV
b. MotionFlags & PMV_EXTSEARCH16 0
SAD iMinSAD currMV
8PMVfast16_Terminate_with_Refine PMV_HALFPELREFINE16

Halfpel16_Refine(pRef, pRefH, pRefV, pRefHV, cur, x, y,


currMV,iMinSAD, center_x, center_y, min_dx, max_dx,
min_dy, max_dy,iFcode, iQuant, iEdgedWidth)
9PMVfast16_Terminate_without_Refine SAD

You might also like