193 |
} |
} |
194 |
|
|
195 |
static __inline void CodeVector(Bitstream *bs, |
static __inline void CodeVector(Bitstream *bs, |
196 |
int16_t value, |
int32_t value, |
197 |
int16_t f_code, |
int32_t f_code, |
198 |
Statistics *pStat) |
Statistics *pStat) |
199 |
{ |
{ |
200 |
|
|
246 |
|
|
247 |
|
|
248 |
static __inline void CodeCoeff(Bitstream *bs, |
static __inline void CodeCoeff(Bitstream *bs, |
249 |
int16_t qcoeff[64], |
const int16_t qcoeff[64], |
250 |
VLC *table, |
VLC *table, |
251 |
const uint16_t *zigzag, |
const uint16_t *zigzag, |
252 |
uint16_t intra) |
uint16_t intra) |
280 |
} |
} |
281 |
|
|
282 |
|
|
283 |
static void CodeBlockIntra(const MBParam * pParam, |
static void CodeBlockIntra(const FRAMEINFO * frame, |
284 |
const MACROBLOCK *pMB, |
const MACROBLOCK *pMB, |
285 |
int16_t qcoeff[6*64], |
int16_t qcoeff[6*64], |
286 |
Bitstream * bs, |
Bitstream * bs, |
292 |
cbpy = pMB->cbp >> 2; |
cbpy = pMB->cbp >> 2; |
293 |
|
|
294 |
// write mcbpc |
// write mcbpc |
295 |
if(pParam->coding_type == I_VOP) { |
if(frame->coding_type == I_VOP) { |
296 |
mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2); |
mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2); |
297 |
BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code, mcbpc_intra_tab[mcbpc].len); |
BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code, mcbpc_intra_tab[mcbpc].len); |
298 |
} |
} |
315 |
BitstreamPutBits(bs, pMB->dquant, 2); |
BitstreamPutBits(bs, pMB->dquant, 2); |
316 |
|
|
317 |
// write interlacing |
// write interlacing |
318 |
if (pParam->global_flags & XVID_INTERLACING) |
if (frame->global_flags & XVID_INTERLACING) |
319 |
{ |
{ |
320 |
BitstreamPutBit(bs, pMB->field_dct); |
BitstreamPutBit(bs, pMB->field_dct); |
321 |
} |
} |
350 |
} |
} |
351 |
|
|
352 |
|
|
353 |
static void CodeBlockInter(const MBParam * pParam, |
static void CodeBlockInter(const FRAMEINFO * frame, |
354 |
const MACROBLOCK *pMB, |
const MACROBLOCK *pMB, |
355 |
int16_t qcoeff[6*64], |
int16_t qcoeff[6*64], |
356 |
Bitstream * bs, |
Bitstream * bs, |
374 |
BitstreamPutBits(bs, pMB->dquant, 2); |
BitstreamPutBits(bs, pMB->dquant, 2); |
375 |
|
|
376 |
// interlacing |
// interlacing |
377 |
if (pParam->global_flags & XVID_INTERLACING) |
if (frame->global_flags & XVID_INTERLACING) |
378 |
{ |
{ |
379 |
BitstreamPutBit(bs, pMB->field_dct); |
BitstreamPutBit(bs, pMB->field_dct); |
380 |
DEBUG1("codep: field_dct: ", pMB->field_dct); |
DEBUG1("codep: field_dct: ", pMB->field_dct); |
397 |
// code motion vector(s) |
// code motion vector(s) |
398 |
for(i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) |
for(i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) |
399 |
{ |
{ |
400 |
CodeVector(bs, pMB->pmvs[i].x, pParam->fixed_code, pStat); |
CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat); |
401 |
CodeVector(bs, pMB->pmvs[i].y, pParam->fixed_code, pStat); |
CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat); |
402 |
} |
} |
403 |
|
|
404 |
bits = BitstreamPos(bs); |
bits = BitstreamPos(bs); |
414 |
} |
} |
415 |
|
|
416 |
|
|
417 |
void MBCoding(const MBParam * pParam, |
void MBCoding(const FRAMEINFO * frame, |
418 |
MACROBLOCK *pMB, |
MACROBLOCK *pMB, |
419 |
int16_t qcoeff[6*64], |
int16_t qcoeff[6*64], |
420 |
Bitstream * bs, |
Bitstream * bs, |
423 |
|
|
424 |
int intra = (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q); |
int intra = (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q); |
425 |
|
|
426 |
if(pParam->coding_type == P_VOP) { |
if(frame->coding_type == P_VOP) { |
427 |
if(pMB->cbp == 0 && pMB->mode == MODE_INTER && |
if(pMB->cbp == 0 && pMB->mode == MODE_INTER && |
428 |
pMB->mvs[0].x == 0 && pMB->mvs[0].y == 0) |
pMB->mvs[0].x == 0 && pMB->mvs[0].y == 0) |
429 |
{ |
{ |
435 |
} |
} |
436 |
|
|
437 |
if(intra) |
if(intra) |
438 |
CodeBlockIntra(pParam, pMB, qcoeff, bs, pStat); |
CodeBlockIntra(frame, pMB, qcoeff, bs, pStat); |
439 |
else |
else |
440 |
CodeBlockInter(pParam, pMB, qcoeff, bs, pStat); |
CodeBlockInter(frame, pMB, qcoeff, bs, pStat); |
441 |
|
|
442 |
} |
} |
443 |
|
|