[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.51.2.8, Sun Aug 29 11:36:22 2004 UTC revision 1.57, Fri May 21 14:40:15 2004 UTC
# Line 4  Line 4 
4   *  - Decoder Module -   *  - Decoder Module -
5   *   *
6   *  Copyright(C) 2002      MinChen <chenm001@163.com>   *  Copyright(C) 2002      MinChen <chenm001@163.com>
7   *               2002-2003 Peter Ross <pross@xvid.org>   *               2002-2004 Peter Ross <pross@xvid.org>
8   *   *
9   *  This program is free software ; you can redistribute it and/or modify   *  This program is free software ; you can redistribute it and/or modify
10   *  it under the terms of the GNU General Public License as published by   *  it under the terms of the GNU General Public License as published by
# Line 303  Line 303 
303    
304                  start_timer();                  start_timer();
305                  predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i, &block[i * 64],                  predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i, &block[i * 64],
306                                           iQuant, iDcScaler, predictors, bound);                                           iQuant, iDcScaler, predictors, bound, dec->bs_version);
307                  if (!acpred_flag) {                  if (!acpred_flag) {
308                          pMB->acpred_directions[i] = 0;                          pMB->acpred_directions[i] = 0;
309                  }                  }
# Line 339  Line 339 
339                  stop_coding_timer();                  stop_coding_timer();
340    
341                  start_timer();                  start_timer();
342                  add_acdc(pMB, i, &block[i * 64], iDcScaler, predictors, dec->bs_version);                  add_acdc(pMB, i, &block[i * 64], iDcScaler, predictors);
343                  stop_prediction_timer();                  stop_prediction_timer();
344    
345                  start_timer();                  start_timer();
# Line 460  Line 460 
460          stop_transfer_timer();          stop_transfer_timer();
461  }  }
462    
 static void __inline  
 validate_vector(VECTOR * mv, unsigned int x_pos, unsigned int y_pos, const DECODER * dec)  
 {  
         /* clip a vector to valid range  
            prevents crashes if bitstream is broken  
         */  
         int shift = 5 + dec->quarterpel;  
         int xborder_high = (int)(dec->mb_width - x_pos) << shift;  
         int xborder_low = (-(int)x_pos-1) << shift;  
         int yborder_high = (int)(dec->mb_height - y_pos) << shift;  
         int yborder_low = (-(int)y_pos-1) << shift;  
   
 #define CHECK_MV(mv) \  
         do { \  
         if ((mv).x > xborder_high) { \  
                 DPRINTF(XVID_DEBUG_MV, "mv.x > max -- %d > %d, MB %d, %d", (mv).x, xborder_high, x_pos, y_pos); \  
                 (mv).x = xborder_high; \  
         } else if ((mv).x < xborder_low) { \  
                 DPRINTF(XVID_DEBUG_MV, "mv.x < min -- %d < %d, MB %d, %d", (mv).x, xborder_low, x_pos, y_pos); \  
                 (mv).x = xborder_low; \  
         } \  
         if ((mv).y > yborder_high) { \  
                 DPRINTF(XVID_DEBUG_MV, "mv.y > max -- %d > %d, MB %d, %d", (mv).y, yborder_high, x_pos, y_pos); \  
                 (mv).y = yborder_high; \  
         } else if ((mv).y < yborder_low) { \  
                 DPRINTF(XVID_DEBUG_MV, "mv.y < min -- %d < %d, MB %d, %d", (mv).y, yborder_low, x_pos, y_pos); \  
                 (mv).y = yborder_low; \  
         } \  
         } while (0)  
   
         CHECK_MV(mv[0]);  
         CHECK_MV(mv[1]);  
         CHECK_MV(mv[2]);  
         CHECK_MV(mv[3]);  
 }  
   
