[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, Wed Feb 19 21:59:30 2003 UTC revision 1.49.2.11, Wed Aug 13 11:43:47 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 158  Line 160 
160    
161          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);
162    
163          return XVID_ERR_OK;          return 0;
164  }  }
165    
166    
167  int  int
168  decoder_create(XVID_DEC_PARAM * param)  decoder_create(xvid_dec_create_t * create)
169  {  {
170          DECODER *dec;          DECODER *dec;
171    
172            if (XVID_VERSION_MAJOR(create->version) != 1)   /* v1.x.x */
173                    return XVID_ERR_VERSION;
174    
175          dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);          dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);
176          if (dec == NULL) {          if (dec == NULL) {
177                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
178          }          }
179          memset(dec, 0, sizeof(DECODER));          memset(dec, 0, sizeof(DECODER));
180    
181          param->handle = dec;          create->handle = dec;
182    
183          dec->width = param->width;          dec->width = create->width;
184          dec->height = param->height;          dec->height = create->height;
185    
186          image_null(&dec->cur);          image_null(&dec->cur);
187          image_null(&dec->refn[0]);          image_null(&dec->refn[0]);
# Line 204  Line 209 
209          if (dec->fixed_dimensions)          if (dec->fixed_dimensions)
210                  return decoder_resize(dec);                  return decoder_resize(dec);
211          else          else
212                  return XVID_ERR_OK;                  return 0;
213  }  }
214    
215    
# Line 225  Line 230 
230          xvid_free(dec);          xvid_free(dec);
231    
232          write_timer();          write_timer();
233          return XVID_ERR_OK;          return 0;
234  }  }
235    
236    
# Line 301  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 579  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 624  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 734  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 761  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 799  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 857  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 898  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 916  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);
# Line 932  Line 925 
925                                  }                                  }
926    
927                                  cbpy = get_cbpy(bs, intra);                                  cbpy = get_cbpy(bs, intra);
928                                  DPRINTF(DPRINTF_MB, "cbpy %i  mcsel %i ", cbpy,mcsel);                                  DPRINTF(XVID_DEBUG_MB, "cbpy %i  mcsel %i \n", cbpy,mcsel);
929    
930                                  cbp = (cbpy << 2) | cbpc;                                  cbp = (cbpy << 2) | cbpc;
931    
932                                  if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) {                                  if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) {
933                                          int dquant = dquant_table[BitstreamGetBits(bs, 2)];                                          int dquant = dquant_table[BitstreamGetBits(bs, 2)];
934                                          DPRINTF(DPRINTF_MB, "dquant %i", dquant);                                          DPRINTF(XVID_DEBUG_MB, "dquant %i\n", dquant);
935                                          quant += dquant;                                          quant += dquant;
936                                          if (quant > 31) {                                          if (quant > 31) {
937                                                  quant = 31;                                                  quant = 31;
938                                          } else if (quant < 1) {                                          } else if (quant < 1) {
939                                                  quant = 1;                                                  quant = 1;
940                                          }                                          }
941                                          DPRINTF(DPRINTF_MB, "quant %i", quant);                                          DPRINTF(XVID_DEBUG_MB, "quant %i\n", quant);
942                                  }                                  }
943                                  mb->quant = quant;                                  mb->quant = quant;
944    
945                                  if (dec->interlacing) {                                  if (dec->interlacing) {
946                                          if (cbp || intra) {                                          if (cbp || intra) {
947                                                  mb->field_dct = BitstreamGetBit(bs);                                                  mb->field_dct = BitstreamGetBit(bs);
948                                                  DPRINTF(DPRINTF_MB,"decp: field_dct: %i", mb->field_dct);                                                  DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct);
949                                          }                                          }
950    
951                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
952                                                  mb->field_pred = BitstreamGetBit(bs);                                                  mb->field_pred = BitstreamGetBit(bs);
953                                                  DPRINTF(DPRINTF_MB, "decp: field_pred: %i", mb->field_pred);                                                  DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred);
954    
955                                                  if (mb->field_pred) {                                                  if (mb->field_pred) {
956                                                          mb->field_for_top = BitstreamGetBit(bs);                                                          mb->field_for_top = BitstreamGetBit(bs);
957                                                          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);
958                                                          mb->field_for_bot = BitstreamGetBit(bs);                                                          mb->field_for_bot = BitstreamGetBit(bs);
959                                                          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);
960                                                  }                                                  }
961                                          }                                          }
962                                  }                                  }
# Line 1688  Line 1681 
1681                                  break;                                  break;
1682    
1683                          default:                          default:
1684                                  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);
1685                          }                          }
1686                  } /* End of for */                  } /* End of for */
1687          }          }
# Line 1702  Line 1695 
1695  #endif  #endif
1696  }  }
1697    
 /* swap two MACROBLOCK array */  
 void  
 mb_swap(MACROBLOCK ** mb1,  
                 MACROBLOCK ** mb2)  
 {  
         MACROBLOCK *temp = *mb1;  
   
         *mb1 = *mb2;  
         *mb2 = temp;  
 }  
