[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.3, Wed Mar 20 00:27:29 2002 UTC revision 1.30, Mon Jul 15 23:50:31 2002 UTC
# Line 1  Line 1 
1  /**************************************************************************  /**************************************************************************
2   *   *
3   *      XVID MPEG-4 VIDEO CODEC   *      XVID MPEG-4 VIDEO CODEC
4   *      decoder main   *  -  Decoder main module  -
5   *   *
6   *      This program is an implementation of a part of one or more MPEG-4   *      This program is an implementation of a part of one or more MPEG-4
7   *      Video tools as specified in ISO/IEC 14496-2 standard.  Those intending   *      Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
# Line 12  Line 12 
12   *      editors and their companies, will have no liability for use of this   *      editors and their companies, will have no liability for use of this
13   *      software or modifications or derivatives thereof.   *      software or modifications or derivatives thereof.
14   *   *
15   *      This program is xvid_free software; you can redistribute it and/or modify   *  This program is free software; you can redistribute it and/or modify
16   *      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
17   *      the xvid_free Software Foundation; either version 2 of the License, or   *  the Free Software Foundation; either version 2 of the License, or
18   *      (at your option) any later version.   *      (at your option) any later version.
19   *   *
20   *      This program is distributed in the hope that it will be useful,   *      This program is distributed in the hope that it will be useful,
# Line 23  Line 23 
23   *      GNU General Public License for more details.   *      GNU General Public License for more details.
24   *   *
25   *      You should have received a copy of the GNU General Public License   *      You should have received a copy of the GNU General Public License
26   *      along with this program; if not, write to the xvid_free Software   *  along with this program; if not, write to the Free Software
27   *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
28   *   *
29   *************************************************************************/   *************************************************************************/
30    
# Line 32  Line 32 
32   *   *
33   *      History:   *      History:
34   *   *
35     *  15.07.2002  fix a bug in B-frame decode at DIRECT mode
36     *              MinChen <chenm001@163.com>
37     *  10.07.2002  added BFRAMES_DEC_DEBUG support
38     *              Fix a little bug for low_delay flage
39     *              MinChen <chenm001@163.com>
40     *  28.06.2002  added basic resync support to iframe/pframe_decode()
41     *  22.06.2002  added primative N_VOP support
42     *                              #define BFRAMES_DEC now enables Minchen's bframe decoder
43     *  08.05.2002  add low_delay support for B_VOP decode
44     *              MinChen <chenm001@163.com>
45     *  05.05.2002  fix some B-frame decode problem
46     *  02.05.2002  add B-frame decode support(have some problem);
47     *              MinChen <chenm001@163.com>
48     *  22.04.2002  add some B-frame decode support;  chenm001 <chenm001@163.com>
49     *  29.03.2002  interlacing fix - compensated block wasn't being used when
50     *              reconstructing blocks, thus artifacts
51     *              interlacing speedup - used transfers to re-interlace
52     *              interlaced decoding should be as fast as progressive now
53     *  26.03.2002  interlacing support - moved transfers outside decode loop
54   *      26.12.2001      decoder_mbinter: dequant/idct moved within if(coded) block   *      26.12.2001      decoder_mbinter: dequant/idct moved within if(coded) block
55   *      22.12.2001      block based interpolation   *  22.12.2001  lock based interpolation
56   *      01.12.2001      inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>   *      01.12.2001      inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>
57   *   *
58     *  $Id$
59     *
60   *************************************************************************/   *************************************************************************/
61    
62  #include <stdlib.h>  #include <stdlib.h>
63  #include <string.h>  // memset  #include <string.h>
64    
65    #ifdef BFRAMES_DEC_DEBUG
66            #define BFRAMES_DEC
67    #endif
68    
69  #include "xvid.h"  #include "xvid.h"
70  #include "portab.h"  #include "portab.h"
# Line 64  Line 89 
89  #include "image/colorspace.h"  #include "image/colorspace.h"
90  #include "utils/mem_align.h"  #include "utils/mem_align.h"
91    
92  int decoder_create(XVID_DEC_PARAM * param)  int
93    decoder_create(XVID_DEC_PARAM * param)
94  {  {
95          DECODER * dec;          DECODER * dec;
96    
97          dec = xvid_malloc(sizeof(DECODER), 16);          dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);
98          if (dec == NULL)          if (dec == NULL) {
         {  
99                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
100          }          }
101          param->handle = dec;          param->handle = dec;
# Line 83  Line 108 
108    
109          dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE;          dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE;
110          dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE;          dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE;
111            dec->low_delay = 0;
112    
113          if (image_create(&dec->cur, dec->edged_width, dec->edged_height))          if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) {
         {  
114                  xvid_free(dec);                  xvid_free(dec);
115                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
116          }          }
117    
118          if (image_create(&dec->refn, dec->edged_width, dec->edged_height))          if (image_create(&dec->refn[0], dec->edged_width, dec->edged_height)) {
119          {                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
120                    xvid_free(dec);
121                    return XVID_ERR_MEMORY;
122            }
123            // add by chenm001 <chenm001@163.com>
124            // for support B-frame to reference last 2 frame
125            if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) {
126                    image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
127                    image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
128                    xvid_free(dec);
129                    return XVID_ERR_MEMORY;
130            }
131            if (image_create(&dec->refn[2], dec->edged_width, dec->edged_height)) {
132                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
133                    image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
134                    image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
135                  xvid_free(dec);                  xvid_free(dec);
136                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
137          }          }
138    
139          dec->mbs = xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, 16);          dec->mbs =
140          if (dec->mbs == NULL)                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,
141          {                                          CACHE_LINE);
142            if (dec->mbs == NULL) {
143                    image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
144                    image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
145                    image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
146                    image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);
147                    xvid_free(dec);
148                    return XVID_ERR_MEMORY;
149            }
150    
151            memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);
152    
153            // add by chenm001 <chenm001@163.com>
154            // for skip MB flag
155            dec->last_mbs =
156                    xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,
157                                            CACHE_LINE);
158            if (dec->last_mbs == NULL) {
159                    xvid_free(dec->mbs);
160                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
161                    image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
162                    image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
163                    image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);
164                  xvid_free(dec);                  xvid_free(dec);
165                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
166          }          }
167    
168            memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);
169    
170          init_timer();          init_timer();
171          create_vlc_tables();  
172            // add by chenm001 <chenm001@163.com>
173            // for support B-frame to save reference frame's time
174            dec->frames = -1;
175            dec->time = dec->time_base = dec->last_time_base = 0;
176    
177          return XVID_ERR_OK;          return XVID_ERR_OK;
178  }  }
179    
180    
181  int decoder_destroy(DECODER * dec)  int
182    decoder_destroy(DECODER * dec)
183  {  {
184            xvid_free(dec->last_mbs);
185          xvid_free(dec->mbs);          xvid_free(dec->mbs);
186          image_destroy(&dec->refn, dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
187            image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
188            image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);
189          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
190          xvid_free(dec);          xvid_free(dec);
191    
         destroy_vlc_tables();  
   
192          write_timer();          write_timer();
193          return XVID_ERR_OK;          return XVID_ERR_OK;
194  }  }
195    
196    
197    
198  static const int32_t dquant_table[4] =  static const int32_t dquant_table[4] = {
 {  
199          -1, -2, 1, 2          -1, -2, 1, 2
200  };  };
201    
202    
203    
204    
205  // decode an intra macroblock  // decode an intra macroblock
206    
207  void decoder_mbintra(DECODER * dec, MACROBLOCK * mb, int x, int y, uint32_t acpred_flag, uint32_t cbp, Bitstream * bs, int quant, int intra_dc_threshold)  void
208  {  decoder_mbintra(DECODER * dec,
209          uint32_t k;                                  MACROBLOCK * pMB,
210                                    const uint32_t x_pos,
211                                    const uint32_t y_pos,
212                                    const uint32_t acpred_flag,
213                                    const uint32_t cbp,
214                                    Bitstream * bs,
215                                    const uint32_t quant,
216                                    const uint32_t intra_dc_threshold,
217                                    const unsigned int bound)
218    {
219    
220            DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
221            DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);
222    
223            uint32_t stride = dec->edged_width;
224            uint32_t stride2 = stride / 2;
225            uint32_t next_block = stride * 8;
226            uint32_t i;
227            uint32_t iQuant = pMB->quant;
228            uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
229    
230            pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
231            pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
232            pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
233    
234          for (k = 0; k < 6; k++)          memset(block, 0, 6 * 64 * sizeof(int16_t));     // clear
235          {  
236                  uint32_t dcscalar;          for (i = 0; i < 6; i++) {
237                  int16_t block[64];                  uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
                 int16_t data[64];  
238                  int16_t predictors[8];                  int16_t predictors[8];
239                  int start_coeff;                  int start_coeff;
240    
                 dcscalar = get_dc_scaler(mb->quant, k < 4);  
   
241                  start_timer();                  start_timer();
242                  predict_acdc(dec->mbs, x, y, dec->mb_width, k, block, mb->quant, dcscalar, predictors);                  predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i, &block[i * 64],
243                  if (!acpred_flag)                                           iQuant, iDcScaler, predictors, bound);
244                  {                  if (!acpred_flag) {
245                          mb->acpred_directions[k] = 0;                          pMB->acpred_directions[i] = 0;
246                  }                  }
247                  stop_prediction_timer();                  stop_prediction_timer();
248    
249                  memset(block, 0, 64*sizeof(int16_t));           // clear                  if (quant < intra_dc_threshold) {
   
                 if (quant < intra_dc_threshold)  
                 {  
250                          int dc_size;                          int dc_size;
251                          int dc_dif;                          int dc_dif;
252    
253                          dc_size = k < 4 ?  get_dc_size_lum(bs) : get_dc_size_chrom(bs);                          dc_size = i < 4 ? get_dc_size_lum(bs) : get_dc_size_chrom(bs);
254                          dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0 ;                          dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0 ;
255    
256                          if (dc_size > 8)                          if (dc_size > 8) {
                         {  
257                                  BitstreamSkip(bs, 1);           // marker                                  BitstreamSkip(bs, 1);           // marker
258                          }                          }
259    
260                          block[0] = dc_dif;                          block[i * 64 + 0] = dc_dif;
261                          start_coeff = 1;                          start_coeff = 1;
262                  }  
263                  else                          DPRINTF(DPRINTF_COEFF,"block[0] %i", dc_dif);
264                  {                  } else {
265                          start_coeff = 0;                          start_coeff = 0;
266                  }                  }
267    
268                  start_timer();                  start_timer();
269                  if (cbp & (1 << (5-k)))                 // coded                  if (cbp & (1 << (5 - i)))       // coded
270                  {                  {
271                          get_intra_block(bs, block, mb->acpred_directions[k], start_coeff);                          get_intra_block(bs, &block[i * 64], pMB->acpred_directions[i],
272                                                            start_coeff);
273                  }                  }
274                  stop_coding_timer();                  stop_coding_timer();
275    
276                  start_timer();                  start_timer();
277                  add_acdc(mb, k, block, dcscalar, predictors);                  add_acdc(pMB, i, &block[i * 64], iDcScaler, predictors);
278                  stop_prediction_timer();                  stop_prediction_timer();
279    
280                  start_timer();                  start_timer();
281                  if (dec->quant_type == 0)                  if (dec->quant_type == 0) {
282                  {                          dequant_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler);
283                          dequant_intra(data, block, mb->quant, dcscalar);                  } else {
284                  }                          dequant4_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler);
                 else  
                 {  
                         dequant4_intra(data, block, mb->quant, dcscalar);  
285                  }                  }
286                  stop_iquant_timer();                  stop_iquant_timer();
287    
288                  start_timer();                  start_timer();
289                  idct(data);                  idct(&data[i * 64]);
290                  stop_idct_timer();                  stop_idct_timer();
   
                 start_timer();  
                 if (k < 4)  
                 {  
                         transfer_16to8copy(dec->cur.y + (16*y*dec->edged_width) + 16*x + (4*(k&2)*dec->edged_width) + 8*(k&1), data, dec->edged_width);  
                 }  
                 else if (k == 4)  
                 {  
                         transfer_16to8copy(dec->cur.u+ 8*y*(dec->edged_width/2) + 8*x, data, (dec->edged_width/2));  
291                  }                  }
292                  else    // if (k == 5)  
293                  {          if (dec->interlacing && pMB->field_dct) {
294                          transfer_16to8copy(dec->cur.v + 8*y*(dec->edged_width/2) + 8*x, data, (dec->edged_width/2));                  next_block = stride;
295                    stride *= 2;
296                  }                  }
297    
298            start_timer();
299            transfer_16to8copy(pY_Cur, &data[0 * 64], stride);
300            transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);
301            transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);
302            transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride);
303            transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);
304            transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);
305                  stop_transfer_timer();                  stop_transfer_timer();
306          }          }
 }  
