[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.9, Sat Jun 28 15:48:39 2003 UTC revision 1.49.4.1, Sat May 3 23:23:38 2003 UTC
# Line 3  Line 3 
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - Decoder Module -   *  - Decoder Module -
5   *   *
6   *  Copyright(C) 2002      MinChen <chenm001@163.com>   *  This file is part of XviD, a free MPEG-4 video encoder/decoder
  *               2002-2003 Peter Ross <pross@xvid.org>  
7   *   *
8   *  This program is free software ; you can redistribute it and/or modify   *  This program is free software ; you can redistribute it and/or modify
9   *  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 54  Line 53 
53  #include "utils/timer.h"  #include "utils/timer.h"
54  #include "utils/emms.h"  #include "utils/emms.h"
55  #include "motion/motion.h"  #include "motion/motion.h"
 #include "motion/gmc.h"  
56    
57  #include "image/image.h"  #include "image/image.h"
58  #include "image/colorspace.h"  #include "image/colorspace.h"
59  #include "utils/mem_align.h"  #include "utils/mem_align.h"
60    #include "image/postprocessing.h"
61    
62  int  int
63  decoder_resize(DECODER * dec)  decoder_resize(DECODER * dec)
# Line 160  Line 159 
159    
160          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);
161    
162          return 0;          return XVID_ERR_OK;
163  }  }
164    
165    
166  int  int
167  decoder_create(xvid_dec_create_t * create)  decoder_create(XVID_DEC_PARAM * param)
168  {  {
169          DECODER *dec;          DECODER *dec;
170    
         if (XVID_MAJOR(create->version) != 1)   /* v1.x.x */  
                 return XVID_ERR_VERSION;  
   
171          dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);          dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);
172          if (dec == NULL) {          if (dec == NULL) {
173                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
174          }          }
175          memset(dec, 0, sizeof(DECODER));          memset(dec, 0, sizeof(DECODER));
176    
177          create->handle = dec;          param->handle = dec;
178    
179          dec->width = create->width;          dec->width = param->width;
180          dec->height = create->height;          dec->height = param->height;
181    
182          image_null(&dec->cur);          image_null(&dec->cur);
183          image_null(&dec->refn[0]);          image_null(&dec->refn[0]);
# Line 209  Line 205 
205          if (dec->fixed_dimensions)          if (dec->fixed_dimensions)
206                  return decoder_resize(dec);                  return decoder_resize(dec);
207          else          else
208                  return 0;                  return XVID_ERR_OK;
209  }  }
210    
211    
# Line 230  Line 226 
226          xvid_free(dec);          xvid_free(dec);
227    
228          write_timer();          write_timer();
229          return 0;          return XVID_ERR_OK;
230  }  }
231    
232    
# Line 306  Line 302 
302                          block[i * 64 + 0] = dc_dif;                          block[i * 64 + 0] = dc_dif;
303                          start_coeff = 1;                          start_coeff = 1;
304    
305                          DPRINTF(XVID_DEBUG_COEFF,"block[0] %i\n", dc_dif);                          DPRINTF(DPRINTF_COEFF,"block[0] %i", dc_dif);
306                  } else {                  } else {
307                          start_coeff = 0;                          start_coeff = 0;
308                  }                  }
# Line 584  Line 580 
580          stop_transfer_timer();          stop_transfer_timer();
581  }  }
582    
583    static __inline int gmc_sanitize(int value, int quarterpel, int fcode)
584    {
585            int length = 1 << (fcode+4);
586    
587    /*      if (quarterpel) value *= 2; */
588    
589            if (value < -length)
590                    return -length;
591            else if (value >= length)
592                    return length-1;
593            else return value;
594    }
595    
596    
597  static void  static void
598  decoder_mbgmc(DECODER * dec,  decoder_mbgmc(DECODER * dec,
# Line 616  Line 625 
625    
626  /* this is where the calculations are done */  /* this is where the calculations are done */
627    
628          {       NEW_GMC_DATA * gmc_data = &dec->new_gmc_data;          {
629                    pMB->amv = generate_GMCimageMB(&dec->gmc_data, &dec->refn[0], x_pos, y_pos,
630                          gmc_data->predict_16x16(gmc_data,                                          stride, stride2, dec->quarterpel, rounding, &dec->cur);
                                         dec->cur.y + y_pos*16*stride + x_pos*16, dec->refn[0].y,  
                                         stride, stride, x_pos, y_pos, rounding);  
   
                         gmc_data->predict_8x8(gmc_data,  
                                         dec->cur.u + y_pos*8*stride2 + x_pos*8, dec->refn[0].u,  
                                         dec->cur.v + y_pos*8*stride2 + x_pos*8, dec->refn[0].v,  
                                         stride2, stride2, x_pos, y_pos, rounding);  
   
                         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 735  Line 735 
735                          }                          }
736                          mb = &dec->mbs[y * dec->mb_width + x];                          mb = &dec->mbs[y * dec->mb_width + x];
737    
738                          DPRINTF(XVID_DEBUG_MB, "macroblock (%i,%i) %08x\n", x, y, BitstreamShowBits(bs, 32));                          DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", 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 762  Line 762 
762    
763                          if (dec->interlacing) {                          if (dec->interlacing) {
764                                  mb->field_dct = BitstreamGetBit(bs);                                  mb->field_dct = BitstreamGetBit(bs);
765                                  DPRINTF(XVID_DEBUG_MB,"deci: field_dct: %i\n", mb->field_dct);                                  DPRINTF(DPRINTF_MB,"deci: field_dct: %i", 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 800  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(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);          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);
804    
805          mv.x += pmv.x;          mv.x += pmv.x;
806          mv.y += pmv.y;          mv.y += pmv.y;
# Line 858  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",                  {
863                            fprintf(stderr,"Wrong GMC parameters acc=%d(-> 1/%d), %d!!!\n",
864                                  dec->sprite_warping_accuracy,(2<<dec->sprite_warping_accuracy),                                  dec->sprite_warping_accuracy,(2<<dec->sprite_warping_accuracy),
865                                  dec->sprite_warping_points);                                  dec->sprite_warping_points);
866                  }*/                  }
867    
868                  generate_GMCparameters( dec->sprite_warping_points,                  generate_GMCparameters( dec->sprite_warping_points,
869                                  dec->sprite_warping_accuracy, gmc_warp,                                  (2 << dec->sprite_warping_accuracy), gmc_warp,
870                                  dec->width, dec->height, &dec->new_gmc_data);                                  dec->width, dec->height, &dec->gmc_data);
871    
872  /* image warping is done block-based  in decoder_mbgmc(), now */  /* image warping is done block-based  in decoder_mbgmc(), now */
873    /*
874            generate_GMCimage(&dec->gmc_data, &dec->refn[0],
875                                            mb_width, mb_height,
876                                            dec->edged_width, dec->edged_width/2,
877                                            fcode, dec->quarterpel, 0,
878                                            rounding, dec->mbs, &dec->gmc);
879    */
880          }          }
881    
882          bound = 0;          bound = 0;
# Line 891  Line 899 
899                          }                          }
900                          mb = &dec->mbs[y * dec->mb_width + x];                          mb = &dec->mbs[y * dec->mb_width + x];
901    
902                          DPRINTF(XVID_DEBUG_MB, "macroblock (%i,%i) %08x\n", x, y, BitstreamShowBits(bs, 32));                          DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32));
903    
904                          /* 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 */
905                          if (!(BitstreamGetBit(bs)))     /* block _is_ coded */                          if (!(BitstreamGetBit(bs)))     /* block _is_ coded */
# Line 909  Line 917 
917                                  mb->mode = mcbpc & 7;                                  mb->mode = mcbpc & 7;
918                                  cbpc = (mcbpc >> 4);                                  cbpc = (mcbpc >> 4);
919    
920                                  DPRINTF(XVID_DEBUG_MB, "mode %i\n", mb->mode);                                  DPRINTF(DPRINTF_MB, "mode %i", mb->mode);
921                                  DPRINTF(XVID_DEBUG_MB, "cbpc %i\n", cbpc);                                  DPRINTF(DPRINTF_MB, "cbpc %i", cbpc);
922                                  acpred_flag = 0;                                  acpred_flag = 0;
923    
924                                  intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q);                                  intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q);
# Line 925  Line 933 
933                                  }                                  }
934    
935                                  cbpy = get_cbpy(bs, intra);                                  cbpy = get_cbpy(bs, intra);
936                                  DPRINTF(XVID_DEBUG_MB, "cbpy %i  mcsel %i \n", cbpy,mcsel);                                  DPRINTF(DPRINTF_MB, "cbpy %i  mcsel %i ", cbpy,mcsel);
937    
938                                  cbp = (cbpy << 2) | cbpc;                                  cbp = (cbpy << 2) | cbpc;
939    
940                                  if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) {                                  if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) {
941                                          int dquant = dquant_table[BitstreamGetBits(bs, 2)];                                          int dquant = dquant_table[BitstreamGetBits(bs, 2)];
942                                          DPRINTF(XVID_DEBUG_MB, "dquant %i\n", dquant);                                          DPRINTF(DPRINTF_MB, "dquant %i", dquant);
943                                          quant += dquant;                                          quant += dquant;
944                                          if (quant > 31) {                                          if (quant > 31) {
945                                                  quant = 31;                                                  quant = 31;
946                                          } else if (quant < 1) {                                          } else if (quant < 1) {
947                                                  quant = 1;                                                  quant = 1;
948                                          }                                          }
949                                          DPRINTF(XVID_DEBUG_MB, "quant %i\n", quant);                                          DPRINTF(DPRINTF_MB, "quant %i", quant);
950                                  }                                  }
951                                  mb->quant = quant;                                  mb->quant = quant;
952    
953                                  if (dec->interlacing) {                                  if (dec->interlacing) {
954                                          if (cbp || intra) {                                          if (cbp || intra) {
955                                                  mb->field_dct = BitstreamGetBit(bs);                                                  mb->field_dct = BitstreamGetBit(bs);
956                                                  DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct);                                                  DPRINTF(DPRINTF_MB,"decp: field_dct: %i", mb->field_dct);
957                                          }                                          }
958    
959                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
960                                                  mb->field_pred = BitstreamGetBit(bs);                                                  mb->field_pred = BitstreamGetBit(bs);
961                                                  DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred);                                                  DPRINTF(DPRINTF_MB, "decp: field_pred: %i", mb->field_pred);
962    
963                                                  if (mb->field_pred) {                                                  if (mb->field_pred) {
964                                                          mb->field_for_top = BitstreamGetBit(bs);                                                          mb->field_for_top = BitstreamGetBit(bs);
965                                                          DPRINTF(XVID_DEBUG_MB,"decp: field_for_top: %i\n", mb->field_for_top);                                                          DPRINTF(DPRINTF_MB,"decp: field_for_top: %i", mb->field_for_top);
966                                                          mb->field_for_bot = BitstreamGetBit(bs);                                                          mb->field_for_bot = BitstreamGetBit(bs);
967                                                          DPRINTF(XVID_DEBUG_MB,"decp: field_for_bot: %i\n", mb->field_for_bot);                                                          DPRINTF(DPRINTF_MB,"decp: field_for_bot: %i", mb->field_for_bot);
968                                                  }                                                  }
969                                          }                                          }
970                                  }                                  }
# Line 1681  Line 1689 
1689                                  break;                                  break;
1690    
1691                          default:                          default:
1692                                  DPRINTF(XVID_DEBUG_ERROR,"Not support B-frame mb_type = %i\n", mb->mb_type);                                  DPRINTF(DPRINTF_ERROR,"Not support B-frame mb_type = %i", mb->mb_type);
1693                          }                          }
1694                  } /* End of for */                  } /* End of for */
1695          }          }
# Line 1695  Line 1703 
1703  #endif  #endif
1704  }  }
1705    
1706    /* swap two MACROBLOCK array */
1707    void
1708    mb_swap(MACROBLOCK ** mb1,
1709                    MACROBLOCK ** mb2)
1710    {
1711            MACROBLOCK *temp = *mb1;
1712    
1713            *mb1 = *mb2;
1714            *mb2 = temp;
1715    }
1716    
1717    
1718  /* perform post processing if necessary, and output the image */  /* perform post processing if necessary, and output the image */
1719  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,
1720                                          xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type)                                          const XVID_DEC_FRAME * frame, int pp_disable)
1721  {  {
1722    
1723            if ((frame->general & (XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV)) && !pp_disable)   /* post process */
         image_output(img, dec->width, dec->height,  
                                  dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride,  
                                  frame->output.csp, dec->interlacing);  
   
         if (stats)  
1724          {          {
1725                  stats->type = coding2type(coding_type);                  /* note: image is stored to tmp */
1726                  stats->data.vop.time_base = (int)dec->time_base;                  image_copy(&dec->tmp, img, dec->edged_width, dec->height);
1727                  stats->data.vop.time_increment = 0;     /* XXX: todo */                  image_deblock(&dec->tmp, dec->edged_width,
1728                                              mbs, dec->mb_width, dec->mb_height, dec->mb_width,
1729                                              frame->general);
1730                    img = &dec->tmp;
1731          }          }
1732    
1733            image_output(img, dec->width, dec->height,
1734                                     dec->edged_width, frame->image, frame->stride,
1735                                     frame->colorspace, dec->interlacing);
1736  }  }
1737    
1738    
1739  int  int
1740  decoder_decode(DECODER * dec,  decoder_decode(DECODER * dec,
1741                             xvid_dec_frame_t * frame, xvid_dec_stats_t * stats)                             XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats)
1742  {  {
1743    
1744          Bitstream bs;          Bitstream bs;
# Line 1729  Line 1749 
1749          uint32_t fcode_backward;          uint32_t fcode_backward;
1750          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
1751          WARPPOINTS gmc_warp;          WARPPOINTS gmc_warp;
1752          int coding_type;          int vop_type;
1753          int success, output, seen_something;          int success = 0;
1754          idctFuncPtr idct_save;          int output = 0;
1755            int seen_something = 0;
         if (XVID_MAJOR(frame->version) != 1 || (stats && XVID_MAJOR(stats->version) != 1))      /* v1.x.x */  
                 return XVID_ERR_VERSION;  
1756    
1757          start_global_timer();          start_global_timer();
1758    
1759          dec->low_delay_default = (frame->general & XVID_LOWDELAY);          dec->low_delay_default = (frame->general & XVID_DEC_LOWDELAY);
1760          if ((frame->general & XVID_DISCONTINUITY))          dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL;
1761    
1762            if ((frame->general & XVID_DEC_DISCONTINUITY))
1763                  dec->frames = 0;                  dec->frames = 0;
         dec->out_frm = (frame->output.csp == XVID_CSP_SLICE) ? &frame->output : NULL;  
1764    
1765          if (frame->length < 0)  /* decoder flush */          if (frame->length < 0)  /* decoder flush */
1766          {          {
         int ret;  
1767                  /* 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
1768                      we have a reference frame, then outout the reference frame */                      we have a reference frame, then outout the reference frame */
1769                  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)
1770                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);                  {
1771              dec->frames = 0;                          decoder_output(dec, &dec->refn[0], dec->mbs, frame, dec->last_reduced_resolution);
1772              ret = 0;                          output = 1;
1773          }else{                  }
1774              if (stats) stats->type = XVID_TYPE_NOTHING;  
1775              ret = XVID_ERR_END;                  frame->length = 0;
1776                    if (stats)
1777                    {
1778                            stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING;
1779                            stats->data.vop.time_base = (int)dec->time_base;
1780                            stats->data.vop.time_increment = 0;     /* XXX: todo */
1781          }          }
1782    
1783                  emms();                  emms();
1784    
1785                  stop_global_timer();                  stop_global_timer();
1786                  return ret;                  return XVID_ERR_OK;
1787          }          }
1788    
1789          BitstreamInit(&bs, frame->bitstream, frame->length);          BitstreamInit(&bs, frame->bitstream, frame->length);
# Line 1767  Line 1791 
1791          /* XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's */          /* XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's */
1792          if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f)          if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f)
1793          {          {
1794                    if (stats)
1795                            stats->notify = XVID_DEC_VOP;
1796                    frame->length = 1;
1797                  image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width,                  image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width,
1798                                           (uint8_t**)frame->output.plane, frame->output.stride, frame->output.csp, dec->interlacing);                                           frame->image, frame->stride, frame->colorspace, dec->interlacing);
                 if (stats) stats->type = XVID_TYPE_NOTHING;  
