[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.37.2.27, Sat Jan 11 14:59:23 2003 UTC revision 1.49.2.14, Fri Oct 3 15:49:21 2003 UTC
# Line 1  Line 1 
1  /**************************************************************************  /*****************************************************************************
2   *   *
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  -  Decoder main module  -   *  - Decoder Module -
5   *   *
6   *  This program is an implementation of a part of one or more MPEG-4   *  Copyright(C) 2002      MinChen <chenm001@163.com>
7   *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending   *               2002-2003 Peter Ross <pross@xvid.org>
  *  to use this software module in hardware or software products are  
  *  advised that its use may infringe existing patents or copyrights, and  
  *  any such use would be at such party's own risk.  The original  
  *  developer of this software module and his/her company, and subsequent  
  *  editors and their companies, will have no liability for use of this  
  *  software or modifications or derivatives thereof.  
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 26  Line 20 
20   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
21   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   *   *
  *************************************************************************/  
   
 /**************************************************************************  
  *  
  *  History:  
  *  
  *  15.07.2002  fix a bug in B-frame decode at DIRECT mode  
  *              MinChen <chenm001@163.com>  
  *  10.07.2002  added BFRAMES_DEC_DEBUG support  
  *              Fix a little bug for low_delay flage  
  *              MinChen <chenm001@163.com>  
  *  28.06.2002  added basic resync support to iframe/pframe_decode()  
  *  22.06.2002  added primative N_VOP support  
  *                              #define BFRAMES_DEC now enables Minchen's bframe decoder  
  *  08.05.2002  add low_delay support for B_VOP decode  
  *              MinChen <chenm001@163.com>  
  *  05.05.2002  fix some B-frame decode problem  
  *  02.05.2002  add B-frame decode support(have some problem);  
  *              MinChen <chenm001@163.com>  
  *  22.04.2002  add some B-frame decode support;  chenm001 <chenm001@163.com>  
  *  29.03.2002  interlacing fix - compensated block wasn't being used when  
  *              reconstructing blocks, thus artifacts  
  *              interlacing speedup - used transfers to re-interlace  
  *              interlaced decoding should be as fast as progressive now  
  *  26.03.2002  interlacing support - moved transfers outside decode loop  
  *  26.12.2001  decoder_mbinter: dequant/idct moved within if(coded) block  
  *  22.12.2001  lock based interpolation  
  *  01.12.2001  inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>  
  *  
23   *  $Id$   *  $Id$
24   *   *
25   *************************************************************************/   ****************************************************************************/
26    
27  #include <stdio.h>  #include <stdio.h>
28  #include <stdlib.h>  #include <stdlib.h>
# Line 89  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 98  Line 64 
64  decoder_resize(DECODER * dec)  decoder_resize(DECODER * dec)
65  {  {
66          /* free existing */          /* free existing */
   
67          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
68          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
69          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
# Line 113  Line 78 
78                  xvid_free(dec->mbs);                  xvid_free(dec->mbs);
79    
80          /* realloc */          /* realloc */
   
81          dec->mb_width = (dec->width + 15) / 16;          dec->mb_width = (dec->width + 15) / 16;
82          dec->mb_height = (dec->height + 15) / 16;          dec->mb_height = (dec->height + 15) / 16;
83    
# Line 131  Line 95 
95                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
96          }          }
97    
98          // add by chenm001 <chenm001@163.com>          /* Support B-frame to reference last 2 frame */
         // for support B-frame to reference last 2 frame  
99          if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) {          if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) {
100                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
101                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
# Line 180  Line 143 
143          }          }
144          memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);          memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);
145    
146          // add by chenm001 <chenm001@163.com>          /* For skip MB flag */
         // for skip MB flag  
147          dec->last_mbs =          dec->last_mbs =
148                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,
149                                          CACHE_LINE);                                          CACHE_LINE);
# Line 198  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 233  Line 198 
198    
199          init_timer();          init_timer();
200    
201          // add by chenm001 <chenm001@163.com>          /* For B-frame support (used to save reference frame's time */
         // for support B-frame to save reference frame's time  
202          dec->frames = 0;          dec->frames = 0;
203          dec->time = dec->time_base = dec->last_time_base = 0;          dec->time = dec->time_base = dec->last_time_base = 0;
204          dec->low_delay = 0;          dec->low_delay = 0;
# Line 245  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 255  Line 219 
219          xvid_free(dec->last_mbs);          xvid_free(dec->last_mbs);
220          xvid_free(dec->mbs);          xvid_free(dec->mbs);
221    
222          image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);          /* image based GMC */          /* image based GMC */
223            image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);
224    
225          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
226          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
# Line 265  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 277  Line 242 
242    
243    
244    
245  // decode an intra macroblock  /* decode an intra macroblock */
   