307    
308    
309    
# Line 235  Line 317 
317    
318  // decode an inter macroblock  // decode an inter macroblock
319    
320  void decoder_mbinter(DECODER * dec, MACROBLOCK * mb, int x, int y, uint32_t acpred_flag, uint32_t cbp, Bitstream * bs, int quant, int rounding)  void
321  {  decoder_mbinter(DECODER * dec,
322          const uint32_t stride = dec->edged_width;                                  const MACROBLOCK * pMB,
323          const uint32_t stride2 = dec->edged_width / 2;                                  const uint32_t x_pos,
324                                    const uint32_t y_pos,
325                                    const uint32_t acpred_flag,
326                                    const uint32_t cbp,
327                                    Bitstream * bs,
328                                    const uint32_t quant,
329                                    const uint32_t rounding)
330    {
331    
332            DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
333            DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);
334    
335            uint32_t stride = dec->edged_width;
336            uint32_t stride2 = stride / 2;
337            uint32_t next_block = stride * 8;
338            uint32_t i;
339            uint32_t iQuant = pMB->quant;
340            uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
341          int uv_dx, uv_dy;          int uv_dx, uv_dy;
         uint32_t k;  
342    
343          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
344          {          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
345                  uv_dx = mb->mvs[0].x;          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
346                  uv_dy = mb->mvs[0].y;  
347            if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {
348                    uv_dx = pMB->mvs[0].x;
349                    uv_dy = pMB->mvs[0].y;
350    
351                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;
352                  uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;                  uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;
353          }          } else {
         else  
         {  
354                  int sum;                  int sum;
                 sum = mb->mvs[0].x + mb->mvs[1].x + mb->mvs[2].x + mb->mvs[3].x;  
                 uv_dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) );  
355    
356                  sum = mb->mvs[0].y + mb->mvs[1].y + mb->mvs[2].y + mb->mvs[3].y;                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;
357                  uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) );                  uv_dx =
358                            (sum ==
359                             0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +
360                                                                      (ABS(sum) / 16) * 2));
361    
362                    sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
363                    uv_dy =
364                            (sum ==
365                             0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +
366                                                                      (ABS(sum) / 16) * 2));
367          }          }
368    
369          start_timer();          start_timer();
370          interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x,     16*y    , mb->mvs[0].x, mb->mvs[0].y, stride,  rounding);          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos, 16 * y_pos,
371          interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x + 8, 16*y    , mb->mvs[1].x, mb->mvs[1].y, stride,  rounding);                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding);
372          interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x,     16*y + 8, mb->mvs[2].x, mb->mvs[2].y, stride,  rounding);          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos + 8,
373          interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x + 8, 16*y + 8, mb->mvs[3].x, mb->mvs[3].y, stride,  rounding);                                                    16 * y_pos, pMB->mvs[1].x, pMB->mvs[1].y, stride,
374          interpolate8x8_switch(dec->cur.u, dec->refn.u, 8*x, 8*y, uv_dx, uv_dy, stride2, rounding);                                                    rounding);
375          interpolate8x8_switch(dec->cur.v, dec->refn.v, 8*x, 8*y, uv_dx, uv_dy, stride2, rounding);          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos,
376                                                      16 * y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride,
377                                                      rounding);
378            interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos + 8,
379                                                      16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride,
380                                                      rounding);
381            interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,
382                                                      uv_dx, uv_dy, stride2, rounding);
383            interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,
384                                                      uv_dx, uv_dy, stride2, rounding);
385          stop_comp_timer();          stop_comp_timer();
386    
387            for (i = 0; i < 6; i++) {
388          for (k = 0; k < 6; k++)                  if (cbp & (1 << (5 - i)))       // coded
389          {          {
390                  int16_t block[64];                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
                 int16_t data[64];  
   
                 if (cbp & (1 << (5-k)))                 // coded  
                 {  
                         memset(block, 0, 64 * sizeof(int16_t));         // clear  
391    
392                          start_timer();                          start_timer();
393                          get_inter_block(bs, block);                          get_inter_block(bs, &block[i * 64]);
394                          stop_coding_timer();                          stop_coding_timer();
395    
396                          start_timer();                          start_timer();
397                          if (dec->quant_type == 0)                          if (dec->quant_type == 0) {
398                          {                                  dequant_inter(&data[i * 64], &block[i * 64], iQuant);
399                                  dequant_inter(data, block, mb->quant);                          } else {
400                          }                                  dequant4_inter(&data[i * 64], &block[i * 64], iQuant);
                         else  
                         {  
                                 dequant4_inter(data, block, mb->quant);  
401                          }                          }
402                          stop_iquant_timer();                          stop_iquant_timer();
403    
404                          start_timer();                          start_timer();
405                          idct(data);                          idct(&data[i * 64]);
406                          stop_idct_timer();                          stop_idct_timer();
   
                         start_timer();  
                         if (k < 4)  
                         {  
                                 transfer_16to8add(dec->cur.y + (16*y + 4*(k&2))*stride + 16*x + 8*(k&1), data, stride);  
407                          }                          }
                         else if (k == 4)  
                         {  
                                 transfer_16to8add(dec->cur.u + 8*y*stride2 + 8*x, data, stride2);  
408                          }                          }
409                          else // k == 5  
410                          {          if (dec->interlacing && pMB->field_dct) {
411                                  transfer_16to8add(dec->cur.v + 8*y*stride2 + 8*x, data, stride2);                  next_block = stride;
412                    stride *= 2;
413                          }                          }
414    
415            start_timer();
416            if (cbp & 32)
417                    transfer_16to8add(pY_Cur, &data[0 * 64], stride);
418            if (cbp & 16)
419                    transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
420            if (cbp & 8)
421                    transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
422            if (cbp & 4)
423                    transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride);
424            if (cbp & 2)
425                    transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
426            if (cbp & 1)
427                    transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
428                          stop_transfer_timer();                          stop_transfer_timer();
429                  }                  }
         }  
 }  
