[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.30, Mon Jul 15 23:50:31 2002 UTC revision 1.37.2.1, Thu Sep 26 01:54:54 2002 UTC
# Line 268  Line 268 
268                  start_timer();                  start_timer();
269                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       // coded
270                  {                  {
271                          get_intra_block(bs, &block[i * 64], pMB->acpred_directions[i],                          int direction = dec->alternate_vertical_scan ?
272                                                          start_coeff);                                  2 : pMB->acpred_directions[i];
273    
274                            get_intra_block(bs, &block[i * 64], direction, start_coeff);
275                  }                  }
276                  stop_coding_timer();                  stop_coding_timer();
277    
# Line 348  Line 350 
350                  uv_dx = pMB->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
351                  uv_dy = pMB->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
352    
353                    if (dec->quarterpel)
354                    {
355                            uv_dx = (uv_dx >> 1) | (uv_dx & 1);
356                            uv_dy = (uv_dy >> 1) | (uv_dy & 1);
357                    }
358    
359                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;
360                  uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;                  uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;
361          } else {          } else {
362                  int sum;                  int sum;
   
363                  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;
364                  uv_dx =  
365                          (sum ==                  if (dec->quarterpel)
366                           0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +                  {
367                                                                    (ABS(sum) / 16) * 2));                          sum /= 2;
368                    }
369    
370                    uv_dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2));
371    
372                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
373                  uv_dy =  
374                          (sum ==                  if (dec->quarterpel)
375                           0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +                  {
376                                                                    (ABS(sum) / 16) * 2));                          sum /= 2;
377                    }
378    
379                    uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2));
380          }          }
381    
382          start_timer();          start_timer();
383            if(dec->quarterpel) {
384                    DEBUG("QUARTERPEL");
385                    interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,
386                                                                      pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);
387                    interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos,
388                                                                      pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);
389                    interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8,
390                                                                      pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);
391                    interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8,
392                                                                      pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);
393            }
394            else {
395          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos, 16 * y_pos,          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos, 16 * y_pos,
396                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding);                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding);
397          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos + 8,                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos,
398                                                    16 * y_pos, pMB->mvs[1].x, pMB->mvs[1].y, stride,                                                            pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);
399                                                    rounding);                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8,
400          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos,                                                            pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);
401                                                    16 * y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride,                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8,
402                                                    rounding);                                                            pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);
403          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos + 8,          }
404                                                    16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride,  
                                                   rounding);  
