[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.2, Sun Mar 16 12:04:13 2003 UTC revision 1.49.2.12, Wed Sep 24 01:38:29 2003 UTC
# Line 3  Line 3 
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - Decoder Module -   *  - Decoder Module -
5   *   *
6   *  This file is part of XviD, a free MPEG-4 video encoder/decoder   *  Copyright(C) 2002      MinChen <chenm001@163.com>
7     *               2002-2003 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 53  Line 54 
54  #include "utils/timer.h"  #include "utils/timer.h"
55  #include "utils/emms.h"  #include "utils/emms.h"
56  #include "motion/motion.h"  #include "motion/motion.h"
57    #include "motion/gmc.h"
58    
59  #include "image/image.h"  #include "image/image.h"
60  #include "image/colorspace.h"  #include "image/colorspace.h"
# Line 167  Line 169 
169  {  {
170          DECODER *dec;          DECODER *dec;
171    
172          if (XVID_MAJOR(create->version) != 1)   /* v1.x.x */          if (XVID_VERSION_MAJOR(create->version) != 1)   /* v1.x.x */
173                  return XVID_ERR_VERSION;                  return XVID_ERR_VERSION;
174    
175          dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);          dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);
# Line 304  Line 306 
306                          block[i * 64 + 0] = dc_dif;                          block[i * 64 + 0] = dc_dif;
307                          start_coeff = 1;                          start_coeff = 1;
308    
309                          DPRINTF(DPRINTF_COEFF,"block[0] %i", dc_dif);                          DPRINTF(XVID_DEBUG_COEFF,"block[0] %i\n", dc_dif);
310                  } else {                  } else {
311                          start_coeff = 0;                          start_coeff = 0;
312                  }                  }
# Line 582  Line 584 
584          stop_transfer_timer();          stop_transfer_timer();
585  }  }
586    
 static __inline int gmc_sanitize(int value, int quarterpel, int fcode)  
 {  
         int length = 1 << (fcode+4);  
   
 /*      if (quarterpel) value *= 2; */  
   
         if (value < -length)  
                 return -length;  
         else if (value >= length)  
                 return length-1;  
         else return value;  
 }  
   
