[svn] / branches / dev-api-3 / xvidcore / src / bitstream / mbcoding.c Repository:
ViewVC logotype

Diff of /branches/dev-api-3/xvidcore/src/bitstream/mbcoding.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/xvidcore/src/bitstream/mbcoding.c revision 153, Thu May 2 00:36:50 2002 UTC branches/dev-api-3/xvidcore/src/bitstream/mbcoding.c revision 631, Thu Nov 7 10:31:03 2002 UTC
# Line 41  Line 41 
41    *                                                                                                                                                        *    *                                                                                                                                                        *
42    *  Revision history:                                                         *    *  Revision history:                                                         *
43    *                                                                            *    *                                                                            *
44      *  28.10.2002 GMC support - gruel                                                                                        *
45      *  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                                                           *
48    *                                                                                                                                                        *    *                                                                                                                                                        *
# Line 66  Line 68 
68  VLC DCT3Dintra[4096];  VLC DCT3Dintra[4096];
69  VLC DCT3Dinter[4096];  VLC DCT3Dinter[4096];
70    
71  void init_vlc_tables(void)  /* 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    int bs_get_spritetrajectory(Bitstream * bs)
87    {
88            int i;
89            for (i = 0; i < 12; i++)
90            {
91                    if (BitstreamShowBits(bs, sprite_trajectory_len[i].len) == sprite_trajectory_len[i].code)
92                    {
93                            BitstreamSkip(bs, sprite_trajectory_len[i].len);
94                            return i;
95                    }
96            }
97            return -1;
98    }
99    
100    void
101    init_vlc_tables(void)
102  {  {
103    
104          int32_t k, l, i, intra, last;          int32_t k, l, i, intra, last;
# Line 94  Line 126 
126    
127                          for(l = 0; l < 64; l++) { // run                          for(l = 0; l < 64; l++) { // run
128                                  int32_t level = k;                                  int32_t level = k;
129                                  uint32_t run = l;                                  ptr_t run = l;
130    
131                                  if((abs(level) <= max_level_ptr[run]) &&                                  if ((abs(level) <= max_level_ptr[run]) && (run <= (uint32_t) max_run_ptr[abs(level)])) {        // level < max_level and run < max_run
                                    (run <= (uint32_t)max_run_ptr[abs(level)])) { // level < max_level and run < max_run  
132    
133                                                  vlc[intra]->code = 0;                                                  vlc[intra]->code = 0;
134                                                  vlc[intra]->len = 0;                                                  vlc[intra]->len = 0;
135                                                  goto loop_end;                                                  goto loop_end;
136                                  }                                  } else {
                                 else {  
137                                          if(level > 0)                                        // correct level                                          if(level > 0)                                        // correct level
138                                                  level -= max_level_ptr[run];                                                  level -= max_level_ptr[run];
139                                          else                                          else
# Line 134  Line 164 
164                                          run += max_run_ptr[abs(level)] + 1;                                          run += max_run_ptr[abs(level)] + 1;
165                                  }                                  }
166    
167                                  vlc[intra]->code = (uint32_t) ((l << 14) | (0x1e + last) << 20) |                                  vlc[intra]->code =
168                                                                                            (1 << 13) | ((k & 0xfff) << 1) | 1;                                          (uint32_t) ((l << 14) | (0x1e + last) << 20) | (1 << 13) |
169                                            ((k & 0xfff) << 1) | 1;
170    
171                                  vlc[intra]->len = 30;                                  vlc[intra]->len = 30;
172                                  vlc[intra]++;                                  vlc[intra]++;
# Line 143  Line 174 
174    
175  loop_end:  loop_end:
176                                  if(level != 0) {                                  if(level != 0) {
177                                          vlc[intra]->code = (vlc[intra]->code << (coeff_ptr[run][abs(level) - 1].len + 1)) |                                          vlc[intra]->code =
178                                                                             (coeff_ptr[run][abs(level) - 1].code << 1);                                                  (vlc[intra]->
179                                          vlc[intra]->len = (coeff_ptr[run][abs(level) - 1].len + 1) + vlc[intra]->len;                                                   code << (coeff_ptr[run][abs(level) - 1].len +
180                                                                      1)) | (coeff_ptr[run][abs(level) -
181                                                                                                                    1].code << 1);
182                                            vlc[intra]->len =
183                                                    (coeff_ptr[run][abs(level) - 1].len + 1) +
184                                                    vlc[intra]->len;
185    
186                                          if(level < 0)                                          if(level < 0)
187                                                  vlc[intra]->code += 1;                                                  vlc[intra]->code += 1;
# Line 160  Line 196 
196                  if(i >= 512) {                  if(i >= 512) {
197                          *vlc1 = DCT3Dtab3[(i >> 5) - 16];                          *vlc1 = DCT3Dtab3[(i >> 5) - 16];
198                          *vlc2 = DCT3Dtab0[(i >> 5) - 16];                          *vlc2 = DCT3Dtab0[(i >> 5) - 16];
199                  }                  } else if (i >= 128) {
                 else if(i >= 128) {  
200                          *vlc1 = DCT3Dtab4[(i >> 2) - 32];                          *vlc1 = DCT3Dtab4[(i >> 2) - 32];
201                          *vlc2 = DCT3Dtab1[(i >> 2) - 32];                          *vlc2 = DCT3Dtab1[(i >> 2) - 32];
202                  }                  } else if (i >= 8) {
                 else if(i >= 8) {  
203                          *vlc1 = DCT3Dtab5[i - 8];                          *vlc1 = DCT3Dtab5[i - 8];
204                          *vlc2 = DCT3Dtab2[i - 8];                          *vlc2 = DCT3Dtab2[i - 8];
205                  }                  } else {
                 else {  
206                          *vlc1 = ERRtab[i];                          *vlc1 = ERRtab[i];
207                          *vlc2 = ERRtab[i];                          *vlc2 = ERRtab[i];
208                  }                  }
# Line 180  Line 213 
213          DCT3D[0] = DCT3Dinter;          DCT3D[0] = DCT3Dinter;
214          DCT3D[1] = DCT3Dintra;          DCT3D[1] = DCT3Dintra;
215    
216    
217    /* init sprite_trajectory tables */
218    /* even if GMC is not specified (it might be used later...) */
219    
220            sprite_trajectory_code[0+16384].code = 0;
221            sprite_trajectory_code[0+16384].len = 0;
222            for (k=0;k<14;k++)
223            {
224                    int limit = (1<<k);
225    
226                    for (i=-(2*limit-1); i<= -limit; i++)
227                    {
228                            sprite_trajectory_code[i+16384].code = (2*limit-1)+i;
229                            sprite_trajectory_code[i+16384].len = k+1;
230  }  }
231    
232  static __inline void CodeVector(Bitstream *bs,                  for (i=limit; i<= 2*limit-1; i++)
233                    {
234                            sprite_trajectory_code[i+16384].code = i;
235                            sprite_trajectory_code[i+16384].len = k+1;
236                    }
237            }
238    }
239    
240    static __inline void
241    CodeVector(Bitstream * bs,
242                                  int32_t value,                                  int32_t value,
243                                  int32_t f_code,                                  int32_t f_code,
244                                  Statistics *pStat)                                  Statistics *pStat)
# Line 201  Line 257 
257          pStat->iMvCount++;          pStat->iMvCount++;
258    
259          if (value == 0) {          if (value == 0) {
260                  BitstreamPutBits(bs, mb_motion_table[32].code, mb_motion_table[32].len);                  BitstreamPutBits(bs, mb_motion_table[32].code,
261                                                     mb_motion_table[32].len);
262          } else {          } else {
263                  uint16_t length, code, mv_res, sign;                  uint16_t length, code, mv_res, sign;
264    
# Line 226  Line 283 
283                          code = -code;                          code = -code;
284    
285                  code += 32;                  code += 32;
286                  BitstreamPutBits(bs, mb_motion_table[code].code, mb_motion_table[code].len);                  BitstreamPutBits(bs, mb_motion_table[code].code,
287                                                     mb_motion_table[code].len);
288    
289                  if(f_code)                  if(f_code)
290                          BitstreamPutBits(bs, mv_res, f_code);                          BitstreamPutBits(bs, mv_res, f_code);
# Line 235  Line 293 
293  }  }
294    
295    
296  static __inline void CodeCoeff(Bitstream *bs,  static __inline void
297    CodeCoeff(Bitstream * bs,
298                                 const int16_t qcoeff[64],                                 const int16_t qcoeff[64],
299                                 VLC *table,                                 VLC *table,
300                                 const uint16_t *zigzag,                                 const uint16_t *zigzag,
# Line 249  Line 308 
308          j = intra;          j = intra;
309          last = intra;          last = intra;
310    
311          while(j < 64 && (v = qcoeff[zigzag[j]]) == 0) j++;          while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)
312                    j++;
313    
314          do {          do {
315                  vlc = table + 64 * 2047 + (v << 6) + j - last;                  vlc = table + 64 * 2047 + (v << 6) + j - last;
316                  last = ++j;                  last = ++j;
317    
318                  // count zeroes                  // count zeroes
319                  while(j < 64 && (v = qcoeff[zigzag[j]]) == 0) j++;                  while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)
320                            j++;
321    
322                  // write code                  // write code
323                  if(j != 64) {                  if(j != 64) {
# Line 271  Line 332 
332  }  }
333    
334    
335  static void CodeBlockIntra(const FRAMEINFO * frame,  static __inline void
336    CodeBlockIntra(const FRAMEINFO * const frame,
337                             const MACROBLOCK *pMB,                             const MACROBLOCK *pMB,
338                             int16_t qcoeff[6*64],                             int16_t qcoeff[6*64],
339                             Bitstream * bs,                             Bitstream * bs,
# Line 285  Line 347 
347          // write mcbpc          // write mcbpc
348          if(frame->coding_type == I_VOP) {          if(frame->coding_type == I_VOP) {
349                  mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2);                  mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2);
350                  BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code, mcbpc_intra_tab[mcbpc].len);                  BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code,
351          }                                                   mcbpc_intra_tab[mcbpc].len);
352          else {          } else {
353                  mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);                  mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);
354                  BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code, mcbpc_inter_tab[mcbpc].len);                  BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code,
355                                                     mcbpc_inter_tab[mcbpc].len);
356          }          }
357    
358          // ac prediction flag          // ac prediction flag
# Line 306  Line 369 
369                  BitstreamPutBits(bs, pMB->dquant, 2);                  BitstreamPutBits(bs, pMB->dquant, 2);
370    
371          // write interlacing          // write interlacing
372          if (frame->global_flags & XVID_INTERLACING)          if (frame->global_flags & XVID_INTERLACING) {
         {  
373                  BitstreamPutBit(bs, pMB->field_dct);                  BitstreamPutBit(bs, pMB->field_dct);
374          }          }
   
