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

Diff of /xvidcore/src/decoder.c

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

revision 1.28, Fri Jul 12 00:49:59 2002 UTC revision 1.42, Sat Oct 19 12:20:33 2002 UTC
# Line 3  Line 3 
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  -  Decoder main module  -   *  -  Decoder main module  -
5   *   *
6     *  Copyright(C) 2002 MinChen <chenm001@163.com>
7     *               2002 Peter Ross <pross@xvid.org>
8     *
9   *  This program is an implementation of a part of one or more MPEG-4   *  This program is an implementation of a part of one or more MPEG-4
10   *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending   *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
11   *  to use this software module in hardware or software products are   *  to use this software module in hardware or software products are
# Line 32  Line 35 
35   *   *
36   *  History:   *  History:
37   *   *
38     *  15.07.2002  fix a bug in B-frame decode at DIRECT mode
39    
40   *  10.07.2002  added BFRAMES_DEC_DEBUG support   *  10.07.2002  added BFRAMES_DEC_DEBUG support
41   *              Fix a little bug for low_delay flage   *              Fix a little bug for low_delay flage
42   *              MinChen <chenm001@163.com>   *              MinChen <chenm001@163.com>
# Line 51  Line 56 
56   *  26.03.2002  interlacing support - moved transfers outside decode loop   *  26.03.2002  interlacing support - moved transfers outside decode loop
57   *  26.12.2001  decoder_mbinter: dequant/idct moved within if(coded) block   *  26.12.2001  decoder_mbinter: dequant/idct moved within if(coded) block
58   *  22.12.2001  lock based interpolation   *  22.12.2001  lock based interpolation
59   *  01.12.2001  inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>   *  01.12.2001  inital version; (c)2001 peter ross <pross@xvid.org>
60   *   *
61   *  $Id$   *  $Id$
62   *   *
# Line 346  Line 351 
351                  uv_dx = pMB->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
352                  uv_dy = pMB->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
353    
354                    if (dec->quarterpel)
355                    {
356                            uv_dx = (uv_dx >> 1) | (uv_dx & 1);
357                            uv_dy = (uv_dy >> 1) | (uv_dy & 1);
358                    }
359    
360                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;
361                  uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;                  uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;
362          } else {          } else {
363                  int sum;                  int sum;
   
364                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;
365                  uv_dx =  
366                          (sum ==                  if (dec->quarterpel)
367                           0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +                  {
368                                                                    (ABS(sum) / 16) * 2));                          sum /= 2;
369                    }
370    
371                    uv_dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2));
372    
373                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
374                  uv_dy =  
375                          (sum ==                  if (dec->quarterpel)
376                           0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +                  {
377                                                                    (ABS(sum) / 16) * 2));                          sum /= 2;
378                    }
379    
380                    uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2));
381          }          }
382    
383          start_timer();          start_timer();
384            if(dec->quarterpel) {
385                    DPRINTF(DPRINTF_DEBUG, "QUARTERPEL\n");
386                    interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,
387                                                                      pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);
388                    interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos,
389                                                                      pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);
390                    interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8,
391                                                                      pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);
392                    interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8,
393                                                                      pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);
394            }
395            else {
396          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos, 16 * y_pos,          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos, 16 * y_pos,
397                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding);                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding);
398          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos + 8,                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos,
399                                                    16 * y_pos, pMB->mvs[1].x, pMB->mvs[1].y, stride,                                                            pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);
400                                                    rounding);                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8,
401          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos,                                                            pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);
402                                                    16 * y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride,                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8,
403                                                    rounding);                                                            pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);
404          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos + 8,          }
405                                                    16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride,  
                                                   rounding);  
