[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.28, Sun Dec 21 19:41:53 2003 UTC revision 1.51.2.1, Sun Apr 11 08:11:09 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);          init_postproc(&dec->postproc);
# Line 228  Line 237 
237  {  {
238          xvid_free(dec->last_mbs);          xvid_free(dec->last_mbs);
239          xvid_free(dec->mbs);          xvid_free(dec->mbs);
240            xvid_free(dec->qscale);
241    
242          /* image based GMC */          /* image based GMC */
243          image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);          image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);
# Line 486  Line 496 
496                          mv[i] = pMB->mvs[i];                          mv[i] = pMB->mvs[i];
497          }          }
498    
499            for (i = 0; i < 4; i++) {
500                    /* clip to valid range */
501                    int border = (int)(dec->mb_width - x_pos) << (5 + dec->quarterpel);
502                    if (mv[i].x > border) {
503                            DPRINTF(XVID_DEBUG_MV, "mv.x > max -- %d > %d, MB %d, %d", mv[i].x, border, x_pos, y_pos);
504                            mv[i].x = border;
505                    } else {
506                            border = (-(int)x_pos-1) << (5 + dec->quarterpel);
507                            if (mv[i].x < border) {
508                                    DPRINTF(XVID_DEBUG_MV, "mv.x < min -- %d < %d, MB %d, %d", mv[i].x, border, x_pos, y_pos);
509                                    mv[i].x = border;
510                            }
511                    }
512    
513                    border = (int)(dec->mb_height - y_pos) << (5 + dec->quarterpel);
514                    if (mv[i].y >  border) {
515                            DPRINTF(XVID_DEBUG_MV, "mv.y > max -- %d > %d, MB %d, %d", mv[i].y, border, x_pos, y_pos);
516                            mv[i].y = border;
517                    } else {
518                            border = (-(int)y_pos-1) << (5 + dec->quarterpel);
519                            if (mv[i].y < border) {
520                                    DPRINTF(XVID_DEBUG_MV, "mv.y < min -- %d < %d, MB %d, %d", mv[i].y, border, x_pos, y_pos);
521                                    mv[i].y = border;
522                            }
523                    }
524            }
525    
526          start_timer();          start_timer();
527    
528          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 779  Line 816 
816    
817          start_timer();          start_timer();
818          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
819                                          dec->width, dec->height);                                          dec->width, dec->height, dec->bs_version);
820          stop_edges_timer();          stop_edges_timer();
821    
822          if (gmc_warp) {          if (gmc_warp) {
# Line 851  Line 888 
888                                  mb->quant = quant;                                  mb->quant = quant;
889    
890                                  if (dec->interlacing) {                                  if (dec->interlacing) {
891                                          if ((cbp || intra) && !mcsel) {                                          if (cbp || intra) {
892                                                  mb->field_dct = BitstreamGetBit(bs);                                                  mb->field_dct = BitstreamGetBit(bs);
893                                                  DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct);                                                  DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct);
894                                          }                                          }
895    
896                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                          if ((mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) && !mcsel) {
897                                                  mb->field_pred = BitstreamGetBit(bs);                                                  mb->field_pred = BitstreamGetBit(bs);
898                                                  DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred);                                                  DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred);
899    
# Line 900  Line 937 
937    
938                          } else if (gmc_warp) {  /* a not coded S(GMC)-VOP macroblock */                          } else if (gmc_warp) {  /* a not coded S(GMC)-VOP macroblock */
939                                  mb->mode = MODE_NOT_CODED_GMC;                                  mb->mode = MODE_NOT_CODED_GMC;
940                                    mb->quant = quant;
941                                  decoder_mbgmc(dec, mb, x, y, fcode, 0x00, bs, rounding);                                  decoder_mbgmc(dec, mb, x, y, fcode, 0x00, bs, rounding);
942    
943                                  if(dec->out_frm && cp_mb > 0) {                                  if(dec->out_frm && cp_mb > 0) {
# Line 909  Line 947 
947                                  st_mb = x+1;                                  st_mb = x+1;
948                          } else {        /* not coded P_VOP macroblock */                          } else {        /* not coded P_VOP macroblock */
949                                  mb->mode = MODE_NOT_CODED;                                  mb->mode = MODE_NOT_CODED;
950                                    mb->quant = quant;
951    
952                                  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;
953                                  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 935  Line 974 
974  get_b_motion_vector(Bitstream * bs,  get_b_motion_vector(Bitstream * bs,
975                                          VECTOR * mv,                                          VECTOR * mv,
976                                          int fcode,                                          int fcode,
977                                          const VECTOR pmv)                                          const VECTOR pmv,
978                                            const DECODER * const dec,
979                                            const int x, const int y)
980  {  {
981          const int scale_fac = 1 << (fcode - 1);          const int scale_fac = 1 << (fcode - 1);
982          const int high = (32 * scale_fac) - 1;          const int high = (32 * scale_fac) - 1;
# Line 1050  Line 1091 
1091                                                          pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);                                                          pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
1092                  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,
1093                                                          pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);                                                          pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
1094                  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,
1095                                                          16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);                                                          pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);
1096          }          }
1097    
1098          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 1178  Line 1219 
1219    
1220          start_timer();          start_timer();
1221          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
1222                                          dec->width, dec->height);                                          dec->width, dec->height, dec->bs_version);
1223          image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height,
1224                                          dec->width, dec->height);                                          dec->width, dec->height, dec->bs_version);
1225          stop_edges_timer();          stop_edges_timer();
1226    
1227          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < dec->mb_height; y++) {
# Line 1264  Line 1305 
1305    
1306                          switch (mb->mode) {                          switch (mb->mode) {
1307                          case MODE_DIRECT:                          case MODE_DIRECT:
1308                                  get_b_motion_vector(bs, &mv, 1, zeromv);                                  get_b_motion_vector(bs, &mv, 1, zeromv, dec, x, y);
1309    
1310                          case MODE_DIRECT_NONE_MV:                          case MODE_DIRECT_NONE_MV:
1311                                  for (i = 0; i < 4; i++) {                                  for (i = 0; i < 4; i++) {
# Line 1283  Line 1324 
1324                                  break;                                  break;
1325    
1326                          case MODE_INTERPOLATE:                          case MODE_INTERPOLATE:
1327                                  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);
1328                                  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];
1329    
1330                                  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);
1331                                  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];
1332    
1333                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
# Line 1294  Line 1335 
1335                                  break;                                  break;
1336    
1337                          case MODE_BACKWARD:                          case MODE_BACKWARD:
1338                                  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);
1339                                  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];
1340    
1341                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 0);                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 0);
1342                                  break;                                  break;
1343    
1344                          case MODE_FORWARD:                          case MODE_FORWARD:
1345                                  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);
1346                                  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];
1347    
1348                                  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 1340  Line 1381 
1381                  stats->type = coding2type(coding_type);                  stats->type = coding2type(coding_type);
1382                  stats->data.vop.time_base = (int)dec->time_base;                  stats->data.vop.time_base = (int)dec->time_base;
1383                  stats->data.vop.time_increment = 0;     /* XXX: todo */                  stats->data.vop.time_increment = 0;     /* XXX: todo */
1384                    stats->data.vop.qscale_stride = dec->mb_width;
1385                    stats->data.vop.qscale = dec->qscale;
1386                    if (stats->data.vop.qscale != NULL && mbs != NULL) {
1387                            int i;
1388                            for (i = 0; i < dec->mb_width*dec->mb_height; i++)
1389                                    stats->data.vop.qscale[i] = mbs[i].quant;
1390                    } else
1391                            stats->data.vop.qscale = NULL;
1392          }          }
1393  }  }
1394    
# Line 1352  Line 1401 
1401          Bitstream bs;          Bitstream bs;
1402          uint32_t rounding;          uint32_t rounding;
1403          uint32_t reduced_resolution;          uint32_t reduced_resolution;
1404          uint32_t quant;          uint32_t quant = 2;
1405          uint32_t fcode_forward;          uint32_t fcode_forward;
1406          uint32_t fcode_backward;          uint32_t fcode_backward;
1407          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
# Line 1508  Line 1557 
1557                          /* attemping to decode a bvop without atleast 2 reference frames */                          /* attemping to decode a bvop without atleast 2 reference frames */
1558                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
1559                                                  "broken b-frame, mising ref frames");                                                  "broken b-frame, mising ref frames");
1560                          stats->type = XVID_TYPE_NOTHING;                          if (stats) stats->type = XVID_TYPE_NOTHING;
1561                  } else if (dec->time_pp <= dec->time_bp) {                  } else if (dec->time_pp <= dec->time_bp) {
1562                          /* this occurs when dx50_bvop_compatibility==0 sequences are                          /* this occurs when dx50_bvop_compatibility==0 sequences are
1563                          decoded in vfw. */                          decoded in vfw. */
1564                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
1565                                                  "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);
1566                          stats->type = XVID_TYPE_NOTHING;                          if (stats) stats->type = XVID_TYPE_NOTHING;
1567                  } else {                  } else {
1568                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);
1569                          decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type, quant);                          decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type, quant);
# Line 1524  Line 1573 
1573                  dec->frames++;                  dec->frames++;
1574          }          }
1575    
1576    #if 0 /* Avoids to read to much data because of 32bit reads in our BS functions */
1577          BitstreamByteAlign(&bs);          BitstreamByteAlign(&bs);
1578    #endif
1579    
1580          /* low_delay_default mode: repeat in packed_mode */          /* low_delay_default mode: repeat in packed_mode */
1581          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 1555  Line 1606 
1606          emms();          emms();
1607          stop_global_timer();          stop_global_timer();
1608    
1609          return BitstreamPos(&bs) / 8;   /* number of bytes consumed */          return (BitstreamPos(&bs) + 7) / 8;     /* number of bytes consumed */
1610  }  }

Legend:
Removed from v.1.49.2.28  
changed lines
  Added in v.1.51.2.1

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