463  /* decode an inter macroblock */  /* decode an inter macroblock */
464  static void  static void
465  decoder_mbinter(DECODER * dec,  decoder_mbinter(DECODER * dec,
# Line 533  Line 497 
497                          mv[i] = pMB->mvs[i];                          mv[i] = pMB->mvs[i];
498          }          }
499    
500          validate_vector(mv, x_pos, y_pos, dec);          for (i = 0; i < 4; i++) {
501                    /* clip to valid range */
502                    int border = (int)(dec->mb_width - x_pos) << (5 + dec->quarterpel);
503                    if (mv[i].x > border) {
504                            DPRINTF(XVID_DEBUG_MV, "mv.x > max -- %d > %d, MB %d, %d", mv[i].x, border, x_pos, y_pos);
505                            mv[i].x = border;
506                    } else {
507                            border = (-(int)x_pos-1) << (5 + dec->quarterpel);
508                            if (mv[i].x < border) {
509                                    DPRINTF(XVID_DEBUG_MV, "mv.x < min -- %d < %d, MB %d, %d", mv[i].x, border, x_pos, y_pos);
510                                    mv[i].x = border;
511                            }
512                    }
513    
514                    border = (int)(dec->mb_height - y_pos) << (5 + dec->quarterpel);
515                    if (mv[i].y >  border) {
516                            DPRINTF(XVID_DEBUG_MV, "mv.y > max -- %d > %d, MB %d, %d", mv[i].y, border, x_pos, y_pos);
517                            mv[i].y = border;
518                    } else {
519                            border = (-(int)y_pos-1) << (5 + dec->quarterpel);
520                            if (mv[i].y < border) {
521                                    DPRINTF(XVID_DEBUG_MV, "mv.y < min -- %d < %d, MB %d, %d", mv[i].y, border, x_pos, y_pos);
522                                    mv[i].y = border;
523                            }
524                    }
525            }
526    
527          start_timer();          start_timer();
528    
# Line 826  Line 815 
815                  mb_height = (dec->height + 31) / 32;                  mb_height = (dec->height + 31) / 32;
816          }          }
817    
818            if (!dec->is_edged[0]) {
819          start_timer();          start_timer();
820          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
821                                          dec->width, dec->height, dec->bs_version);                                          dec->width, dec->height, dec->bs_version);
822                    dec->is_edged[0] = 1;
823          stop_edges_timer();          stop_edges_timer();
824            }
825    
826          if (gmc_warp) {          if (gmc_warp) {
827                  /* accuracy: 0==1/2, 1=1/4, 2=1/8, 3=1/16 */                  /* accuracy: 0==1/2, 1=1/4, 2=1/8, 3=1/16 */
# Line 1020  Line 1012 
1012  decoder_bf_interpolate_mbinter(DECODER * dec,  decoder_bf_interpolate_mbinter(DECODER * dec,
1013                                                                  IMAGE forward,                                                                  IMAGE forward,
1014                                                                  IMAGE backward,                                                                  IMAGE backward,
1015                                                                  MACROBLOCK * pMB,                                                                  const MACROBLOCK * pMB,
1016                                                                  const uint32_t x_pos,                                                                  const uint32_t x_pos,
1017                                                                  const uint32_t y_pos,                                                                  const uint32_t y_pos,
1018                                                                  Bitstream * bs,                                                                  Bitstream * bs,
# Line 1037  Line 1029 
1029          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
1030          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
1031    
         validate_vector(pMB->mvs, x_pos, y_pos, dec);  
         validate_vector(pMB->b_mvs, x_pos, y_pos, dec);  
   
1032          if (!direct) {          if (!direct) {
1033                  uv_dx = pMB->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
1034                  uv_dy = pMB->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
# Line 1154  Line 1143 
1143          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1144                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1145                                                  dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos,                                                  dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos,
1146                                                  stride, 0, 8);                                                  stride, 1, 8);
1147    
1148          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1149                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1150                                                  dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos + 8,                                                  dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1151                                                  stride, 0, 8);                                                  stride, 1, 8);
1152    
1153          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1154                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1155                                                  dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,                                                  dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1156                                                  stride, 0, 8);                                                  stride, 1, 8);
1157    
1158          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1159                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1160                                                  dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,                                                  dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1161                                                  stride, 0, 8);                                                  stride, 1, 8);
1162    
1163          interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,          interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1164                                                  dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1165                                                  dec->tmp.u + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->tmp.u + (8 * y_pos * stride2) + 8 * x_pos,
1166                                                  stride2, 0, 8);                                                  stride2, 1, 8);
1167    
1168          interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,          interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1169                                                  dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1170                                                  dec->tmp.v + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->tmp.v + (8 * y_pos * stride2) + 8 * x_pos,
1171                                                  stride2, 0, 8);                                                  stride2, 1, 8);
1172    
1173          stop_comp_timer();          stop_comp_timer();
1174    
# Line 1229  Line 1218 
1218          uint32_t x, y;          uint32_t x, y;
1219          VECTOR mv;          VECTOR mv;
1220          const VECTOR zeromv = {0,0};          const VECTOR zeromv = {0,0};
1221            const int32_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp;
1222          int i;          int i;
1223    
1224            if (!dec->is_edged[0]) {
1225          start_timer();          start_timer();
1226          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
1227                                          dec->width, dec->height, dec->bs_version);                                          dec->width, dec->height, dec->bs_version);
1228                    dec->is_edged[0] = 1;
1229                    stop_edges_timer();
1230            }
1231    
1232            if (!dec->is_edged[1]) {
1233                    start_timer();
1234          image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height,
1235                                          dec->width, dec->height, dec->bs_version);                                          dec->width, dec->height, dec->bs_version);
1236                    dec->is_edged[1] = 1;
1237          stop_edges_timer();          stop_edges_timer();
1238            }
1239    
1240          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < dec->mb_height; y++) {
1241                  /* Initialize Pred Motion Vector */                  /* Initialize Pred Motion Vector */
# Line 1323  Line 1322 
1322    
1323                          case MODE_DIRECT_NONE_MV:                          case MODE_DIRECT_NONE_MV:
1324                                  for (i = 0; i < 4; i++) {                                  for (i = 0; i < 4; i++) {
1325                                          mb->mvs[i].x = last_mb->mvs[i].x*dec->time_bp/dec->time_pp + mv.x;                                          mb->mvs[i].x = (int32_t) ((TRB * last_mb->mvs[i].x) / TRD + mv.x);
1326                                          mb->mvs[i].y = last_mb->mvs[i].y*dec->time_bp/dec->time_pp + mv.y;                                          mb->b_mvs[i].x = (int32_t) ((mv.x == 0)
1327                                                                            ? ((TRB - TRD) * last_mb->mvs[i].x) / TRD
1328                                          mb->b_mvs[i].x = (mv.x)                                                                          : mb->mvs[i].x - last_mb->mvs[i].x);
1329                                                  ?  mb->mvs[i].x - last_mb->mvs[i].x                                          mb->mvs[i].y = (int32_t) ((TRB * last_mb->mvs[i].y) / TRD + mv.y);
1330                                                  : last_mb->mvs[i].x*(dec->time_bp - dec->time_pp)/dec->time_pp;                                          mb->b_mvs[i].y = (int32_t) ((mv.y == 0)
1331                                          mb->b_mvs[i].y = (mv.y)                                                                          ? ((TRB - TRD) * last_mb->mvs[i].y) / TRD
1332                                                  ? mb->mvs[i].y - last_mb->mvs[i].y                                                                          : mb->mvs[i].y - last_mb->mvs[i].y);
                                                 : last_mb->mvs[i].y*(dec->time_bp - dec->time_pp)/dec->time_pp;  
1333                                  }                                  }
1334    
1335                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
# Line 1375  Line 1373 
1373                                          xvid_dec_frame_t * frame, xvid_dec_stats_t * stats,                                          xvid_dec_frame_t * frame, xvid_dec_stats_t * stats,
1374                                          int coding_type, int quant)                                          int coding_type, int quant)
1375  {  {
1376            const int brightness = XVID_VERSION_MINOR(frame->version) >= 1 ? frame->brightness : 0;
1377    
1378          if (dec->cartoon_mode)          if (dec->cartoon_mode)
1379                  frame->general &= ~XVID_FILMEFFECT;                  frame->general &= ~XVID_FILMEFFECT;
1380    
1381          if (frame->general & (XVID_DEBLOCKY|XVID_DEBLOCKUV|XVID_FILMEFFECT) && mbs != NULL)     /* post process */          if ((frame->general & (XVID_DEBLOCKY|XVID_DEBLOCKUV|XVID_FILMEFFECT) || brightness!=0)
1382                    && mbs != NULL) /* post process */
1383          {          {
1384                  /* note: image is stored to tmp */                  /* note: image is stored to tmp */
1385                  image_copy(&dec->tmp, img, dec->edged_width, dec->height);                  image_copy(&dec->tmp, img, dec->edged_width, dec->height);
1386                  image_postproc(&dec->postproc, &dec->tmp, dec->edged_width,                  image_postproc(&dec->postproc, &dec->tmp, dec->edged_width,
1387                                             mbs, dec->mb_width, dec->mb_height, dec->mb_width,                                             mbs, dec->mb_width, dec->mb_height, dec->mb_width,
1388                                             frame->general, dec->frames, (coding_type == B_VOP));                                             frame->general, brightness, dec->frames, (coding_type == B_VOP));
1389                  img = &dec->tmp;                  img = &dec->tmp;
1390          }          }
1391    
# Line 1407  Line 1408 
1408          }          }
1409  }  }
1410    
1411    
1412  int  int
1413  decoder_decode(DECODER * dec,  decoder_decode(DECODER * dec,
1414                                  xvid_dec_frame_t * frame, xvid_dec_stats_t * stats)                                  xvid_dec_frame_t * frame, xvid_dec_stats_t * stats)
# Line 1557  Line 1559 
1559                  }                  }
1560    
1561                  image_swap(&dec->refn[0], &dec->refn[1]);                  image_swap(&dec->refn[0], &dec->refn[1]);
1562                    dec->is_edged[1] = dec->is_edged[0];
1563                  image_swap(&dec->cur, &dec->refn[0]);                  image_swap(&dec->cur, &dec->refn[0]);
1564                    dec->is_edged[0] = 0;
1565                  SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs);                  SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs);
1566                  dec->last_reduced_resolution = reduced_resolution;                  dec->last_reduced_resolution = reduced_resolution;
1567                  dec->last_coding_type = coding_type;                  dec->last_coding_type = coding_type;
# Line 1569  Line 1573 
1573    
1574                  if (dec->low_delay) {                  if (dec->low_delay) {
1575                          DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n");                          DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n");
1576                          dec->low_delay = 0;                          dec->low_delay = 1;
1577                  }                  }
1578    
1579                  if (dec->frames < 2) {                  if (dec->frames < 2) {

Legend:
Removed from v.1.51.2.8  
changed lines
  Added in v.1.57

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