246  void  void
247  decoder_mbintra(DECODER * dec,  decoder_mbintra(DECODER * dec,
248                                  MACROBLOCK * pMB,                                  MACROBLOCK * pMB,
# Line 313  Line 277 
277                  pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);                  pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
278          }          }
279    
280          memset(block, 0, 6 * 64 * sizeof(int16_t));     // clear          memset(block, 0, 6 * 64 * sizeof(int16_t));     /* clear */
281    
282          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
283                  uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);                  uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
# Line 336  Line 300 
300                          dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0;                          dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0;
301    
302                          if (dc_size > 8) {                          if (dc_size > 8) {
303                                  BitstreamSkip(bs, 1);   // marker                                  BitstreamSkip(bs, 1);   /* marker */
304                          }                          }
305    
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                  }                  }
313    
314                  start_timer();                  start_timer();
315                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       /* coded */
316                  {                  {
317                          int direction = dec->alternate_vertical_scan ?                          int direction = dec->alternate_vertical_scan ?
318                                  2 : pMB->acpred_directions[i];                                  2 : pMB->acpred_directions[i];
# Line 405  Line 369 
369    
370    
371    
372  // decode an inter macroblock  /* decode an inter macroblock */
   
373  void  void
374  decoder_mbinter(DECODER * dec,  decoder_mbinter(DECODER * dec,
375                                  const MACROBLOCK * pMB,                                  const MACROBLOCK * pMB,
376                                  const uint32_t x_pos,                                  const uint32_t x_pos,
377                                  const uint32_t y_pos,                                  const uint32_t y_pos,
378                                  const uint32_t acpred_flag,                                  const uint32_t fcode,
379                                  const uint32_t cbp,                                  const uint32_t cbp,
380                                  Bitstream * bs,                                  Bitstream * bs,
381                                  const uint32_t quant,                                  const uint32_t quant,
382                                  const uint32_t rounding,                                  const uint32_t rounding,
383                                  const int reduced_resolution,                                  const int reduced_resolution)
                                 const int mcsel)  
384  {  {
385    
386          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
# Line 430  Line 392 
392          uint32_t i;          uint32_t i;
393          uint32_t iQuant = pMB->quant;          uint32_t iQuant = pMB->quant;
394          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
         uint8_t *pY_Ref, *pU_Ref, *pV_Ref;              /* ref for GMC is _not_ pRef itself */  
395    
396          int uv_dx, uv_dy;          int uv_dx, uv_dy;
397          VECTOR mv[4];   /* local copy of mvs */          VECTOR mv[4];   /* local copy of mvs */
# Line 451  Line 412 
412                          mv[i] = pMB->mvs[i];                          mv[i] = pMB->mvs[i];
413          }          }
414    
         if (mcsel) {  
                 mv[0].x = mv[0].y = mv[1].x = mv[1].y = mv[2].x = mv[2].y = mv[3].x = mv[3].y = 0;  
                         /* position in ref is same as the block, set vector to (0,0) */  
                 pY_Ref = dec->gmc.y;  
                 pU_Ref = dec->gmc.u;  
                 pV_Ref = dec->gmc.v;  
                         /* but reference itself isn't. It's warped... */  
                         /* Btw., this is too slow! For GMC it should simply be transfer_16to8add() */  
         } else {  
                 pY_Ref = dec->refn[0].y;  
                 pU_Ref = dec->refn[0].u;  
                 pV_Ref = dec->refn[0].v;  
         }  
   
415          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {
416    
417                  uv_dx = mv[0].x / (1 + dec->quarterpel);                  uv_dx = mv[0].x / (1 + dec->quarterpel);
# Line 476  Line 423 
423                  start_timer();                  start_timer();
424                  if (reduced_resolution)                  if (reduced_resolution)
425                  {                  {
426                          interpolate32x32_switch(dec->cur.y, pY_Ref , 32*x_pos, 32*y_pos,                          interpolate32x32_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,
427                                                                    mv[0].x, mv[0].y, stride,  rounding);                                                                    mv[0].x, mv[0].y, stride,  rounding);
428                          interpolate16x16_switch(dec->cur.u, pU_Ref , 16 * x_pos, 16 * y_pos,                          interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos,
429                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
430                          interpolate16x16_switch(dec->cur.v, pV_Ref , 16 * x_pos, 16 * y_pos,                          interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos,
431                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
432    
433                  }                  }
434                  else                  else
435                  {                  {
436                          if(dec->quarterpel) {                          if(dec->quarterpel) {
437                                  interpolate16x16_quarterpel(dec->cur.y, pY_Ref , dec->qtmp.y, dec->qtmp.y + 64,                                  interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->qtmp.y, dec->qtmp.y + 64,
438                                                                                          dec->qtmp.y + 128, 16*x_pos, 16*y_pos,                                                                                          dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
439                                                                                          mv[0].x, mv[0].y, stride, rounding);                                                                                          mv[0].x, mv[0].y, stride, rounding);
440                          }                          }
441                          else {                          else {
442                                  interpolate16x16_switch(dec->cur.y, pY_Ref , 16*x_pos, 16*y_pos,                                  interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,
443                                                                            mv[0].x, mv[0].y, stride, rounding);                                                                            mv[0].x, mv[0].y, stride, rounding);
444                          }                          }
445    
446                          interpolate8x8_switch(dec->cur.u, pU_Ref , 8 * x_pos, 8 * y_pos,                          interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,
447                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
448                          interpolate8x8_switch(dec->cur.v, pV_Ref , 8 * x_pos, 8 * y_pos,                          interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,
449                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
450                  }                  }
451                  stop_comp_timer();                  stop_comp_timer();
# Line 523  Line 470 
470                  start_timer();                  start_timer();
471                  if (reduced_resolution)                  if (reduced_resolution)
472                  {                  {
473                          interpolate16x16_switch(dec->cur.y, pY_Ref , 32*x_pos, 32*y_pos,                          interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,
474                                                                    mv[0].x, mv[0].y, stride,  rounding);                                                                    mv[0].x, mv[0].y, stride,  rounding);
475                          interpolate16x16_switch(dec->cur.y, pY_Ref , 32*x_pos + 16, 32*y_pos,                          interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos + 16, 32*y_pos,
476                                                                    mv[1].x, mv[1].y, stride,  rounding);                                                                    mv[1].x, mv[1].y, stride,  rounding);
477                          interpolate16x16_switch(dec->cur.y, pY_Ref , 32*x_pos, 32*y_pos + 16,                          interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos, 32*y_pos + 16,
478                                                                    mv[2].x, mv[2].y, stride,  rounding);                                                                    mv[2].x, mv[2].y, stride,  rounding);
479                          interpolate16x16_switch(dec->cur.y, pY_Ref , 32*x_pos + 16, 32*y_pos + 16,                          interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos + 16, 32*y_pos + 16,
480                                                                    mv[3].x, mv[3].y, stride,  rounding);                                                                    mv[3].x, mv[3].y, stride,  rounding);
481                          interpolate16x16_switch(dec->cur.u, pU_Ref , 16 * x_pos, 16 * y_pos,                          interpolate16x16_switch(dec->cur.u, dec->refn[0].u , 16 * x_pos, 16 * y_pos,
482                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
483                          interpolate16x16_switch(dec->cur.v, pV_Ref , 16 * x_pos, 16 * y_pos,                          interpolate16x16_switch(dec->cur.v, dec->refn[0].v , 16 * x_pos, 16 * y_pos,
484                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
485    
486                          // set_block(pY_Cur, stride, 32, 32, 127);                          /* set_block(pY_Cur, stride, 32, 32, 127); */
487                  }                  }
488                  else                  else
489                  {                  {
490                          if(dec->quarterpel) {                          if(dec->quarterpel) {
491                                  interpolate8x8_quarterpel(dec->cur.y, pY_Ref , dec->qtmp.y, dec->qtmp.y + 64,                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
492                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos,                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
493                                                                                    mv[0].x, mv[0].y, stride,  rounding);                                                                                    mv[0].x, mv[0].y, stride,  rounding);
494                                  interpolate8x8_quarterpel(dec->cur.y, pY_Ref , dec->qtmp.y, dec->qtmp.y + 64,                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
495                                                                                    dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos,                                                                                    dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos,
496                                                                                    mv[1].x, mv[1].y, stride,  rounding);                                                                                    mv[1].x, mv[1].y, stride,  rounding);
497                                  interpolate8x8_quarterpel(dec->cur.y, pY_Ref , dec->qtmp.y, dec->qtmp.y + 64,                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
498                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8,                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8,
499                                                                                    mv[2].x, mv[2].y, stride,  rounding);                                                                                    mv[2].x, mv[2].y, stride,  rounding);
500                                  interpolate8x8_quarterpel(dec->cur.y, pY_Ref , dec->qtmp.y, dec->qtmp.y + 64,                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
501                                                                                    dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8,                                                                                    dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8,
502                                                                                    mv[3].x, mv[3].y, stride,  rounding);                                                                                    mv[3].x, mv[3].y, stride,  rounding);
503                          }                          }
504                          else {                          else {
505                                  interpolate8x8_switch(dec->cur.y, pY_Ref , 16*x_pos, 16*y_pos,                                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y , 16*x_pos, 16*y_pos,
506                                                                            mv[0].x, mv[0].y, stride,  rounding);                                                                            mv[0].x, mv[0].y, stride,  rounding);
507                                  interpolate8x8_switch(dec->cur.y, pY_Ref , 16*x_pos + 8, 16*y_pos,                                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y , 16*x_pos + 8, 16*y_pos,
508                                                                            mv[1].x, mv[1].y, stride,  rounding);                                                                            mv[1].x, mv[1].y, stride,  rounding);
509                                  interpolate8x8_switch(dec->cur.y, pY_Ref , 16*x_pos, 16*y_pos + 8,                                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y , 16*x_pos, 16*y_pos + 8,
510                                                                            mv[2].x, mv[2].y, stride,  rounding);                                                                            mv[2].x, mv[2].y, stride,  rounding);
511                                  interpolate8x8_switch(dec->cur.y, pY_Ref , 16*x_pos + 8, 16*y_pos + 8,                                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y , 16*x_pos + 8, 16*y_pos + 8,
512                                                                            mv[3].x, mv[3].y, stride,  rounding);                                                                            mv[3].x, mv[3].y, stride,  rounding);
513                          }                          }
514    
515                          interpolate8x8_switch(dec->cur.u, pU_Ref , 8 * x_pos, 8 * y_pos,                          interpolate8x8_switch(dec->cur.u, dec->refn[0].u , 8 * x_pos, 8 * y_pos,
516                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
517                          interpolate8x8_switch(dec->cur.v, pV_Ref , 8 * x_pos, 8 * y_pos,                          interpolate8x8_switch(dec->cur.v, dec->refn[0].v , 8 * x_pos, 8 * y_pos,
518                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
519                  }                  }
520                  stop_comp_timer();                  stop_comp_timer();
# Line 576  Line 523 
523          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
524                  int direction = dec->alternate_vertical_scan ? 2 : 0;                  int direction = dec->alternate_vertical_scan ? 2 : 0;
525    
526                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       /* coded */
527                  {                  {
528                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        /* clear */
529    
530                          start_timer();                          start_timer();
531                          get_inter_block(bs, &block[i * 64], direction);                          get_inter_block(bs, &block[i * 64], direction);
# Line 638  Line 585 
585  }  }
586    
587    
588    static void
589    decoder_mbgmc(DECODER * dec,
590                                    MACROBLOCK * const pMB,
591                                    const uint32_t x_pos,
592                                    const uint32_t y_pos,
593                                    const uint32_t fcode,
594                                    const uint32_t cbp,
595                                    Bitstream * bs,
596                                    const uint32_t quant,
597                                    const uint32_t rounding,
598                                    const int reduced_resolution)   /* no reduced res support */
599    {
600    
601            DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
602            DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);
603    
604            const uint32_t stride = dec->edged_width;
605            const uint32_t stride2 = stride / 2;
606            const uint32_t next_block = stride * (reduced_resolution ? 16 : 8);
607            uint32_t i;
608            const uint32_t iQuant = pMB->quant;
609            uint8_t *const pY_Cur=dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
610            uint8_t *const pU_Cur=dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
611            uint8_t *const pV_Cur=dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
612    
613            pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
614    
615            start_timer();
616    
617    /* this is where the calculations are done */
618    
619            {       NEW_GMC_DATA * gmc_data = &dec->new_gmc_data;
620    
621                            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);
633                    pMB->amv.y = gmc_sanitize(pMB->amv.y, dec->quarterpel, fcode);
634            }
635            pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
636    
637    /*
638            transfer16x16_copy(pY_Cur, dec->gmc.y + (y_pos << 4)*stride + (x_pos  << 4), stride);
639            transfer8x8_copy(pU_Cur, dec->gmc.u + (y_pos << 3)*stride2 + (x_pos  << 3), stride2);
640            transfer8x8_copy(pV_Cur, dec->gmc.v + (y_pos << 3)*stride2 + (x_pos << 3), stride2);
641    */
642    
643    
644            stop_transfer_timer();
645    
646            if (!cbp) return;
647    
648            for (i = 0; i < 6; i++) {
649                    int direction = dec->alternate_vertical_scan ? 2 : 0;
650    
651                    if (cbp & (1 << (5 - i)))       /* coded */
652                    {
653                            memset(&block[i * 64], 0, 64 * sizeof(int16_t));        /* clear */
654    
655                            start_timer();
656                            get_inter_block(bs, &block[i * 64], direction);
657                            stop_coding_timer();
658    
659                            start_timer();
660                            if (dec->quant_type == 0) {
661                                    dequant_inter(&data[i * 64], &block[i * 64], iQuant);
662                            } else {
663                                    dequant4_inter(&data[i * 64], &block[i * 64], iQuant);
664                            }
665                            stop_iquant_timer();
666    
667                            start_timer();
668                            idct(&data[i * 64]);
669                            stop_idct_timer();
670                    }
671            }
672    
673    /* interlace + GMC is this possible ??? */
674    /*
675      if (dec->interlacing && pMB->field_dct) {
676              next_block = stride;
677              stride *= 2;
678      }
679    */
680            start_timer();
681            if (cbp & 32)
682                    transfer_16to8add(pY_Cur, &data[0 * 64], stride);
683            if (cbp & 16)
684                    transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
685            if (cbp & 8)
686                    transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
687            if (cbp & 4)
688                    transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride);
689            if (cbp & 2)
690                    transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
691            if (cbp & 1)
692                    transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
693            stop_transfer_timer();
694    }
695    
696    
697  void  void
698  decoder_iframe(DECODER * dec,  decoder_iframe(DECODER * dec,
699                             Bitstream * bs,                             Bitstream * bs,
# Line 679  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 706  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 744  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 767  Line 823 
823    
824    
825    
 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;  
 }  
826    
827    
828  /* for P_VOP set gmc_warp to NULL */  /* for P_VOP set gmc_warp to NULL */
# Line 799  Line 843 
843          uint32_t mb_width = dec->mb_width;          uint32_t mb_width = dec->mb_width;
844          uint32_t mb_height = dec->mb_height;          uint32_t mb_height = dec->mb_height;
845    
         static int framecount=0;  
846          if (reduced_resolution)          if (reduced_resolution)
847          {          {
848                  mb_width = (dec->width + 31) / 32;                  mb_width = (dec->width + 31) / 32;
# Line 813  Line 856 
856    
857          if (gmc_warp)          if (gmc_warp)
858          {          {
859                  char filename[80];  
860                  sprintf(filename,"dGMC%05d.pgm",framecount);                  /* accuracy:  0==1/2, 1=1/4, 2=1/8, 3=1/16 */
861                  // accuracy:  0==1/2, 1=1/4, 2=1/8, 3=1/16  /*              {
862                  if ( (dec->sprite_warping_accuracy != 3) || (dec->sprite_warping_points != 2) )                          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);
   
                 generate_GMCimage(&dec->gmc_data, &dec->refn[0],  
                                         mb_width, mb_height,  
                                         dec->edged_width, dec->edged_width/2,  
                                         fcode, 0, 0,  
                                         rounding, dec->mbs, &dec->gmc);  
870    
871  /*  /* image warping is done block-based  in decoder_mbgmc(), now */
                 sprintf(filename,"dGMC%05d.pgm",framecount);  
                 image_dump_yuvpgm(&dec->gmc,  
                                         dec->edged_width, dec->width, dec->height, filename);  
   
                 sprintf(filename,"dREF%05d.pgm",framecount);  
                 image_dump_yuvpgm(&dec->refn[0],  
                                         dec->edged_width, dec->width, dec->height, filename);  
                 sprintf(filename,"dCUR%05d.pgm",framecount);  
                 image_dump_yuvpgm(&dec->cur,  
                                         dec->edged_width, dec->width, dec->height, filename);  
                 framecount++;  
 */  
872          }          }
873    
874          bound = 0;          bound = 0;
# Line 855  Line 878 
878                  for (x = 0; x < mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
879                          MACROBLOCK *mb;                          MACROBLOCK *mb;
880    
881                          // skip stuffing                          /* skip stuffing */
882                          while (BitstreamShowBits(bs, 10) == 1)                          while (BitstreamShowBits(bs, 10) == 1)
883                                  BitstreamSkip(bs, 10);                                  BitstreamSkip(bs, 10);
884    
# Line 868  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 */
898                          {                          {
899                                  uint32_t mcbpc;                                  uint32_t mcbpc;
900                                  uint32_t cbpc;                                  uint32_t cbpc;
# Line 879  Line 902 
902                                  uint32_t cbpy;                                  uint32_t cbpy;
903                                  uint32_t cbp;                                  uint32_t cbp;
904                                  uint32_t intra;                                  uint32_t intra;
905                                  int mcsel = 0;          // mcsel: '0'=local motion, '1'=GMC                                  int mcsel = 0;          /* mcsel: '0'=local motion, '1'=GMC */
906    
907                                  cp_mb++;                                  cp_mb++;
908                                  mcbpc = get_mcbpc_inter(bs);                                  mcbpc = get_mcbpc_inter(bs);
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) && !mcsel) {
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                                  }                                  }
960    
961                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                  if (mcsel) {
962                                            decoder_mbgmc(dec, mb, x, y, fcode, cbp, bs, quant,
963                                                                    rounding, reduced_resolution);
964                                            continue;
965    
966                                          if (mcsel)                                  } else if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
                                         {  
                                                 mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->amv;  
                                            /* already clipped to fcode */  
967    
968                                          } else if (dec->interlacing && mb->field_pred) {                                          if (dec->interlacing && mb->field_pred) {
969                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],
970                                                                                    fcode, bound);                                                                                    fcode, bound);
971                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1],
# Line 961  Line 981 
981                                          get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode, bound);                                          get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode, bound);
982                                          get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode, bound);                                          get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode, bound);
983                                          get_motion_vector(dec, bs, x, y, 3, &mb->mvs[3], fcode, bound);                                          get_motion_vector(dec, bs, x, y, 3, &mb->mvs[3], fcode, bound);
984                                  } else                  // MODE_INTRA, MODE_INTRA_Q                                  } else                  /* MODE_INTRA, MODE_INTRA_Q */
985                                  {                                  {
986                                          mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x =                                          mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x =
987                                                  0;                                                  0;
# Line 972  Line 992 
992                                          continue;                                          continue;
993                                  }                                  }
994    
995                                  decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant,                                  decoder_mbinter(dec, mb, x, y, fcode, cbp, bs, quant,
996                                                                  rounding, reduced_resolution, mcsel);                                                                  rounding, reduced_resolution);
997    
998                          }                          }
999                          else if (gmc_warp)      /* a not coded S(GMC)-VOP macroblock */                          else if (gmc_warp)      /* a not coded S(GMC)-VOP macroblock */
1000                          {                          {
1001                                  mb->mode = MODE_NOT_CODED_GMC;                                  mb->mode = MODE_NOT_CODED_GMC;
                                 mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->amv;  
1002    
1003                                  start_timer();                                  start_timer();
1004    
1005                                  transfer16x16_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x),                                  decoder_mbgmc(dec, mb, x, y, fcode, 0x00, bs, quant,
1006                                                                   dec->gmc.y + (16*y)*dec->edged_width + (16*x),                                                                  rounding, reduced_resolution);
                                                                  dec->edged_width);  
   
                                 transfer8x8_copy(dec->cur.u + (8*y)*dec->edged_width/2 + (8*x),  
                                                                 dec->gmc.u + (8*y)*dec->edged_width/2 + (8*x),  
                                                                 dec->edged_width/2);  
   
                                 transfer8x8_copy(dec->cur.v + (8*y)*dec->edged_width/2 + (8*x),  
                                                                  dec->gmc.v + (8*y)*dec->edged_width/2 + (8*x),  
                                                                  dec->edged_width/2);  