375          // code block coeffs          // code block coeffs
376          for(i = 0; i < 6; i++)          for (i = 0; i < 6; i++) {
         {  
377                  if(i < 4)                  if(i < 4)
378                          BitstreamPutBits(bs,                          BitstreamPutBits(bs, dcy_tab[qcoeff[i * 64 + 0] + 255].code,
                                          dcy_tab[qcoeff[i*64 + 0] + 255].code,  
379                                           dcy_tab[qcoeff[i*64 + 0] + 255].len);                                           dcy_tab[qcoeff[i*64 + 0] + 255].len);
380                  else                  else
381                          BitstreamPutBits(bs,                          BitstreamPutBits(bs, dcc_tab[qcoeff[i * 64 + 0] + 255].code,
                                          dcc_tab[qcoeff[i*64 + 0] + 255].code,  
382                                           dcc_tab[qcoeff[i*64 + 0] + 255].len);                                           dcc_tab[qcoeff[i*64 + 0] + 255].len);
383    
384                  if(pMB->cbp & (1 << (5 - i)))                  if (pMB->cbp & (1 << (5 - i))) {
385                  {                          const uint16_t *scan_table =
386                                    frame->global_flags & XVID_ALTERNATESCAN ?
387                                    scan_tables[2] : scan_tables[pMB->acpred_directions[i]];
388    
389                          bits = BitstreamPos(bs);                          bits = BitstreamPos(bs);
390    
391                          CodeCoeff(bs,                          CodeCoeff(bs, &qcoeff[i * 64], intra_table, scan_table, 1);
                                   &qcoeff[i*64],  
                                   intra_table,  
                                   scan_tables[pMB->acpred_directions[i]],  
                                   1);  
392    
393                          bits = BitstreamPos(bs) - bits;                          bits = BitstreamPos(bs) - bits;
394                          pStat->iTextBits += bits;                          pStat->iTextBits += bits;
# Line 341  Line 398 
398  }  }
399    
400    
401  static void CodeBlockInter(const FRAMEINFO * frame,  static void
402    CodeBlockInter(const FRAMEINFO * const frame,
403                             const MACROBLOCK *pMB,                             const MACROBLOCK *pMB,
404                             int16_t qcoeff[6*64],                             int16_t qcoeff[6*64],
405                             Bitstream * bs,                             Bitstream * bs,
# Line 350  Line 408 
408    
409          int32_t i;          int32_t i;
410          uint32_t bits, mcbpc, cbpy;          uint32_t bits, mcbpc, cbpy;
411            int mcsel=0;
412    
413          mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);          mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);
414          cbpy = 15 - (pMB->cbp >> 2);          cbpy = 15 - (pMB->cbp >> 2);
415    
416          // write mcbpc          // write mcbpc
417          BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code, mcbpc_inter_tab[mcbpc].len);          BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code,
418                                             mcbpc_inter_tab[mcbpc].len);
419    
420            if ( (frame->coding_type == S_VOP) && (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) )
421            {
422                    if (frame->quarterpel) {
423                            if ( (pMB->qmvs[0].x == frame->GMC_MV.x) && (pMB->qmvs[0].y == frame->GMC_MV.y) )
424                                    mcsel=1;
425                    } else {
426                            if ( (pMB->mvs[0].x == frame->GMC_MV.x) && (pMB->mvs[0].y == frame->GMC_MV.y) )
427                                    mcsel=1;
428                    }
429                    BitstreamPutBit(bs, mcsel);             // mcsel: '0'=local motion, '1'=GMC
430            }
431    
432          // write cbpy          // write cbpy
433          BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);          BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);
# Line 365  Line 437 
437                  BitstreamPutBits(bs, pMB->dquant, 2);                  BitstreamPutBits(bs, pMB->dquant, 2);
438    
439          // interlacing          // interlacing
440          if (frame->global_flags & XVID_INTERLACING)          if (frame->global_flags & XVID_INTERLACING) {
441          {                  if (pMB->cbp) {
442                  BitstreamPutBit(bs, pMB->field_dct);                  BitstreamPutBit(bs, pMB->field_dct);
443                  DEBUG1("codep: field_dct: ", pMB->field_dct);                  DEBUG1("codep: field_dct: ", pMB->field_dct);
444                    }
445    
446                  // if inter block, write field ME flag                  // if inter block, write field ME flag
447                  if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)                  if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {
                 {  
448                          BitstreamPutBit(bs, pMB->field_pred);                          BitstreamPutBit(bs, pMB->field_pred);
449                          DEBUG1("codep: field_pred: ", pMB->field_pred);                          DEBUG1("codep: field_pred: ", pMB->field_pred);
450    
451                          // write field prediction references                          // write field prediction references
452                          if (pMB->field_pred)                          if (pMB->field_pred) {
                         {  
453                                  BitstreamPutBit(bs, pMB->field_for_top);                                  BitstreamPutBit(bs, pMB->field_for_top);
454                                  BitstreamPutBit(bs, pMB->field_for_bot);                                  BitstreamPutBit(bs, pMB->field_for_bot);
455                          }                          }
456                  }                  }
457          }          }
458            // code motion vector(s) if motion is local
459          // code motion vector(s)          if (mcsel==0)
460          for(i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++)                  for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) {
         {  
461                  CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat);                  CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat);
462                  CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat);                  CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat);
463          }          }
# Line 397  Line 467 
467          // code block coeffs          // code block coeffs
468          for(i = 0; i < 6; i++)          for(i = 0; i < 6; i++)
469                  if(pMB->cbp & (1 << (5 - i)))                  if(pMB->cbp & (1 << (5 - i)))
470                          CodeCoeff(bs, &qcoeff[i*64], inter_table, scan_tables[0], 0);                  {
471                            const uint16_t *scan_table =
472                                    frame->global_flags & XVID_ALTERNATESCAN ?
473                                    scan_tables[2] : scan_tables[0];
474    
475                            CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_table, 0);
476                    }
477    
478          bits = BitstreamPos(bs) - bits;          bits = BitstreamPos(bs) - bits;
479          pStat->iTextBits += bits;          pStat->iTextBits += bits;
   