587    
588  static void  static void
589  decoder_mbgmc(DECODER * dec,  decoder_mbgmc(DECODER * dec,
# Line 627  Line 616 
616    
617  /* this is where the calculations are done */  /* this is where the calculations are done */
618    
619          {          {       NEW_GMC_DATA * gmc_data = &dec->new_gmc_data;
620                  pMB->amv = generate_GMCimageMB(&dec->gmc_data, &dec->refn[0], x_pos, y_pos,  
621                                          stride, stride2, dec->quarterpel, rounding, &dec->cur);                          gmc_data->predict_16x16(gmc_data,
622                                            dec->cur.y + y_pos*16*stride + x_pos*16, dec->refn[0].y,
623                                            stride, stride, x_pos, y_pos, rounding);
624    
625                            gmc_data->predict_8x8(gmc_data,
626                                            dec->cur.u + y_pos*8*stride2 + x_pos*8, dec->refn[0].u,
627                                            dec->cur.v + y_pos*8*stride2 + x_pos*8, dec->refn[0].v,
628                                            stride2, stride2, x_pos, y_pos, rounding);
629    
630                            gmc_data->get_average_mv(gmc_data, &pMB->amv, x_pos, y_pos, dec->quarterpel);
631    
632                  pMB->amv.x = gmc_sanitize(pMB->amv.x, dec->quarterpel, fcode);                  pMB->amv.x = gmc_sanitize(pMB->amv.x, dec->quarterpel, fcode);
633                  pMB->amv.y = gmc_sanitize(pMB->amv.y, dec->quarterpel, fcode);                  pMB->amv.y = gmc_sanitize(pMB->amv.y, dec->quarterpel, fcode);
# Line 737  Line 735 
735                          }                          }
736                          mb = &dec->mbs[y * dec->mb_width + x];                          mb = &dec->mbs[y * dec->mb_width + x];
737    
738                          DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32));                          DPRINTF(XVID_DEBUG_MB, "macroblock (%i,%i) %08x\n", x, y, BitstreamShowBits(bs, 32));
739    
740                          mcbpc = get_mcbpc_intra(bs);                          mcbpc = get_mcbpc_intra(bs);
741                          mb->mode = mcbpc & 7;                          mb->mode = mcbpc & 7;
# Line 764  Line 762 
762    
763                          if (dec->interlacing) {                          if (dec->interlacing) {
764                                  mb->field_dct = BitstreamGetBit(bs);                                  mb->field_dct = BitstreamGetBit(bs);
765                                  DPRINTF(DPRINTF_MB,"deci: field_dct: %i", mb->field_dct);                                  DPRINTF(XVID_DEBUG_MB,"deci: field_dct: %i\n", mb->field_dct);
766                          }                          }
767    
768                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
# Line 802  Line 800 
800          mv.x = get_mv(bs, fcode);          mv.x = get_mv(bs, fcode);
801          mv.y = get_mv(bs, fcode);          mv.y = get_mv(bs, fcode);
802    
803          DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)", mv.x, mv.y, pmv.x, pmv.y, mv.x+pmv.x, mv.y+pmv.y);          DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", mv.x, mv.y, pmv.x, pmv.y, mv.x+pmv.x, mv.y+pmv.y);
804    
805          mv.x += pmv.x;          mv.x += pmv.x;
806          mv.y += pmv.y;          mv.y += pmv.y;
# Line 860  Line 858 
858          {          {
859    
860                  /* 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 */
861                  if ( (dec->sprite_warping_accuracy != 3) || (dec->sprite_warping_points != 2) )  /*              {
862                  {                          fprintf(stderr,"GMC parameters acc=%d(-> 1/%d), %d pts!!!\n",
                         fprintf(stderr,"Wrong GMC parameters acc=%d(-> 1/%d), %d!!!\n",  
863                                  dec->sprite_warping_accuracy,(2<<dec->sprite_warping_accuracy),                                  dec->sprite_warping_accuracy,(2<<dec->sprite_warping_accuracy),
864                                  dec->sprite_warping_points);                                  dec->sprite_warping_points);
865                  }                  }*/
866    
867                  generate_GMCparameters( dec->sprite_warping_points,                  generate_GMCparameters( dec->sprite_warping_points,
868                                  (2 << dec->sprite_warping_accuracy), gmc_warp,                                  dec->sprite_warping_accuracy, gmc_warp,
869                                  dec->width, dec->height, &dec->gmc_data);                                  dec->width, dec->height, &dec->new_gmc_data);
870    
871  /* image warping is done block-based  in decoder_mbgmc(), now */  /* image warping is done block-based  in decoder_mbgmc(), now */
 /*  
         generate_GMCimage(&dec->gmc_data, &dec->refn[0],  
                                         mb_width, mb_height,  
                                         dec->edged_width, dec->edged_width/2,  
                                         fcode, dec->quarterpel, 0,  
                                         rounding, dec->mbs, &dec->gmc);  
 */  
872          }          }
873    
874          bound = 0;          bound = 0;
# Line 901  Line 891 
891                          }                          }
892                          mb = &dec->mbs[y * dec->mb_width + x];                          mb = &dec->mbs[y * dec->mb_width + x];
893    
894                          DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32));                          DPRINTF(XVID_DEBUG_MB, "macroblock (%i,%i) %08x\n", x, y, BitstreamShowBits(bs, 32));
895    
896                          /* if (!(dec->mb_skip[y*dec->mb_width + x]=BitstreamGetBit(bs))) */ /* not_coded */                          /* if (!(dec->mb_skip[y*dec->mb_width + x]=BitstreamGetBit(bs))) */ /* not_coded */
897                          if (!(BitstreamGetBit(bs)))     /* block _is_ coded */                          if (!(BitstreamGetBit(bs)))     /* block _is_ coded */
# Line 919  Line 909 
909                                  mb->mode = mcbpc & 7;                                  mb->mode = mcbpc & 7;
910                                  cbpc = (mcbpc >> 4);                                  cbpc = (mcbpc >> 4);
911    
912                                  DPRINTF(DPRINTF_MB, "mode %i", mb->mode);                                  DPRINTF(XVID_DEBUG_MB, "mode %i\n", mb->mode);
913                                  DPRINTF(DPRINTF_MB, "cbpc %i", cbpc);                                  DPRINTF(XVID_DEBUG_MB, "cbpc %i\n", cbpc);
914                                  acpred_flag = 0;                                  acpred_flag = 0;
915    
916                                  intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q);                                  intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q);
917    
                                 if (intra) {  
                                         acpred_flag = BitstreamGetBit(bs);  
                                 }  
   
