[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.49.2.24, Wed Dec 10 15:07:42 2003 UTC revision 1.51.2.8, Sun Aug 29 11:36:22 2004 UTC
# Line 77  Line 77 
77                  xvid_free(dec->last_mbs);                  xvid_free(dec->last_mbs);
78          if (dec->mbs)          if (dec->mbs)
79                  xvid_free(dec->mbs);                  xvid_free(dec->mbs);
80            if (dec->qscale)
81                    xvid_free(dec->qscale);
82    
83          /* realloc */          /* realloc */
84          dec->mb_width = (dec->width + 15) / 16;          dec->mb_width = (dec->width + 15) / 16;
# Line 161  Line 163 
163    
164          memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);          memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);
165    
166            /* nothing happens if that fails */
167            dec->qscale =
168                    xvid_malloc(sizeof(int) * dec->mb_width * dec->mb_height, CACHE_LINE);
169    
170            if (dec->qscale)
171                    memset(dec->qscale, 0, sizeof(int) * dec->mb_width * dec->mb_height);
172    
173          return 0;          return 0;
174  }  }
175    
# Line 200  Line 209 
209          /* image based GMC */          /* image based GMC */
210          image_null(&dec->gmc);          image_null(&dec->gmc);
211    
   
212          dec->mbs = NULL;          dec->mbs = NULL;
213          dec->last_mbs = NULL;          dec->last_mbs = NULL;
214            dec->qscale = NULL;
215    
216          init_timer();          init_timer();
217            init_postproc(&dec->postproc);
218          init_mpeg_matrix(dec->mpeg_quant_matrices);          init_mpeg_matrix(dec->mpeg_quant_matrices);
219    
220          /* For B-frame support (used to save reference frame's time */          /* For B-frame support (used to save reference frame's time */
# Line 212  Line 222 
222          dec->time = dec->time_base = dec->last_time_base = 0;          dec->time = dec->time_base = dec->last_time_base = 0;
223          dec->low_delay = 0;          dec->low_delay = 0;
224          dec->packed_mode = 0;          dec->packed_mode = 0;
225            dec->time_inc_resolution = 1; /* until VOL header says otherwise */
226    
227          dec->fixed_dimensions = (dec->width > 0 && dec->height > 0);          dec->fixed_dimensions = (dec->width > 0 && dec->height > 0);
228    
# Line 227  Line 238 
238  {  {
239          xvid_free(dec->last_mbs);          xvid_free(dec->last_mbs);
240          xvid_free(dec->mbs);          xvid_free(dec->mbs);
241            xvid_free(dec->qscale);
242    
243          /* image based GMC */          /* image based GMC */
244          image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);          image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);
# Line 327  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);                  add_acdc(pMB, i, &block[i * 64], iDcScaler, predictors, dec->bs_version);
343                  stop_prediction_timer();                  stop_prediction_timer();
344    
345                  start_timer();                  start_timer();
# Line 448  Line 460 
460          stop_transfer_timer();          stop_transfer_timer();
461  }  }
462    
463    static void __inline
464    validate_vector(VECTOR * mv, unsigned int x_pos, unsigned int y_pos, const DECODER * dec)
465    {
466            /* clip a vector to valid range
467               prevents crashes if bitstream is broken
468            */
469            int shift = 5 + dec->quarterpel;
470            int xborder_high = (int)(dec->mb_width - x_pos) << shift;
471            int xborder_low = (-(int)x_pos-1) << shift;
472            int yborder_high = (int)(dec->mb_height - y_pos) << shift;
473            int yborder_low = (-(int)y_pos-1) << shift;
474    
475    #define CHECK_MV(mv) \
476            do { \
477            if ((mv).x > xborder_high) { \
478                    DPRINTF(XVID_DEBUG_MV, "mv.x > max -- %d > %d, MB %d, %d", (mv).x, xborder_high, x_pos, y_pos); \
479                    (mv).x = xborder_high; \
480            } else if ((mv).x < xborder_low) { \
481                    DPRINTF(XVID_DEBUG_MV, "mv.x < min -- %d < %d, MB %d, %d", (mv).x, xborder_low, x_pos, y_pos); \
482                    (mv).x = xborder_low; \
483            } \
484            if ((mv).y > yborder_high) { \
485                    DPRINTF(XVID_DEBUG_MV, "mv.y > max -- %d > %d, MB %d, %d", (mv).y, yborder_high, x_pos, y_pos); \
486                    (mv).y = yborder_high; \
487            } else if ((mv).y < yborder_low) { \
488                    DPRINTF(XVID_DEBUG_MV, "mv.y < min -- %d < %d, MB %d, %d", (mv).y, yborder_low, x_pos, y_pos); \
489                    (mv).y = yborder_low; \
490            } \
491            } while (0)
492    
493            CHECK_MV(mv[0]);
494            CHECK_MV(mv[1]);
495            CHECK_MV(mv[2]);
496            CHECK_MV(mv[3]);
497    }
498    
499  /* decode an inter macroblock */  /* decode an inter macroblock */
500  static void  static void
501  decoder_mbinter(DECODER * dec,  decoder_mbinter(DECODER * dec,
# Line 485  Line 533 
533                          mv[i] = pMB->mvs[i];                          mv[i] = pMB->mvs[i];
534          }          }
535    
536            validate_vector(mv, x_pos, y_pos, dec);
537    
538          start_timer();          start_timer();
539    
540          if (pMB->mode != MODE_INTER4V) { /* INTER, INTER_Q, NOT_CODED, FORWARD, BACKWARD */          if (pMB->mode != MODE_INTER4V) { /* INTER, INTER_Q, NOT_CODED, FORWARD, BACKWARD */
# Line 778  Line 828 
828    
829          start_timer();          start_timer();
830          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
831                                          dec->width, dec->height);                                          dec->width, dec->height, dec->bs_version);
832          stop_edges_timer();          stop_edges_timer();
833    
834          if (gmc_warp) {          if (gmc_warp) {
# Line 850  Line 900 
900                                  mb->quant = quant;                                  mb->quant = quant;
901    
902                                  if (dec->interlacing) {                                  if (dec->interlacing) {
903                                          if ((cbp || intra) && !mcsel) {                                          if (cbp || intra) {
904                                                  mb->field_dct = BitstreamGetBit(bs);                                                  mb->field_dct = BitstreamGetBit(bs);
905                                                  DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct);                                                  DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct);
906                                          }                                          }
907    
908                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                          if ((mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) && !mcsel) {
909                                                  mb->field_pred = BitstreamGetBit(bs);                                                  mb->field_pred = BitstreamGetBit(bs);
910                                                  DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred);                                                  DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred);
911    
# Line 899  Line 949 
949    
950                          } else if (gmc_warp) {  /* a not coded S(GMC)-VOP macroblock */                          } else if (gmc_warp) {  /* a not coded S(GMC)-VOP macroblock */
951                                  mb->mode = MODE_NOT_CODED_GMC;                                  mb->mode = MODE_NOT_CODED_GMC;
952                                    mb->quant = quant;
953                                  decoder_mbgmc(dec, mb, x, y, fcode, 0x00, bs, rounding);                                  decoder_mbgmc(dec, mb, x, y, fcode, 0x00, bs, rounding);
954    
955                                  if(dec->out_frm && cp_mb > 0) {                                  if(dec->out_frm && cp_mb > 0) {
# Line 908  Line 959 
959                                  st_mb = x+1;                                  st_mb = x+1;
960                          } else {        /* not coded P_VOP macroblock */                          } else {        /* not coded P_VOP macroblock */
961                                  mb->mode = MODE_NOT_CODED;                                  mb->mode = MODE_NOT_CODED;
962                                    mb->quant = quant;
963    
964                                  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;
965                                  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 934  Line 986 
986  get_b_motion_vector(Bitstream * bs,  get_b_motion_vector(Bitstream * bs,
987                                          VECTOR * mv,                                          VECTOR * mv,
988                                          int fcode,                                          int fcode,
989                                          const VECTOR pmv)                                          const VECTOR pmv,
990                                            const DECODER * const dec,
991                                            const int x, const int y)
992  {  {
993          const int scale_fac = 1 << (fcode - 1);          const int scale_fac = 1 << (fcode - 1);
994          const int high = (32 * scale_fac) - 1;          const int high = (32 * scale_fac) - 1;
# Line 966  Line 1020 
1020  decoder_bf_interpolate_mbinter(DECODER * dec,  decoder_bf_interpolate_mbinter(DECODER * dec,
1021                                                                  IMAGE forward,                                                                  IMAGE forward,
1022                                                                  IMAGE backward,                                                                  IMAGE backward,
1023                                                                  const MACROBLOCK * pMB,                                                                  MACROBLOCK * pMB,
1024                                                                  const uint32_t x_pos,                                                                  const uint32_t x_pos,
1025                                                                  const uint32_t y_pos,                                                                  const uint32_t y_pos,
1026                                                                  Bitstream * bs,                                                                  Bitstream * bs,
# Line 983  Line 1037 
1037          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
1038          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
1039    
1040            validate_vector(pMB->mvs, x_pos, y_pos, dec);
1041            validate_vector(pMB->b_mvs, x_pos, y_pos, dec);
1042    
1043          if (!direct) {          if (!direct) {
1044                  uv_dx = pMB->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
1045                  uv_dy = pMB->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
# Line 1049  Line 1106 
1106                                                          pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);                                                          pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
1107                  interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos + 8,                  interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos + 8,
1108                                                          pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);                                                          pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
1109                  interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8,                  interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, 16 * y_pos + 8,
1110                                                          16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);                                                          pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);
1111          }          }
1112    
1113          interpolate8x8_switch(dec->cur.u, forward.u, 8 * x_pos, 8 * y_pos, uv_dx,          interpolate8x8_switch(dec->cur.u, forward.u, 8 * x_pos, 8 * y_pos, uv_dx,
# Line 1097  Line 1154 
1154          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1155                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1156                                                  dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos,                                                  dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos,
1157                                                  stride, 1, 8);                                                  stride, 0, 8);
1158    
1159          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,
1160                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1161                                                  dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos + 8,                                                  dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1162                                                  stride, 1, 8);                                                  stride, 0, 8);
1163    
1164          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,
1165                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1166                                                  dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,                                                  dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1167                                                  stride, 1, 8);                                                  stride, 0, 8);
1168    
1169          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,
1170                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1171                                                  dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,                                                  dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1172                                                  stride, 1, 8);                                                  stride, 0, 8);
1173    
1174          interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,          interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1175                                                  dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1176                                                  dec->tmp.u + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->tmp.u + (8 * y_pos * stride2) + 8 * x_pos,
1177                                                  stride2, 1, 8);                                                  stride2, 0, 8);
1178    
1179          interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,          interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1180                                                  dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1181                                                  dec->tmp.v + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->tmp.v + (8 * y_pos * stride2) + 8 * x_pos,
1182                                                  stride2, 1, 8);                                                  stride2, 0, 8);
1183    
1184          stop_comp_timer();          stop_comp_timer();
1185    
# Line 1172  Line 1229 
1229          uint32_t x, y;          uint32_t x, y;
1230          VECTOR mv;          VECTOR mv;
1231          const VECTOR zeromv = {0,0};          const VECTOR zeromv = {0,0};
         const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp;  
