41 |
* * |
* * |
42 |
* Revision history: * |
* Revision history: * |
43 |
* * |
* * |
44 |
|
* 28.10.2002 GMC support - gruel * |
45 |
* 28.06.2002 added check_resync_marker() * |
* 28.06.2002 added check_resync_marker() * |
46 |
* 14.04.2002 bframe encoding * |
* 14.04.2002 bframe encoding * |
47 |
* 08.03.2002 initial version; isibaar * |
* 08.03.2002 initial version; isibaar * |
68 |
VLC DCT3Dintra[4096]; |
VLC DCT3Dintra[4096]; |
69 |
VLC DCT3Dinter[4096]; |
VLC DCT3Dinter[4096]; |
70 |
|
|
71 |
|
/* not really MB related, but VLCs are only available here */ |
72 |
|
void bs_put_spritetrajectory(Bitstream * bs, const int val) |
73 |
|
{ |
74 |
|
const int code = sprite_trajectory_code[val+16384].code; |
75 |
|
const int len = sprite_trajectory_code[val+16384].len; |
76 |
|
const int code2 = sprite_trajectory_len[len].code; |
77 |
|
const int len2 = sprite_trajectory_len[len].len; |
78 |
|
|
79 |
|
// printf("GMC=%d Code/Len = %d / %d ",val, code,len); |
80 |
|
// printf("Code2 / Len2 = %d / %d \n",code2,len2); |
81 |
|
|
82 |
|
BitstreamPutBits(bs, code2, len2); |
83 |
|
if (len) BitstreamPutBits(bs, code, len); |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
void |
void |
88 |
init_vlc_tables(void) |
init_vlc_tables(void) |
89 |
{ |
{ |
200 |
DCT3D[0] = DCT3Dinter; |
DCT3D[0] = DCT3Dinter; |
201 |
DCT3D[1] = DCT3Dintra; |
DCT3D[1] = DCT3Dintra; |
202 |
|
|
203 |
|
|
204 |
|
/* init sprite_trajectory tables */ |
205 |
|
/* even if GMC is not specified (it might be used later...) */ |
206 |
|
|
207 |
|
sprite_trajectory_code[0+16384].code = 0; |
208 |
|
sprite_trajectory_code[0+16384].len = 0; |
209 |
|
for (k=0;k<14;k++) |
210 |
|
{ |
211 |
|
int limit = (1<<k); |
212 |
|
|
213 |
|
for (i=-(2*limit-1); i<= -limit; i++) |
214 |
|
{ |
215 |
|
sprite_trajectory_code[i+16384].code = (2*limit-1)+i; |
216 |
|
sprite_trajectory_code[i+16384].len = k+1; |
217 |
|
} |
218 |
|
|
219 |
|
for (i=limit; i<= 2*limit-1; i++) |
220 |
|
{ |
221 |
|
sprite_trajectory_code[i+16384].code = i; |
222 |
|
sprite_trajectory_code[i+16384].len = k+1; |
223 |
|
} |
224 |
|
} |
225 |
} |
} |
226 |
|
|
227 |
static __inline void |
static __inline void |
320 |
|
|
321 |
|
|
322 |
static __inline void |
static __inline void |
323 |
CodeBlockIntra(const FRAMEINFO * frame, |
CodeBlockIntra(const FRAMEINFO * const frame, |
324 |
const MACROBLOCK * pMB, |
const MACROBLOCK * pMB, |
325 |
int16_t qcoeff[6 * 64], |
int16_t qcoeff[6 * 64], |
326 |
Bitstream * bs, |
Bitstream * bs, |
386 |
|
|
387 |
|
|
388 |
static void |
static void |
389 |
CodeBlockInter(const FRAMEINFO * frame, |
CodeBlockInter(const FRAMEINFO * const frame, |
390 |
const MACROBLOCK * pMB, |
const MACROBLOCK * pMB, |
391 |
int16_t qcoeff[6 * 64], |
int16_t qcoeff[6 * 64], |
392 |
Bitstream * bs, |
Bitstream * bs, |
395 |
|
|
396 |
int32_t i; |
int32_t i; |
397 |
uint32_t bits, mcbpc, cbpy; |
uint32_t bits, mcbpc, cbpy; |
398 |
|
int mcsel=0; |
399 |
|
|
400 |
mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3); |
mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3); |
401 |
cbpy = 15 - (pMB->cbp >> 2); |
cbpy = 15 - (pMB->cbp >> 2); |
404 |
BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code, |
BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code, |
405 |
mcbpc_inter_tab[mcbpc].len); |
mcbpc_inter_tab[mcbpc].len); |
406 |
|
|
407 |
|
if ( (frame->coding_type == S_VOP) && (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) ) |
408 |
|
{ |
409 |
|
if (frame->quarterpel) { |
410 |
|
if ( (pMB->qmvs[0].x == frame->GMC_MV.x) && (pMB->qmvs[0].y == frame->GMC_MV.y) ) |
411 |
|
mcsel=1; |
412 |
|
} else { |
413 |
|
if ( (pMB->mvs[0].x == frame->GMC_MV.x) && (pMB->mvs[0].y == frame->GMC_MV.y) ) |
414 |
|
mcsel=1; |
415 |
|
} |
416 |
|
BitstreamPutBit(bs, mcsel); // mcsel: '0'=local motion, '1'=GMC |
417 |
|
} |
418 |
|
|
419 |
// write cbpy |
// write cbpy |
420 |
BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len); |
BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len); |
421 |
|
|
442 |
} |
} |
443 |
} |
} |
444 |
} |
} |
445 |
// code motion vector(s) |
// code motion vector(s) if motion is local |
446 |
|
if (mcsel==0) |
447 |
for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) { |
for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) { |
448 |
CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat); |
CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat); |
449 |
CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat); |
CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat); |
464 |
|
|
465 |
bits = BitstreamPos(bs) - bits; |
bits = BitstreamPos(bs) - bits; |
466 |
pStat->iTextBits += bits; |
pStat->iTextBits += bits; |
|
|
|
467 |
} |
} |
468 |
|
|
469 |
|
|
470 |
void |
void |
471 |
MBCoding(const FRAMEINFO * frame, |
MBCoding(const FRAMEINFO * const frame, |
472 |
MACROBLOCK * pMB, |
MACROBLOCK * pMB, |
473 |
int16_t qcoeff[6 * 64], |
int16_t qcoeff[6 * 64], |
474 |
Bitstream * bs, |
Bitstream * bs, |
475 |
Statistics * pStat) |
Statistics * pStat) |
476 |
{ |
{ |
477 |
|
if (frame->coding_type != I_VOP) |
478 |
if (frame->coding_type == P_VOP) { |
BitstreamPutBit(bs, 0); // not_coded |
|
BitstreamPutBit(bs, 0); // coded |
|
|
} |
|
479 |
|
|
480 |
if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) |
if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) |
481 |
CodeBlockIntra(frame, pMB, qcoeff, bs, pStat); |
CodeBlockIntra(frame, pMB, qcoeff, bs, pStat); |