406          interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,
407                                                    uv_dx, uv_dy, stride2, rounding);                                                    uv_dx, uv_dy, stride2, rounding);
408          interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,
# Line 478  Line 505 
505                                  }                                  }
506                          }                          }
507                          mb->quant = quant;                          mb->quant = quant;
508                            mb->mvs[0].x = mb->mvs[0].y =
509                            mb->mvs[1].x = mb->mvs[1].y =
510                            mb->mvs[2].x = mb->mvs[2].y =
511                            mb->mvs[3].x = mb->mvs[3].y =0;
512    
513                          if (dec->interlacing) {                          if (dec->interlacing) {
514                                  mb->field_dct = BitstreamGetBit(bs);                                  mb->field_dct = BitstreamGetBit(bs);
515                                  DEBUG1("deci: field_dct: ", mb->field_dct);                                  DPRINTF(DPRINTF_DEBUG, "deci: field_dct: %d", mb->field_dct);
516                          }                          }
517    
518                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
519                                                          intra_dc_threshold, bound);                                                          intra_dc_threshold, bound);
520                  }                  }
521                    if(dec->out_frm)
522                      output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,dec->mb_width);
523    
524          }          }
525    
526  }  }
# Line 550  Line 584 
584    
585          uint32_t x, y;          uint32_t x, y;
586          uint32_t bound;          uint32_t bound;
587            int cp_mb, st_mb;
588    
589          start_timer();          start_timer();
590          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
591                                     dec->width, dec->height, dec->interlacing);                                     dec->width, dec->height);
592          stop_edges_timer();          stop_edges_timer();
593    
594          bound = 0;          bound = 0;
595    
596          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < dec->mb_height; y++) {
597                    cp_mb = st_mb = 0;
598                  for (x = 0; x < dec->mb_width; x++) {                  for (x = 0; x < dec->mb_width; x++) {
599                          MACROBLOCK *mb;                          MACROBLOCK *mb;
600    
# Line 586  Line 622 
622                                  uint32_t cbp;                                  uint32_t cbp;
623                                  uint32_t intra;                                  uint32_t intra;
624    
625                                    cp_mb++;
626                                  mcbpc = get_mcbpc_inter(bs);                                  mcbpc = get_mcbpc_inter(bs);
627                                  mb->mode = mcbpc & 7;                                  mb->mode = mcbpc & 7;
628                                  cbpc = (mcbpc >> 4);                                  cbpc = (mcbpc >> 4);
# Line 619  Line 656 
656                                  mb->quant = quant;                                  mb->quant = quant;
657    
658                                  if (dec->interlacing) {                                  if (dec->interlacing) {
659                                            if (cbp || intra) {
660                                          mb->field_dct = BitstreamGetBit(bs);                                          mb->field_dct = BitstreamGetBit(bs);
661                                          DEBUG1("decp: field_dct: ", mb->field_dct);                                                  DPRINTF(DPRINTF_DEBUG, "decp: field_dct: %d", mb->field_dct);
662                                            }
663    
664                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
665                                                  mb->field_pred = BitstreamGetBit(bs);                                                  mb->field_pred = BitstreamGetBit(bs);
666                                                  DEBUG1("decp: field_pred: ", mb->field_pred);                                                  DPRINTF(DPRINTF_DEBUG, "decp: field_pred: %d", mb->field_pred);
667    
668                                                  if (mb->field_pred) {                                                  if (mb->field_pred) {
669                                                          mb->field_for_top = BitstreamGetBit(bs);                                                          mb->field_for_top = BitstreamGetBit(bs);
670                                                          DEBUG1("decp: field_for_top: ", mb->field_for_top);                                                          DPRINTF(DPRINTF_DEBUG, "decp: field_for_top: %d", mb->field_for_top);
671                                                          mb->field_for_bot = BitstreamGetBit(bs);                                                          mb->field_for_bot = BitstreamGetBit(bs);
672                                                          DEBUG1("decp: field_for_bot: ", mb->field_for_bot);                                                          DPRINTF(DPRINTF_DEBUG, "decp: field_for_bot: %d", mb->field_for_bot);
673                                                  }                                                  }
674                                          }                                          }
675                                  }                                  }
# Line 649  Line 688 
688                                                  mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =                                                  mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =
689                                                          mb->mvs[0].y;                                                          mb->mvs[0].y;
690                                          }                                          }
691                                  } else if (mb->mode ==                                  } else if (mb->mode == MODE_INTER4V ) {
692                                                     MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */ ) {  
693                                          get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound);                                          get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound);
694                                          get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode, bound);                                          get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode, bound);
695                                          get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode, bound);                                          get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode, bound);
# Line 670  Line 709 
709                                                                  rounding);                                                                  rounding);
710                          } else                          // not coded                          } else                          // not coded
711                          {                          {
712                                  //DEBUG2("P-frame MB at (X,Y)=",x,y);                                  DPRINTF(DPRINTF_DEBUG, "P-frame MB at (X,Y)=(%d,%d)", x, y);
713    
714                                  mb->mode = MODE_NOT_CODED;                                  mb->mode = MODE_NOT_CODED;
715                                  mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0;                                  mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0;
716                                  mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0;                                  mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0;
# Line 712  Line 752 
752                                                                   dec->refn[0].v +                                                                   dec->refn[0].v +
753                                                                   (8 * y) * dec->edged_width / 2 + (8 * x),                                                                   (8 * y) * dec->edged_width / 2 + (8 * x),
754                                                                   dec->edged_width / 2);                                                                   dec->edged_width / 2);
   