1007    
1008                                  stop_transfer_timer();                                  stop_transfer_timer();
1009    
# Line 1009  Line 1019 
1019    
1020                                  mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0;                                  mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0;
1021                                  mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0;                                  mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0;
1022                                  // copy macroblock directly from ref to cur                                  /* copy macroblock directly from ref to cur */
1023    
1024                                  start_timer();                                  start_timer();
1025    
# Line 1057  Line 1067 
1067  }  }
1068    
1069    
1070  // add by MinChen <chenm001@163.com>  /* decode B-frame motion vector */
 // decode B-frame motion vector  
1071  void  void
1072  get_b_motion_vector(DECODER * dec,  get_b_motion_vector(DECODER * dec,
1073                                          Bitstream * bs,                                          Bitstream * bs,
# Line 1102  Line 1111 
1111  }  }
1112    
1113    
1114  // add by MinChen <chenm001@163.com>  /* decode an B-frame forward & backward inter macroblock */
 // decode an B-frame forward & backward inter macroblock  
1115  void  void
1116  decoder_bf_mbinter(DECODER * dec,  decoder_bf_mbinter(DECODER * dec,
1117                                     const MACROBLOCK * pMB,                                     const MACROBLOCK * pMB,
# Line 1187  Line 1195 
1195          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
1196                  int direction = dec->alternate_vertical_scan ? 2 : 0;                  int direction = dec->alternate_vertical_scan ? 2 : 0;
1197    
1198                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       /* coded */
1199                  {                  {
1200                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        /* clear */
1201    
1202                          start_timer();                          start_timer();
1203                          get_inter_block(bs, &block[i * 64], direction);                          get_inter_block(bs, &block[i * 64], direction);
# Line 1230  Line 1238 
1238          stop_transfer_timer();          stop_transfer_timer();
1239  }  }
1240    
1241  // add by MinChen <chenm001@163.com>  /* decode an B-frame direct &  inter macroblock */
 // decode an B-frame direct &  inter macroblock  
1242  void  void
1243  decoder_bf_interpolate_mbinter(DECODER * dec,  decoder_bf_interpolate_mbinter(DECODER * dec,
1244                                                             IMAGE forward,                                                             IMAGE forward,
# Line 1428  Line 1435 
1435          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
1436                  int direction = dec->alternate_vertical_scan ? 2 : 0;                  int direction = dec->alternate_vertical_scan ? 2 : 0;
1437    
1438                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       /* coded */
1439                  {                  {
1440                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        /* clear */
1441    
1442                          start_timer();                          start_timer();
1443                          get_inter_block(bs, &block[i * 64], direction);                          get_inter_block(bs, &block[i * 64], direction);
# Line 1472  Line 1479 
1479  }  }
1480    
1481    
1482  // add by MinChen <chenm001@163.com>  /* for decode B-frame dbquant */
 // for decode B-frame dbquant  
1483  int32_t __inline  int32_t __inline
1484  get_dbquant(Bitstream * bs)  get_dbquant(Bitstream * bs)
1485  {  {
1486          if (!BitstreamGetBit(bs))       // '0'          if (!BitstreamGetBit(bs))      /*  '0' */
1487                  return (0);                  return (0);
1488          else if (!BitstreamGetBit(bs))  // '10'          else if (!BitstreamGetBit(bs)) /* '10' */
1489                  return (-2);                  return (-2);
1490          else          else                           /* '11' */
1491                  return (2);                             // '11'                  return (2);
1492  }  }
1493    
1494  // add by MinChen <chenm001@163.com>  /*
1495  // for decode B-frame mb_type   * For decode B-frame mb_type
1496  // bit   ret_value   * bit   ret_value
1497  // 1        0   * 1        0
1498  // 01       1   * 01       1
1499  // 001      2   * 001      2
1500  // 0001     3   * 0001     3
1501     */
1502  int32_t __inline  int32_t __inline
1503  get_mbtype(Bitstream * bs)  get_mbtype(Bitstream * bs)
1504  {  {
# Line 1540  Line 1547 
1547  #endif  #endif
1548    
1549          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < dec->mb_height; y++) {
1550                  // Initialize Pred Motion Vector                  /* Initialize Pred Motion Vector */
1551                  dec->p_fmv = dec->p_bmv = zeromv;                  dec->p_fmv = dec->p_bmv = zeromv;
1552                  for (x = 0; x < dec->mb_width; x++) {                  for (x = 0; x < dec->mb_width; x++) {
1553                          MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x];                          MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x];
# Line 1550  Line 1557 
1557                          mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] =                          mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] =
1558                          mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv;                          mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv;
1559    
1560                          // skip if the co-located P_VOP macroblock is not coded                          /*
1561                          // note: gmc+not_coded isn't skipped                           * skip if the co-located P_VOP macroblock is not coded
1562                             * if not codec in co-located S_VOP macroblock is _not_
1563                             * automatically skipped
1564                             */
1565    
1566                          if (last_mb->mode == MODE_NOT_CODED) {                          if (last_mb->mode == MODE_NOT_CODED) {
1567                                  //DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y);                                  /* DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); */
1568                                  mb->cbp = 0;                                  mb->cbp = 0;
1569  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
1570                                  mb->mb_type = MODE_NOT_CODED;                                  mb->mb_type = MODE_NOT_CODED;
# Line 1562  Line 1572 
1572  #endif  #endif
1573                                  mb->mb_type = MODE_FORWARD;                                  mb->mb_type = MODE_FORWARD;
1574                                  mb->quant = last_mb->quant;                                  mb->quant = last_mb->quant;
1575                                  //mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x;                                  /*
1576                                  //mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y;                                    mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x;
1577                                      mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y;
1578                                    */
1579    
1580                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, mb->quant, 1);                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, mb->quant, 1);
1581                                  continue;                                  continue;
1582                          }                          }
1583    
1584                          if (!BitstreamGetBit(bs)) {     // modb=='0'                          if (!BitstreamGetBit(bs)) {     /* modb=='0' */
1585                                  const uint8_t modb2 = BitstreamGetBit(bs);                                  const uint8_t modb2 = BitstreamGetBit(bs);
1586    
1587                                  mb->mb_type = get_mbtype(bs);                                  mb->mb_type = get_mbtype(bs);
1588    
1589                                  if (!modb2) {   // modb=='00'                                  if (!modb2) {   /* modb=='00' */
1590                                          mb->cbp = BitstreamGetBits(bs, 6);                                          mb->cbp = BitstreamGetBits(bs, 6);
1591                                  } else {                                  } else {
1592                                          mb->cbp = 0;                                          mb->cbp = 0;
# Line 1588  Line 1600 
1600                                                  quant = 1;                                                  quant = 1;
1601                                          }                                          }
1602                                  }                                  }
1603    
1604                                    if (dec->interlacing) {
1605                                            if (mb->cbp) {
1606                                                    mb->field_dct = BitstreamGetBit(bs);
1607                                                    DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct);
1608                                            }
1609    
1610                                            if (mb->mb_type) {
1611                                                    mb->field_pred = BitstreamGetBit(bs);
1612                                                    DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred);
1613    
1614                                                    if (mb->field_pred) {
1615                                                            mb->field_for_top = BitstreamGetBit(bs);
1616                                                            DPRINTF(XVID_DEBUG_MB,"decp: field_for_top: %i\n", mb->field_for_top);
1617                                                            mb->field_for_bot = BitstreamGetBit(bs);
1618                                                            DPRINTF(XVID_DEBUG_MB,"decp: field_for_bot: %i\n", mb->field_for_bot);
1619                                                    }
1620                                            }
1621                                    }
1622    
1623                          } else {                          } else {
1624                                  mb->mb_type = MODE_DIRECT_NONE_MV;                                  mb->mb_type = MODE_DIRECT_NONE_MV;
1625                                  mb->cbp = 0;                                  mb->cbp = 0;
# Line 1595  Line 1627 
1627    
1628                          mb->quant = quant;                          mb->quant = quant;
1629                          mb->mode = MODE_INTER4V;                          mb->mode = MODE_INTER4V;
1630                          //DEBUG1("Switch bm_type=",mb->mb_type);                          /* DEBUG1("Switch bm_type=",mb->mb_type); */
1631    
1632  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
1633          BFRAME_DEBUG          BFRAME_DEBUG
# Line 1624  Line 1656 
1656                                                                                    / TRD                                                                                    / TRD
1657                                                                              : mb->mvs[i].y - last_mb->mvs[i].y);                                                                              : mb->mvs[i].y - last_mb->mvs[i].y);
1658                                          }                                          }
1659                                          //DEBUG("B-frame Direct!\n");                                          /* DEBUG("B-frame Direct!\n"); */
1660                                  }                                  }
1661                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
1662                                                                                             mb, x, y, bs);                                                                                             mb, x, y, bs);
# Line 1642  Line 1674 
1674    
1675                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
1676                                                                                             mb, x, y, bs);                                                                                             mb, x, y, bs);
1677                                  //DEBUG("B-frame Bidir!\n");                                  /* DEBUG("B-frame Bidir!\n"); */
1678                                  break;                                  break;
1679    
1680                          case MODE_BACKWARD:                          case MODE_BACKWARD:
# Line 1652  Line 1684 
1684    
1685                                  mb->mode = MODE_INTER;                                  mb->mode = MODE_INTER;
1686                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0);                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0);
1687                                  //DEBUG("B-frame Backward!\n");                                  /* DEBUG("B-frame Backward!\n"); */
1688                                  break;                                  break;
1689    
1690                          case MODE_FORWARD:                          case MODE_FORWARD:
# Line 1662  Line 1694 
1694    
1695                                  mb->mode = MODE_INTER;                                  mb->mode = MODE_INTER;
1696                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1);                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1);
1697                                  //DEBUG("B-frame Forward!\n");                                  /* DEBUG("B-frame Forward!\n"); */
1698                                  break;                                  break;
1699    
1700                          default:                          default:
1701                                  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);
1702                          }                          }
1703                    } /* End of for */
                 }                                               // end of FOR  
