[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.37.2.3, Thu Oct 10 12:16:00 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 33  Line 36 
36   *  History:   *  History:
37   *   *
38   *  15.07.2002  fix a bug in B-frame decode at DIRECT mode   *  15.07.2002  fix a bug in B-frame decode at DIRECT mode
39   *              MinChen <chenm001@163.com>  
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 53  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 136  Line 139 
139                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
140          }          }
141    
         if (image_create(&dec->refh, dec->edged_width, dec->edged_height)) {  
                 image_destroy(&dec->cur, dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);  
                 xvid_free(dec);  
                 return XVID_ERR_MEMORY;  
         }  
   
142          dec->mbs =          dec->mbs =
143                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,
144                                          CACHE_LINE);                                          CACHE_LINE);
# Line 153  Line 147 
147                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
148                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
149                  image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);
                 image_destroy(&dec->refh, dec->edged_width, dec->edged_height);  
150                  xvid_free(dec);                  xvid_free(dec);
151                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
152          }          }
# Line 171  Line 164 
164                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
165                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
166                  image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);
                 image_destroy(&dec->refh, dec->edged_width, dec->edged_height);  
167                  xvid_free(dec);                  xvid_free(dec);
168                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
169          }          }
# Line 197  Line 189 
189          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
190          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
191          image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);
         image_destroy(&dec->refh, dec->edged_width, dec->edged_height);  
192          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
193          xvid_free(dec);          xvid_free(dec);
194    
# Line 280  Line 271 
271                  start_timer();                  start_timer();
272                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       // coded
273                  {                  {
274                          int direction = dec->alternate_vertical_scan ?                          get_intra_block(bs, &block[i * 64], pMB->acpred_directions[i],
275                                  2 : pMB->acpred_directions[i];                                                          start_coeff);
   
                         get_intra_block(bs, &block[i * 64], direction, start_coeff);  
276                  }                  }
277                  stop_coding_timer();                  stop_coding_timer();
278    
# Line 370  Line 359 
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;
   
                 start_timer();  
                 if(dec->quarterpel) {  
                         interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,  
                                                                             dec->refh.y + 128, 16*x_pos, 16*y_pos,  
                                                                             pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);  
                 }  
                 else {  
                         interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,  
                                                                   pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);  
                         interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos,  
                                                               pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);  
                         interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8,  
                                                                   pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);  
                         interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8,  
                                                                   pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);  
                 }  
   
                 interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,  
                                                           uv_dx, uv_dy, stride2, rounding);  
                 interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,  
                                                           uv_dx, uv_dy, stride2, rounding);  
                 stop_comp_timer();  
   
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;
# Line 413  Line 378 
378                  }                  }
379    
380                  uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2));                  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) {                  if(dec->quarterpel) {
385                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                  DPRINTF(DPRINTF_DEBUG, "QUARTERPEL\n");
386                                                                            dec->refh.y + 128, 16*x_pos, 16*y_pos,                  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);                                                                            pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);
388                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos,
                                                                           dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,  
389                                                                            pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);                                                                            pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);
390                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8,
                                                                           dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,  
391                                                                            pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);                                                                            pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);
392                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8,
                                                                           dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,  
393                                                                            pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);                                                                            pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);
394                  }                  }
395                  else {                  else {
# Line 445  Line 408 
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,
409                                                            uv_dx, uv_dy, stride2, rounding);                                                            uv_dx, uv_dy, stride2, rounding);
410                  stop_comp_timer();                  stop_comp_timer();
         }  
411    
412          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
                 int direction = dec->alternate_vertical_scan ? 2 : 0;  
   
413                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       // coded
414                  {                  {
415                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
416    
417                          start_timer();                          start_timer();
418                          get_inter_block(bs, &block[i * 64], direction);                          get_inter_block(bs, &block[i * 64]);
419                          stop_coding_timer();                          stop_coding_timer();
420    
421                          start_timer();                          start_timer();
# Line 552  Line 512 
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,
# Line 698  Line 658 
658                                  if (dec->interlacing) {                                  if (dec->interlacing) {
659                                          if (cbp || intra) {                                          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 749  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 919  Line 880 
880          stop_comp_timer();          stop_comp_timer();
881    
882          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
                 int direction = dec->alternate_vertical_scan ? 2 : 0;  
   
883                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       // coded
884                  {                  {
885                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
886    
887                          start_timer();                          start_timer();
888                          get_inter_block(bs, &block[i * 64], direction);                          get_inter_block(bs, &block[i * 64]);
889                          stop_coding_timer();                          stop_coding_timer();
890    
891                          start_timer();                          start_timer();
# Line 1072  Line 1031 
1031          interpolate8x8_switch(dec->refn[2].v, backward.v, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->refn[2].v, backward.v, 8 * x_pos, 8 * y_pos,
1032                                                    b_uv_dx, b_uv_dy, stride2, 0);                                                    b_uv_dx, b_uv_dy, stride2, 0);
1033    
1034          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,          interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos, 16 * y_pos,
1035                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,                                           stride);
1036                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos,          interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos + 8, 16 * y_pos,
1037                                                  stride, 0);                                           stride);
1038            interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos, 16 * y_pos + 8,
1039          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,                                           stride);
1040                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,          interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos + 8,
1041                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8,                                           16 * y_pos + 8, stride);
1042                                                  stride, 0);          interpolate8x8_c(dec->cur.u, dec->refn[2].u, 8 * x_pos, 8 * y_pos,
1043                                             stride2);
1044          interpolate8x8_avg2(dec->cur.y + (16 * (y_pos + 8) * stride) + 16 * x_pos,          interpolate8x8_c(dec->cur.v, dec->refn[2].v, 8 * x_pos, 8 * y_pos,
1045                                                  dec->cur.y + (16 * (y_pos + 8) * stride) + 16 * x_pos,                                           stride2);
                                                 dec->refn[2].y + (16 * (y_pos + 8) * stride) + 16 * x_pos,  
                                                 stride, 0);  
   
         interpolate8x8_avg2(dec->cur.y + (16 * (y_pos + 8) * stride) + 16 * x_pos + 8,  
                                                 dec->cur.y + (16 * (y_pos + 8) * stride) + 16 * x_pos + 8,  
                                                 dec->refn[2].y + (16 * (y_pos + 8) * stride) + 16 * x_pos + 8,  
                                                 stride, 0);  
   
         interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride) + 8 * x_pos,  
                                                 dec->cur.u + (8 * y_pos * stride) + 8 * x_pos,  
                                                 dec->refn[2].u + (8 * y_pos * stride) + 8 * x_pos,  
                                                 stride2, 0);  
   
         interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride) + 8 * x_pos,  
                                                 dec->cur.v + (8 * y_pos * stride) + 8 * x_pos,  
                                                 dec->refn[2].v + (8 * y_pos * stride) + 8 * x_pos,  
                                                 stride2, 0);  
   
1046          stop_comp_timer();          stop_comp_timer();
1047    
1048          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
                 int direction = dec->alternate_vertical_scan ? 2 : 0;  
   
1049                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       // coded
1050                  {                  {
1051                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
1052    
1053                          start_timer();                          start_timer();
1054                          get_inter_block(bs, &block[i * 64], direction);                          get_inter_block(bs, &block[i * 64]);
1055                          stop_coding_timer();                          stop_coding_timer();
1056    
1057                          start_timer();                          start_timer();
# Line 1343  Line 1282 
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 1401  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 1436  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;

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

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