1232          int i;          int i;
1233    
1234          start_timer();          start_timer();
1235          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
1236                                          dec->width, dec->height);                                          dec->width, dec->height, dec->bs_version);
1237          image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height,
1238                                          dec->width, dec->height);                                          dec->width, dec->height, dec->bs_version);
1239          stop_edges_timer();          stop_edges_timer();
1240    
1241          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < dec->mb_height; y++) {
# Line 1263  Line 1319 
1319    
1320                          switch (mb->mode) {                          switch (mb->mode) {
1321                          case MODE_DIRECT:                          case MODE_DIRECT:
1322                                  get_b_motion_vector(bs, &mv, 1, zeromv);                                  get_b_motion_vector(bs, &mv, 1, zeromv, dec, x, y);
1323    
1324                          case MODE_DIRECT_NONE_MV:                          case MODE_DIRECT_NONE_MV:
1325                                  for (i = 0; i < 4; i++) {                                  for (i = 0; i < 4; i++) {
1326                                          mb->mvs[i].x = (int32_t) ((TRB * last_mb->mvs[i].x) / TRD + mv.x);                                          mb->mvs[i].x = last_mb->mvs[i].x*dec->time_bp/dec->time_pp + mv.x;
1327                                          mb->b_mvs[i].x = (int32_t) ((mv.x == 0)                                          mb->mvs[i].y = last_mb->mvs[i].y*dec->time_bp/dec->time_pp + mv.y;
1328                                                                          ? ((TRB - TRD) * last_mb->mvs[i].x) / TRD  
1329                                                                          : mb->mvs[i].x - last_mb->mvs[i].x);                                          mb->b_mvs[i].x = (mv.x)
1330                                          mb->mvs[i].y = (int32_t) ((TRB * last_mb->mvs[i].y) / TRD + mv.y);                                                  ?  mb->mvs[i].x - last_mb->mvs[i].x
1331                                          mb->b_mvs[i].y = (int32_t) ((mv.y == 0)                                                  : last_mb->mvs[i].x*(dec->time_bp - dec->time_pp)/dec->time_pp;
1332                                                                          ? ((TRB - TRD) * last_mb->mvs[i].y) / TRD                                          mb->b_mvs[i].y = (mv.y)
1333                                                                          : mb->mvs[i].y - last_mb->mvs[i].y);                                                  ? mb->mvs[i].y - last_mb->mvs[i].y
1334                                                    : last_mb->mvs[i].y*(dec->time_bp - dec->time_pp)/dec->time_pp;
1335                                  }                                  }
1336    
1337                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
# Line 1282  Line 1339 
1339                                  break;                                  break;
1340    
1341                          case MODE_INTERPOLATE:                          case MODE_INTERPOLATE:
1342                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv);                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv, dec, x, y);
1343                                  dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];                                  dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
1344    
1345                                  get_b_motion_vector(bs, &mb->b_mvs[0], fcode_backward, dec->p_bmv);                                  get_b_motion_vector(bs, &mb->b_mvs[0], fcode_backward, dec->p_bmv, dec, x, y);
1346                                  dec->p_bmv = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = mb->b_mvs[0];                                  dec->p_bmv = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = mb->b_mvs[0];
1347    
1348                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
# Line 1293  Line 1350 
1350                                  break;                                  break;
1351    
1352                          case MODE_BACKWARD:                          case MODE_BACKWARD:
1353                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_backward, dec->p_bmv);                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_backward, dec->p_bmv, dec, x, y);
1354                                  dec->p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];                                  dec->p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
1355    
1356                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 0);                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 0);
1357                                  break;                                  break;
1358    
1359                          case MODE_FORWARD:                          case MODE_FORWARD:
1360                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv);                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv, dec, x, y);
1361                                  dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];                                  dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
1362    
1363                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 1);                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 1);
# Line 1315  Line 1372 
1372    
1373  /* perform post processing if necessary, and output the image */  /* perform post processing if necessary, and output the image */
1374  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,
1375                                          xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type)                                          xvid_dec_frame_t * frame, xvid_dec_stats_t * stats,
1376                                            int coding_type, int quant)
1377  {  {
1378          if (frame->general & (XVID_DEBLOCKY|XVID_DEBLOCKUV))    /* post process */          if (dec->cartoon_mode)
1379                    frame->general &= ~XVID_FILMEFFECT;
1380    
1381            if (frame->general & (XVID_DEBLOCKY|XVID_DEBLOCKUV|XVID_FILMEFFECT) && mbs != NULL)     /* post process */
1382          {          {
1383                  /* note: image is stored to tmp */                  /* note: image is stored to tmp */
1384                  image_copy(&dec->tmp, img, dec->edged_width, dec->height);                  image_copy(&dec->tmp, img, dec->edged_width, dec->height);
1385                  image_deblock(&dec->tmp, dec->edged_width,                  image_postproc(&dec->postproc, &dec->tmp, dec->edged_width,
1386                                            mbs, dec->mb_width, dec->mb_height, dec->mb_width,                                            mbs, dec->mb_width, dec->mb_height, dec->mb_width,
1387                                            frame->general);                                             frame->general, dec->frames, (coding_type == B_VOP));
1388                  img = &dec->tmp;                  img = &dec->tmp;
1389          }          }
1390    
# Line 1335  Line 1396 
1396                  stats->type = coding2type(coding_type);                  stats->type = coding2type(coding_type);
1397                  stats->data.vop.time_base = (int)dec->time_base;                  stats->data.vop.time_base = (int)dec->time_base;
1398                  stats->data.vop.time_increment = 0;     /* XXX: todo */                  stats->data.vop.time_increment = 0;     /* XXX: todo */
1399                    stats->data.vop.qscale_stride = dec->mb_width;
1400                    stats->data.vop.qscale = dec->qscale;
1401                    if (stats->data.vop.qscale != NULL && mbs != NULL) {
1402                            int i;
1403                            for (i = 0; i < dec->mb_width*dec->mb_height; i++)
1404                                    stats->data.vop.qscale[i] = mbs[i].quant;
1405                    } else
1406                            stats->data.vop.qscale = NULL;
1407          }          }
1408  }  }
1409    
   