755                                  stop_transfer_timer();                                  stop_transfer_timer();
756                                    if(dec->out_frm && cp_mb > 0) {
757                                      output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb);
758                                      cp_mb = 0;
759                          }                          }
760                                    st_mb = x+1;
761                  }                  }
762          }          }
763                    if(dec->out_frm && cp_mb > 0)
764                      output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb);
765            }
766  }  }
767    
768    
# Line 793  Line 839 
839          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
840          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
841    
842    
843          if (!(pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) {          if (!(pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) {
844                  uv_dx = pMB->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
845                  uv_dy = pMB->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
# Line 886  Line 933 
933                                                             const MACROBLOCK * pMB,                                                             const MACROBLOCK * pMB,
934                                                             const uint32_t x_pos,                                                             const uint32_t x_pos,
935                                                             const uint32_t y_pos,                                                             const uint32_t y_pos,
                                                            const uint32_t cbp,  
936                                                             Bitstream * bs)                                                             Bitstream * bs)
937  {  {
938    
# Line 901  Line 947 
947          int b_uv_dx, b_uv_dy;          int b_uv_dx, b_uv_dy;
948          uint32_t i;          uint32_t i;
949          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
950        const uint32_t cbp = pMB->cbp;
951    
952          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
953          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
954          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
955    
956    
957          if ((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) {          if ((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) {
958                  uv_dx = pMB->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
959                  uv_dy = pMB->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
# Line 995  Line 1043 
1043                                           stride2);                                           stride2);
1044          interpolate8x8_c(dec->cur.v, dec->refn[2].v, 8 * x_pos, 8 * y_pos,          interpolate8x8_c(dec->cur.v, dec->refn[2].v, 8 * x_pos, 8 * y_pos,
1045                                           stride2);                                           stride2);
   
1046          stop_comp_timer();          stop_comp_timer();
1047    
1048          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
# Line 1086  Line 1133 
1133                             int fcode_forward,                             int fcode_forward,
1134                             int fcode_backward)                             int fcode_backward)
1135  {  {
   
1136          uint32_t x, y;          uint32_t x, y;
1137          VECTOR mv, zeromv;          VECTOR mv;
1138            const VECTOR zeromv = {0,0};
1139  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
1140          FILE *fp;          FILE *fp;
1141          static char first=0;          static char first=0;
# Line 1099  Line 1146 
1146    
1147          start_timer();          start_timer();
1148          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
1149                                     dec->width, dec->height, dec->interlacing);                                     dec->width, dec->height);
1150          //image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, dec->width, dec->height, dec->interlacing);          image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height,
1151                                       dec->width, dec->height);
1152          stop_edges_timer();          stop_edges_timer();
1153    
1154  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
# Line 1111  Line 1159 
1159    
1160          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < dec->mb_height; y++) {
1161                  // Initialize Pred Motion Vector                  // Initialize Pred Motion Vector
1162                  dec->p_fmv.x = dec->p_fmv.y = dec->p_bmv.x = dec->p_bmv.y = 0;                  dec->p_fmv = dec->p_bmv = zeromv;
1163                  for (x = 0; x < dec->mb_width; x++) {                  for (x = 0; x < dec->mb_width; x++) {
1164                          MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x];                          MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x];
1165                          MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x];                          MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x];
1166    
1167                          mb->mvs[0].x = mb->mvs[0].y = zeromv.x = zeromv.y = mv.x = mv.y = 0;                          mv =
1168                            mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] =
1169                            mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv;
1170    
1171                          // the last P_VOP is skip macroblock ?                          // the last P_VOP is skip macroblock ?
1172                          if (last_mb->mode == MODE_NOT_CODED) {                          if (last_mb->mode == MODE_NOT_CODED) {
1173                                  //DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y);                                  //DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y);
                                 mb->mb_type = MODE_NOT_CODED;  
1174                                  mb->cbp = 0;                                  mb->cbp = 0;
1175  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
1176                                    mb->mb_type = MODE_NOT_CODED;
1177          BFRAME_DEBUG          BFRAME_DEBUG
1178  #endif  #endif
1179                                  mb->mb_type = MODE_FORWARD;                                  mb->mb_type = MODE_FORWARD;
1180                                  mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x;                                  mb->quant = last_mb->quant;
1181                                  mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y;                                  //mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x;
1182                                  mb->quant = 8;                                  //mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y;
1183    
1184                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1);                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, mb->quant, 1);
1185                                  continue;                                  continue;
1186                          }                          }
                         //t=BitstreamShowBits(bs,32);  
