[cvs] / xvidcore / src / bitstream / mbcoding.c Repository:
ViewVC logotype

Diff of /xvidcore/src/bitstream/mbcoding.c

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

revision 1.17, Wed Jun 12 20:38:40 2002 UTC revision 1.25.2.2, Thu Sep 26 01:54:54 2002 UTC
# Line 41  Line 41 
41    *                                                                                                                                                        *    *                                                                                                                                                        *
42    *  Revision history:                                                         *    *  Revision history:                                                         *
43    *                                                                            *    *                                                                            *
44      *  28.06.2002 added check_resync_marker()                                    *
45    *  14.04.2002 bframe encoding                                                                                            *    *  14.04.2002 bframe encoding                                                                                            *
46    *  08.03.2002 initial version; isibaar                                                           *    *  08.03.2002 initial version; isibaar                                                           *
47    *                                                                                                                                                        *    *                                                                                                                                                        *
# Line 95  Line 96 
96    
97                          for (l = 0; l < 64; l++) {      // run                          for (l = 0; l < 64; l++) {      // run
98                                  int32_t level = k;                                  int32_t level = k;
99                                  uint32_t run = l;                                  ptr_t run = l;
100    
101                                  if ((abs(level) <= max_level_ptr[run]) && (run <= (uint32_t) max_run_ptr[abs(level)])) {        // level < max_level and run < max_run                                  if ((abs(level) <= max_level_ptr[run]) && (run <= (uint32_t) max_run_ptr[abs(level)])) {        // level < max_level and run < max_run
102    
# Line 279  Line 280 
280  }  }
281    
282    
283  static void  static __inline void
284  CodeBlockIntra(const FRAMEINFO * frame,  CodeBlockIntra(const FRAMEINFO * frame,
285                             const MACROBLOCK * pMB,                             const MACROBLOCK * pMB,
286                             int16_t qcoeff[6 * 64],                             int16_t qcoeff[6 * 64],
# Line 329  Line 330 
330                                                           dcc_tab[qcoeff[i * 64 + 0] + 255].len);                                                           dcc_tab[qcoeff[i * 64 + 0] + 255].len);
331    
332                  if (pMB->cbp & (1 << (5 - i))) {                  if (pMB->cbp & (1 << (5 - i))) {
333                            const uint16_t *scan_table =
334                                    frame->global_flags & XVID_ALTERNATESCAN ?
335                                    scan_tables[2] : scan_tables[pMB->acpred_directions[i]];
336    
337                          bits = BitstreamPos(bs);                          bits = BitstreamPos(bs);
338    
339                          CodeCoeff(bs, &qcoeff[i * 64], intra_table,                          CodeCoeff(bs, &qcoeff[i * 64], intra_table, scan_table, 1);
                                           scan_tables[pMB->acpred_directions[i]], 1);  
340    
341                          bits = BitstreamPos(bs) - bits;                          bits = BitstreamPos(bs) - bits;
342                          pStat->iTextBits += bits;                          pStat->iTextBits += bits;
# Line 369  Line 373 
373    
374          // interlacing          // interlacing
375          if (frame->global_flags & XVID_INTERLACING) {          if (frame->global_flags & XVID_INTERLACING) {
376                    if (pMB->cbp) {
377                  BitstreamPutBit(bs, pMB->field_dct);                  BitstreamPutBit(bs, pMB->field_dct);
378                  DEBUG1("codep: field_dct: ", pMB->field_dct);                  DEBUG1("codep: field_dct: ", pMB->field_dct);
379                    }
380    
381                  // if inter block, write field ME flag                  // if inter block, write field ME flag
382                  if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {                  if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {
# Line 395  Line 401 
401          // code block coeffs          // code block coeffs
402          for (i = 0; i < 6; i++)          for (i = 0; i < 6; i++)
403                  if (pMB->cbp & (1 << (5 - i)))                  if (pMB->cbp & (1 << (5 - i)))
404                          CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[0], 0);                  {
405                            const uint16_t *scan_table =
406                                    frame->global_flags & XVID_ALTERNATESCAN ?
407                                    scan_tables[2] : scan_tables[0];
408    
409                            CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_table, 0);
410                    }
411    
412          bits = BitstreamPos(bs) - bits;          bits = BitstreamPos(bs) - bits;
413          pStat->iTextBits += bits;          pStat->iTextBits += bits;
# Line 411  Line 423 
423                   Statistics * pStat)                   Statistics * pStat)
424  {  {
425    
         int intra = (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q);  
   
426          if (frame->coding_type == P_VOP) {          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  
427                          BitstreamPutBit(bs, 0); // coded                          BitstreamPutBit(bs, 0); // coded
428          }          }
429    
430          if (intra)          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q)
431                  CodeBlockIntra(frame, pMB, qcoeff, bs, pStat);                  CodeBlockIntra(frame, pMB, qcoeff, bs, pStat);
432          else          else
433                  CodeBlockInter(frame, pMB, qcoeff, bs, pStat);                  CodeBlockInter(frame, pMB, qcoeff, bs, pStat);
434    
435  }  }
436    
437    /*
438    // moved to mbcoding.h so that in can be 'static __inline'
439    void
440    MBSkip(Bitstream * bs)
441    {
442            BitstreamPutBit(bs, 1); // not coded
443    }
444    */
445    
446  /***************************************************************  /***************************************************************
447   * bframe encoding start   * bframe encoding start
448   ***************************************************************/   ***************************************************************/
# Line 441  Line 455 
455          3       0001b   forward mc+q            dbquant, mvdf          3       0001b   forward mc+q            dbquant, mvdf
456  */  */
457    
458  void  static __inline void
459  put_bvop_mbtype(Bitstream * bs,  put_bvop_mbtype(Bitstream * bs,
460                                  int value)                                  int value)
461  {  {
462          switch (value) {          switch (value) {
463          case 0:                  case MODE_FORWARD:
                 BitstreamPutBit(bs, 1);  
                 return;  
   
         case 1:  
464                  BitstreamPutBit(bs, 0);                  BitstreamPutBit(bs, 0);
465                  BitstreamPutBit(bs, 1);                  case MODE_BACKWARD:
                 return;  
   
         case 2:  
466                  BitstreamPutBit(bs, 0);                  BitstreamPutBit(bs, 0);
467                    case MODE_INTERPOLATE:
468                  BitstreamPutBit(bs, 0);                  BitstreamPutBit(bs, 0);
469                    case MODE_DIRECT:
470                  BitstreamPutBit(bs, 1);                  BitstreamPutBit(bs, 1);
471                  return;                  default:
472                            break;
         case 3:  
                 BitstreamPutBit(bs, 0);  
                 BitstreamPutBit(bs, 0);  
                 BitstreamPutBit(bs, 0);  
                 BitstreamPutBit(bs, 1);  
                 return;  
   
         default:;                                       // invalid!  
   
473          }          }
   
474  }  }
475    
476  /*  /*
# Line 481  Line 480 
480          +2      11b          +2      11b
481  */  */
482    
483  void  static __inline void
484  put_bvop_dbquant(Bitstream * bs,  put_bvop_dbquant(Bitstream * bs,
485                                   int value)                                   int value)
486  {  {
# Line 512  Line 511 
511                           const int32_t fcode,                           const int32_t fcode,
512                           const int32_t bcode,                           const int32_t bcode,
513                           Bitstream * bs,                           Bitstream * bs,
514                           Statistics * pStat)                           Statistics * pStat,
515                             int direction)
516  {  {
517          int i;          int vcode = fcode;
518            unsigned int i;
519    
520  /*      ------------------------------------------------------------------  /*      ------------------------------------------------------------------
521                  when a block is skipped it is decoded DIRECT(0,)                  when a block is skipped it is decoded DIRECT(0,0)
522                  hence are interpolated from forward & backward frames                  hence is interpolated from forward & backward frames
523          ------------------------------------------------------------------ */          ------------------------------------------------------------------ */
524    
525          if (mb->mode == 5) {          if (mb->mode == MODE_DIRECT_NONE_MV) {
526                  BitstreamPutBit(bs, 1); // skipped                  BitstreamPutBit(bs, 1); // skipped
527                  return;                  return;
528          }          }
# Line 544  Line 545 
545                  put_bvop_dbquant(bs, 0);        // todo: mb->dquant = 0                  put_bvop_dbquant(bs, 0);        // todo: mb->dquant = 0
546          }          }
547    
548          if (mb->mode == MODE_INTERPOLATE || mb->mode == MODE_FORWARD) {          switch (mb->mode) {
549                  CodeVector(bs, mb->pmvs[0].x, fcode, pStat);                  case MODE_INTERPOLATE:
550                  CodeVector(bs, mb->pmvs[0].y, fcode, pStat);                          CodeVector(bs, mb->pmvs[1].x, vcode, pStat); //forward vector of interpolate mode
551          }                          CodeVector(bs, mb->pmvs[1].y, vcode, pStat);
552                    case MODE_BACKWARD:
553          if (mb->mode == MODE_INTERPOLATE || mb->mode == MODE_BACKWARD) {                          vcode = bcode;
554                  CodeVector(bs, mb->b_pmvs[0].x, bcode, pStat);                  case MODE_FORWARD:
555                  CodeVector(bs, mb->b_pmvs[0].y, bcode, pStat);                          CodeVector(bs, mb->pmvs[0].x, vcode, pStat);
556          }                          CodeVector(bs, mb->pmvs[0].y, vcode, pStat);
557                            break;
558          if (mb->mode == MODE_DIRECT) {                  case MODE_DIRECT:
559                  // TODO: direct                          CodeVector(bs, mb->pmvs[3].x, 1, pStat);        // fcode is always 1 for delta vector
560                            CodeVector(bs, mb->pmvs[3].y, 1, pStat);        // prediction is always (0,0)
561                    default: break;
562          }          }
563    
564          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
565                  if (mb->cbp & (1 << (5 - i))) {                  if (mb->cbp & (1 << (5 - i))) {
566                          CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[0], 0);                          CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[direction], 0);
567                  }                  }
568          }          }
569  }  }
# Line 571  Line 574 
574   * decoding stuff starts here                                  *   * decoding stuff starts here                                  *
575   ***************************************************************/   ***************************************************************/
576    
577    
578    // for IVOP addbits == 0
579    // for PVOP addbits == fcode - 1
580    // for BVOP addbits == max(fcode,bcode) - 1
581    // returns true or false
582    int
583    check_resync_marker(Bitstream * bs, int addbits)
584    {
585            uint32_t nbits;
586            uint32_t code;
587            uint32_t nbitsresyncmarker = NUMBITS_VP_RESYNC_MARKER + addbits;
588    
589            nbits = BitstreamNumBitsToByteAlign(bs);
590            code = BitstreamShowBits(bs, nbits);
591    
592            if (code == (((uint32_t)1 << (nbits - 1)) - 1))
593            {
594                    return BitstreamShowBitsFromByteAlign(bs, nbitsresyncmarker) == RESYNC_MARKER;
595            }
596    
597            return 0;
598    }
599    
600    
601    
602  int  int
603  get_mcbpc_intra(Bitstream * bs)  get_mcbpc_intra(Bitstream * bs)
604  {  {
605    
606          uint32_t index;          uint32_t index;
607    
608          while ((index = BitstreamShowBits(bs, 9)) == 1)          index = BitstreamShowBits(bs, 9);
                 BitstreamSkip(bs, 9);  
   
609          index >>= 3;          index >>= 3;
610    
611          BitstreamSkip(bs, mcbpc_intra_table[index].len);          BitstreamSkip(bs, mcbpc_intra_table[index].len);
# Line 594  Line 620 
620    
621          uint32_t index;          uint32_t index;
622    
623          while ((index = CLIP(BitstreamShowBits(bs, 9), 256)) == 1)          index = CLIP(BitstreamShowBits(bs, 9), 256);
                 BitstreamSkip(bs, 9);  
624    
625          BitstreamSkip(bs, mcbpc_inter_table[index].len);          BitstreamSkip(bs, mcbpc_inter_table[index].len);
626    
# Line 621  Line 646 
646    
647  }  }
648    
649  int  static __inline int
650  get_mv_data(Bitstream * bs)  get_mv_data(Bitstream * bs)
651  {  {
652    
# Line 738  Line 763 
763  {  {
764    
765          const uint16_t *scan = scan_tables[direction];          const uint16_t *scan = scan_tables[direction];
766          int level;          int level, run, last;
         int run;  
         int last;  
767    
768          do {          do {
769                  level = get_coeff(bs, &run, &last, 1, 0);                  level = get_coeff(bs, &run, &last, 1, 0);
# Line 750  Line 773 
773                  }                  }
774                  coeff += run;                  coeff += run;
775                  block[scan[coeff]] = level;                  block[scan[coeff]] = level;
776    
777                    DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[coeff], level);
778                    //DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[coeff], level, BitstreamShowBits(bs, 32));
779    
780                  if (level < -127 || level > 127) {                  if (level < -127 || level > 127) {
781                          DEBUG1("warning: intra_overflow", level);                          DEBUG1("warning: intra_overflow", level);
782                  }                  }
# Line 760  Line 787 
787    
788  void  void
789  get_inter_block(Bitstream * bs,  get_inter_block(Bitstream * bs,
790                                  int16_t * block)                                  int16_t * block,
791                                    int direction)
792  {  {
793    
794          const uint16_t *scan = scan_tables[0];          const uint16_t *scan = scan_tables[direction];
795          int p;          int p;
796          int level;          int level;
797          int run;          int run;
# Line 779  Line 807 
807                  p += run;                  p += run;
808    
809                  block[scan[p]] = level;                  block[scan[p]] = level;
810    
811                    DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[p], level);
812                    // DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[p], level, BitstreamShowBits(bs, 32));
813    
814                  if (level < -127 || level > 127) {                  if (level < -127 || level > 127) {
815                          DEBUG1("warning: inter_overflow", level);                          DEBUG1("warning: inter_overflow", level);
816                  }                  }

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.25.2.2

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