1704          }          }
1705    
1706  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
1707          if (!first){          if (!first){
1708                  first=1;                  first=1;
# Line 1680  Line 1712 
1712  #endif  #endif
1713  }  }
1714    
 // swap two MACROBLOCK array  
 void  
 mb_swap(MACROBLOCK ** mb1,  
                 MACROBLOCK ** mb2)  
 {  
         MACROBLOCK *temp = *mb1;  
   
         *mb1 = *mb2;  
         *mb2 = temp;  
 }  
1715    
1716    
1717  /* perform post processing if necessary, and output the image */  /* perform post processing if necessary, and output the image */
1718  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,
1719                                          const XVID_DEC_FRAME * frame, int pp_disable)                                          xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type)
1720  {  {
1721    
         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;  
         }  
1722    
1723          image_output(img, dec->width, dec->height,          image_output(img, dec->width, dec->height,
1724                                   dec->edged_width, frame->image, frame->stride,                                   dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride,
1725                                   frame->colorspace, dec->interlacing);                                   frame->output.csp, dec->interlacing);
1726    
1727            if (stats)
1728            {
1729                    stats->type = coding2type(coding_type);
1730                    stats->data.vop.time_base = (int)dec->time_base;
1731                    stats->data.vop.time_increment = 0;     /* XXX: todo */
1732            }
1733  }  }
1734    
1735    
1736  int  int
1737  decoder_decode(DECODER * dec,  decoder_decode(DECODER * dec,
1738                             XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats)                             xvid_dec_frame_t * frame, xvid_dec_stats_t * stats)
1739  {  {
1740    
1741          Bitstream bs;          Bitstream bs;
# Line 1726  Line 1746 
1746          uint32_t fcode_backward;          uint32_t fcode_backward;
1747          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
1748          WARPPOINTS gmc_warp;          WARPPOINTS gmc_warp;
1749          uint32_t vop_type;          int coding_type;
1750          int success = 0;          int success, output, seen_something;
         int output = 0;  
         int seen_something = 0;  
1751    
1752          start_global_timer();          if (XVID_VERSION_MAJOR(frame->version) != 1 || (stats && XVID_VERSION_MAJOR(stats->version) != 1))      /* v1.x.x */
1753                    return XVID_ERR_VERSION;
1754    
1755          dec->low_delay_default = (frame->general & XVID_DEC_LOWDELAY);          start_global_timer();
         dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL;  
1756    
1757          if ((frame->general & XVID_DEC_DISCONTINUITY))          dec->low_delay_default = (frame->general & XVID_LOWDELAY);
1758            if ((frame->general & XVID_DISCONTINUITY))
1759                  dec->frames = 0;                  dec->frames = 0;
1760            dec->out_frm = (frame->output.csp == XVID_CSP_SLICE) ? &frame->output : NULL;
1761    
1762          if (frame->length < 0)  /* decoder flush */          if (frame->length < 0)  /* decoder flush */
1763          {          {
1764            int ret;
1765                  /* 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
1766                      we have a reference frame, then outout the reference frame */                      we have a reference frame, then outout the reference frame */
1767                  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) {
1768                  {                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);
1769                          decoder_output(dec, &dec->refn[0], dec->mbs, frame, dec->last_reduced_resolution);              dec->frames = 0;
1770                          output = 1;              ret = 0;
1771                  }          }else{
1772                if (stats) stats->type = XVID_TYPE_NOTHING;
1773                  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  
1774                  }                  }
1775    
1776                  emms();                  emms();
   
1777                  stop_global_timer();                  stop_global_timer();
1778                  return XVID_ERR_OK;                  return ret;
1779          }          }
1780    
1781          BitstreamInit(&bs, frame->bitstream, frame->length);          BitstreamInit(&bs, frame->bitstream, frame->length);
1782    
1783          // XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's          /* XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's */
1784          if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f)          if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f)
1785          {          {
                 if (stats)  
                         stats->notify = XVID_DEC_VOP;  
                 frame->length = 1;  
1786                  image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width,                  image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width,
1787                                           frame->image, frame->stride, frame->colorspace, dec->interlacing);                                           (uint8_t**)frame->output.plane, frame->output.stride, frame->output.csp, dec->interlacing);
1788                    if (stats) stats->type = XVID_TYPE_NOTHING;
1789                  emms();                  emms();
1790                  return XVID_ERR_OK;                  return 1;   /* one byte consumed */
1791          }          }
1792    
1793            success = 0;
1794            output = 0;
1795            seen_something = 0;
1796    
1797  repeat:  repeat:
1798    
1799          vop_type =      BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,          coding_type =   BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,
1800                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp);                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp);
1801    
1802          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",
1803                                                          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);
1804    
1805          if (vop_type == - 1)          if (coding_type == -1) /* nothing */
1806          {          {
1807                  if (success) goto done;                  if (success) goto done;
1808            if (stats) stats->type = XVID_TYPE_NOTHING;
1809                  emms();                  emms();
1810                  return XVID_ERR_FAIL;          return BitstreamPos(&bs)/8;
1811          }          }
1812    
1813          if (vop_type == -2 || vop_type == -3)          if (coding_type == -2 || coding_type == -3)   /* vol and/or resize */
1814          {          {
1815                  if (vop_type == -3)                  if (coding_type == -3)
1816                          decoder_resize(dec);                          decoder_resize(dec);
1817    
1818                  if (stats)                  if (stats)
1819                  {                  {
1820                          stats->notify = XVID_DEC_VOL;                          stats->type = XVID_TYPE_VOL;
1821                          stats->data.vol.general = 0;                          stats->data.vol.general = 0;
1822                          if (dec->interlacing)                          /*XXX: if (dec->interlacing)
1823                                  stats->data.vol.general |= XVID_INTERLACING;                                  stats->data.vol.general |= ++INTERLACING; */
1824                          stats->data.vol.width = dec->width;                          stats->data.vol.width = dec->width;
1825                          stats->data.vol.height = dec->height;                          stats->data.vol.height = dec->height;
1826                          stats->data.vol.aspect_ratio = dec->aspect_ratio;                          stats->data.vol.par = dec->aspect_ratio;
1827                          stats->data.vol.par_width = dec->par_width;                          stats->data.vol.par_width = dec->par_width;
1828                          stats->data.vol.par_height = dec->par_height;                          stats->data.vol.par_height = dec->par_height;
                         frame->length = BitstreamPos(&bs) / 8;  
1829                          emms();                          emms();
1830                          return XVID_ERR_OK;                          return BitstreamPos(&bs)/8;     /* number of bytes consumed */
1831                  }                  }
1832                  goto repeat;                  goto repeat;
1833          }          }
1834    
1835          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 */
   