1187    
1188                          if (!BitstreamGetBit(bs)) {     // modb=='0'                          if (!BitstreamGetBit(bs)) {     // modb=='0'
1189                                  const uint8_t modb2 = BitstreamGetBit(bs);                                  const uint8_t modb2 = BitstreamGetBit(bs);
# Line 1154  Line 1203 
1203                                          } else if (quant < 1) {                                          } else if (quant < 1) {
1204                                                  quant = 1;                                                  quant = 1;
1205                                          }                                          }
                                 } else {  
                                         quant = 8;  
1206                                  }                                  }
                                 mb->quant = quant;  
1207                          } else {                          } else {
1208                                  mb->mb_type = MODE_DIRECT_NONE_MV;                                  mb->mb_type = MODE_DIRECT_NONE_MV;
1209                                  mb->cbp = 0;                                  mb->cbp = 0;
1210                          }                          }
1211    
1212                          mb->mode = MODE_INTER;                          mb->quant = quant;
1213                            mb->mode = MODE_INTER4V;
1214                          //DEBUG1("Switch bm_type=",mb->mb_type);                          //DEBUG1("Switch bm_type=",mb->mb_type);
1215    
1216  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
1217          BFRAME_DEBUG          BFRAME_DEBUG
1218  #endif  #endif
1219    
1220                          switch (mb->mb_type) {                          switch (mb->mb_type) {
1221                          case MODE_DIRECT:                          case MODE_DIRECT:
1222                                  get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], 1, zeromv);                                  get_b_motion_vector(dec, bs, x, y, &mv, 1, zeromv);
1223    
1224                          case MODE_DIRECT_NONE_MV:                          case MODE_DIRECT_NONE_MV:
1225                                  {                               // Because this file is a C file not C++ so I use '{' to define var                                  {
1226                                          const int64_t TRB = dec->time_pp - dec->time_bp, TRD =                                          const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp;
                                                 dec->time_pp;  
1227                                          int i;                                          int i;
1228    
1229                                          for (i = 0; i < 4; i++) {                                          for (i = 0; i < 4; i++) {
1230                                                  mb->mvs[i].x =                                                  mb->mvs[i].x = (int32_t) ((TRB * last_mb->mvs[i].x)
1231                                                          (int32_t) ((TRB * last_mb->mvs[i].x) / TRD +                                                                        / TRD + mv.x);
1232                                                                             mb->mvs[0].x);                                                  mb->b_mvs[i].x = (int32_t) ((mv.x == 0)
1233                                                  mb->b_mvs[i].x =                                                                                  ? ((TRB - TRD) * last_mb->mvs[i].x)
1234                                                          (int32_t) ((mb->mvs[0].x ==                                                                                    / TRD
1235                                                                                  0) ? ((TRB -                                                                                  : mb->mvs[i].x - last_mb->mvs[i].x);
1236                                                                                             TRD) * last_mb->mvs[i].x) /                                                  mb->mvs[i].y = (int32_t) ((TRB * last_mb->mvs[i].y)
1237                                                                             TRD : mb->mvs[i].x - last_mb->mvs[i].x);                                                                        / TRD + mv.y);
1238                                                  mb->mvs[i].y =                                                  mb->b_mvs[i].y = (int32_t) ((mv.y == 0)
1239                                                          (int32_t) ((TRB * last_mb->mvs[i].y) / TRD +                                                                                  ? ((TRB - TRD) * last_mb->mvs[i].y)
1240                                                                             mb->mvs[0].y);                                                                                    / TRD
1241                                                  mb->b_mvs[i].y =                                                                              : mb->mvs[i].y - last_mb->mvs[i].y);
                                                         (int32_t) ((mb->mvs[0].y ==  
                                                                                 0) ? ((TRB -  
                                                                                            TRD) * last_mb->mvs[i].y) /  
                                                                            TRD : mb->mvs[i].y - last_mb->mvs[i].y);  
1242                                          }                                          }
1243                                          //DEBUG("B-frame Direct!\n");                                          //DEBUG("B-frame Direct!\n");
1244                                  }                                  }
                                 mb->mode = MODE_INTER4V;  