405          interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,
406                                                    uv_dx, uv_dy, stride2, rounding);                                                    uv_dx, uv_dy, stride2, rounding);
407          interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,
# Line 385  Line 409 
409          stop_comp_timer();          stop_comp_timer();
410    
411          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
412                    int direction = dec->alternate_vertical_scan ? 2 : 0;
413    
414                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       // coded
415                  {                  {
416                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
417    
418                          start_timer();                          start_timer();
419                          get_inter_block(bs, &block[i * 64]);                          get_inter_block(bs, &block[i * 64], direction);
420                          stop_coding_timer();                          stop_coding_timer();
421    
422                          start_timer();                          start_timer();
# Line 493  Line 519 
519                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
520                                                          intra_dc_threshold, bound);                                                          intra_dc_threshold, bound);
521                  }                  }
522                    if(dec->out_frm)
523                      output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,dec->mb_width);
524    
525          }          }
526    
527  }  }
# Line 556  Line 585 
585    
586          uint32_t x, y;          uint32_t x, y;
587          uint32_t bound;          uint32_t bound;
588            int cp_mb, st_mb;
589    
590          start_timer();          start_timer();
591          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
592                                     dec->width, dec->height, dec->interlacing);                                     dec->width, dec->height);
593          stop_edges_timer();          stop_edges_timer();
594    
595          bound = 0;          bound = 0;
596    
597          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < dec->mb_height; y++) {
598                    cp_mb = st_mb = 0;
599                  for (x = 0; x < dec->mb_width; x++) {                  for (x = 0; x < dec->mb_width; x++) {
600                          MACROBLOCK *mb;                          MACROBLOCK *mb;
601    
# Line 592  Line 623 
623                                  uint32_t cbp;                                  uint32_t cbp;
624                                  uint32_t intra;                                  uint32_t intra;
625    
626                                    cp_mb++;
627                                  mcbpc = get_mcbpc_inter(bs);                                  mcbpc = get_mcbpc_inter(bs);
628                                  mb->mode = mcbpc & 7;                                  mb->mode = mcbpc & 7;
629                                  cbpc = (mcbpc >> 4);                                  cbpc = (mcbpc >> 4);
# Line 625  Line 657 
657                                  mb->quant = quant;                                  mb->quant = quant;
658    
659                                  if (dec->interlacing) {                                  if (dec->interlacing) {
660                                            if (cbp || intra) {
661                                          mb->field_dct = BitstreamGetBit(bs);                                          mb->field_dct = BitstreamGetBit(bs);
662                                          DEBUG1("decp: field_dct: ", mb->field_dct);                                          DEBUG1("decp: field_dct: ", mb->field_dct);
663                                            }
664    
665                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
666                                                  mb->field_pred = BitstreamGetBit(bs);                                                  mb->field_pred = BitstreamGetBit(bs);
# Line 655  Line 689 
689                                                  mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =                                                  mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =
690                                                          mb->mvs[0].y;                                                          mb->mvs[0].y;
691                                          }                                          }
692                                  } else if (mb->mode ==                                  } else if (mb->mode == MODE_INTER4V ) {
693                                                     MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */ ) {  
694                                          get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound);                                          get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound);
695                                          get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode, bound);                                          get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode, bound);
696                                          get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode, bound);                                          get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode, bound);
# Line 676  Line 710 
710                                                                  rounding);                                                                  rounding);
711                          } else                          // not coded                          } else                          // not coded
712                          {                          {
713                                  //DEBUG2("P-frame MB at (X,Y)=",x,y);                                  DEBUG2("P-frame MB at (X,Y)=",x,y);
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 718  Line 752 
752                                                                   dec->refn[0].v +                                                                   dec->refn[0].v +
753                                                                   (8 * y) * dec->edged_width / 2 + (8 * x),                                                                   (8 * y) * dec->edged_width / 2 + (8 * x),
754                                                                   dec->edged_width / 2);                                                                   dec->edged_width / 2);
   