1698    
1699    
1700  /* perform post processing if necessary, and output the image */  /* perform post processing if necessary, and output the image */
1701  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,
1702                                          const XVID_DEC_FRAME * frame, int pp_disable)                                          xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type)
1703  {  {
1704    
         if ((frame->general & (XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV)) && !pp_disable)   /* post process */  
         {  
                 /* note: image is stored to tmp */  
                 image_copy(&dec->tmp, img, dec->edged_width, dec->height);  
                 image_deblock_rrv(&dec->tmp, dec->edged_width,  
                                                 mbs, dec->mb_width, dec->mb_height, dec->mb_width,  
                                                 8, frame->general);  
                 img = &dec->tmp;  
         }  
1705    
1706          image_output(img, dec->width, dec->height,          image_output(img, dec->width, dec->height,
1707                                   dec->edged_width, frame->image, frame->stride,                                   dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride,
1708                                   frame->colorspace, dec->interlacing);                                   frame->output.csp, dec->interlacing);
1709    
1710            if (stats)
1711            {
1712                    stats->type = coding2type(coding_type);
1713                    stats->data.vop.time_base = (int)dec->time_base;
1714                    stats->data.vop.time_increment = 0;     /* XXX: todo */
1715            }
1716  }  }
1717    
1718    
1719  int  int
1720  decoder_decode(DECODER * dec,  decoder_decode(DECODER * dec,
1721                             XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats)                             xvid_dec_frame_t * frame, xvid_dec_stats_t * stats)
1722  {  {
1723    
1724          Bitstream bs;          Bitstream bs;
# Line 1748  Line 1729 
1729          uint32_t fcode_backward;          uint32_t fcode_backward;
1730          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
1731          WARPPOINTS gmc_warp;          WARPPOINTS gmc_warp;
1732          int vop_type;          int coding_type;
1733          int success = 0;          int success, output, seen_something;
         int output = 0;  
         int seen_something = 0;  
1734    
1735          start_global_timer();          if (XVID_VERSION_MAJOR(frame->version) != 1 || (stats && XVID_VERSION_MAJOR(stats->version) != 1))      /* v1.x.x */
1736                    return XVID_ERR_VERSION;
1737    
1738          dec->low_delay_default = (frame->general & XVID_DEC_LOWDELAY);          start_global_timer();
         dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL;  
1739    
1740          if ((frame->general & XVID_DEC_DISCONTINUITY))          dec->low_delay_default = (frame->general & XVID_LOWDELAY);
1741            if ((frame->general & XVID_DISCONTINUITY))
1742                  dec->frames = 0;                  dec->frames = 0;
1743            dec->out_frm = (frame->output.csp == XVID_CSP_SLICE) ? &frame->output : NULL;
1744    
1745          if (frame->length < 0)  /* decoder flush */          if (frame->length < 0)  /* decoder flush */
1746          {          {
1747            int ret;
1748                  /* 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
1749                      we have a reference frame, then outout the reference frame */                      we have a reference frame, then outout the reference frame */
1750                  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) {
1751                  {                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);
1752                          decoder_output(dec, &dec->refn[0], dec->mbs, frame, dec->last_reduced_resolution);              dec->frames = 0;
1753                          output = 1;              ret = 0;
1754                  }          }else{
1755                if (stats) stats->type = XVID_TYPE_NOTHING;
1756                  frame->length = 0;              ret = XVID_ERR_END;
                 if (stats)  
                 {  
                         stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING;  
                         stats->data.vop.time_base = (int)dec->time_base;  
                         stats->data.vop.time_increment = 0;     /* XXX: todo */  
1757                  }                  }
1758    
1759                  emms();                  emms();
   
1760                  stop_global_timer();                  stop_global_timer();
1761                  return XVID_ERR_OK;                  return ret;
1762          }          }
1763    
1764          BitstreamInit(&bs, frame->bitstream, frame->length);          BitstreamInit(&bs, frame->bitstream, frame->length);
# Line 1790  Line 1766 
1766          /* XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's */          /* XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's */
1767          if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f)          if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f)
1768          {          {
                 if (stats)  
                         stats->notify = XVID_DEC_VOP;  
                 frame->length = 1;  
1769                  image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width,                  image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width,
1770                                           frame->image, frame->stride, frame->colorspace, dec->interlacing);                                           (uint8_t**)frame->output.plane, frame->output.stride, frame->output.csp, dec->interlacing);
1771                    if (stats) stats->type = XVID_TYPE_NOTHING;
1772                  emms();                  emms();
1773                  return XVID_ERR_OK;                  return 1;   /* one byte consumed */
1774          }          }
1775    
1776            success = 0;
1777            output = 0;
1778            seen_something = 0;
1779    
1780  repeat:  repeat:
1781    
1782          vop_type =      BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,          coding_type =   BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,
1783                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp);                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp);
1784    
1785          DPRINTF(DPRINTF_HEADER, "vop_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",
1786                                                          vop_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);
1787    
1788          if (vop_type == -1)          if (coding_type == -1) /* nothing */
1789          {          {
1790                  if (success) goto done;                  if (success) goto done;
1791            if (stats) stats->type = XVID_TYPE_NOTHING;
1792                  emms();                  emms();
1793                  return XVID_ERR_FAIL;          return BitstreamPos(&bs)/8;
1794          }          }
1795    
1796          if (vop_type == -2 || vop_type == -3)          if (coding_type == -2 || coding_type == -3)   /* vol and/or resize */
1797          {          {
1798                  if (vop_type == -3)                  if (coding_type == -3)
1799                          decoder_resize(dec);                          decoder_resize(dec);
1800    
1801                  if (stats)                  if (stats)
1802                  {                  {
1803                          stats->notify = XVID_DEC_VOL;                          stats->type = XVID_TYPE_VOL;
1804                          stats->data.vol.general = 0;                          stats->data.vol.general = 0;
1805                          if (dec->interlacing)                          /*XXX: if (dec->interlacing)
1806                                  stats->data.vol.general |= XVID_INTERLACING;                                  stats->data.vol.general |= ++INTERLACING; */
1807                          stats->data.vol.width = dec->width;                          stats->data.vol.width = dec->width;
1808                          stats->data.vol.height = dec->height;                          stats->data.vol.height = dec->height;
1809                          stats->data.vol.aspect_ratio = dec->aspect_ratio;                          stats->data.vol.par = dec->aspect_ratio;
1810                          stats->data.vol.par_width = dec->par_width;                          stats->data.vol.par_width = dec->par_width;
1811                          stats->data.vol.par_height = dec->par_height;                          stats->data.vol.par_height = dec->par_height;
                         frame->length = BitstreamPos(&bs) / 8;  
1812                          emms();                          emms();
1813                          return XVID_ERR_OK;                          return BitstreamPos(&bs)/8;     /* number of bytes consumed */
1814                  }                  }
1815                  goto repeat;                  goto repeat;
1816          }          }
1817    
1818          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 */
1819    
   