1245                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
1246                                                                                             mb, x, y, mb->cbp, bs);                                                                                             mb, x, y, bs);
1247                                  break;                                  break;
1248    
1249                          case MODE_INTERPOLATE:                          case MODE_INTERPOLATE:
1250                                  get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_forward,                                  get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_forward,
1251                                                                          dec->p_fmv);                                                                          dec->p_fmv);
1252                                  dec->p_fmv.x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x =                                  dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
                                         mb->mvs[0].x;  
                                 dec->p_fmv.y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =  
                                         mb->mvs[0].y;  
1253    
1254                                  get_b_motion_vector(dec, bs, x, y, &mb->b_mvs[0],                                  get_b_motion_vector(dec, bs, x, y, &mb->b_mvs[0],
1255                                                                          fcode_backward, dec->p_bmv);                                                                          fcode_backward, dec->p_bmv);
1256                                  dec->p_bmv.x = mb->b_mvs[1].x = mb->b_mvs[2].x =                                  dec->p_bmv = mb->b_mvs[1] = mb->b_mvs[2] =
1257                                          mb->b_mvs[3].x = mb->b_mvs[0].x;                                          mb->b_mvs[3] = mb->b_mvs[0];
                                 dec->p_bmv.y = mb->b_mvs[1].y = mb->b_mvs[2].y =  
                                         mb->b_mvs[3].y = mb->b_mvs[0].y;  
1258    
1259                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
1260                                                                                             mb, x, y, mb->cbp, bs);                                                                                             mb, x, y, bs);
1261                                  //DEBUG("B-frame Bidir!\n");                                  //DEBUG("B-frame Bidir!\n");
1262                                  break;                                  break;
1263    
1264                          case MODE_BACKWARD:                          case MODE_BACKWARD:
1265                                  get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_backward,                                  get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_backward,
1266                                                                          dec->p_bmv);                                                                          dec->p_bmv);
1267                                  dec->p_bmv.x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x =                                  dec->p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
                                         mb->mvs[0].x;  
                                 dec->p_bmv.y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =  
                                         mb->mvs[0].y;  
1268    
1269                                    mb->mode = MODE_INTER;
1270                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0);                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0);
1271                                  //DEBUG("B-frame Backward!\n");                                  //DEBUG("B-frame Backward!\n");
1272                                  break;                                  break;
# Line 1239  Line 1274 
1274                          case MODE_FORWARD:                          case MODE_FORWARD:
1275                                  get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_forward,                                  get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_forward,
1276                                                                          dec->p_fmv);                                                                          dec->p_fmv);
1277                                  dec->p_fmv.x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x =                                  dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
                                         mb->mvs[0].x;  
                                 dec->p_fmv.y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =  
                                         mb->mvs[0].y;  
1278    
1279                                    mb->mode = MODE_INTER;
1280                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1);                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1);
1281                                  //DEBUG("B-frame Forward!\n");                                  //DEBUG("B-frame Forward!\n");
1282                                  break;                                  break;
1283    
1284                          default:                          default:
1285                                  //DEBUG1("Not support B-frame mb_type =", mb->mb_type);                                  DPRINTF(DPRINTF_ERROR, "Not support B-frame mb_type = %d", mb->mb_type);
                                 ;  