1799                  emms();                  emms();
1800                  return 1;   /* one byte consumed */                  return XVID_ERR_OK;
1801          }          }
1802    
         success = 0;  
         output = 0;  
         seen_something = 0;  
         idct_save = idct;  
   
1803  repeat:  repeat:
1804    
1805          coding_type =   BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,          vop_type =      BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,
1806                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp);                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp);
1807    
1808          DPRINTF(XVID_DEBUG_HEADER, "coding_type=%i,  packed=%i,  time=%lli,  time_pp=%i,  time_bp=%i\n",          DPRINTF(DPRINTF_HEADER, "vop_type=%i,  packed=%i,  time=%lli,  time_pp=%i,  time_bp=%i",
1809                                                          coding_type,    dec->packed_mode, dec->time, dec->time_pp, dec->time_bp);                                                          vop_type,       dec->packed_mode, dec->time, dec->time_pp, dec->time_bp);
1810    
1811          if (coding_type == -1) /* nothing */          if (vop_type == -1)
1812          {          {
1813                  if (success) goto done;                  if (success) goto done;
         if (stats) stats->type = XVID_TYPE_NOTHING;  
1814                  emms();                  emms();
1815          return BitstreamPos(&bs)/8;                  return XVID_ERR_FAIL;
1816          }          }
1817    
1818          if (coding_type == -2 || coding_type == -3)   /* vol and/or resize */          if (vop_type == -2 || vop_type == -3)
1819          {          {
1820                  if (coding_type == -3)                  if (vop_type == -3)
1821                          decoder_resize(dec);                          decoder_resize(dec);
1822    
1823                  if (stats)                  if (stats)
1824                  {                  {
1825                          stats->type = XVID_TYPE_VOL;                          stats->notify = XVID_DEC_VOL;
1826                          stats->data.vol.general = 0;                          stats->data.vol.general = 0;
1827                          /*XXX: if (dec->interlacing)                          if (dec->interlacing)
1828                                  stats->data.vol.general |= ++INTERLACING; */                                  stats->data.vol.general |= XVID_INTERLACING;
1829                          stats->data.vol.width = dec->width;                          stats->data.vol.width = dec->width;
1830                          stats->data.vol.height = dec->height;                          stats->data.vol.height = dec->height;
1831                          stats->data.vol.par = dec->aspect_ratio;                          stats->data.vol.aspect_ratio = dec->aspect_ratio;
1832                          stats->data.vol.par_width = dec->par_width;                          stats->data.vol.par_width = dec->par_width;
1833                          stats->data.vol.par_height = dec->par_height;                          stats->data.vol.par_height = dec->par_height;
1834                            frame->length = BitstreamPos(&bs) / 8;
1835                          emms();                          emms();
1836                          return BitstreamPos(&bs)/8;     /* number of bytes consumed */                          return XVID_ERR_OK;
1837                  }                  }
1838                  goto repeat;                  goto repeat;
1839          }          }
1840    
1841          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 */
1842    
 #if defined(ARCH_IS_IA32)  
         /*  
          * /!\ Ugly hack /!\  
          * IA32: Prior to xvid bitstream 10, we were using Walten's mmx/xmm idct  
          */  
         if((idct == simple_idct_mmx) && (dec->bs_version < 10))  
                 idct = idct_mmx;  
 #endif  