430    
431    
432    void
433  void decoder_iframe(DECODER * dec, Bitstream * bs, int quant, int intra_dc_threshold)  decoder_iframe(DECODER * dec,
434                               Bitstream * bs,
435                               int quant,
436                               int intra_dc_threshold)
437  {  {
438            uint32_t bound;
439          uint32_t x, y;          uint32_t x, y;
440    
441          for (y = 0; y < dec->mb_height; y++)          bound = 0;
         {  
                 for (x = 0; x < dec->mb_width; x++)  
                 {  
                         MACROBLOCK * mb = &dec->mbs[y*dec->mb_width + x];  
442    
443            for (y = 0; y < dec->mb_height; y++) {
444                    for (x = 0; x < dec->mb_width; x++) {
445                            MACROBLOCK *mb;
446                          uint32_t mcbpc;                          uint32_t mcbpc;
447                          uint32_t cbpc;                          uint32_t cbpc;
448                          uint32_t acpred_flag;                          uint32_t acpred_flag;
449                          uint32_t cbpy;                          uint32_t cbpy;
450                          uint32_t cbp;                          uint32_t cbp;
451    
452                            while (BitstreamShowBits(bs, 9) == 1)
453                                    BitstreamSkip(bs, 9);
454    
455                            if (check_resync_marker(bs, 0))
456                            {
457                                    bound = read_video_packet_header(bs, 0, &quant);
458                                    x = bound % dec->mb_width;
459                                    y = bound / dec->mb_width;
460                            }
461                            mb = &dec->mbs[y * dec->mb_width + x];
462    
463                            DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32));
464    
465                          mcbpc = get_mcbpc_intra(bs);                          mcbpc = get_mcbpc_intra(bs);
466                          mb->mode = mcbpc & 7;                          mb->mode = mcbpc & 7;
467                          cbpc = (mcbpc >> 4);                          cbpc = (mcbpc >> 4);
468    
469                          acpred_flag = BitstreamGetBit(bs);                          acpred_flag = BitstreamGetBit(bs);
470    
                         if (mb->mode == MODE_STUFFING)  
                         {  
                                 DEBUG("-- STUFFING ?");  
                                 continue;  
                         }  
   
471                          cbpy = get_cbpy(bs, 1);                          cbpy = get_cbpy(bs, 1);
472                          cbp = (cbpy << 2) | cbpc;                          cbp = (cbpy << 2) | cbpc;
473    
474                          if (mb->mode == MODE_INTRA_Q)                          if (mb->mode == MODE_INTRA_Q) {
                         {  
475                                  quant += dquant_table[BitstreamGetBits(bs,2)];                                  quant += dquant_table[BitstreamGetBits(bs,2)];
476                                  if (quant > 31)                                  if (quant > 31) {
                                 {  
477                                          quant = 31;                                          quant = 31;
478                                  }                                  } else if (quant < 1) {
                                 else if (quant < 1)  
                                 {  
479                                          quant = 1;                                          quant = 1;
480                                  }                                  }
481                          }                          }
482                          mb->quant = quant;                          mb->quant = quant;
483                            mb->mvs[0].x = mb->mvs[0].y =
484                            mb->mvs[1].x = mb->mvs[1].y =
485                            mb->mvs[2].x = mb->mvs[2].y =
486                            mb->mvs[3].x = mb->mvs[3].y =0;
487    
488                            if (dec->interlacing) {
489                                    mb->field_dct = BitstreamGetBit(bs);
490                                    DEBUG1("deci: field_dct: ", mb->field_dct);
491                            }
492    
493                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, intra_dc_threshold);                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
494                                                            intra_dc_threshold, bound);
495                  }                  }
496          }          }
497    
498  }  }
499    
500    
501  void get_motion_vector(DECODER *dec, Bitstream *bs, int x, int y, int k, VECTOR * mv, int fcode)  void
502    get_motion_vector(DECODER * dec,
503                                      Bitstream * bs,
504                                      int x,
505                                      int y,
506                                      int k,
507                                      VECTOR * mv,
508                                      int fcode,
509                                      const int bound)
510  {  {
511    
512          int scale_fac = 1 << (fcode - 1);          int scale_fac = 1 << (fcode - 1);
513          int high = (32 * scale_fac) - 1;          int high = (32 * scale_fac) - 1;
514          int low = ((-32) * scale_fac);          int low = ((-32) * scale_fac);
515          int range = (64 * scale_fac);          int range = (64 * scale_fac);
516    
517          VECTOR pmv[4];          VECTOR pmv;
         uint32_t psad[4];  
   
518          int mv_x, mv_y;          int mv_x, mv_y;
         int pmv_x, pmv_y;  
   
   
         get_pmvdata(dec->mbs, x, y, dec->mb_width, k, pmv, psad);  
519    
520          pmv_x = pmv[0].x;          pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k);
         pmv_y = pmv[0].y;  
521    
522          mv_x = get_mv(bs, fcode);          mv_x = get_mv(bs, fcode);
523          mv_y = get_mv(bs, fcode);          mv_y = get_mv(bs, fcode);
524    
525          mv_x += pmv_x;          DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i)", mv_x, mv_y, pmv.x, pmv.y);
         mv_y += pmv_y;  