1286                          }                          }
1287    
1288                  }                                               // end of FOR                  }                                               // end of FOR
# Line 1290  Line 1322 
1322    
1323          start_global_timer();          start_global_timer();
1324    
1325            dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL;
1326    
1327          BitstreamInit(&bs, frame->bitstream, frame->length);          BitstreamInit(&bs, frame->bitstream, frame->length);
1328    
1329          // add by chenm001 <chenm001@163.com>          // add by chenm001 <chenm001@163.com>
# Line 1306  Line 1340 
1340                  decoder_pframe(dec, &bs, rounding, quant, fcode_forward,                  decoder_pframe(dec, &bs, rounding, quant, fcode_forward,
1341                                             intra_dc_threshold);                                             intra_dc_threshold);
1342  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1343                  DEBUG1("P_VOP  Time=", dec->time);                  DPRINTF(DPRINTF_DEBUG, "P_VOP  Time=%d", dec->time);
1344  #endif  #endif
1345                  break;                  break;
1346    
1347          case I_VOP:          case I_VOP:
1348                  decoder_iframe(dec, &bs, quant, intra_dc_threshold);                  decoder_iframe(dec, &bs, quant, intra_dc_threshold);
1349  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1350                  DEBUG1("I_VOP  Time=", dec->time);                  DPRINTF(DPRINTF_DEBUG, "I_VOP  Time=%d", dec->time);
1351  #endif  #endif
1352                  break;                  break;
1353    
1354          case B_VOP:          case B_VOP:
1355  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1356                  if (dec->time_pp > dec->time_bp) {                  if (dec->time_pp > dec->time_bp) {
1357                          DEBUG1("B_VOP  Time=", dec->time);                          DPRINTF(DPRINTF_DEBUG, "B_VOP  Time=%d", dec->time);
1358                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);
1359                  } else {                  } else {
1360                          DEBUG("broken B-frame!");                          DPRINTF(DPRINTF_DEBUG, "Broken B_VOP");
1361                  }                  }
1362  #else  #else
1363                  image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);                  image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);
# Line 1341  Line 1375 
1375    
1376  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
1377          if (frame->length != BitstreamPos(&bs) / 8){          if (frame->length != BitstreamPos(&bs) / 8){
1378                  DEBUG2("InLen/UseLen",frame->length, BitstreamPos(&bs) / 8);                  DPRINTF(DPRINTF_DEBUG, "InLen: %d / UseLen: %d", frame->length, BitstreamPos(&bs) / 8);
1379          }          }
1380  #endif  #endif
1381          frame->length = BitstreamPos(&bs) / 8;          frame->length = BitstreamPos(&bs) / 8;
# Line 1349  Line 1383 
1383    
1384  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1385          // test if no B_VOP          // test if no B_VOP
1386          if (dec->low_delay) {          if (dec->low_delay || dec->frames == 0) {
1387  #endif  #endif
1388          image_output(&dec->cur, dec->width, dec->height, dec->edged_width,          image_output(&dec->cur, dec->width, dec->height, dec->edged_width,
1389                                           frame->image, frame->stride, frame->colorspace);                                           frame->image, frame->stride, frame->colorspace);
1390    
1391  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1392          } else {          } else {
1393                  if (dec->frames >= 0) {                  if (dec->frames >= 1) {
1394                          start_timer();                          start_timer();
1395                          if ((vop_type == I_VOP || vop_type == P_VOP)) {                          if ((vop_type == I_VOP || vop_type == P_VOP)) {
1396                                  image_output(&dec->refn[0], dec->width, dec->height,                                  image_output(&dec->refn[0], dec->width, dec->height,
# Line 1375  Line 1409 
1409          if (vop_type == I_VOP || vop_type == P_VOP) {          if (vop_type == I_VOP || vop_type == P_VOP) {
1410                  image_swap(&dec->refn[0], &dec->refn[1]);                  image_swap(&dec->refn[0], &dec->refn[1]);
1411                  image_swap(&dec->cur, &dec->refn[0]);                  image_swap(&dec->cur, &dec->refn[0]);
1412    
1413                  // swap MACROBLOCK                  // swap MACROBLOCK
1414                  if (!dec->low_delay && vop_type == P_VOP)                  // the Divx will not set the low_delay flage some times
1415                    // so follow code will wrong to not swap at that time
1416                    // this will broken bitstream! so I'm change it,
1417                    // But that is not the best way! can anyone tell me how
1418                    // to do another way?
1419                    // 18-07-2002   MinChen<chenm001@163.com>
1420                    //if (!dec->low_delay && vop_type == P_VOP)
1421                    if (vop_type == P_VOP)
1422                          mb_swap(&dec->mbs, &dec->last_mbs);                          mb_swap(&dec->mbs, &dec->last_mbs);
1423          }          }
1424    

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.42

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