1843    
1844          /* packed_mode: special-N_VOP treament */          /* packed_mode: special-N_VOP treament */
1845          if (dec->packed_mode && coding_type == N_VOP)          if (dec->packed_mode && vop_type == N_VOP)
1846          {          {
1847                  if (dec->low_delay_default && dec->frames > 0)                  if (dec->low_delay_default && dec->frames > 0)
1848                  {                  {
1849                          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, dec->last_reduced_resolution);
1850                          output = 1;                          output = 1;
1851                  }                  }
1852                  /* ignore otherwise */                  /* ignore otherwise */
1853          }          }
1854          else if (coding_type != B_VOP)          else if (vop_type != B_VOP)
1855          {          {
1856                  switch(coding_type)                  switch(vop_type)
1857                  {                  {
1858                  case I_VOP :                  case I_VOP :
1859                          decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);                          decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);
# Line 1854  Line 1867 
1867                                                  fcode_forward, intra_dc_threshold, &gmc_warp);                                                  fcode_forward, intra_dc_threshold, &gmc_warp);
1868                          break;                          break;
1869                  case N_VOP :                  case N_VOP :
                         /* XXX: not_coded vops are not used for forward prediction */  
                         /* we should not swap(last_mbs,mbs) */  
1870                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);
1871                          break;                          break;
1872                  }                  }
# Line 1864  Line 1875 
1875                  {                  {
1876                          image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,                          image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,
1877                                  (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width,                                  (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width,
1878                                  16, 0);                                  16, XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV);
1879                  }                  }
1880    
1881                  /* 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 */
# Line 1872  Line 1883 
1883                  {                  {
1884                          if (dec->low_delay)                          if (dec->low_delay)
1885                          {                          {
1886                                  decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);                                  decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution);
1887                                  output = 1;                                  output = 1;
1888                          }                          }
1889                          else if (dec->frames > 0)       /* is the reference frame valid? */                          else if (dec->frames > 0)       /* is the reference frame valid? */
1890                          {                          {
1891                                  /* output the reference frame */                                  /* output the reference frame */
1892                                  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, dec->last_reduced_resolution);
1893                                  output = 1;                                  output = 1;
1894                          }                          }
1895                  }                  }
1896    
1897                  image_swap(&dec->refn[0], &dec->refn[1]);                  image_swap(&dec->refn[0], &dec->refn[1]);
1898                  image_swap(&dec->cur, &dec->refn[0]);                  image_swap(&dec->cur, &dec->refn[0]);
1899          SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs);                  mb_swap(&dec->mbs, &dec->last_mbs);
1900                  dec->last_reduced_resolution = reduced_resolution;                  dec->last_reduced_resolution = reduced_resolution;
         dec->last_coding_type = coding_type;  