1820          /* packed_mode: special-N_VOP treament */          /* packed_mode: special-N_VOP treament */
1821          if (dec->packed_mode && vop_type == N_VOP)          if (dec->packed_mode && coding_type == N_VOP)
1822          {          {
1823                  if (dec->low_delay_default && dec->frames > 0)                  if (dec->low_delay_default && dec->frames > 0)
1824                  {                  {
1825                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution);                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);
1826                          output = 1;                          output = 1;
1827                  }                  }
1828                  /* ignore otherwise */                  /* ignore otherwise */
1829          }          }
1830          else if (vop_type != B_VOP)          else if (coding_type != B_VOP)
1831          {          {
1832                  switch(vop_type)                  switch(coding_type)
1833                  {                  {
1834                  case I_VOP :                  case I_VOP :
1835                          decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);                          decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);
# Line 1866  Line 1843 
1843                                                  fcode_forward, intra_dc_threshold, &gmc_warp);                                                  fcode_forward, intra_dc_threshold, &gmc_warp);
1844                          break;                          break;
1845                  case N_VOP :                  case N_VOP :
1846                            /* XXX: not_coded vops are not used for forward prediction */
1847                            /* we should not swap(last_mbs,mbs) */
1848                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);
1849                          break;                          break;
1850                  }                  }
# Line 1874  Line 1853 
1853                  {                  {
1854                          image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,                          image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,
1855                                  (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width,                                  (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width,
1856                                  16, XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV);                                  16, 0);
1857                  }                  }
1858    
1859                  /* 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 1882  Line 1861 
1861                  {                  {
1862                          if (dec->low_delay)                          if (dec->low_delay)
1863                          {                          {
1864                                  decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution);                                  decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);
1865                                  output = 1;                                  output = 1;
1866                          }                          }
1867                          else if (dec->frames > 0)       /* is the reference frame valid? */                          else if (dec->frames > 0)       /* is the reference frame valid? */
1868                          {                          {
1869                                  /* output the reference frame */                                  /* output the reference frame */
1870                                  decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution);                                  decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);
1871                                  output = 1;                                  output = 1;
1872                          }                          }
1873                  }                  }
1874    
1875                  image_swap(&dec->refn[0], &dec->refn[1]);                  image_swap(&dec->refn[0], &dec->refn[1]);
1876                  image_swap(&dec->cur, &dec->refn[0]);                  image_swap(&dec->cur, &dec->refn[0]);
1877                  mb_swap(&dec->mbs, &dec->last_mbs);          SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs);
1878                  dec->last_reduced_resolution = reduced_resolution;                  dec->last_reduced_resolution = reduced_resolution;
1879            dec->last_coding_type = coding_type;
1880    
1881                  dec->frames++;                  dec->frames++;
1882                  seen_something = 1;                  seen_something = 1;
# Line 1905  Line 1885 
1885    
1886                  if (dec->low_delay)                  if (dec->low_delay)
1887                  {                  {
1888                          DPRINTF(DPRINTF_ERROR, "warning: bvop found in low_delay==1 stream");                          DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n");
1889                          dec->low_delay = 1;                          dec->low_delay = 1;
1890                  }                  }
1891    
# Line 1923  Line 1903 
1903                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);
1904                  }                  }
1905    
1906                  decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution);                  decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);
1907                  output = 1;                  output = 1;
1908                  dec->frames++;                  dec->frames++;
1909          }          }
# Line 1946  Line 1926 
1926                  if (dec->packed_mode && seen_something)                  if (dec->packed_mode && seen_something)
1927                  {                  {
1928                          /* output the recently decoded frame */                          /* output the recently decoded frame */
1929                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution);                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);
                         output = 1;  
1930                  }                  }
1931                  else                  else
1932                  {                  {
# Line 1957  Line 1936 
1936                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,
1937                                  "bframe decoder lag");                                  "bframe decoder lag");
1938    
1939                          decoder_output(dec, &dec->cur, NULL, frame, 1 /*disable pp*/);                          decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP);
1940                  }                          if (stats) stats->type = XVID_TYPE_NOTHING;
         }  
   
         frame->length = BitstreamPos(&bs) / 8;  
1941    
1942          if (stats)                  }
         {  
                 stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING;  
                 stats->data.vop.time_base = (int)dec->time_base;  
                 stats->data.vop.time_increment = 0;     /* XXX: todo */  
1943          }          }
1944    
1945          emms();          emms();
   
1946          stop_global_timer();          stop_global_timer();
1947    
1948          return XVID_ERR_OK;          return BitstreamPos(&bs) / 8;   /* number of bytes consumed */
1949  }  }

Legend:
Removed from v.1.49  
changed lines
  Added in v.1.49.2.11

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