1410  int  int
1411  decoder_decode(DECODER * dec,  decoder_decode(DECODER * dec,
1412                                  xvid_dec_frame_t * frame, xvid_dec_stats_t * stats)                                  xvid_dec_frame_t * frame, xvid_dec_stats_t * stats)
# Line 1347  Line 1415 
1415          Bitstream bs;          Bitstream bs;
1416          uint32_t rounding;          uint32_t rounding;
1417          uint32_t reduced_resolution;          uint32_t reduced_resolution;
1418          uint32_t quant;          uint32_t quant = 2;
1419          uint32_t fcode_forward;          uint32_t fcode_forward;
1420          uint32_t fcode_backward;          uint32_t fcode_backward;
1421          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
# Line 1370  Line 1438 
1438                  /* if not decoding "low_delay/packed", and this isn't low_delay and                  /* if not decoding "low_delay/packed", and this isn't low_delay and
1439                          we have a reference frame, then outout the reference frame */                          we have a reference frame, then outout the reference frame */
1440                  if (!(dec->low_delay_default && dec->packed_mode) && !dec->low_delay && dec->frames>0) {                  if (!(dec->low_delay_default && dec->packed_mode) && !dec->low_delay && dec->frames>0) {
1441                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant);
1442                          dec->frames = 0;                          dec->frames = 0;
1443                          ret = 0;                          ret = 0;
1444                  } else {                  } else {
# Line 1435  Line 1503 
1503                  goto repeat;                  goto repeat;
1504          }          }
1505    
1506            if(dec->frames == 0 && coding_type != I_VOP) {
1507                    /* 1st frame is not an i-vop */
1508                    goto repeat;
1509            }
1510    
1511          dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0;  /* init pred vector to 0 */          dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0;  /* init pred vector to 0 */
1512    
1513          /* packed_mode: special-N_VOP treament */          /* packed_mode: special-N_VOP treament */
1514          if (dec->packed_mode && coding_type == N_VOP) {          if (dec->packed_mode && coding_type == N_VOP) {
1515                  if (dec->low_delay_default && dec->frames > 0) {                  if (dec->low_delay_default && dec->frames > 0) {
1516                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant);
1517                          output = 1;                          output = 1;
1518                  }                  }
1519                  /* ignore otherwise */                  /* ignore otherwise */
# Line 1474  Line 1547 
1547                  /* note: for packed_mode, output is performed when the special-N_VOP is decoded */                  /* note: for packed_mode, output is performed when the special-N_VOP is decoded */
1548                  if (!(dec->low_delay_default && dec->packed_mode)) {                  if (!(dec->low_delay_default && dec->packed_mode)) {
1549                          if (dec->low_delay) {                          if (dec->low_delay) {
1550                                  decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);                                  decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type, quant);
1551                                  output = 1;                                  output = 1;
1552                          } else if (dec->frames > 0)     { /* is the reference frame valid? */                          } else if (dec->frames > 0)     { /* is the reference frame valid? */
1553                                  /* output the reference frame */                                  /* output the reference frame */
1554                                  decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);                                  decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant);
1555                                  output = 1;                                  output = 1;
1556                          }                          }
1557                  }                  }
# Line 1496  Line 1569 
1569    
1570                  if (dec->low_delay) {                  if (dec->low_delay) {
1571                          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");
1572                          dec->low_delay = 1;                          dec->low_delay = 0;
1573                  }                  }
1574    
1575                  if (dec->frames < 2) {                  if (dec->frames < 2) {
1576                          /* attemping to decode a bvop without atleast 2 reference frames */                          /* attemping to decode a bvop without atleast 2 reference frames */
1577                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
1578                                                  "broken b-frame, mising ref frames");                                                  "broken b-frame, mising ref frames");
1579                          stats->type = XVID_TYPE_NOTHING;                          if (stats) stats->type = XVID_TYPE_NOTHING;
1580                  } else if (dec->time_pp <= dec->time_bp) {                  } else if (dec->time_pp <= dec->time_bp) {
1581                          /* this occurs when dx50_bvop_compatibility==0 sequences are                          /* this occurs when dx50_bvop_compatibility==0 sequences are
1582                          decoded in vfw. */                          decoded in vfw. */
1583                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
1584                                                  "broken b-frame, tpp=%i tbp=%i", dec->time_pp, dec->time_bp);                                                  "broken b-frame, tpp=%i tbp=%i", dec->time_pp, dec->time_bp);
1585                          stats->type = XVID_TYPE_NOTHING;                          if (stats) stats->type = XVID_TYPE_NOTHING;
1586                  } else {                  } else {
1587                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);
1588                          decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);                          decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type, quant);
1589                  }                  }
1590    
1591                  output = 1;                  output = 1;
1592                  dec->frames++;                  dec->frames++;
1593          }          }
1594    
1595    #if 0 /* Avoids to read to much data because of 32bit reads in our BS functions */
1596          BitstreamByteAlign(&bs);          BitstreamByteAlign(&bs);
1597    #endif
1598    
1599          /* low_delay_default mode: repeat in packed_mode */          /* low_delay_default mode: repeat in packed_mode */
1600          if (dec->low_delay_default && dec->packed_mode && output == 0 && success == 0) {          if (dec->low_delay_default && dec->packed_mode && output == 0 && success == 0) {
# Line 1534  Line 1609 
1609          if (dec->low_delay_default && output == 0) {          if (dec->low_delay_default && output == 0) {
1610                  if (dec->packed_mode && seen_something) {                  if (dec->packed_mode && seen_something) {
1611                          /* output the recently decoded frame */                          /* output the recently decoded frame */
1612                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant);
1613                  } else {                  } else {
1614                          image_clear(&dec->cur, dec->width, dec->height, dec->edged_width, 0, 128, 128);                          image_clear(&dec->cur, dec->width, dec->height, dec->edged_width, 0, 128, 128);
1615                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
# Line 1542  Line 1617 
1617                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,
1618                                  "bframe decoder lag");                                  "bframe decoder lag");
1619    
1620                          decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP);                          decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP, quant);
1621                          if (stats) stats->type = XVID_TYPE_NOTHING;                          if (stats) stats->type = XVID_TYPE_NOTHING;
1622                  }                  }
1623          }          }
# Line 1550  Line 1625 
1625          emms();          emms();
1626          stop_global_timer();          stop_global_timer();
1627    
1628          return BitstreamPos(&bs) / 8;   /* number of bytes consumed */          return (BitstreamPos(&bs) + 7) / 8;     /* number of bytes consumed */
1629  }  }

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

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