1901    
1902                  dec->frames++;                  dec->frames++;
1903                  seen_something = 1;                  seen_something = 1;
# Line 1896  Line 1906 
1906    
1907                  if (dec->low_delay)                  if (dec->low_delay)
1908                  {                  {
1909                          DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n");                          DPRINTF(DPRINTF_ERROR, "warning: bvop found in low_delay==1 stream");
1910                          dec->low_delay = 1;                          dec->low_delay = 1;
1911                  }                  }
1912    
# Line 1914  Line 1924 
1924                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);
1925                  }                  }
1926    
1927                  decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);                  decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution);
1928                  output = 1;                  output = 1;
1929                  dec->frames++;                  dec->frames++;
1930          }          }
# Line 1937  Line 1947 
1947                  if (dec->packed_mode && seen_something)                  if (dec->packed_mode && seen_something)
1948                  {                  {
1949                          /* output the recently decoded frame */                          /* output the recently decoded frame */
1950                          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, dec->last_reduced_resolution);
1951                            output = 1;
1952                  }                  }
1953                  else                  else
1954                  {                  {
# Line 1947  Line 1958 
1958                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,
1959                                  "bframe decoder lag");                                  "bframe decoder lag");
1960    
1961                          decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP);                          decoder_output(dec, &dec->cur, NULL, frame, 1 /*disable pp*/);
                         if (stats) stats->type = XVID_TYPE_NOTHING;  
   
1962                  }                  }
1963          }          }
1964    
1965            frame->length = BitstreamPos(&bs) / 8;
1966    
1967            if (stats)
1968            {
1969                    stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING;
1970                    stats->data.vop.time_base = (int)dec->time_base;
1971                    stats->data.vop.time_increment = 0;     /* XXX: todo */
1972            }
1973    
1974          emms();          emms();
         stop_global_timer();  
1975    
1976          idct = idct_save;          stop_global_timer();
1977    
1978          return BitstreamPos(&bs) / 8;   /* number of bytes consumed */          return XVID_ERR_OK;
1979  }  }

Legend:
Removed from v.1.49.2.9  
changed lines
  Added in v.1.49.4.1

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