918                                  if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q))                                  if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q))
                                 {  
919                                          mcsel = BitstreamGetBit(bs);                                          mcsel = BitstreamGetBit(bs);
920                                  }  
921                                    if (intra)
922                                            acpred_flag = BitstreamGetBit(bs);
923    
924                                  cbpy = get_cbpy(bs, intra);                                  cbpy = get_cbpy(bs, intra);
925                                  DPRINTF(DPRINTF_MB, "cbpy %i  mcsel %i ", cbpy,mcsel);                                  DPRINTF(XVID_DEBUG_MB, "cbpy %i  mcsel %i \n", cbpy,mcsel);
926    
927                                  cbp = (cbpy << 2) | cbpc;                                  cbp = (cbpy << 2) | cbpc;
928    
929                                  if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) {                                  if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) {
930                                          int dquant = dquant_table[BitstreamGetBits(bs, 2)];                                          int dquant = dquant_table[BitstreamGetBits(bs, 2)];
931                                          DPRINTF(DPRINTF_MB, "dquant %i", dquant);                                          DPRINTF(XVID_DEBUG_MB, "dquant %i\n", dquant);
932                                          quant += dquant;                                          quant += dquant;
933                                          if (quant > 31) {                                          if (quant > 31) {
934                                                  quant = 31;                                                  quant = 31;
935                                          } else if (quant < 1) {                                          } else if (quant < 1) {
936                                                  quant = 1;                                                  quant = 1;
937                                          }                                          }
938                                          DPRINTF(DPRINTF_MB, "quant %i", quant);                                          DPRINTF(XVID_DEBUG_MB, "quant %i\n", quant);
939                                  }                                  }
940                                  mb->quant = quant;                                  mb->quant = quant;
941    
942                                  if (dec->interlacing) {                                  if (dec->interlacing) {
943                                          if (cbp || intra) {                                          if (cbp || intra) {
944                                                  mb->field_dct = BitstreamGetBit(bs);                                                  mb->field_dct = BitstreamGetBit(bs);
945                                                  DPRINTF(DPRINTF_MB,"decp: field_dct: %i", mb->field_dct);                                                  DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct);
946                                          }                                          }
947    
948                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
949                                                  mb->field_pred = BitstreamGetBit(bs);                                                  mb->field_pred = BitstreamGetBit(bs);
950                                                  DPRINTF(DPRINTF_MB, "decp: field_pred: %i", mb->field_pred);                                                  DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred);
951    
952                                                  if (mb->field_pred) {                                                  if (mb->field_pred) {
953                                                          mb->field_for_top = BitstreamGetBit(bs);                                                          mb->field_for_top = BitstreamGetBit(bs);
954                                                          DPRINTF(DPRINTF_MB,"decp: field_for_top: %i", mb->field_for_top);                                                          DPRINTF(XVID_DEBUG_MB,"decp: field_for_top: %i\n", mb->field_for_top);
955                                                          mb->field_for_bot = BitstreamGetBit(bs);                                                          mb->field_for_bot = BitstreamGetBit(bs);
956                                                          DPRINTF(DPRINTF_MB,"decp: field_for_bot: %i", mb->field_for_bot);                                                          DPRINTF(XVID_DEBUG_MB,"decp: field_for_bot: %i\n", mb->field_for_bot);
957                                                  }                                                  }
958                                          }                                          }
959                                  }                                  }
# Line 1691  Line 1678 
1678                                  break;                                  break;
1679    
1680                          default:                          default:
1681                                  DPRINTF(DPRINTF_ERROR,"Not support B-frame mb_type = %i", mb->mb_type);                                  DPRINTF(XVID_DEBUG_ERROR,"Not support B-frame mb_type = %i\n", mb->mb_type);
1682                          }                          }
1683                  } /* End of for */                  } /* End of for */
1684          }          }
# Line 1721  Line 1708 
1708          {          {
1709                  stats->type = coding2type(coding_type);                  stats->type = coding2type(coding_type);
1710                  stats->data.vop.time_base = (int)dec->time_base;                  stats->data.vop.time_base = (int)dec->time_base;
1711                  stats->data.vop.time_increment = 0;     //XXX: todo                  stats->data.vop.time_increment = 0;     /* XXX: todo */
1712          }          }
1713  }  }
1714    
# Line 1742  Line 1729 
1729          int coding_type;          int coding_type;
1730          int success, output, seen_something;          int success, output, seen_something;
1731    
1732          if (XVID_MAJOR(frame->version) != 1 || (stats && XVID_MAJOR(stats->version) != 1))      /* v1.x.x */          if (XVID_VERSION_MAJOR(frame->version) != 1 || (stats && XVID_VERSION_MAJOR(stats->version) != 1))      /* v1.x.x */
1733                  return XVID_ERR_VERSION;                  return XVID_ERR_VERSION;
1734    
1735          start_global_timer();          start_global_timer();
# Line 1754  Line 1741 
1741    
1742          if (frame->length < 0)  /* decoder flush */          if (frame->length < 0)  /* decoder flush */
1743          {          {
1744            int ret;
1745                  /* 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
1746                      we have a reference frame, then outout the reference frame */                      we have a reference frame, then outout the reference frame */
1747                  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) {
                 {  
1748                          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);
1749                dec->frames = 0;
1750                ret = 0;
1751          }else{          }else{
1752              if (stats) stats->type = XVID_TYPE_NOTHING;              if (stats) stats->type = XVID_TYPE_NOTHING;
1753                ret = XVID_ERR_END;
1754          }          }
1755    
1756                  emms();                  emms();
1757                  stop_global_timer();                  stop_global_timer();
1758                  return 0;                  return ret;
1759          }          }
1760    
1761          BitstreamInit(&bs, frame->bitstream, frame->length);          BitstreamInit(&bs, frame->bitstream, frame->length);
# Line 1789  Line 1779 
1779          coding_type =   BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,          coding_type =   BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,
1780                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp);                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp);
1781    
1782          DPRINTF(DPRINTF_HEADER, "coding_type=%i,  packed=%i,  time=%lli,  time_pp=%i,  time_bp=%i",          DPRINTF(XVID_DEBUG_HEADER, "coding_type=%i,  packed=%i,  time=%lli,  time_pp=%i,  time_bp=%i\n",
1783                                                          coding_type,    dec->packed_mode, dec->time, dec->time_pp, dec->time_bp);                                                          coding_type,    dec->packed_mode, dec->time, dec->time_pp, dec->time_bp);
1784    
1785          if (coding_type == -1) /* nothing */          if (coding_type == -1) /* nothing */
# Line 1824  Line 1814 
1814    
1815          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 */
1816    
   
1817          /* packed_mode: special-N_VOP treament */          /* packed_mode: special-N_VOP treament */
1818          if (dec->packed_mode && coding_type == N_VOP)          if (dec->packed_mode && coding_type == N_VOP)
1819          {          {
# Line 1851  Line 1840 
1840                                                  fcode_forward, intra_dc_threshold, &gmc_warp);                                                  fcode_forward, intra_dc_threshold, &gmc_warp);
1841                          break;                          break;
1842                  case N_VOP :                  case N_VOP :
1843                          // XXX: not_coded vops are not used for forward prediction                          /* XXX: not_coded vops are not used for forward prediction */
1844                          //              we should not swap(last_mbs,mbs)                          /* we should not swap(last_mbs,mbs) */
1845                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);
1846                          break;                          break;
1847                  }                  }
# Line 1893  Line 1882 
1882    
1883                  if (dec->low_delay)                  if (dec->low_delay)
1884                  {                  {
1885                          DPRINTF(DPRINTF_ERROR, "warning: bvop found in low_delay==1 stream");                          DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n");
1886                          dec->low_delay = 1;                          dec->low_delay = 1;
1887                  }                  }
1888    

Legend:
Removed from v.1.49.2.2  
changed lines
  Added in v.1.49.2.12

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