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

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

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

revision 1038, Thu May 22 16:36:07 2003 UTC revision 1053, Mon Jun 9 01:25:19 2003 UTC
# Line 88  Line 88 
88          const int code2 = sprite_trajectory_len[len].code;          const int code2 = sprite_trajectory_len[len].code;
89          const int len2 = sprite_trajectory_len[len].len;          const int len2 = sprite_trajectory_len[len].len;
90    
91  //      printf("GMC=%d Code/Len  = %d / %d ",val, code,len);  #if 0
92  //      printf("Code2 / Len2 = %d / %d \n",code2,len2);          printf("GMC=%d Code/Len  = %d / %d ",val, code,len);
93            printf("Code2 / Len2 = %d / %d \n",code2,len2);
94    #endif
95    
96          BitstreamPutBits(bs, code2, len2);          BitstreamPutBits(bs, code2, len2);
97          if (len) BitstreamPutBits(bs, code, len);          if (len) BitstreamPutBits(bs, code, len);
# Line 648  Line 650 
650    
651          cbpy = pMB->cbp >> 2;          cbpy = pMB->cbp >> 2;
652    
653          // write mcbpc          /* write mcbpc */
654          if (frame->coding_type == I_VOP) {          if (frame->coding_type == I_VOP) {
655                  mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2);                  mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2);
656                  BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code,                  BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code,
# Line 659  Line 661 
661                                                   mcbpc_inter_tab[mcbpc].len);                                                   mcbpc_inter_tab[mcbpc].len);
662          }          }
663    
664          // ac prediction flag          /* ac prediction flag */
665          if (pMB->acpred_directions[0])          if (pMB->acpred_directions[0])
666                  BitstreamPutBits(bs, 1, 1);                  BitstreamPutBits(bs, 1, 1);
667          else          else
668                  BitstreamPutBits(bs, 0, 1);                  BitstreamPutBits(bs, 0, 1);
669    
670          // write cbpy          /* write cbpy */
671          BitstreamPutBits(bs, xvid_cbpy_tab[cbpy].code, xvid_cbpy_tab[cbpy].len);          BitstreamPutBits(bs, xvid_cbpy_tab[cbpy].code, xvid_cbpy_tab[cbpy].len);
672    
673          // write dquant          /* write dquant */
674          if (pMB->mode == MODE_INTRA_Q)          if (pMB->mode == MODE_INTRA_Q)
675                  BitstreamPutBits(bs, DQ_VALUE2INDEX(pMB->dquant), 2);                  BitstreamPutBits(bs, DQ_VALUE2INDEX(pMB->dquant), 2);
676    
677          // write interlacing          /* write interlacing */
678          if (frame->vol_flags & XVID_VOL_INTERLACING) {          if (frame->vol_flags & XVID_VOL_INTERLACING) {
679                  BitstreamPutBit(bs, pMB->field_dct);                  BitstreamPutBit(bs, pMB->field_dct);
680          }          }
681          // code block coeffs          /* code block coeffs */
682          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
683                  if (i < 4)                  if (i < 4)
684                          BitstreamPutBits(bs, dcy_tab[qcoeff[i * 64 + 0] + 255].code,                          BitstreamPutBits(bs, dcy_tab[qcoeff[i * 64 + 0] + 255].code,
# Line 720  Line 722 
722          mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);          mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);
723          cbpy = 15 - (pMB->cbp >> 2);          cbpy = 15 - (pMB->cbp >> 2);
724    
725          // write mcbpc          /* write mcbpc */
726          BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code,          BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code,
727                                           mcbpc_inter_tab[mcbpc].len);                                           mcbpc_inter_tab[mcbpc].len);
728    
729          if ( (frame->coding_type == S_VOP) && (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) )          if ( (frame->coding_type == S_VOP) && (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) )
730                  BitstreamPutBit(bs, pMB->mcsel);                // mcsel: '0'=local motion, '1'=GMC                  BitstreamPutBit(bs, pMB->mcsel);                /* mcsel: '0'=local motion, '1'=GMC */
731    
732          // write cbpy          /* write cbpy */
733          BitstreamPutBits(bs, xvid_cbpy_tab[cbpy].code, xvid_cbpy_tab[cbpy].len);          BitstreamPutBits(bs, xvid_cbpy_tab[cbpy].code, xvid_cbpy_tab[cbpy].len);
734    
735          // write dquant          /* write dquant */
736          if (pMB->mode == MODE_INTER_Q)          if (pMB->mode == MODE_INTER_Q)
737                  BitstreamPutBits(bs, DQ_VALUE2INDEX(pMB->dquant), 2);                  BitstreamPutBits(bs, DQ_VALUE2INDEX(pMB->dquant), 2);
738    
739          // interlacing          /* interlacing */
740          if (frame->vol_flags & XVID_VOL_INTERLACING) {          if (frame->vol_flags & XVID_VOL_INTERLACING) {
741                  if (pMB->cbp) {                  if (pMB->cbp) {
742                          BitstreamPutBit(bs, pMB->field_dct);                          BitstreamPutBit(bs, pMB->field_dct);
743                          DPRINTF(XVID_DEBUG_MB,"codep: field_dct: %i\n", pMB->field_dct);                          DPRINTF(XVID_DEBUG_MB,"codep: field_dct: %i\n", pMB->field_dct);
744                  }                  }
745    
746                  // if inter block, write field ME flag                  /* if inter block, write field ME flag */
747                  if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {                  if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {
748                          BitstreamPutBit(bs, pMB->field_pred);                          BitstreamPutBit(bs, pMB->field_pred);
749                          DPRINTF(XVID_DEBUG_MB,"codep: field_pred: %i\n", pMB->field_pred);                          DPRINTF(XVID_DEBUG_MB,"codep: field_pred: %i\n", pMB->field_pred);
750    
751                          // write field prediction references                          /* write field prediction references */
752                          if (pMB->field_pred) {                          if (pMB->field_pred) {
753                                  BitstreamPutBit(bs, pMB->field_for_top);                                  BitstreamPutBit(bs, pMB->field_for_top);
754                                  BitstreamPutBit(bs, pMB->field_for_bot);                                  BitstreamPutBit(bs, pMB->field_for_bot);
755                          }                          }
756                  }                  }
757          }          }
758          // code motion vector(s) if motion is local          /* code motion vector(s) if motion is local  */
759          if (!pMB->mcsel)          if (!pMB->mcsel)
760                  for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) {                  for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) {
761                          CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat);                          CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat);
# Line 762  Line 764 
764    
765          bits = BitstreamPos(bs);          bits = BitstreamPos(bs);
766    
767          // code block coeffs          /* code block coeffs */
768          for (i = 0; i < 6; i++)          for (i = 0; i < 6; i++)
769                  if (pMB->cbp & (1 << (5 - i)))                  if (pMB->cbp & (1 << (5 - i)))
770                  {                  {
# Line 790  Line 792 
792                   Statistics * pStat)                   Statistics * pStat)
793  {  {
794          if (frame->coding_type != I_VOP)          if (frame->coding_type != I_VOP)
795                          BitstreamPutBit(bs, 0); // not_coded                          BitstreamPutBit(bs, 0); /* not_coded */
796    
797          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q)          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q)
798                  CodeBlockIntra(frame, pMB, qcoeff, bs, pStat);                  CodeBlockIntra(frame, pMB, qcoeff, bs, pStat);
# Line 799  Line 801 
801    
802  }  }
803    
804  /*  
805  // moved to mbcoding.h so that in can be 'static __inline'  /* moved to mbcoding.h so that in can be 'static __inline' */
806    #if 0
807  void  void
808  MBSkip(Bitstream * bs)  MBSkip(Bitstream * bs)
809  {  {
810          BitstreamPutBit(bs, 1); // not coded          BitstreamPutBit(bs, 1); /* not coded */
811  }  }
812  */  #endif
813    
814  /***************************************************************  /***************************************************************
815   * bframe encoding start   * bframe encoding start
# Line 864  Line 867 
867                  BitstreamPutBit(bs, 1);                  BitstreamPutBit(bs, 1);
868                  return;                  return;
869    
870          default:;                                       // invalid          default:;                                       /* invalid */
871          }          }
872  }  }
873    
# Line 888  Line 891 
891          ------------------------------------------------------------------ */          ------------------------------------------------------------------ */
892    
893          if (mb->mode == MODE_DIRECT_NONE_MV) {          if (mb->mode == MODE_DIRECT_NONE_MV) {
894                  BitstreamPutBit(bs, 1); // skipped                  BitstreamPutBit(bs, 1); /* skipped */
895                  return;                  return;
896          }          }
897    
898          BitstreamPutBit(bs, 0);         // not skipped          BitstreamPutBit(bs, 0);         /* not skipped */
899    
900          if (mb->cbp == 0) {          if (mb->cbp == 0) {
901                  BitstreamPutBit(bs, 1); // cbp == 0                  BitstreamPutBit(bs, 1); /* cbp == 0 */
902          } else {          } else {
903                  BitstreamPutBit(bs, 0); // cbp == xxx                  BitstreamPutBit(bs, 0); /* cbp == xxx */
904          }          }
905    
906          put_bvop_mbtype(bs, mb->mode);          put_bvop_mbtype(bs, mb->mode);
# Line 907  Line 910 
910          }          }
911    
912          if (mb->mode != MODE_DIRECT && mb->cbp != 0) {          if (mb->mode != MODE_DIRECT && mb->cbp != 0) {
913                  put_bvop_dbquant(bs, 0);        // todo: mb->dquant = 0                  put_bvop_dbquant(bs, 0);        /* todo: mb->dquant = 0 */
914          }          }
915    
916          switch (mb->mode) {          switch (mb->mode) {
917                  case MODE_INTERPOLATE:                  case MODE_INTERPOLATE:
918                          CodeVector(bs, mb->pmvs[1].x, vcode, pStat); //forward vector of interpolate mode                          CodeVector(bs, mb->pmvs[1].x, vcode, pStat); /* forward vector of interpolate mode */
919                          CodeVector(bs, mb->pmvs[1].y, vcode, pStat);                          CodeVector(bs, mb->pmvs[1].y, vcode, pStat);
920                  case MODE_BACKWARD:                  case MODE_BACKWARD:
921                          vcode = bcode;                          vcode = bcode;
# Line 921  Line 924 
924                          CodeVector(bs, mb->pmvs[0].y, vcode, pStat);                          CodeVector(bs, mb->pmvs[0].y, vcode, pStat);
925                          break;                          break;
926                  case MODE_DIRECT:                  case MODE_DIRECT:
927                          CodeVector(bs, mb->pmvs[3].x, 1, pStat);        // fcode is always 1 for delta vector                          CodeVector(bs, mb->pmvs[3].x, 1, pStat);        /* fcode is always 1 for delta vector */
928                          CodeVector(bs, mb->pmvs[3].y, 1, pStat);        // prediction is always (0,0)                          CodeVector(bs, mb->pmvs[3].y, 1, pStat);        /* prediction is always (0,0) */
929                  default: break;                  default: break;
930          }          }
931    
# Line 944  Line 947 
947   ***************************************************************/   ***************************************************************/
948    
949    
950  // for IVOP addbits == 0  /*
951  // for PVOP addbits == fcode - 1   * for IVOP addbits == 0
952  // for BVOP addbits == max(fcode,bcode) - 1   * for PVOP addbits == fcode - 1
953  // returns true or false   * for BVOP addbits == max(fcode,bcode) - 1
954     * returns true or false
955     */
956  int  int
957  check_resync_marker(Bitstream * bs, int addbits)  check_resync_marker(Bitstream * bs, int addbits)
958  {  {
# Line 1225  Line 1230 
1230                  block[scan[coeff]] = level;                  block[scan[coeff]] = level;
1231    
1232                  DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i\n", scan[coeff], level);                  DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i\n", scan[coeff], level);
1233                  //DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i %08x\n", scan[coeff], level, BitstreamShowBits(bs, 32));  #if 0
1234                    DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i %08x\n", scan[coeff], level, BitstreamShowBits(bs, 32));
1235    #endif
1236    
1237                  if (level < -2047 || level > 2047) {                  if (level < -2047 || level > 2047) {
1238                          DPRINTF(XVID_DEBUG_ERROR,"warning: intra_overflow %i\n", level);                          DPRINTF(XVID_DEBUG_ERROR,"warning: intra_overflow %i\n", level);
# Line 1259  Line 1266 
1266                  block[scan[p]] = level;                  block[scan[p]] = level;
1267    
1268                  DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i\n", scan[p], level);                  DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i\n", scan[p], level);
1269                  // DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i %08x\n", scan[p], level, BitstreamShowBits(bs, 32));                  /* DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i %08x\n", scan[p], level, BitstreamShowBits(bs, 32)); */
1270    
1271                  if (level < -2047 || level > 2047) {                  if (level < -2047 || level > 2047) {
1272                          DPRINTF(XVID_DEBUG_ERROR,"warning: inter overflow %i\n", level);                          DPRINTF(XVID_DEBUG_ERROR,"warning: inter overflow %i\n", level);

Legend:
Removed from v.1038  
changed lines
  Added in v.1053

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