526    
527          if (mv_x < low)          mv_x += pmv.x;
528          {          mv_y += pmv.y;
529    
530            if (mv_x < low) {
531                  mv_x += range;                  mv_x += range;
532          }          } else if (mv_x > high) {
         else if (mv_x > high)  
         {  
533                  mv_x -= range;                  mv_x -= range;
534          }          }
535    
536          if (mv_y < low)          if (mv_y < low) {
         {  
537                  mv_y += range;                  mv_y += range;
538          }          } else if (mv_y > high) {
         else if (mv_y > high)  
         {  
539                  mv_y -= range;                  mv_y -= range;
540          }          }
541    
# Line 419  Line 545 
545  }  }
546    
547    
548  void decoder_pframe(DECODER * dec, Bitstream * bs, int rounding, int quant, int fcode, int intra_dc_threshold)  void
549    decoder_pframe(DECODER * dec,
550                               Bitstream * bs,
551                               int rounding,
552                               int quant,
553                               int fcode,
554                               int intra_dc_threshold)
555  {  {
         uint32_t x, y;  
556    
557          image_swap(&dec->cur, &dec->refn);          uint32_t x, y;
558            uint32_t bound;
559    
560          start_timer();          start_timer();
561          image_setedges(&dec->refn, dec->edged_width, dec->edged_height, dec->width, dec->height);          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
562                                       dec->width, dec->height, dec->interlacing);
563          stop_edges_timer();          stop_edges_timer();
564    
565          for (y = 0; y < dec->mb_height; y++)          bound = 0;
566          {  
567                  for (x = 0; x < dec->mb_width; x++)          for (y = 0; y < dec->mb_height; y++) {
568                    for (x = 0; x < dec->mb_width; x++) {
569                            MACROBLOCK *mb;
570    
571                            // skip stuffing
572                            while (BitstreamShowBits(bs, 10) == 1)
573                                    BitstreamSkip(bs, 10);
574    
575                            if (check_resync_marker(bs, fcode - 1))
576                  {                  {
577                          MACROBLOCK * mb = &dec->mbs[y*dec->mb_width + x];                                  bound = read_video_packet_header(bs, fcode - 1, &quant);
578                                    x = bound % dec->mb_width;
579                                    y = bound / dec->mb_width;
580                            }
581                            mb = &dec->mbs[y * dec->mb_width + x];
582    
583                          if (!BitstreamGetBit(bs))                       // not_coded                          DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32));
584    
585                            //if (!(dec->mb_skip[y*dec->mb_width + x]=BitstreamGetBit(bs)))         // not_coded
586                            if (!(BitstreamGetBit(bs)))     // not_coded
587                          {                          {
588                                  uint32_t mcbpc;                                  uint32_t mcbpc;
589                                  uint32_t cbpc;                                  uint32_t cbpc;
# Line 447  Line 595 
595                                  mcbpc = get_mcbpc_inter(bs);                                  mcbpc = get_mcbpc_inter(bs);
596                                  mb->mode = mcbpc & 7;                                  mb->mode = mcbpc & 7;
597                                  cbpc = (mcbpc >> 4);                                  cbpc = (mcbpc >> 4);
598    
599                                    DPRINTF(DPRINTF_MB, "mode %i", mb->mode);
600                                    DPRINTF(DPRINTF_MB, "cbpc %i", cbpc);
601                                  acpred_flag = 0;                                  acpred_flag = 0;
602    
603                                  intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q);                                  intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q);
604    
605                                  if (intra)                                  if (intra) {
                                 {  
606                                          acpred_flag = BitstreamGetBit(bs);                                          acpred_flag = BitstreamGetBit(bs);
607                                  }                                  }
608    
                                 if (mb->mode == MODE_STUFFING)  
                                 {  
                                         DEBUG("-- STUFFING ?");  
                                         continue;  
                                 }  
   
609                                  cbpy = get_cbpy(bs, intra);                                  cbpy = get_cbpy(bs, intra);
610                                    DPRINTF(DPRINTF_MB, "cbpy %i", cbpy);
611    
612                                  cbp = (cbpy << 2) | cbpc;                                  cbp = (cbpy << 2) | cbpc;
613    
614                                  if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q)                                  if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) {
615                                  {                                          int dquant = dquant_table[BitstreamGetBits(bs, 2)];
616                                          quant += dquant_table[BitstreamGetBits(bs,2)];                                          DPRINTF(DPRINTF_MB, "dquant %i", dquant);
617                                          if (quant > 31)                                          quant += dquant;
618                                          {                                          if (quant > 31) {
619                                                  quant = 31;                                                  quant = 31;
620                                          }                                          } else if (quant < 1) {
                                         else if (mb->quant < 1)  
                                         {  
621                                                  quant = 1;                                                  quant = 1;
622                                          }                                          }
623                                            DPRINTF(DPRINTF_MB, "quant %i", quant);
624                                  }                                  }
625                                  mb->quant = quant;                                  mb->quant = quant;
626    
627                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)                                  if (dec->interlacing) {
628                                  {                                          mb->field_dct = BitstreamGetBit(bs);
629                                            DEBUG1("decp: field_dct: ", mb->field_dct);
630                                          get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode);  
631                                          mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x;                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
632                                          mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y;                                                  mb->field_pred = BitstreamGetBit(bs);
633                                                    DEBUG1("decp: field_pred: ", mb->field_pred);
634    
635                                                    if (mb->field_pred) {
636                                                            mb->field_for_top = BitstreamGetBit(bs);
637                                                            DEBUG1("decp: field_for_top: ", mb->field_for_top);
638                                                            mb->field_for_bot = BitstreamGetBit(bs);
639                                                            DEBUG1("decp: field_for_bot: ", mb->field_for_bot);
640                                  }                                  }
                                 else if (mb->mode == MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */)  
                                 {  
                                         get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode);  
                                         get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode);  
                                         get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode);  
                                         get_motion_vector(dec, bs, x, y, 3, &mb->mvs[3], fcode);  