1836    
1837          /* packed_mode: special-N_VOP treament */          /* packed_mode: special-N_VOP treament */
1838          if (dec->packed_mode && vop_type == N_VOP)          if (dec->packed_mode && coding_type == N_VOP)
1839          {          {
1840                  if (dec->low_delay_default && dec->frames > 0)                  if (dec->low_delay_default && dec->frames > 0)
1841                  {                  {
1842                          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);
1843                          output = 1;                          output = 1;
1844                  }                  }
1845                  /* ignore otherwise */                  /* ignore otherwise */
1846          }          }
1847          else if (vop_type != B_VOP)          else if (coding_type != B_VOP)
1848          {          {
1849                  switch(vop_type)                  switch(coding_type)
1850                  {                  {
1851                  case I_VOP :                  case I_VOP :
1852                          decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);                          decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);
# Line 1844  Line 1860 
1860                                                  fcode_forward, intra_dc_threshold, &gmc_warp);                                                  fcode_forward, intra_dc_threshold, &gmc_warp);
1861                          break;                          break;
1862                  case N_VOP :                  case N_VOP :
1863                            /* XXX: not_coded vops are not used for forward prediction */
1864                            /* we should not swap(last_mbs,mbs) */
1865                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);
1866                          break;                          break;
1867                  }                  }
# Line 1852  Line 1870 
1870                  {                  {
1871                          image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,                          image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,
1872                                  (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width,                                  (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width,
1873                                  16, XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV);                                  16, 0);
1874                  }                  }
1875    
1876                  /* 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 1860  Line 1878 
1878                  {                  {
1879                          if (dec->low_delay)                          if (dec->low_delay)
1880                          {                          {
1881                                  decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution);                                  decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);
1882                                  output = 1;                                  output = 1;
1883                          }                          }
1884                          else if (dec->frames > 0)       /* is the reference frame valid? */                          else if (dec->frames > 0)       /* is the reference frame valid? */
1885                          {                          {
1886                                  /* output the reference frame */                                  /* output the reference frame */
1887                                  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);
1888                                  output = 1;                                  output = 1;
1889                          }                          }
1890                  }                  }
1891    
1892                  image_swap(&dec->refn[0], &dec->refn[1]);                  image_swap(&dec->refn[0], &dec->refn[1]);
1893                  image_swap(&dec->cur, &dec->refn[0]);                  image_swap(&dec->cur, &dec->refn[0]);
1894                  mb_swap(&dec->mbs, &dec->last_mbs);          SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs);
1895                  dec->last_reduced_resolution = reduced_resolution;                  dec->last_reduced_resolution = reduced_resolution;
1896            dec->last_coding_type = coding_type;
1897    
1898                  dec->frames++;                  dec->frames++;
1899                  seen_something = 1;                  seen_something = 1;
# Line 1883  Line 1902 
1902    
1903                  if (dec->low_delay)                  if (dec->low_delay)
1904                  {                  {
1905                          DPRINTF(DPRINTF_ERROR, "warning: bvop found in low_delay==1 stream");                          DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n");
1906                          dec->low_delay = 1;                          dec->low_delay = 1;
1907                  }                  }
1908    
# Line 1901  Line 1920 
1920                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);
1921                  }                  }
1922    
1923                  decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution);                  decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);
1924                  output = 1;                  output = 1;
1925                  dec->frames++;                  dec->frames++;
1926          }          }
# Line 1924  Line 1943 
1943                  if (dec->packed_mode && seen_something)                  if (dec->packed_mode && seen_something)
1944                  {                  {
1945                          /* output the recently decoded frame */                          /* output the recently decoded frame */
1946                          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;  
1947                  }                  }
1948                  else                  else
1949                  {                  {
# Line 1935  Line 1953 
1953                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,
1954                                  "bframe decoder lag");                                  "bframe decoder lag");
1955    
1956                          decoder_output(dec, &dec->cur, NULL, frame, 1 /*disable pp*/);                          decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP);
1957                  }                          if (stats) stats->type = XVID_TYPE_NOTHING;
         }  
   
         frame->length = BitstreamPos(&bs) / 8;  
1958    
1959          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  
1960          }          }
1961    
1962          emms();          emms();
   
1963          stop_global_timer();          stop_global_timer();
1964    
1965          return XVID_ERR_OK;          return BitstreamPos(&bs) / 8;   /* number of bytes consumed */
1966  }  }

Legend:
Removed from v.1.37.2.27  
changed lines
  Added in v.1.49.2.14

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