755                                  stop_transfer_timer();                                  stop_transfer_timer();
756                                    if(dec->out_frm && cp_mb > 0) {
757                                      output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb);
758                                      cp_mb = 0;
759                          }                          }
760                                    st_mb = x+1;
761                  }                  }
762          }          }
763                    if(dec->out_frm && cp_mb > 0)
764                      output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb);
765            }
766  }  }
767    
768    
# Line 840  Line 880 
880          stop_comp_timer();          stop_comp_timer();
881    
882          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
883                    int direction = dec->alternate_vertical_scan ? 2 : 0;
884    
885                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       // coded
886                  {                  {
887                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
888    
889                          start_timer();                          start_timer();
890                          get_inter_block(bs, &block[i * 64]);                          get_inter_block(bs, &block[i * 64], direction);
891                          stop_coding_timer();                          stop_coding_timer();
892    
893                          start_timer();                          start_timer();
# Line 1006  Line 1048 
1048          stop_comp_timer();          stop_comp_timer();
1049    
1050          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
1051                    int direction = dec->alternate_vertical_scan ? 2 : 0;
1052    
1053                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       // coded
1054                  {                  {
1055                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
1056    
1057                          start_timer();                          start_timer();
1058                          get_inter_block(bs, &block[i * 64]);                          get_inter_block(bs, &block[i * 64], direction);
1059                          stop_coding_timer();                          stop_coding_timer();
1060    
1061                          start_timer();                          start_timer();
# Line 1106  Line 1150 
1150    
1151          start_timer();          start_timer();
1152          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
1153                                     dec->width, dec->height, dec->interlacing);                                     dec->width, dec->height);
1154          image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height,
1155                                     dec->width, dec->height, dec->interlacing);                                     dec->width, dec->height);
1156          stop_edges_timer();          stop_edges_timer();
1157    
1158  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
# Line 1176  Line 1220 
1220  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
1221          BFRAME_DEBUG          BFRAME_DEBUG
1222  #endif  #endif
1223    
1224                          switch (mb->mb_type) {                          switch (mb->mb_type) {
1225                          case MODE_DIRECT:                          case MODE_DIRECT:
1226                                  get_b_motion_vector(dec, bs, x, y, &mv, 1, zeromv);                                  get_b_motion_vector(dec, bs, x, y, &mv, 1, zeromv);
1227    
1228                          case MODE_DIRECT_NONE_MV:                          case MODE_DIRECT_NONE_MV:
1229                                  {                               // Because this file is a C file not C++ so I use '{' to define var                                  {
1230                                          const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp;                                          const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp;
1231                                          int i;                                          int i;
1232    
# Line 1241  Line 1286 
1286                                  break;                                  break;
1287    
1288                          default:                          default:
1289                                  //DEBUG1("Not support B-frame mb_type =", mb->mb_type);                                  DEBUG1("Not support B-frame mb_type =", mb->mb_type);
                                 ;  
1290                          }                          }
1291    
1292                  }                                               // end of FOR                  }                                               // end of FOR
# Line 1282  Line 1326 
1326    
1327          start_global_timer();          start_global_timer();
1328    
1329            dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL;
1330    
1331          BitstreamInit(&bs, frame->bitstream, frame->length);          BitstreamInit(&bs, frame->bitstream, frame->length);
1332    
1333          // add by chenm001 <chenm001@163.com>          // add by chenm001 <chenm001@163.com>
# Line 1341  Line 1387 
1387    
1388  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1389          // test if no B_VOP          // test if no B_VOP
1390          if (dec->low_delay) {          if (dec->low_delay || dec->frames == 0) {
1391  #endif  #endif
1392          image_output(&dec->cur, dec->width, dec->height, dec->edged_width,          image_output(&dec->cur, dec->width, dec->height, dec->edged_width,
1393                                           frame->image, frame->stride, frame->colorspace);                                           frame->image, frame->stride, frame->colorspace);
1394    
1395  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1396          } else {          } else {
1397                  if (dec->frames >= 0) {                  if (dec->frames >= 1) {
1398                          start_timer();                          start_timer();
1399                          if ((vop_type == I_VOP || vop_type == P_VOP)) {                          if ((vop_type == I_VOP || vop_type == P_VOP)) {
1400                                  image_output(&dec->refn[0], dec->width, dec->height,                                  image_output(&dec->refn[0], dec->width, dec->height,
# Line 1367  Line 1413 
1413          if (vop_type == I_VOP || vop_type == P_VOP) {          if (vop_type == I_VOP || vop_type == P_VOP) {
1414                  image_swap(&dec->refn[0], &dec->refn[1]);                  image_swap(&dec->refn[0], &dec->refn[1]);
1415                  image_swap(&dec->cur, &dec->refn[0]);                  image_swap(&dec->cur, &dec->refn[0]);
1416    
1417                  // swap MACROBLOCK                  // swap MACROBLOCK
1418                  if (!dec->low_delay && vop_type == P_VOP)                  // the Divx will not set the low_delay flage some times
1419                    // so follow code will wrong to not swap at that time
1420                    // this will broken bitstream! so I'm change it,
1421                    // But that is not the best way! can anyone tell me how
1422                    // to do another way?
1423                    // 18-07-2002   MinChen<chenm001@163.com>
1424                    //if (!dec->low_delay && vop_type == P_VOP)
1425                    if (vop_type == P_VOP)
1426                          mb_swap(&dec->mbs, &dec->last_mbs);                          mb_swap(&dec->mbs, &dec->last_mbs);
1427          }          }
1428    

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.37.2.1

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