641                                  }                                  }
                                 else  // MODE_INTRA, MODE_INTRA_Q  
                                 {  
                                         mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0;  
                                         mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0;  
                                         decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, intra_dc_threshold);  
                                         continue;  
642                                  }                                  }
643    
644                                  decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant, rounding);                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
645                                            if (dec->interlacing && mb->field_pred) {
646                                                    get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],
647                                                                                      fcode, bound);
648                                                    get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1],
649                                                                                      fcode, bound);
650                                            } else {
651                                                    get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],
652                                                                                      fcode, bound);
653                                                    mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x =
654                                                            mb->mvs[0].x;
655                                                    mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =
656                                                            mb->mvs[0].y;
657                                            }
658                                    } else if (mb->mode ==
659                                                       MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */ ) {
660                                            get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound);
661                                            get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode, bound);
662                                            get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode, bound);
663                                            get_motion_vector(dec, bs, x, y, 3, &mb->mvs[3], fcode, bound);
664                                    } else                  // MODE_INTRA, MODE_INTRA_Q
665                                    {
666                                            mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x =
667                                                    0;
668                                            mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =
669                                                    0;
670                                            decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
671                                                                            intra_dc_threshold, bound);
672                                            continue;
673                          }                          }
                         else    // not coded  
                         {  
674    
675                                    decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant,
676                                                                    rounding);
677                            } else                          // not coded
678                            {
679                                    //DEBUG2("P-frame MB at (X,Y)=",x,y);
680                                  mb->mode = MODE_NOT_CODED;                                  mb->mode = MODE_NOT_CODED;
681                                  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;
682                                  mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0;                                  mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0;
# Line 514  Line 685 
685    
686                                  start_timer();                                  start_timer();
687    
688                                  transfer8x8_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x),                                  transfer8x8_copy(dec->cur.y + (16 * y) * dec->edged_width +
689                                                                  dec->refn.y + (16*y)*dec->edged_width + (16*x),                                                                   (16 * x),
690                                                                  dec->edged_width);                                                                   dec->refn[0].y + (16 * y) * dec->edged_width +
691                                                                     (16 * x), dec->edged_width);
692                                  transfer8x8_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x+8),  
693                                                                  dec->refn.y + (16*y)*dec->edged_width + (16*x+8),                                  transfer8x8_copy(dec->cur.y + (16 * y) * dec->edged_width +
694                                                                  dec->edged_width);                                                                   (16 * x + 8),
695                                                                     dec->refn[0].y + (16 * y) * dec->edged_width +
696                                  transfer8x8_copy(dec->cur.y + (16*y+8)*dec->edged_width + (16*x),                                                                   (16 * x + 8), dec->edged_width);
697                                                                  dec->refn.y + (16*y+8)*dec->edged_width + (16*x),  
698                                                                  dec->edged_width);                                  transfer8x8_copy(dec->cur.y + (16 * y + 8) * dec->edged_width +
699                                                                     (16 * x),
700                                  transfer8x8_copy(dec->cur.y + (16*y+8)*dec->edged_width + (16*x+8),                                                                   dec->refn[0].y + (16 * y +
701                                                                  dec->refn.y + (16*y+8)*dec->edged_width + (16*x+8),                                                                                                     8) * dec->edged_width +
702                                                                  dec->edged_width);                                                                   (16 * x), dec->edged_width);
703    
704                                  transfer8x8_copy(dec->cur.u + (8*y)*dec->edged_width/2 + (8*x),                                  transfer8x8_copy(dec->cur.y + (16 * y + 8) * dec->edged_width +
705                                                                  dec->refn.u + (8*y)*dec->edged_width/2 + (8*x),                                                                   (16 * x + 8),
706                                                                     dec->refn[0].y + (16 * y +
707                                                                                                       8) * dec->edged_width +
708                                                                     (16 * x + 8), dec->edged_width);
709    
710                                    transfer8x8_copy(dec->cur.u + (8 * y) * dec->edged_width / 2 +
711                                                                     (8 * x),
712                                                                     dec->refn[0].u +
713                                                                     (8 * y) * dec->edged_width / 2 + (8 * x),
714                                                                  dec->edged_width/2);                                                                  dec->edged_width/2);
715    
716                                  transfer8x8_copy(dec->cur.v + (8*y)*dec->edged_width/2 + (8*x),                                  transfer8x8_copy(dec->cur.v + (8 * y) * dec->edged_width / 2 +
717                                                                  dec->refn.v + (8*y)*dec->edged_width/2 + (8*x),                                                                   (8 * x),
718                                                                     dec->refn[0].v +
719                                                                     (8 * y) * dec->edged_width / 2 + (8 * x),
720                                                                  dec->edged_width/2);                                                                  dec->edged_width/2);
721    
722                                  stop_transfer_timer();                                  stop_transfer_timer();
# Line 544  Line 725 
725          }          }
726  }  }
727    
728  int decoder_decode(DECODER * dec, XVID_DEC_FRAME * frame)  
729    // add by MinChen <chenm001@163.com>
730    // decode B-frame motion vector
731    void
732    get_b_motion_vector(DECODER * dec,
733                                            Bitstream * bs,
734                                            int x,
735                                            int y,
736                                            VECTOR * mv,
737                                            int fcode,
738                                            const VECTOR pmv)
739  {  {
740            int scale_fac = 1 << (fcode - 1);
741            int high = (32 * scale_fac) - 1;
742            int low = ((-32) * scale_fac);
743            int range = (64 * scale_fac);
744    
745            int mv_x, mv_y;
746            int pmv_x, pmv_y;
747    
748            pmv_x = pmv.x;
749            pmv_y = pmv.y;
750    
751            mv_x = get_mv(bs, fcode);
752            mv_y = get_mv(bs, fcode);
753    
754            mv_x += pmv_x;
755            mv_y += pmv_y;
756    
757            if (mv_x < low) {
758                    mv_x += range;
759            } else if (mv_x > high) {
760                    mv_x -= range;
761            }
762    
763            if (mv_y < low) {
764                    mv_y += range;
765            } else if (mv_y > high) {
766                    mv_y -= range;
767            }
768    
769            mv->x = mv_x;
770            mv->y = mv_y;
771    }
772    
773    
774    // add by MinChen <chenm001@163.com>
775    // decode an B-frame forward & backward inter macroblock
776    void
777    decoder_bf_mbinter(DECODER * dec,
778                                       const MACROBLOCK * pMB,
779                                       const uint32_t x_pos,
780                                       const uint32_t y_pos,
781                                       const uint32_t cbp,
782                                       Bitstream * bs,
783                                       const uint32_t quant,
784                                       const uint8_t ref)
785    {
786    
787            DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
788            DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);
789    
790            uint32_t stride = dec->edged_width;
791            uint32_t stride2 = stride / 2;
792            uint32_t next_block = stride * 8;
793            uint32_t i;
794            uint32_t iQuant = pMB->quant;
795            uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
796            int uv_dx, uv_dy;
797    
798            pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
799            pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
800            pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
801    
802    
803            if (!(pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) {
804                    uv_dx = pMB->mvs[0].x;
805                    uv_dy = pMB->mvs[0].y;
806    
807                    uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;
808                    uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;
809            } else {
810                    int sum;
811    
812                    sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;
813                    uv_dx =
814                            (sum ==
815                             0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +
816                                                                      (ABS(sum) / 16) * 2));
817    
818                    sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
819                    uv_dy =
820                            (sum ==
821                             0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +
822                                                                      (ABS(sum) / 16) * 2));
823            }
824    
825            start_timer();
826            interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos, 16 * y_pos,
827                                                      pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
828            interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos + 8,
829                                                      16 * y_pos, pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
830            interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos,
831                                                      16 * y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride,
832                                                      0);
833            interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos + 8,
834                                                      16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride,
835                                                      0);
836            interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos,
837                                                      uv_dx, uv_dy, stride2, 0);
838            interpolate8x8_switch(dec->cur.v, dec->refn[ref].v, 8 * x_pos, 8 * y_pos,
839                                                      uv_dx, uv_dy, stride2, 0);
840            stop_comp_timer();
841    
842            for (i = 0; i < 6; i++) {
843                    if (cbp & (1 << (5 - i)))       // coded
844                    {
845                            memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
846    
847                            start_timer();
848                            get_inter_block(bs, &block[i * 64]);
849                            stop_coding_timer();
850    
851                            start_timer();
852                            if (dec->quant_type == 0) {
853                                    dequant_inter(&data[i * 64], &block[i * 64], iQuant);
854                            } else {
855                                    dequant4_inter(&data[i * 64], &block[i * 64], iQuant);
856                            }
857                            stop_iquant_timer();
858    
859                            start_timer();
860                            idct(&data[i * 64]);
861                            stop_idct_timer();
862                    }
863            }
864    
865            if (dec->interlacing && pMB->field_dct) {
866                    next_block = stride;
867                    stride *= 2;
868            }
869    
870            start_timer();
871            if (cbp & 32)
872                    transfer_16to8add(pY_Cur, &data[0 * 64], stride);
873            if (cbp & 16)
874                    transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
875            if (cbp & 8)
876                    transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
877            if (cbp & 4)
878                    transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride);
879            if (cbp & 2)
880                    transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
881            if (cbp & 1)
882                    transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
883            stop_transfer_timer();
884    }
885    
886    
887    // add by MinChen <chenm001@163.com>
888    // decode an B-frame direct &  inter macroblock
889    void
890    decoder_bf_interpolate_mbinter(DECODER * dec,
891                                                               IMAGE forward,
892                                                               IMAGE backward,
893                                                               const MACROBLOCK * pMB,
894                                                               const uint32_t x_pos,
895                                                               const uint32_t y_pos,
896                                                               Bitstream * bs)
897    {
898    
899            DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
900            DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);
901    
902            uint32_t stride = dec->edged_width;
903            uint32_t stride2 = stride / 2;
904            uint32_t next_block = stride * 8;
905            uint32_t iQuant = pMB->quant;
906            int uv_dx, uv_dy;
907            int b_uv_dx, b_uv_dy;
908            uint32_t i;
909            uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
910        const uint32_t cbp = pMB->cbp;
911    
912            pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
913            pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
914            pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
915    
916    
917            if ((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) {
918                    uv_dx = pMB->mvs[0].x;
919                    uv_dy = pMB->mvs[0].y;
920    
921                    uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;
922                    uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;
923    
924                    b_uv_dx = pMB->b_mvs[0].x;
925                    b_uv_dy = pMB->b_mvs[0].y;
926    
927                    b_uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;
928                    b_uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;
929            } else {
930                    int sum;
931    
932                    sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;
933                    uv_dx =
934                            (sum ==
935                             0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +
936                                                                      (ABS(sum) / 16) * 2));
937    
938                    sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
939                    uv_dy =
940                            (sum ==
941                             0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +
942                                                                      (ABS(sum) / 16) * 2));
943    
944                    sum =
945                            pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x +
946                            pMB->b_mvs[3].x;
947                    b_uv_dx =
948                            (sum ==
949                             0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +
950                                                                      (ABS(sum) / 16) * 2));
951    
952                    sum =
953                            pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y +
954                            pMB->b_mvs[3].y;
955                    b_uv_dy =
956                            (sum ==
957                             0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +
958                                                                      (ABS(sum) / 16) * 2));
959            }
960    
961    
962            start_timer();
963            interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos,
964                                                      pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
965            interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, 16 * y_pos,
966                                                      pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
967            interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos + 8,
968                                                      pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
969            interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8,
970                                                      16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride,
971                                                      0);
972            interpolate8x8_switch(dec->cur.u, forward.u, 8 * x_pos, 8 * y_pos, uv_dx,
973                                                      uv_dy, stride2, 0);
974            interpolate8x8_switch(dec->cur.v, forward.v, 8 * x_pos, 8 * y_pos, uv_dx,
975                                                      uv_dy, stride2, 0);
976    
977    
978            interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos, 16 * y_pos,
979                                                      pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
980            interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,
981                                                      16 * y_pos, pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride,
982                                                      0);
983            interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos,
984                                                      16 * y_pos + 8, pMB->b_mvs[2].x, pMB->b_mvs[2].y,
985                                                      stride, 0);
986            interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,
987                                                      16 * y_pos + 8, pMB->b_mvs[3].x, pMB->b_mvs[3].y,
988                                                      stride, 0);
989            interpolate8x8_switch(dec->refn[2].u, backward.u, 8 * x_pos, 8 * y_pos,
990                                                      b_uv_dx, b_uv_dy, stride2, 0);
991            interpolate8x8_switch(dec->refn[2].v, backward.v, 8 * x_pos, 8 * y_pos,
992                                                      b_uv_dx, b_uv_dy, stride2, 0);
993    
994            interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos, 16 * y_pos,
995                                             stride);
996            interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos + 8, 16 * y_pos,
997                                             stride);
998            interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos, 16 * y_pos + 8,
999                                             stride);
1000            interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos + 8,
1001                                             16 * y_pos + 8, stride);
1002            interpolate8x8_c(dec->cur.u, dec->refn[2].u, 8 * x_pos, 8 * y_pos,
1003                                             stride2);
1004            interpolate8x8_c(dec->cur.v, dec->refn[2].v, 8 * x_pos, 8 * y_pos,
1005                                             stride2);
1006            stop_comp_timer();
1007    
1008            for (i = 0; i < 6; i++) {
1009                    if (cbp & (1 << (5 - i)))       // coded
1010                    {
1011                            memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
1012    
1013                            start_timer();
1014                            get_inter_block(bs, &block[i * 64]);
1015                            stop_coding_timer();
1016    
1017                            start_timer();
1018                            if (dec->quant_type == 0) {
1019                                    dequant_inter(&data[i * 64], &block[i * 64], iQuant);
1020                            } else {
1021                                    dequant4_inter(&data[i * 64], &block[i * 64], iQuant);
1022                            }
1023                            stop_iquant_timer();
1024    
1025                            start_timer();
1026                            idct(&data[i * 64]);
1027                            stop_idct_timer();
1028                    }
1029            }
1030    
1031            if (dec->interlacing && pMB->field_dct) {
1032                    next_block = stride;
1033                    stride *= 2;
1034            }
1035    
1036            start_timer();
1037            if (cbp & 32)
1038                    transfer_16to8add(pY_Cur, &data[0 * 64], stride);
1039            if (cbp & 16)
1040                    transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
1041            if (cbp & 8)
1042                    transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
1043            if (cbp & 4)
1044                    transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride);
1045            if (cbp & 2)
1046                    transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
1047            if (cbp & 1)
1048                    transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
1049            stop_transfer_timer();
1050    }
1051    
1052    
1053    // add by MinChen <chenm001@163.com>
1054    // for decode B-frame dbquant
1055    int32_t __inline
1056    get_dbquant(Bitstream * bs)
1057    {
1058            if (!BitstreamGetBit(bs))       // '0'
1059                    return (0);
1060            else if (!BitstreamGetBit(bs))  // '10'
1061                    return (-2);
1062            else
1063                    return (2);                             // '11'
1064    }
1065    
1066    // add by MinChen <chenm001@163.com>
1067    // for decode B-frame mb_type
1068    // bit   ret_value
1069    // 1        0
1070    // 01       1
1071    // 001      2
1072    // 0001     3
1073    int32_t __inline
1074    get_mbtype(Bitstream * bs)
1075    {
1076            int32_t mb_type;
1077    
1078            for (mb_type = 0; mb_type <= 3; mb_type++) {
1079                    if (BitstreamGetBit(bs))
1080                            break;
1081            }
1082    
1083            if (mb_type <= 3)
1084                    return (mb_type);
1085            else
1086                    return (-1);
1087    }
1088    
1089    void
1090    decoder_bframe(DECODER * dec,
1091                               Bitstream * bs,
1092                               int quant,
1093                               int fcode_forward,
1094                               int fcode_backward)
1095    {
1096            uint32_t x, y;
1097            VECTOR mv;
1098            const VECTOR zeromv = {0,0};
1099    #ifdef BFRAMES_DEC_DEBUG
1100            FILE *fp;
1101            static char first=0;
1102    #define BFRAME_DEBUG    if (!first && fp){ \
1103                    fprintf(fp,"Y=%3d   X=%3d   MB=%2d   CBP=%02X\n",y,x,mb->mb_type,mb->cbp); \
1104            }
1105    #endif
1106    
1107            start_timer();
1108            image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
1109                                       dec->width, dec->height, dec->interlacing);
1110            image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height,
1111                                       dec->width, dec->height, dec->interlacing);
1112            stop_edges_timer();
1113    
1114    #ifdef BFRAMES_DEC_DEBUG
1115            if (!first){
1116                    fp=fopen("C:\\XVIDDBG.TXT","w");
1117            }
1118    #endif
1119    
1120            for (y = 0; y < dec->mb_height; y++) {
1121                    // Initialize Pred Motion Vector
1122                    dec->p_fmv = dec->p_bmv = zeromv;
1123                    for (x = 0; x < dec->mb_width; x++) {
1124                            MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x];
1125                            MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x];
1126    
1127                            mv =
1128                            mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] =
1129                            mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv;
1130    
1131                            // the last P_VOP is skip macroblock ?
1132                            if (last_mb->mode == MODE_NOT_CODED) {
1133                                    //DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y);
1134                                    mb->cbp = 0;
1135    #ifdef BFRAMES_DEC_DEBUG
1136                                    mb->mb_type = MODE_NOT_CODED;
1137            BFRAME_DEBUG
1138    #endif
1139                                    mb->mb_type = MODE_FORWARD;
1140                                    mb->quant = last_mb->quant;
1141                                    //mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x;
1142                                    //mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y;
1143    
1144                                    decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, mb->quant, 1);
1145                                    continue;
1146                            }
1147    
1148                            if (!BitstreamGetBit(bs)) {     // modb=='0'
1149                                    const uint8_t modb2 = BitstreamGetBit(bs);
1150    
1151                                    mb->mb_type = get_mbtype(bs);
1152    
1153                                    if (!modb2) {   // modb=='00'
1154                                            mb->cbp = BitstreamGetBits(bs, 6);
1155                                    } else {
1156                                            mb->cbp = 0;
1157                                    }
1158                                    if (mb->mb_type && mb->cbp) {
1159                                            quant += get_dbquant(bs);
1160    
1161                                            if (quant > 31) {
1162                                                    quant = 31;
1163                                            } else if (quant < 1) {
1164                                                    quant = 1;
1165                                            }
1166                                    }
1167                            } else {
1168                                    mb->mb_type = MODE_DIRECT_NONE_MV;
1169                                    mb->cbp = 0;
1170                            }
1171    
1172                            mb->quant = quant;
1173                            mb->mode = MODE_INTER4V;
1174                            //DEBUG1("Switch bm_type=",mb->mb_type);
1175    
1176    #ifdef BFRAMES_DEC_DEBUG
1177            BFRAME_DEBUG
1178    #endif
1179                            switch (mb->mb_type) {
1180                            case MODE_DIRECT:
1181                                    get_b_motion_vector(dec, bs, x, y, &mv, 1, zeromv);
1182    
1183                            case MODE_DIRECT_NONE_MV:
1184                                    {                               // Because this file is a C file not C++ so I use '{' to define var
1185                                            const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp;
1186                                            int i;
1187    
1188                                            for (i = 0; i < 4; i++) {
1189                                                    mb->mvs[i].x = (int32_t) ((TRB * last_mb->mvs[i].x)
1190                                                                          / TRD + mv.x);
1191                                                    mb->b_mvs[i].x = (int32_t) ((mv.x == 0)
1192                                                                                    ? ((TRB - TRD) * last_mb->mvs[i].x)
1193                                                                                      / TRD
1194                                                                                    : mb->mvs[i].x - last_mb->mvs[i].x);
1195                                                    mb->mvs[i].y = (int32_t) ((TRB * last_mb->mvs[i].y)
1196                                                                          / TRD + mv.y);
1197                                                    mb->b_mvs[i].y = (int32_t) ((mv.y == 0)
1198                                                                                    ? ((TRB - TRD) * last_mb->mvs[i].y)
1199                                                                                      / TRD
1200                                                                                : mb->mvs[i].y - last_mb->mvs[i].y);
1201                                            }
1202                                            //DEBUG("B-frame Direct!\n");
1203                                    }
1204                                    decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
1205                                                                                               mb, x, y, bs);
1206                                    break;
1207    
1208                            case MODE_INTERPOLATE:
1209                                    get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_forward,
1210                                                                            dec->p_fmv);
1211                                    dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
1212    
1213                                    get_b_motion_vector(dec, bs, x, y, &mb->b_mvs[0],
1214                                                                            fcode_backward, dec->p_bmv);
1215                                    dec->p_bmv = mb->b_mvs[1] = mb->b_mvs[2] =
1216                                            mb->b_mvs[3] = mb->b_mvs[0];
1217    
1218                                    decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
1219                                                                                               mb, x, y, bs);
1220                                    //DEBUG("B-frame Bidir!\n");
1221                                    break;
1222    
1223                            case MODE_BACKWARD:
1224                                    get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_backward,
1225                                                                            dec->p_bmv);
1226                                    dec->p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
1227    
1228                                    mb->mode = MODE_INTER;
1229                                    decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0);
1230                                    //DEBUG("B-frame Backward!\n");
1231                                    break;
1232    
1233                            case MODE_FORWARD:
1234                                    get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_forward,
1235                                                                            dec->p_fmv);
1236                                    dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
1237    
1238                                    mb->mode = MODE_INTER;
1239                                    decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1);
1240                                    //DEBUG("B-frame Forward!\n");
1241                                    break;
1242    
1243                            default:
1244                                    //DEBUG1("Not support B-frame mb_type =", mb->mb_type);
1245                                    ;
1246                            }
1247    
1248                    }                                               // end of FOR
1249            }
1250    #ifdef BFRAMES_DEC_DEBUG
1251            if (!first){
1252                    first=1;
1253                    if (fp)
1254                            fclose(fp);
1255            }
1256    #endif
1257    }
1258    
1259    // swap two MACROBLOCK array
1260    void
1261    mb_swap(MACROBLOCK ** mb1,
1262                    MACROBLOCK ** mb2)
1263    {
1264            MACROBLOCK *temp = *mb1;
1265    
1266            *mb1 = *mb2;
1267            *mb2 = temp;
1268    }
1269    
1270    int
1271    decoder_decode(DECODER * dec,
1272                               XVID_DEC_FRAME * frame)
1273    {
1274    
1275          Bitstream bs;          Bitstream bs;
1276          uint32_t rounding;          uint32_t rounding;
1277          uint32_t quant;          uint32_t quant;
1278          uint32_t fcode;          uint32_t fcode_forward;
1279            uint32_t fcode_backward;
1280          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
1281            uint32_t vop_type;
1282    
1283          start_global_timer();          start_global_timer();
1284    
1285          BitstreamInit(&bs, frame->bitstream, frame->length);          BitstreamInit(&bs, frame->bitstream, frame->length);
1286    
1287          switch (BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode, &intra_dc_threshold))          // add by chenm001 <chenm001@163.com>
1288          {          // for support B-frame to reference last 2 frame
1289            dec->frames++;
1290            vop_type =
1291                    BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode_forward,
1292                                                             &fcode_backward, &intra_dc_threshold);
1293    
1294            dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0;  // init pred vector to 0
1295    
1296            switch (vop_type) {
1297          case P_VOP :          case P_VOP :
1298                  decoder_pframe(dec, &bs, rounding, quant, fcode, intra_dc_threshold);                  decoder_pframe(dec, &bs, rounding, quant, fcode_forward,
1299                                               intra_dc_threshold);
1300    #ifdef BFRAMES_DEC
1301                    DEBUG1("P_VOP  Time=", dec->time);
1302    #endif
1303                  break;                  break;
1304    
1305          case I_VOP :          case I_VOP :
                 //DEBUG1("",intra_dc_threshold);  
1306                  decoder_iframe(dec, &bs, quant, intra_dc_threshold);                  decoder_iframe(dec, &bs, quant, intra_dc_threshold);
1307    #ifdef BFRAMES_DEC
1308                    DEBUG1("I_VOP  Time=", dec->time);
1309    #endif
1310                  break;                  break;
1311    
1312          case B_VOP :    // ignore          case B_VOP:
1313    #ifdef BFRAMES_DEC
1314                    if (dec->time_pp > dec->time_bp) {
1315                            DEBUG1("B_VOP  Time=", dec->time);
1316                            decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);
1317                    } else {
1318                            DEBUG("broken B-frame!");
1319                    }
1320    #else
1321                    image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);
1322    #endif
1323                  break;                  break;
1324    
1325          case N_VOP :    // vop not coded          case N_VOP :    // vop not coded
1326                    // when low_delay==0, N_VOP's should interpolate between the past and future frames
1327                    image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);
1328                  break;                  break;
1329    
1330          default :          default :
1331                  return XVID_ERR_FAIL;                  return XVID_ERR_FAIL;
1332          }          }
1333    
1334    #ifdef BFRAMES_DEC_DEBUG
1335            if (frame->length != BitstreamPos(&bs) / 8){
1336                    DEBUG2("InLen/UseLen",frame->length, BitstreamPos(&bs) / 8);
1337            }
1338    #endif
1339          frame->length = BitstreamPos(&bs) / 8;          frame->length = BitstreamPos(&bs) / 8;
1340    
1341          start_timer();  
1342    #ifdef BFRAMES_DEC
1343            // test if no B_VOP
1344            if (dec->low_delay) {
1345    #endif
1346          image_output(&dec->cur, dec->width, dec->height, dec->edged_width,          image_output(&dec->cur, dec->width, dec->height, dec->edged_width,
1347                                  frame->image, frame->stride, frame->colorspace);                                  frame->image, frame->stride, frame->colorspace);
1348    
1349    #ifdef BFRAMES_DEC
1350            } else {
1351                    if (dec->frames >= 0) {
1352                            start_timer();
1353                            if ((vop_type == I_VOP || vop_type == P_VOP)) {
1354                                    image_output(&dec->refn[0], dec->width, dec->height,
1355                                                             dec->edged_width, frame->image, frame->stride,
1356                                                             frame->colorspace);
1357                            } else if (vop_type == B_VOP) {
1358                                    image_output(&dec->cur, dec->width, dec->height,
1359                                                             dec->edged_width, frame->image, frame->stride,
1360                                                             frame->colorspace);
1361                            }
1362          stop_conv_timer();          stop_conv_timer();
1363                    }
1364            }
1365    #endif
1366    
1367            if (vop_type == I_VOP || vop_type == P_VOP) {
1368                    image_swap(&dec->refn[0], &dec->refn[1]);
1369                    image_swap(&dec->cur, &dec->refn[0]);
1370                    // swap MACROBLOCK
1371                    if (!dec->low_delay && vop_type == P_VOP)
1372                            mb_swap(&dec->mbs, &dec->last_mbs);
1373            }
1374    
1375          emms();          emms();
1376    

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

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