480  }  }
481    
482    
483  void MBCoding(const FRAMEINFO * frame,  void
484    MBCoding(const FRAMEINFO * const frame,
485                MACROBLOCK *pMB,                MACROBLOCK *pMB,
486                int16_t qcoeff[6*64],                int16_t qcoeff[6*64],
487                Bitstream * bs,                Bitstream * bs,
488                Statistics * pStat)                Statistics * pStat)
489  {  {
490            if (frame->coding_type != I_VOP)
491                            BitstreamPutBit(bs, 0); // not_coded
492    
493          int intra = (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q);          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q)
   
         if(frame->coding_type == P_VOP) {  
                 if(pMB->cbp == 0 && pMB->mode == MODE_INTER &&  
                    pMB->mvs[0].x == 0 && pMB->mvs[0].y == 0)  
                 {  
                         BitstreamPutBit(bs, 1);         // not_coded  
                         return;  
                 }  
                 else  
                         BitstreamPutBit(bs, 0);         // coded  
         }  
   
         if(intra)  
494                  CodeBlockIntra(frame, pMB, qcoeff, bs, pStat);                  CodeBlockIntra(frame, pMB, qcoeff, bs, pStat);
495          else          else
496                  CodeBlockInter(frame, pMB, qcoeff, bs, pStat);                  CodeBlockInter(frame, pMB, qcoeff, bs, pStat);
497    
498  }  }
499    
500    /*
501    // moved to mbcoding.h so that in can be 'static __inline'
502    void
503    MBSkip(Bitstream * bs)
504    {
505            BitstreamPutBit(bs, 1); // not coded
506    }
507    */
508    
509  /***************************************************************  /***************************************************************
510   * bframe encoding start   * bframe encoding start
511   ***************************************************************/   ***************************************************************/
# Line 444  Line 518 
518          3       0001b   forward mc+q            dbquant, mvdf          3       0001b   forward mc+q            dbquant, mvdf
519  */  */
520    
521  void put_bvop_mbtype(Bitstream * bs, int value)  static __inline void
522  {  put_bvop_mbtype(Bitstream * bs,
523          switch(value)                                  int value)
524          {          {
525          case 0 :        BitstreamPutBit(bs, 1);          switch (value) {
526                                  return;                  case MODE_FORWARD:
   
         case 1 :        BitstreamPutBit(bs, 0);  
                                 BitstreamPutBit(bs, 1);  
                                 return;  
   
         case 2 :        BitstreamPutBit(bs, 0);  
527                                  BitstreamPutBit(bs, 0);                                  BitstreamPutBit(bs, 0);
528                                  BitstreamPutBit(bs, 1);                  case MODE_BACKWARD:
                                 return;  
   
         case 3 :        BitstreamPutBit(bs, 0);  
529                                  BitstreamPutBit(bs, 0);                                  BitstreamPutBit(bs, 0);
530                    case MODE_INTERPOLATE:
531                                  BitstreamPutBit(bs, 0);                                  BitstreamPutBit(bs, 0);
532                    case MODE_DIRECT:
533                                  BitstreamPutBit(bs, 1);                                  BitstreamPutBit(bs, 1);
534                                  return;                  default:
535                            break;
         default :       ; // invalid!  
   
536          }          }
   
537  }  }
538    
539  /*  /*
# Line 479  Line 543 
543          +2      11b          +2      11b
544  */  */
545    
546  void put_bvop_dbquant(Bitstream *bs, int value)  static __inline void
547  {  put_bvop_dbquant(Bitstream * bs,
548          switch (value)                                   int value)
549          {          {
550          case 0 :        BitstreamPutBit(bs, 0);          switch (value) {
551            case 0:
552                    BitstreamPutBit(bs, 0);
553                                  return;                                  return;
554    
555          case -2 :       BitstreamPutBit(bs, 1);          case -2:
556                    BitstreamPutBit(bs, 1);
557                                  BitstreamPutBit(bs, 0);                                  BitstreamPutBit(bs, 0);
558                                  return;                                  return;
559    
560          case 2 :        BitstreamPutBit(bs, 1);          case 2:
561                    BitstreamPutBit(bs, 1);
562                                  BitstreamPutBit(bs, 1);                                  BitstreamPutBit(bs, 1);
563                                  return;                                  return;
564    
# Line 500  Line 568 
568    
569    
570    
571  void MBCodingBVOP(const MACROBLOCK * mb,  void
572    MBCodingBVOP(const MACROBLOCK * mb,
573                                    const int16_t qcoeff[6*64],                                    const int16_t qcoeff[6*64],
574                                    const int32_t fcode,                                    const int32_t fcode,
575                                    const int32_t bcode,                                    const int32_t bcode,
576                                    Bitstream * bs,                                    Bitstream * bs,
577                                    Statistics * pStat)                           Statistics * pStat,
578                             int direction)
579  {  {
580          int i;          int vcode = fcode;
581            unsigned int i;
582    
583  /*      ------------------------------------------------------------------  /*      ------------------------------------------------------------------
584                  when a block is skipped it is decoded DIRECT(0,)                  when a block is skipped it is decoded DIRECT(0,0)
585                  hence are interpolated from forward & backward frames                  hence is interpolated from forward & backward frames
586          ------------------------------------------------------------------ */          ------------------------------------------------------------------ */
587    
588          if (mb->mode == 5)          if (mb->mode == MODE_DIRECT_NONE_MV) {
         {  
589                  BitstreamPutBit(bs, 1);         // skipped                  BitstreamPutBit(bs, 1);         // skipped
590                  return;                  return;
591          }          }
592    
593          BitstreamPutBit(bs, 0);         // not skipped          BitstreamPutBit(bs, 0);         // not skipped
594    
595          if (mb->cbp == 0)          if (mb->cbp == 0) {
         {  
596                  BitstreamPutBit(bs, 1);         // cbp == 0                  BitstreamPutBit(bs, 1);         // cbp == 0
597          }          } else {
         else  
         {  
598                  BitstreamPutBit(bs, 0);         // cbp == xxx                  BitstreamPutBit(bs, 0);         // cbp == xxx
599          }          }
600    
601          put_bvop_mbtype(bs, mb->mode);          put_bvop_mbtype(bs, mb->mode);
602    
603          if (mb->cbp)          if (mb->cbp) {
         {  
604                  BitstreamPutBits(bs, mb->cbp, 6);                  BitstreamPutBits(bs, mb->cbp, 6);
605          }          }
606    
607          if (mb->mode != MODE_DIRECT && mb->cbp != 0)          if (mb->mode != MODE_DIRECT && mb->cbp != 0) {
         {  
608                  put_bvop_dbquant(bs, 0); // todo: mb->dquant = 0                  put_bvop_dbquant(bs, 0); // todo: mb->dquant = 0
609          }          }
610    
611          if (mb->mode == MODE_INTERPOLATE || mb->mode == MODE_FORWARD)          switch (mb->mode) {
612          {                  case MODE_INTERPOLATE:
613              CodeVector(bs, mb->pmvs[0].x, fcode, pStat);                          CodeVector(bs, mb->pmvs[1].x, vcode, pStat); //forward vector of interpolate mode
614              CodeVector(bs, mb->pmvs[0].y, fcode, pStat);                          CodeVector(bs, mb->pmvs[1].y, vcode, pStat);
615          }                  case MODE_BACKWARD:
616                            vcode = bcode;
617          if (mb->mode == MODE_INTERPOLATE || mb->mode == MODE_BACKWARD)                  case MODE_FORWARD:
618          {                          CodeVector(bs, mb->pmvs[0].x, vcode, pStat);
619              CodeVector(bs, mb->b_pmvs[0].x, bcode, pStat);                          CodeVector(bs, mb->pmvs[0].y, vcode, pStat);
620              CodeVector(bs, mb->b_pmvs[0].y, bcode, pStat);                          break;
621                    case MODE_DIRECT:
622                            CodeVector(bs, mb->pmvs[3].x, 1, pStat);        // fcode is always 1 for delta vector
623                            CodeVector(bs, mb->pmvs[3].y, 1, pStat);        // prediction is always (0,0)
624                    default: break;
625          }          }
626    
627          if (mb->mode == MODE_DIRECT)          for (i = 0; i < 6; i++) {
628          {                  if (mb->cbp & (1 << (5 - i))) {
629                  // TODO: direct                          CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[direction], 0);
         }  
   
     for (i = 0; i < 6; i++)  
     {  
                 if (mb->cbp & (1 << (5 - i)))  
                 {  
                         CodeCoeff(bs, &qcoeff[i*64], inter_table, scan_tables[0], 0);  
630                  }                  }
631      }      }
632  }  }
# Line 575  Line 637 
637   * decoding stuff starts here                                  *   * decoding stuff starts here                                  *
638   ***************************************************************/   ***************************************************************/
639    
640  int get_mcbpc_intra(Bitstream * bs)  
641    // for IVOP addbits == 0
642    // for PVOP addbits == fcode - 1
643    // for BVOP addbits == max(fcode,bcode) - 1
644    // returns true or false
645    int
646    check_resync_marker(Bitstream * bs, int addbits)
647    {
648            uint32_t nbits;
649            uint32_t code;
650            uint32_t nbitsresyncmarker = NUMBITS_VP_RESYNC_MARKER + addbits;
651    
652            nbits = BitstreamNumBitsToByteAlign(bs);
653            code = BitstreamShowBits(bs, nbits);
654    
655            if (code == (((uint32_t)1 << (nbits - 1)) - 1))
656  {  {
657                    return BitstreamShowBitsFromByteAlign(bs, nbitsresyncmarker) == RESYNC_MARKER;
658            }
659    
660            return 0;
661    }
662    
         uint32_t index;  
663    
         while((index = BitstreamShowBits(bs, 9)) == 1)  
                 BitstreamSkip(bs, 9);  
664    
665    int
666    get_mcbpc_intra(Bitstream * bs)
667    {
668    
669            uint32_t index;
670    
671            index = BitstreamShowBits(bs, 9);
672          index >>= 3;          index >>= 3;
673    
674          BitstreamSkip(bs, mcbpc_intra_table[index].len);          BitstreamSkip(bs, mcbpc_intra_table[index].len);
# Line 591  Line 677 
677    
678  }  }
679    
680  int get_mcbpc_inter(Bitstream * bs)  int
681    get_mcbpc_inter(Bitstream * bs)
682  {  {
683    
684          uint32_t index;          uint32_t index;
685    
686          while((index = CLIP(BitstreamShowBits(bs, 9), 256)) == 1)          index = CLIP(BitstreamShowBits(bs, 9), 256);
                 BitstreamSkip(bs, 9);  
687    
688          BitstreamSkip(bs,  mcbpc_inter_table[index].len);          BitstreamSkip(bs,  mcbpc_inter_table[index].len);
689    
# Line 605  Line 691 
691    
692  }  }
693    
694  int get_cbpy(Bitstream * bs, int intra)  int
695    get_cbpy(Bitstream * bs,
696                     int intra)
697  {  {
698    
699          int cbpy;          int cbpy;
# Line 621  Line 709 
709    
710  }  }
711    
712  int get_mv_data(Bitstream * bs)  static __inline int
713    get_mv_data(Bitstream * bs)
714  {  {
715    
716          uint32_t index;          uint32_t index;
# Line 631  Line 720 
720    
721          index = BitstreamShowBits(bs, 12);          index = BitstreamShowBits(bs, 12);
722    
723          if(index >= 512)          if (index >= 512) {
         {  
724                  index = (index >> 8) - 2;                  index = (index >> 8) - 2;
725                  BitstreamSkip(bs, TMNMVtab0[index].len);                  BitstreamSkip(bs, TMNMVtab0[index].len);
726                  return TMNMVtab0[index].code;                  return TMNMVtab0[index].code;
727          }          }
728    
729          if(index >= 128)          if (index >= 128) {
         {  
730                  index = (index >> 2) - 32;                  index = (index >> 2) - 32;
731                  BitstreamSkip(bs, TMNMVtab1[index].len);                  BitstreamSkip(bs, TMNMVtab1[index].len);
732                  return TMNMVtab1[index].code;                  return TMNMVtab1[index].code;
# Line 652  Line 739 
739    
740  }  }
741    
742  int get_mv(Bitstream * bs, int fcode)  int
743    get_mv(Bitstream * bs,
744               int fcode)
745  {  {
746    
747          int data;          int data;
# Line 672  Line 761 
761    
762  }  }
763    
764  int get_dc_dif(Bitstream * bs, uint32_t dc_size)  int
765    get_dc_dif(Bitstream * bs,
766                       uint32_t dc_size)
767  {  {
768    
769          int code = BitstreamGetBits(bs, dc_size);          int code = BitstreamGetBits(bs, dc_size);
# Line 685  Line 776 
776    
777  }  }
778    
779  int get_dc_size_lum(Bitstream * bs)  int
780    get_dc_size_lum(Bitstream * bs)
781  {  {
782    
783          int code, i;          int code, i;
784    
785          code = BitstreamShowBits(bs, 11);          code = BitstreamShowBits(bs, 11);
786    
787          for(i = 11; i > 3; i--) {          for(i = 11; i > 3; i--) {
# Line 705  Line 798 
798  }  }
799    
800    
801  int get_dc_size_chrom(Bitstream * bs)  int
802    get_dc_size_chrom(Bitstream * bs)
803  {  {
804    
805          uint32_t code, i;          uint32_t code, i;
806    
807          code = BitstreamShowBits(bs, 12);          code = BitstreamShowBits(bs, 12);
808    
809          for(i = 12; i > 2; i--) {          for(i = 12; i > 2; i--) {
# Line 723  Line 818 
818    
819  }  }
820    
821  void get_intra_block(Bitstream * bs, int16_t * block, int direction, int coeff)  void
822    get_intra_block(Bitstream * bs,
823                                    int16_t * block,
824                                    int direction,
825                                    int coeff)
826  {  {
827    
828          const uint16_t * scan = scan_tables[ direction ];          const uint16_t * scan = scan_tables[ direction ];
829          int level;          int level, run, last;
         int run;  
         int last;  
830    
831          do          do {
         {  
832                  level = get_coeff(bs, &run, &last, 1, 0);                  level = get_coeff(bs, &run, &last, 1, 0);
833                  if (run == -1)                  if (run == -1) {
                 {  
834                          DEBUG("fatal: invalid run");                          DEBUG("fatal: invalid run");
835                          break;                          break;
836                  }                  }
837                  coeff += run;                  coeff += run;
838                  block[ scan[coeff] ] = level;                  block[ scan[coeff] ] = level;
839                  if (level < -127 || level > 127)  
840                  {                  DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[coeff], level);
841                    //DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[coeff], level, BitstreamShowBits(bs, 32));
842    
843                    if (level < -127 || level > 127) {
844                          DEBUG1("warning: intra_overflow", level);                          DEBUG1("warning: intra_overflow", level);
845                  }                  }
846                  coeff++;                  coeff++;
# Line 750  Line 848 
848    
849  }  }
850    
851  void get_inter_block(Bitstream * bs, int16_t * block)  void
852    get_inter_block(Bitstream * bs,
853                                    int16_t * block,
854                                    int direction)
855  {  {
856    
857          const uint16_t * scan = scan_tables[0];          const uint16_t *scan = scan_tables[direction];
858          int p;          int p;
859          int level;          int level;
860          int run;          int run;
861          int last;          int last;
862    
863          p = 0;          p = 0;
864          do          do {
         {  
865                  level = get_coeff(bs, &run, &last, 0, 0);                  level = get_coeff(bs, &run, &last, 0, 0);
866                  if (run == -1)                  if (run == -1) {
                 {  
867                          DEBUG("fatal: invalid run");                          DEBUG("fatal: invalid run");
868                          break;                          break;
869                  }                  }
870                  p += run;                  p += run;
871    
872                  block[ scan[p] ] = level;                  block[ scan[p] ] = level;
873                  if (level < -127 || level > 127)  
874                  {                  DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[p], level);
875                    // DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[p], level, BitstreamShowBits(bs, 32));
876    
877                    if (level < -127 || level > 127) {
878                          DEBUG1("warning: inter_overflow", level);                          DEBUG1("warning: inter_overflow", level);
879                  }                  }
880                  p++;                  p++;

Legend:
Removed from v.153  
changed lines
  Added in v.631

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4