[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.46, Tue Feb 11 21:56:31 2003 UTC revision 1.49.2.24, Wed Dec 10 15:07:42 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   *  Copyright(C) 2002 MinChen <chenm001@163.com>   *  Copyright(C) 2002 MinChen <chenm001@163.com>
7   *               2002 Peter Ross <pross@xvid.org>   *               2002-2003 Peter Ross <pross@xvid.org>
8   *   *
9   *  This file is part of XviD, a free MPEG-4 video encoder/decoder   *  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
  *  XviD is free software; you can redistribute it and/or modify it  
  *  under the terms of the GNU General Public License as published by  
11   *  the Free Software Foundation; either version 2 of the License, or   *  the Free Software Foundation; either version 2 of the License, or
12   *  (at your option) any later version.   *  (at your option) any later version.
13   *   *
# Line 22  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   *   *
  *  Under section 8 of the GNU General Public License, the copyright  
  *  holders of XVID explicitly forbid distribution in the following  
  *  countries:  
  *  
  *    - Japan  
  *    - United States of America  
  *  
  *  Linking XviD statically or dynamically with other modules is making a  
  *  combined work based on XviD.  Thus, the terms and conditions of the  
  *  GNU General Public License cover the whole combination.  
  *  
  *  As a special exception, the copyright holders of XviD give you  
  *  permission to link XviD with independent modules that communicate with  
  *  XviD solely through the VFW1.1 and DShow interfaces, regardless of the  
  *  license terms of these independent modules, and to copy and distribute  
  *  the resulting combined work under terms of your choice, provided that  
  *  every copy of the combined work is accompanied by a complete copy of  
  *  the source code of XviD (the version of XviD used to produce the  
  *  combined work), being distributed under the terms of the GNU General  
  *  Public License plus this exception.  An independent module is a module  
  *  which is not derived from or based on XviD.  
  *  
  *  Note that people who make modified versions of XviD are not obligated  
  *  to grant this special exception for their modified versions; it is  
  *  their choice whether to do so.  The GNU General Public License gives  
  *  permission to release a modified version without this exception; this  
  *  exception also makes it possible to release a modified version which  
  *  carries forward this exception.  
  *  
23   * $Id$   * $Id$
24   *   *
25   *************************************************************************/   ****************************************************************************/
26    
27    #include <stdio.h>
28  #include <stdlib.h>  #include <stdlib.h>
29  #include <string.h>  #include <string.h>
30    
# Line 64  Line 34 
34    
35  #include "xvid.h"  #include "xvid.h"
36  #include "portab.h"  #include "portab.h"
37    #include "global.h"
38    
39  #include "decoder.h"  #include "decoder.h"
40  #include "bitstream/bitstream.h"  #include "bitstream/bitstream.h"
41  #include "bitstream/mbcoding.h"  #include "bitstream/mbcoding.h"
42    
43  #include "quant/quant_h263.h"  #include "quant/quant.h"
44  #include "quant/quant_mpeg4.h"  #include "quant/quant_matrix.h"
45  #include "dct/idct.h"  #include "dct/idct.h"
46  #include "dct/fdct.h"  #include "dct/fdct.h"
47  #include "utils/mem_transfer.h"  #include "utils/mem_transfer.h"
48  #include "image/interpolate8x8.h"  #include "image/interpolate8x8.h"
49    #include "image/reduced.h"
50    #include "image/font.h"
51    
52  #include "bitstream/mbcoding.h"  #include "bitstream/mbcoding.h"
53  #include "prediction/mbprediction.h"  #include "prediction/mbprediction.h"
54  #include "utils/timer.h"  #include "utils/timer.h"
55  #include "utils/emms.h"  #include "utils/emms.h"
56    #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"
61    #include "image/postprocessing.h"
62  #include "utils/mem_align.h"  #include "utils/mem_align.h"
63    
64  int  static int
65  decoder_create(XVID_DEC_PARAM * param)  decoder_resize(DECODER * dec)
66  {  {
67          DECODER *dec;          /* free existing */
68            image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
69            image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
70            image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
71            image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
72            image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);
73    
74          dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);          image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);
         if (dec == NULL) {  
                 return XVID_ERR_MEMORY;  
         }  
         param->handle = dec;  
75    
76          dec->width = param->width;          if (dec->last_mbs)
77          dec->height = param->height;                  xvid_free(dec->last_mbs);
78            if (dec->mbs)
79                    xvid_free(dec->mbs);
80    
81            /* realloc */
82          dec->mb_width = (dec->width + 15) / 16;          dec->mb_width = (dec->width + 15) / 16;
83          dec->mb_height = (dec->height + 15) / 16;          dec->mb_height = (dec->height + 15) / 16;
84    
85          dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE;          dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE;
86          dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE;          dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE;
         dec->low_delay = 0;  
87    
88          if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) {          if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) {
89                  xvid_free(dec);                  xvid_free(dec);
# Line 116  Line 95 
95                  xvid_free(dec);                  xvid_free(dec);
96                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
97          }          }
98          /* add by chenm001 <chenm001@163.com> */  
99          /* for support B-frame to reference last 2 frame */          /* Support B-frame to reference last 2 frame */
100          if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) {          if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) {
101                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
102                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
103                  xvid_free(dec);                  xvid_free(dec);
104                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
105          }          }
106          if (image_create(&dec->refn[2], dec->edged_width, dec->edged_height)) {          if (image_create(&dec->tmp, dec->edged_width, dec->edged_height)) {
107                    image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
108                    image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
109                    image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
110                    xvid_free(dec);
111                    return XVID_ERR_MEMORY;
112            }
113    
114            if (image_create(&dec->qtmp, dec->edged_width, dec->edged_height)) {
115                    image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
116                    image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
117                    image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
118                    image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
119                    xvid_free(dec);
120                    return XVID_ERR_MEMORY;
121            }
122    
123            if (image_create(&dec->gmc, dec->edged_width, dec->edged_height)) {
124                    image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);
125                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
126                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
127                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
128                    image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
129                  xvid_free(dec);                  xvid_free(dec);
130                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
131          }          }
# Line 139  Line 137 
137                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
138                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
139                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
140                  image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);                  image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
141                    image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);
142                  xvid_free(dec);                  xvid_free(dec);
143                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
144          }          }
   
145          memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);          memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);
146    
147          /* add by chenm001 <chenm001@163.com> */          /* For skip MB flag */
         /* for skip MB flag */  
148          dec->last_mbs =          dec->last_mbs =
149                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,
150                                          CACHE_LINE);                                          CACHE_LINE);
# Line 156  Line 153 
153                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
154                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
155                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
156                  image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);                  image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
157                    image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);
158                  xvid_free(dec);                  xvid_free(dec);
159                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
160          }          }
161    
162          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);
163    
164            return 0;
165    }
166    
167    
168    int
169    decoder_create(xvid_dec_create_t * create)
170    {
171            DECODER *dec;
172    
173            if (XVID_VERSION_MAJOR(create->version) != 1)   /* v1.x.x */
174                    return XVID_ERR_VERSION;
175    
176            dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);
177            if (dec == NULL) {
178                    return XVID_ERR_MEMORY;
179            }
180    
181            memset(dec, 0, sizeof(DECODER));
182    
183            dec->mpeg_quant_matrices = xvid_malloc(sizeof(uint16_t) * 64 * 8, CACHE_LINE);
184            if (dec->mpeg_quant_matrices == NULL) {
185                    xvid_free(dec);
186                    return XVID_ERR_MEMORY;
187            }
188    
189            create->handle = dec;
190    
191            dec->width = create->width;
192            dec->height = create->height;
193    
194            image_null(&dec->cur);
195            image_null(&dec->refn[0]);
196            image_null(&dec->refn[1]);
197            image_null(&dec->tmp);
198            image_null(&dec->qtmp);
199    
200            /* image based GMC */
201            image_null(&dec->gmc);
202    
203    
204            dec->mbs = NULL;
205            dec->last_mbs = NULL;
206    
207          init_timer();          init_timer();
208            init_mpeg_matrix(dec->mpeg_quant_matrices);
209    
210          /* add by chenm001 <chenm001@163.com> */          /* For B-frame support (used to save reference frame's time */
211          /* for support B-frame to save reference frame's time */          dec->frames = 0;
         dec->frames = -1;  
212          dec->time = dec->time_base = dec->last_time_base = 0;          dec->time = dec->time_base = dec->last_time_base = 0;
213            dec->low_delay = 0;
214            dec->packed_mode = 0;
215    
216            dec->fixed_dimensions = (dec->width > 0 && dec->height > 0);
217    
218          return XVID_ERR_OK;          if (dec->fixed_dimensions)
219                    return decoder_resize(dec);
220            else
221                    return 0;
222  }  }
223    
224    
# Line 179  Line 227 
227  {  {
228          xvid_free(dec->last_mbs);          xvid_free(dec->last_mbs);
229          xvid_free(dec->mbs);          xvid_free(dec->mbs);
230    
231            /* image based GMC */
232            image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);
233    
234          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
235          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
236          image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);          image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
237            image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);
238          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
239            xvid_free(dec->mpeg_quant_matrices);
240          xvid_free(dec);          xvid_free(dec);
241    
242          write_timer();          write_timer();
243          return XVID_ERR_OK;          return 0;
244  }  }
245    
   
   
246  static const int32_t dquant_table[4] = {  static const int32_t dquant_table[4] = {
247          -1, -2, 1, 2          -1, -2, 1, 2
248  };  };
249    
   
   
   
250  /* decode an intra macroblock */  /* decode an intra macroblock */
251    static void
 void  
252  decoder_mbintra(DECODER * dec,  decoder_mbintra(DECODER * dec,
253                                  MACROBLOCK * pMB,                                  MACROBLOCK * pMB,
254                                  const uint32_t x_pos,                                  const uint32_t x_pos,
# Line 210  Line 258 
258                                  Bitstream * bs,                                  Bitstream * bs,
259                                  const uint32_t quant,                                  const uint32_t quant,
260                                  const uint32_t intra_dc_threshold,                                  const uint32_t intra_dc_threshold,
261                                  const unsigned int bound)                                  const unsigned int bound,
262                                    const int reduced_resolution)
263  {  {
264    
265          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
# Line 223  Line 272 
272          uint32_t iQuant = pMB->quant;          uint32_t iQuant = pMB->quant;
273          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
274    
275            if (reduced_resolution) {
276                    pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5);
277                    pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4);
278                    pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4);
279            }else{
280          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
281          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
282          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
283            }
284    
285          memset(block, 0, 6 * 64 * sizeof(int16_t));     /* clear */          memset(block, 0, 6 * 64 * sizeof(int16_t));     /* clear */
286    
# Line 256  Line 311 
311                          block[i * 64 + 0] = dc_dif;                          block[i * 64 + 0] = dc_dif;
312                          start_coeff = 1;                          start_coeff = 1;
313    
314                          DPRINTF(DPRINTF_COEFF,"block[0] %i", dc_dif);                          DPRINTF(XVID_DEBUG_COEFF,"block[0] %i\n", dc_dif);
315                  } else {                  } else {
316                          start_coeff = 0;                          start_coeff = 0;
317                  }                  }
# Line 264  Line 319 
319                  start_timer();                  start_timer();
320                  if (cbp & (1 << (5 - i)))       /* coded */                  if (cbp & (1 << (5 - i)))       /* coded */
321                  {                  {
322                          get_intra_block(bs, &block[i * 64], pMB->acpred_directions[i],                          int direction = dec->alternate_vertical_scan ?
323                                                          start_coeff);                                  2 : pMB->acpred_directions[i];
324    
325                            get_intra_block(bs, &block[i * 64], direction, start_coeff);
326                  }                  }
327                  stop_coding_timer();                  stop_coding_timer();
328    
# Line 275  Line 332 
332    
333                  start_timer();                  start_timer();
334                  if (dec->quant_type == 0) {                  if (dec->quant_type == 0) {
335                          dequant_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler);                          dequant_h263_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler, dec->mpeg_quant_matrices);
336                  } else {                  } else {
337                          dequant4_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler);                          dequant_mpeg_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler, dec->mpeg_quant_matrices);
338                  }                  }
339                  stop_iquant_timer();                  stop_iquant_timer();
340    
341                  start_timer();                  start_timer();
342                  idct(&data[i * 64]);                  idct(&data[i * 64]);
343                  stop_idct_timer();                  stop_idct_timer();
344    
345          }          }
346    
347          if (dec->interlacing && pMB->field_dct) {          if (dec->interlacing && pMB->field_dct) {
# Line 292  Line 350 
350          }          }
351    
352          start_timer();          start_timer();
353    
354            if (reduced_resolution)
355            {
356                    next_block*=2;
357                    copy_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
358                    copy_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
359                    copy_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
360                    copy_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);
361                    copy_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
362                    copy_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
363            }else{
364          transfer_16to8copy(pY_Cur, &data[0 * 64], stride);          transfer_16to8copy(pY_Cur, &data[0 * 64], stride);
365          transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);          transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);
366          transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);          transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);
367          transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride);          transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride);
368          transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);          transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);
369          transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);          transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);
370            }
371          stop_transfer_timer();          stop_transfer_timer();
372  }  }
373    
374    static void
375    decoder_mb_decode(DECODER * dec,
376                                    const uint32_t cbp,
377                                    Bitstream * bs,
378                                    uint8_t * pY_Cur,
379                                    uint8_t * pU_Cur,
380                                    uint8_t * pV_Cur,
381                                    const int reduced_resolution,
382                                    const MACROBLOCK * pMB)
383    {
384            DECLARE_ALIGNED_MATRIX(block, 1, 64, int16_t, CACHE_LINE);
385            DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);
386    
387            int stride = dec->edged_width;
388            int next_block = stride * (reduced_resolution ? 16 : 8);
389            const int stride2 = stride/2;
390            int i;
391            const uint32_t iQuant = pMB->quant;
392            const int direction = dec->alternate_vertical_scan ? 2 : 0;
393            const quant_interFuncPtr dequant = dec->quant_type == 0 ? dequant_h263_inter : dequant_mpeg_inter;
394    
395            for (i = 0; i < 6; i++) {
396    
397                    if (cbp & (1 << (5 - i))) {     /* coded */
398    
399  #define SIGN(X) (((X)>0)?1:-1)                          memset(block, 0, 64 * sizeof(int16_t)); /* clear */
 #define ABS(X) (((X)>0)?(X):-(X))  
 static const uint32_t roundtab[16] =  
         { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 };  
400    
401                            start_timer();
402                            get_inter_block(bs, block, direction);
403                            stop_coding_timer();
404    
405  /* decode an inter macroblock */                          start_timer();
406                            dequant(&data[i * 64], block, iQuant, dec->mpeg_quant_matrices);
407                            stop_iquant_timer();
408    
409                            start_timer();
410                            idct(&data[i * 64]);
411                            stop_idct_timer();
412                    }
413            }
414    
415  void          if (dec->interlacing && pMB->field_dct) {
416                    next_block = stride;
417                    stride *= 2;
418            }
419    
420            start_timer();
421            if (reduced_resolution) {
422                    if (cbp & 32)
423                            add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
424                    if (cbp & 16)
425                            add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
426                    if (cbp & 8)
427                            add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
428                    if (cbp & 4)
429                            add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);
430                    if (cbp & 2)
431                            add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
432                    if (cbp & 1)
433                            add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
434            } else {
435                    if (cbp & 32)
436                            transfer_16to8add(pY_Cur, &data[0 * 64], stride);
437                    if (cbp & 16)
438                            transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
439                    if (cbp & 8)
440                            transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
441                    if (cbp & 4)
442                            transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride);
443                    if (cbp & 2)
444                            transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
445                    if (cbp & 1)
446                            transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
447            }
448            stop_transfer_timer();
449    }
450    
451    /* decode an inter macroblock */
452    static void
453  decoder_mbinter(DECODER * dec,  decoder_mbinter(DECODER * dec,
454                                  const MACROBLOCK * pMB,                                  const MACROBLOCK * pMB,
455                                  const uint32_t x_pos,                                  const uint32_t x_pos,
456                                  const uint32_t y_pos,                                  const uint32_t y_pos,
                                 const uint32_t acpred_flag,  
457                                  const uint32_t cbp,                                  const uint32_t cbp,
458                                  Bitstream * bs,                                  Bitstream * bs,
459                                  const uint32_t quant,                                  const uint32_t rounding,
460                                  const uint32_t rounding)                                  const int reduced_resolution,
461                                    const int ref)
462  {  {
   
         DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);  
         DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);  
   
463          uint32_t stride = dec->edged_width;          uint32_t stride = dec->edged_width;
464          uint32_t stride2 = stride / 2;          uint32_t stride2 = stride / 2;
         uint32_t next_block = stride * 8;  
465          uint32_t i;          uint32_t i;
466          uint32_t iQuant = pMB->quant;  
467          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
468    
469          int uv_dx, uv_dy;          int uv_dx, uv_dy;
470            VECTOR mv[4];   /* local copy of mvs */
471    
472            if (reduced_resolution) {
473                    pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5);
474                    pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4);
475                    pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4);
476                    for (i = 0; i < 4; i++) {
477                            mv[i].x = RRV_MV_SCALEUP(pMB->mvs[i].x);
478                            mv[i].y = RRV_MV_SCALEUP(pMB->mvs[i].y);
479                    }
480            } else {
481          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
482          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
483          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
484                    for (i = 0; i < 4; i++)
485                            mv[i] = pMB->mvs[i];
486            }
487    
488          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {          start_timer();
                 uv_dx = pMB->mvs[0].x;  
                 uv_dy = pMB->mvs[0].y;  
489    
490                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;          if (pMB->mode != MODE_INTER4V) { /* INTER, INTER_Q, NOT_CODED, FORWARD, BACKWARD */
                 uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;  
         } else {  
                 int sum;  
                 sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;  
491    
492                  uv_dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2));                  uv_dx = mv[0].x;
493                    uv_dy = mv[0].y;
494                    if (dec->quarterpel) {
495                            uv_dx /= 2;
496                            uv_dy /= 2;
497                    }
498                    uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
499                    uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
500    
501                    if (reduced_resolution)
502                            interpolate32x32_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,
503                                                                            mv[0].x, mv[0].y, stride, rounding);
504                    else if (dec->quarterpel)
505                            interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->qtmp.y, dec->qtmp.y + 64,
506                                                                            dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
507                                                                                            mv[0].x, mv[0].y, stride, rounding);
508                    else
509                            interpolate16x16_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos, 16*y_pos,
510                                                                            mv[0].x, mv[0].y, stride, rounding);
511    
512            } else {        /* MODE_INTER4V */
513    
514                    if(dec->quarterpel) {
515                            uv_dx = (mv[0].x / 2) + (mv[1].x / 2) + (mv[2].x / 2) + (mv[3].x / 2);
516                            uv_dy = (mv[0].y / 2) + (mv[1].y / 2) + (mv[2].y / 2) + (mv[3].y / 2);
517                    } else {
518                            uv_dx = mv[0].x + mv[1].x + mv[2].x + mv[3].x;
519                            uv_dy = mv[0].y + mv[1].y + mv[2].y + mv[3].y;
520                    }
521    
522                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;                  uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf];
523                    uv_dy = (uv_dy >> 3) + roundtab_76[uv_dy & 0xf];
524    
525                  uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2));                  if (reduced_resolution) {
526          }                          interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,
527                                                                    mv[0].x, mv[0].y, stride, rounding);
528                            interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos + 16, 32*y_pos,
529                                                                    mv[1].x, mv[1].y, stride, rounding);
530                            interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos, 32*y_pos + 16,
531                                                                    mv[2].x, mv[2].y, stride, rounding);
532                            interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos + 16, 32*y_pos + 16,
533                                                                    mv[3].x, mv[3].y, stride, rounding);
534                            interpolate16x16_switch(dec->cur.u, dec->refn[0].u , 16 * x_pos, 16 * y_pos,
535                                                                    uv_dx, uv_dy, stride2, rounding);
536                            interpolate16x16_switch(dec->cur.v, dec->refn[0].v , 16 * x_pos, 16 * y_pos,
537                                                                    uv_dx, uv_dy, stride2, rounding);
538    
539          start_timer();                  } else if (dec->quarterpel) {
540                            interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
541                                                                            dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
542                                                                            mv[0].x, mv[0].y, stride, rounding);
543                            interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
544                                                                            dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos,
545                                                                            mv[1].x, mv[1].y, stride, rounding);
546                            interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
547                                                                            dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8,
548                                                                            mv[2].x, mv[2].y, stride, rounding);
549                            interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
550                                                                            dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8,
551                                                                            mv[3].x, mv[3].y, stride, rounding);
552                    } else {
553          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,
554                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);                                                                  mv[0].x, mv[0].y, stride, rounding);
555          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos,          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos,
556                                                    pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);                                                                  mv[1].x, mv[1].y, stride, rounding);
557          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8,          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8,
558                                                    pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);                                                                  mv[2].x, mv[2].y, stride, rounding);
559          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 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,
560                                                    pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);                                                                  mv[3].x, mv[3].y, stride, rounding);
561          interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,                  }
562            }
563    
564            /* chroma */
565            if (reduced_resolution) {
566                    interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos,
567                                                                    uv_dx, uv_dy, stride2, rounding);
568                    interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos,
569                                                                    uv_dx, uv_dy, stride2, rounding);
570            } else {
571                    interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos,
572                                                    uv_dx, uv_dy, stride2, rounding);                                                    uv_dx, uv_dy, stride2, rounding);
573          interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,                  interpolate8x8_switch(dec->cur.v, dec->refn[ref].v, 8 * x_pos, 8 * y_pos,
574                                                    uv_dx, uv_dy, stride2, rounding);                                                    uv_dx, uv_dy, stride2, rounding);
575            }
576    
577          stop_comp_timer();          stop_comp_timer();
578    
579          for (i = 0; i < 6; i++) {          if (cbp)
580                  if (cbp & (1 << (5 - i)))       /* coded */                  decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur,
581                                                            reduced_resolution, pMB);
582    }
583    
584    static void
585    decoder_mbgmc(DECODER * dec,
586                                    MACROBLOCK * const pMB,
587                                    const uint32_t x_pos,
588                                    const uint32_t y_pos,
589                                    const uint32_t fcode,
590                                    const uint32_t cbp,
591                                    Bitstream * bs,
592                                    const uint32_t rounding)
593                  {                  {
594                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        /* clear */          const uint32_t stride = dec->edged_width;
595            const uint32_t stride2 = stride / 2;
596    
597                          start_timer();          uint8_t *const pY_Cur=dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
598                          get_inter_block(bs, &block[i * 64]);          uint8_t *const pU_Cur=dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
599                          stop_coding_timer();          uint8_t *const pV_Cur=dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
600    
601                          start_timer();          NEW_GMC_DATA * gmc_data = &dec->new_gmc_data;
602                          if (dec->quant_type == 0) {  
603                                  dequant_inter(&data[i * 64], &block[i * 64], iQuant);          pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
                         } else {  
                                 dequant4_inter(&data[i * 64], &block[i * 64], iQuant);  
                         }  
                         stop_iquant_timer();  
604    
605                          start_timer();                          start_timer();
                         idct(&data[i * 64]);  
                         stop_idct_timer();  
                 }  
         }  
606    
607          if (dec->interlacing && pMB->field_dct) {  /* this is where the calculations are done */
608                  next_block = stride;  
609                  stride *= 2;          gmc_data->predict_16x16(gmc_data,
610          }                          dec->cur.y + y_pos*16*stride + x_pos*16, dec->refn[0].y,
611                            stride, stride, x_pos, y_pos, rounding);
612    
613            gmc_data->predict_8x8(gmc_data,
614                            dec->cur.u + y_pos*8*stride2 + x_pos*8, dec->refn[0].u,
615                            dec->cur.v + y_pos*8*stride2 + x_pos*8, dec->refn[0].v,
616                            stride2, stride2, x_pos, y_pos, rounding);
617    
618            gmc_data->get_average_mv(gmc_data, &pMB->amv, x_pos, y_pos, dec->quarterpel);
619    
620            pMB->amv.x = gmc_sanitize(pMB->amv.x, dec->quarterpel, fcode);
621            pMB->amv.y = gmc_sanitize(pMB->amv.y, dec->quarterpel, fcode);
622    
623            pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
624    
         start_timer();  
         if (cbp & 32)  
                 transfer_16to8add(pY_Cur, &data[0 * 64], stride);  
         if (cbp & 16)  
                 transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);  
         if (cbp & 8)  
                 transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);  
         if (cbp & 4)  
                 transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride);  
         if (cbp & 2)  
                 transfer_16to8add(pU_Cur, &data[4 * 64], stride2);  
         if (cbp & 1)  
                 transfer_16to8add(pV_Cur, &data[5 * 64], stride2);  
625          stop_transfer_timer();          stop_transfer_timer();
626    
627            if (cbp)
628                    decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, 0, pMB);
629    
630  }  }
631    
632    
633  void  static void
634  decoder_iframe(DECODER * dec,  decoder_iframe(DECODER * dec,
635                             Bitstream * bs,                             Bitstream * bs,
636                                    int reduced_resolution,
637                             int quant,                             int quant,
638                             int intra_dc_threshold)                             int intra_dc_threshold)
639  {  {
640          uint32_t bound;          uint32_t bound;
641          uint32_t x, y;          uint32_t x, y;
642            uint32_t mb_width = dec->mb_width;
643            uint32_t mb_height = dec->mb_height;
644    
645            if (reduced_resolution) {
646                    mb_width = (dec->width + 31) / 32;
647                    mb_height = (dec->height + 31) / 32;
648            }
649    
650          bound = 0;          bound = 0;
651    
652          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < mb_height; y++) {
653                  for (x = 0; x < dec->mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
654                          MACROBLOCK *mb;                          MACROBLOCK *mb;
655                          uint32_t mcbpc;                          uint32_t mcbpc;
656                          uint32_t cbpc;                          uint32_t cbpc;
# Line 442  Line 663 
663    
664                          if (check_resync_marker(bs, 0))                          if (check_resync_marker(bs, 0))
665                          {                          {
666                                  bound = read_video_packet_header(bs, 0, &quant);                                  bound = read_video_packet_header(bs, dec, 0,
667                                  x = bound % dec->mb_width;                                                          &quant, NULL, NULL, &intra_dc_threshold);
668                                  y = bound / dec->mb_width;                                  x = bound % mb_width;
669                                    y = bound / mb_width;
670                          }                          }
671                          mb = &dec->mbs[y * dec->mb_width + x];                          mb = &dec->mbs[y * dec->mb_width + x];
672    
673                          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));
674    
675                          mcbpc = get_mcbpc_intra(bs);                          mcbpc = get_mcbpc_intra(bs);
676                          mb->mode = mcbpc & 7;                          mb->mode = mcbpc & 7;
# Line 475  Line 697 
697    
698                          if (dec->interlacing) {                          if (dec->interlacing) {
699                                  mb->field_dct = BitstreamGetBit(bs);                                  mb->field_dct = BitstreamGetBit(bs);
700                                  DPRINTF(DPRINTF_DEBUG, "deci: field_dct: %d", mb->field_dct);                                  DPRINTF(XVID_DEBUG_MB,"deci: field_dct: %i\n", mb->field_dct);
701                          }                          }
702    
703                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
704                                                          intra_dc_threshold, bound);                                                          intra_dc_threshold, bound, reduced_resolution);
705    
706                  }                  }
707                  if(dec->out_frm)                  if(dec->out_frm)
708                    output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,dec->mb_width);                          output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,mb_width);
   
709          }          }
710    
711  }  }
712    
713    
714  void  static void
715  get_motion_vector(DECODER * dec,  get_motion_vector(DECODER * dec,
716                                    Bitstream * bs,                                    Bitstream * bs,
717                                    int x,                                    int x,
718                                    int y,                                    int y,
719                                    int k,                                    int k,
720                                    VECTOR * mv,                                  VECTOR * ret_mv,
721                                    int fcode,                                    int fcode,
722                                    const int bound)                                    const int bound)
723  {  {
724    
725          int scale_fac = 1 << (fcode - 1);          const int scale_fac = 1 << (fcode - 1);
726          int high = (32 * scale_fac) - 1;          const int high = (32 * scale_fac) - 1;
727          int low = ((-32) * scale_fac);          const int low = ((-32) * scale_fac);
728          int range = (64 * scale_fac);          const int range = (64 * scale_fac);
   
         VECTOR pmv;  
         int mv_x, mv_y;  
729    
730          pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k);          const VECTOR pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k);
731            VECTOR mv;
732    
733          mv_x = get_mv(bs, fcode);          mv.x = get_mv(bs, fcode);
734          mv_y = get_mv(bs, fcode);          mv.y = get_mv(bs, fcode);
735    
736          DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i)", mv_x, mv_y, pmv.x, 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);
737    
738          mv_x += pmv.x;          mv.x += pmv.x;
739          mv_y += pmv.y;          mv.y += pmv.y;
740    
741          if (mv_x < low) {          if (mv.x < low) {
742                  mv_x += range;                  mv.x += range;
743          } else if (mv_x > high) {          } else if (mv.x > high) {
744                  mv_x -= range;                  mv.x -= range;
745          }          }
746    
747          if (mv_y < low) {          if (mv.y < low) {
748                  mv_y += range;                  mv.y += range;
749          } else if (mv_y > high) {          } else if (mv.y > high) {
750                  mv_y -= range;                  mv.y -= range;
751          }          }
752    
753          mv->x = mv_x;          ret_mv->x = mv.x;
754          mv->y = mv_y;          ret_mv->y = mv.y;
   
755  }  }
756    
757    /* for P_VOP set gmc_warp to NULL */
758  void  static void
759  decoder_pframe(DECODER * dec,  decoder_pframe(DECODER * dec,
760                             Bitstream * bs,                             Bitstream * bs,
761                             int rounding,                             int rounding,
762                                    int reduced_resolution,
763                             int quant,                             int quant,
764                             int fcode,                             int fcode,
765                             int intra_dc_threshold)                                  int intra_dc_threshold,
766                                    const WARPPOINTS *const gmc_warp)
767  {  {
   
768          uint32_t x, y;          uint32_t x, y;
769          uint32_t bound;          uint32_t bound;
770          int cp_mb, st_mb;          int cp_mb, st_mb;
771            uint32_t mb_width = dec->mb_width;
772            uint32_t mb_height = dec->mb_height;
773    
774            if (reduced_resolution) {
775                    mb_width = (dec->width + 31) / 32;
776                    mb_height = (dec->height + 31) / 32;
777            }
778    
779          start_timer();          start_timer();
780          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
781                                     dec->width, dec->height);                                     dec->width, dec->height);
782          stop_edges_timer();          stop_edges_timer();
783    
784            if (gmc_warp) {
785                    /* accuracy: 0==1/2, 1=1/4, 2=1/8, 3=1/16 */
786                    generate_GMCparameters( dec->sprite_warping_points,
787                                    dec->sprite_warping_accuracy, gmc_warp,
788                                    dec->width, dec->height, &dec->new_gmc_data);
789    
790                    /* image warping is done block-based in decoder_mbgmc(), now */
791            }
792    
793          bound = 0;          bound = 0;
794    
795          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < mb_height; y++) {
796                  cp_mb = st_mb = 0;                  cp_mb = st_mb = 0;
797                  for (x = 0; x < dec->mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
798                          MACROBLOCK *mb;                          MACROBLOCK *mb;
799    
800                          /* skip stuffing */                          /* skip stuffing */
801                          while (BitstreamShowBits(bs, 10) == 1)                          while (BitstreamShowBits(bs, 10) == 1)
802                                  BitstreamSkip(bs, 10);                                  BitstreamSkip(bs, 10);
803    
804                          if (check_resync_marker(bs, fcode - 1))                          if (check_resync_marker(bs, fcode - 1)) {
805                          {                                  bound = read_video_packet_header(bs, dec, fcode - 1,
806                                  bound = read_video_packet_header(bs, fcode - 1, &quant);                                          &quant, &fcode, NULL, &intra_dc_threshold);
807                                  x = bound % dec->mb_width;                                  x = bound % mb_width;
808                                  y = bound / dec->mb_width;                                  y = bound / mb_width;
809                          }                          }
810                          mb = &dec->mbs[y * dec->mb_width + x];                          mb = &dec->mbs[y * dec->mb_width + x];
811    
812                          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));
813    
814                          /*if (!(dec->mb_skip[y*dec->mb_width + x]=BitstreamGetBit(bs)))          not_coded */                          if (!(BitstreamGetBit(bs)))     { /* block _is_ coded */
815                          if (!(BitstreamGetBit(bs)))     /* not_coded */                                  uint32_t mcbpc, cbpc, cbpy, cbp;
816                          {                                  uint32_t intra, acpred_flag = 0;
817                                  uint32_t mcbpc;                                  int mcsel = 0;          /* mcsel: '0'=local motion, '1'=GMC */
                                 uint32_t cbpc;  
                                 uint32_t acpred_flag;  
                                 uint32_t cbpy;  
                                 uint32_t cbp;  
                                 uint32_t intra;  
818    
819                                  cp_mb++;                                  cp_mb++;
820                                  mcbpc = get_mcbpc_inter(bs);                                  mcbpc = get_mcbpc_inter(bs);
821                                  mb->mode = mcbpc & 7;                                  mb->mode = mcbpc & 7;
822                                  cbpc = (mcbpc >> 4);                                  cbpc = (mcbpc >> 4);
823    
824                                  DPRINTF(DPRINTF_MB, "mode %i", mb->mode);                                  DPRINTF(XVID_DEBUG_MB, "mode %i\n", mb->mode);
825                                  DPRINTF(DPRINTF_MB, "cbpc %i", cbpc);                                  DPRINTF(XVID_DEBUG_MB, "cbpc %i\n", cbpc);
                                 acpred_flag = 0;  
826    
827                                  intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q);                                  intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q);
828    
829                                  if (intra) {                                  if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q))
830                                            mcsel = BitstreamGetBit(bs);
831                                    else if (intra)
832                                          acpred_flag = BitstreamGetBit(bs);                                          acpred_flag = BitstreamGetBit(bs);
                                 }  
833    
834                                  cbpy = get_cbpy(bs, intra);                                  cbpy = get_cbpy(bs, intra);
835                                  DPRINTF(DPRINTF_MB, "cbpy %i", cbpy);                                  DPRINTF(XVID_DEBUG_MB, "cbpy %i mcsel %i \n", cbpy,mcsel);
836    
837                                  cbp = (cbpy << 2) | cbpc;                                  cbp = (cbpy << 2) | cbpc;
838    
839                                  if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) {                                  if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) {
840                                          int dquant = dquant_table[BitstreamGetBits(bs, 2)];                                          int dquant = dquant_table[BitstreamGetBits(bs, 2)];
841                                          DPRINTF(DPRINTF_MB, "dquant %i", dquant);                                          DPRINTF(XVID_DEBUG_MB, "dquant %i\n", dquant);
842                                          quant += dquant;                                          quant += dquant;
843                                          if (quant > 31) {                                          if (quant > 31) {
844                                                  quant = 31;                                                  quant = 31;
845                                          } else if (quant < 1) {                                          } else if (quant < 1) {
846                                                  quant = 1;                                                  quant = 1;
847                                          }                                          }
848                                          DPRINTF(DPRINTF_MB, "quant %i", quant);                                          DPRINTF(XVID_DEBUG_MB, "quant %i\n", quant);
849                                  }                                  }
850                                  mb->quant = quant;                                  mb->quant = quant;
851    
852                                  if (dec->interlacing) {                                  if (dec->interlacing) {
853                                          if (cbp || intra) {                                          if ((cbp || intra) && !mcsel) {
854                                                  mb->field_dct = BitstreamGetBit(bs);                                                  mb->field_dct = BitstreamGetBit(bs);
855                                                  DPRINTF(DPRINTF_DEBUG, "decp: field_dct: %d", mb->field_dct);                                                  DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct);
856                                          }                                          }
857    
858                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
859                                                  mb->field_pred = BitstreamGetBit(bs);                                                  mb->field_pred = BitstreamGetBit(bs);
860                                                  DPRINTF(DPRINTF_DEBUG, "decp: field_pred: %d", mb->field_pred);                                                  DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred);
861    
862                                                  if (mb->field_pred) {                                                  if (mb->field_pred) {
863                                                          mb->field_for_top = BitstreamGetBit(bs);                                                          mb->field_for_top = BitstreamGetBit(bs);
864                                                          DPRINTF(DPRINTF_DEBUG, "decp: field_for_top: %d", mb->field_for_top);                                                          DPRINTF(XVID_DEBUG_MB,"decp: field_for_top: %i\n", mb->field_for_top);
865                                                          mb->field_for_bot = BitstreamGetBit(bs);                                                          mb->field_for_bot = BitstreamGetBit(bs);
866                                                          DPRINTF(DPRINTF_DEBUG, "decp: field_for_bot: %d", mb->field_for_bot);                                                          DPRINTF(XVID_DEBUG_MB,"decp: field_for_bot: %i\n", mb->field_for_bot);
867                                                  }                                                  }
868                                          }                                          }
869                                  }                                  }
870    
871                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                  if (mcsel) {
872                                            decoder_mbgmc(dec, mb, x, y, fcode, cbp, bs, rounding);
873                                            continue;
874    
875                                    } else if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
876    
877                                          if (dec->interlacing && mb->field_pred) {                                          if (dec->interlacing && mb->field_pred) {
878                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound);
879                                                                                    fcode, bound);                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1], fcode, bound);
880                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1],                                          } else {
881                                                                                    fcode, bound);                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound);
882                                          } else {                                                  mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0];
                                                 get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],  
                                                                                   fcode, bound);  
                                                 mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x =  
                                                         mb->mvs[0].x;  
                                                 mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =  
                                                         mb->mvs[0].y;  
883                                          }                                          }
884                                  } else if (mb->mode == MODE_INTER4V ) {                                  } else if (mb->mode == MODE_INTER4V ) {
   
885                                          get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound);                                          get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound);
886                                          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);
887                                          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);
888                                          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);
889                                  } else                  /* MODE_INTRA, MODE_INTRA_Q */                                  } else {                /* MODE_INTRA, MODE_INTRA_Q */
890                                  {                                          mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0;
891                                          mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x =                                          mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =     0;
                                                 0;  
                                         mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =  
                                                 0;  
892                                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,                                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
893                                                                          intra_dc_threshold, bound);                                                                          intra_dc_threshold, bound, reduced_resolution);
894                                          continue;                                          continue;
895                                  }                                  }
896    
897                                  decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant,                                  decoder_mbinter(dec, mb, x, y, cbp, bs,
898                                                                  rounding);                                                                  rounding, reduced_resolution, 0);
                         } else                          /* not coded */  
                         {  
                                 DPRINTF(DPRINTF_DEBUG, "P-frame MB at (X,Y)=(%d,%d)", x, y);  
899    
900                            } else if (gmc_warp) {  /* a not coded S(GMC)-VOP macroblock */
901                                    mb->mode = MODE_NOT_CODED_GMC;
902                                    decoder_mbgmc(dec, mb, x, y, fcode, 0x00, bs, rounding);
903    
904                                    if(dec->out_frm && cp_mb > 0) {
905                                            output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb);
906                                            cp_mb = 0;
907                                    }
908                                    st_mb = x+1;
909                            } else {        /* not coded P_VOP macroblock */
910                                  mb->mode = MODE_NOT_CODED;                                  mb->mode = MODE_NOT_CODED;
911    
912                                  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;
913                                  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;
914    
915                                  /* copy macroblock directly from ref to cur */                                  decoder_mbinter(dec, mb, x, y, 0, bs,
916                                                                    rounding, reduced_resolution, 0);
                                 start_timer();  
917    
                                 transfer8x8_copy(dec->cur.y + (16 * y) * dec->edged_width +  
                                                                  (16 * x),  
                                                                  dec->refn[0].y + (16 * y) * dec->edged_width +  
                                                                  (16 * x), dec->edged_width);  
   
                                 transfer8x8_copy(dec->cur.y + (16 * y) * dec->edged_width +  
                                                                  (16 * x + 8),  
                                                                  dec->refn[0].y + (16 * y) * dec->edged_width +  
                                                                  (16 * x + 8), dec->edged_width);  
   
                                 transfer8x8_copy(dec->cur.y + (16 * y + 8) * dec->edged_width +  
                                                                  (16 * x),  
                                                                  dec->refn[0].y + (16 * y +  
                                                                                                    8) * dec->edged_width +  
                                                                  (16 * x), dec->edged_width);  
   
                                 transfer8x8_copy(dec->cur.y + (16 * y + 8) * dec->edged_width +  
                                                                  (16 * x + 8),  
                                                                  dec->refn[0].y + (16 * y +  
                                                                                                    8) * dec->edged_width +  
                                                                  (16 * x + 8), dec->edged_width);  
   
                                 transfer8x8_copy(dec->cur.u + (8 * y) * dec->edged_width / 2 +  
                                                                  (8 * x),  
                                                                  dec->refn[0].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->refn[0].v +  
                                                                  (8 * y) * dec->edged_width / 2 + (8 * x),  
                                                                  dec->edged_width / 2);  
                                 stop_transfer_timer();  
918                                  if(dec->out_frm && cp_mb > 0) {                                  if(dec->out_frm && cp_mb > 0) {
919                                    output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb);                                    output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb);
920                                    cp_mb = 0;                                    cp_mb = 0;
# Line 723  Line 922 
922                                  st_mb = x+1;                                  st_mb = x+1;
923                          }                          }
924                  }                  }
925    
926                  if(dec->out_frm && cp_mb > 0)                  if(dec->out_frm && cp_mb > 0)
927                    output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb);                    output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb);
928          }          }
929  }  }
930    
931  /* swap two MACROBLOCK array */  
932  void  /* decode B-frame motion vector */
933  mb_swap(MACROBLOCK ** mb1,  static void
934                  MACROBLOCK ** mb2)  get_b_motion_vector(Bitstream * bs,
935                                            VECTOR * mv,
936                                            int fcode,
937                                            const VECTOR pmv)
938  {  {
939          MACROBLOCK *temp = *mb1;          const int scale_fac = 1 << (fcode - 1);
940            const int high = (32 * scale_fac) - 1;
941            const int low = ((-32) * scale_fac);
942            const int range = (64 * scale_fac);
943    
944            int mv_x = get_mv(bs, fcode);
945            int mv_y = get_mv(bs, fcode);
946    
947            mv_x += pmv.x;
948            mv_y += pmv.y;
949    
950            if (mv_x < low)
951                    mv_x += range;
952            else if (mv_x > high)
953                    mv_x -= range;
954    
955          *mb1 = *mb2;          if (mv_y < low)
956          *mb2 = temp;                  mv_y += range;
957            else if (mv_y > high)
958                    mv_y -= range;
959    
960            mv->x = mv_x;
961            mv->y = mv_y;
962  }  }
963    
964    /* decode an B-frame direct & interpolate macroblock */
965    static void
966    decoder_bf_interpolate_mbinter(DECODER * dec,
967                                                                    IMAGE forward,
968                                                                    IMAGE backward,
969                                                                    const MACROBLOCK * pMB,
970                                                                    const uint32_t x_pos,
971                                                                    const uint32_t y_pos,
972                                                                    Bitstream * bs,
973                                                                    const int direct)
974    {
975            uint32_t stride = dec->edged_width;
976            uint32_t stride2 = stride / 2;
977            int uv_dx, uv_dy;
978            int b_uv_dx, b_uv_dy;
979            uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
980            const uint32_t cbp = pMB->cbp;
981    
982            pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
983            pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
984            pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
985    
986            if (!direct) {
987                    uv_dx = pMB->mvs[0].x;
988                    uv_dy = pMB->mvs[0].y;
989    
990                    b_uv_dx = pMB->b_mvs[0].x;
991                    b_uv_dy = pMB->b_mvs[0].y;
992    
993                    if (dec->quarterpel) {
994                            uv_dx /= 2;
995                            uv_dy /= 2;
996                            b_uv_dx /= 2;
997                            b_uv_dy /= 2;
998                    }
999    
1000                    uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
1001                    uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
1002    
1003                    b_uv_dx = (b_uv_dx >> 1) + roundtab_79[b_uv_dx & 0x3];
1004                    b_uv_dy = (b_uv_dy >> 1) + roundtab_79[b_uv_dy & 0x3];
1005    
1006            } else {
1007                    if(dec->quarterpel) {
1008                            uv_dx = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2);
1009                            uv_dy = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2);
1010                            b_uv_dx = (pMB->b_mvs[0].x / 2) + (pMB->b_mvs[1].x / 2) + (pMB->b_mvs[2].x / 2) + (pMB->b_mvs[3].x / 2);
1011                            b_uv_dy = (pMB->b_mvs[0].y / 2) + (pMB->b_mvs[1].y / 2) + (pMB->b_mvs[2].y / 2) + (pMB->b_mvs[3].y / 2);
1012                    } else {
1013                            uv_dx = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;
1014                            uv_dy = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
1015                            b_uv_dx = pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + pMB->b_mvs[3].x;
1016                            b_uv_dy = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y;
1017                    }
1018    
1019                    uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf];
1020                    uv_dy = (uv_dy >> 3) + roundtab_76[uv_dy & 0xf];
1021                    b_uv_dx = (b_uv_dx >> 3) + roundtab_76[b_uv_dx & 0xf];
1022                    b_uv_dy = (b_uv_dy >> 3) + roundtab_76[b_uv_dy & 0xf];
1023            }
1024    
1025            start_timer();
1026            if(dec->quarterpel) {
1027                    if(!direct) {
1028                            interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64,
1029                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
1030                                                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1031                    } else {
1032                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64,
1033                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
1034                                                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1035                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64,
1036                                                                                    dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos,
1037                                                                                    pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
1038                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64,
1039                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8,
1040                                                                                    pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
1041                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64,
1042                                                                                    dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8,
1043                                                                                    pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);
1044                    }
1045            } else {
1046                    interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos,
1047                                                            pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1048                    interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, 16 * y_pos,
1049                                                            pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
1050                    interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos + 8,
1051                                                            pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
1052                    interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8,
1053                                                            16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);
1054            }
1055    
1056            interpolate8x8_switch(dec->cur.u, forward.u, 8 * x_pos, 8 * y_pos, uv_dx,
1057                                                    uv_dy, stride2, 0);
1058            interpolate8x8_switch(dec->cur.v, forward.v, 8 * x_pos, 8 * y_pos, uv_dx,
1059                                                    uv_dy, stride2, 0);
1060    
1061    
1062            if(dec->quarterpel) {
1063                    if(!direct) {
1064                            interpolate16x16_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64,
1065                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
1066                                                                                    pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1067                    } else {
1068                            interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64,
1069                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
1070                                                                                    pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1071                            interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64,
1072                                                                                    dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos,
1073                                                                                    pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0);
1074                            interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64,
1075                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8,
1076                                                                                    pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0);
1077                            interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64,
1078                                                                                    dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8,
1079                                                                                    pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0);
1080                    }
1081            } else {
1082                    interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos, 16 * y_pos,
1083                                                            pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1084                    interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8,
1085                                                            16 * y_pos, pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0);
1086                    interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos,
1087                                                            16 * y_pos + 8, pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0);
1088                    interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8,
1089                                                            16 * y_pos + 8, pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0);
1090            }
1091    
1092            interpolate8x8_switch(dec->tmp.u, backward.u, 8 * x_pos, 8 * y_pos,
1093                                                    b_uv_dx, b_uv_dy, stride2, 0);
1094            interpolate8x8_switch(dec->tmp.v, backward.v, 8 * x_pos, 8 * y_pos,
1095                                                    b_uv_dx, b_uv_dy, stride2, 0);
1096    
1097            interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1098                                                    dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1099                                                    dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos,
1100                                                    stride, 1, 8);
1101    
1102            interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1103                                                    dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1104                                                    dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1105                                                    stride, 1, 8);
1106    
1107            interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1108                                                    dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1109                                                    dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1110                                                    stride, 1, 8);
1111    
1112            interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1113                                                    dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1114                                                    dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1115                                                    stride, 1, 8);
1116    
1117            interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1118                                                    dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1119                                                    dec->tmp.u + (8 * y_pos * stride2) + 8 * x_pos,
1120                                                    stride2, 1, 8);
1121    
1122            interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1123                                                    dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1124                                                    dec->tmp.v + (8 * y_pos * stride2) + 8 * x_pos,
1125                                                    stride2, 1, 8);
1126    
1127            stop_comp_timer();
1128    
1129            if (cbp)
1130                    decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, 0, pMB);
1131    }
1132    
1133    /* for decode B-frame dbquant */
1134    static __inline int32_t
1135    get_dbquant(Bitstream * bs)
1136    {
1137            if (!BitstreamGetBit(bs))               /*  '0' */
1138                    return (0);
1139            else if (!BitstreamGetBit(bs))  /* '10' */
1140                    return (-2);
1141            else                                                    /* '11' */
1142                    return (2);
1143    }
1144    
1145    /*
1146     * decode B-frame mb_type
1147     * bit          ret_value
1148     * 1            0
1149     * 01           1
1150     * 001          2
1151     * 0001         3
1152     */
1153    static int32_t __inline
1154    get_mbtype(Bitstream * bs)
1155    {
1156            int32_t mb_type;
1157    
1158            for (mb_type = 0; mb_type <= 3; mb_type++)
1159                    if (BitstreamGetBit(bs))
1160                            return (mb_type);
1161    
1162            return -1;
1163    }
1164    
1165    static void
1166    decoder_bframe(DECODER * dec,
1167                                    Bitstream * bs,
1168                                    int quant,
1169                                    int fcode_forward,
1170                                    int fcode_backward)
1171    {
1172            uint32_t x, y;
1173            VECTOR mv;
1174            const VECTOR zeromv = {0,0};
1175            const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp;
1176            int i;
1177    
1178            start_timer();
1179            image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
1180                                            dec->width, dec->height);
1181            image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height,
1182                                            dec->width, dec->height);
1183            stop_edges_timer();
1184    
1185            for (y = 0; y < dec->mb_height; y++) {
1186                    /* Initialize Pred Motion Vector */
1187                    dec->p_fmv = dec->p_bmv = zeromv;
1188                    for (x = 0; x < dec->mb_width; x++) {
1189                            MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x];
1190                            MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x];
1191                            const int fcode_max = (fcode_forward>fcode_backward) ? fcode_forward : fcode_backward;
1192                            uint32_t intra_dc_threshold; /* fake variable */
1193    
1194                            if (check_resync_marker(bs, fcode_max  - 1)) {
1195                                    int bound = read_video_packet_header(bs, dec, fcode_max - 1, &quant,
1196                                                                                                             &fcode_forward, &fcode_backward, &intra_dc_threshold);
1197                                    x = bound % dec->mb_width;
1198                                    y = bound / dec->mb_width;
1199                                    /* reset predicted macroblocks */
1200                                    dec->p_fmv = dec->p_bmv = zeromv;
1201                            }
1202    
1203                            mv =
1204                            mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] =
1205                            mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv;
1206                            mb->quant = quant;
1207    
1208                            /*
1209                             * skip if the co-located P_VOP macroblock is not coded
1210                             * if not codec in co-located S_VOP macroblock is _not_
1211                             * automatically skipped
1212                             */
1213    
1214                            if (last_mb->mode == MODE_NOT_CODED) {
1215                                    mb->cbp = 0;
1216                                    mb->mode = MODE_FORWARD;
1217                                    decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 1);
1218                                    continue;
1219                            }
1220    
1221                            if (!BitstreamGetBit(bs)) {     /* modb=='0' */
1222                                    const uint8_t modb2 = BitstreamGetBit(bs);
1223    
1224                                    mb->mode = get_mbtype(bs);
1225    
1226                                    if (!modb2)             /* modb=='00' */
1227                                            mb->cbp = BitstreamGetBits(bs, 6);
1228                                    else
1229                                            mb->cbp = 0;
1230    
1231                                    if (mb->mode && mb->cbp) {
1232                                            quant += get_dbquant(bs);
1233                                            if (quant > 31)
1234                                                    quant = 31;
1235                                            else if (quant < 1)
1236                                                    quant = 1;
1237                                    }
1238                                    mb->quant = quant;
1239    
1240                                    if (dec->interlacing) {
1241                                            if (mb->cbp) {
1242                                                    mb->field_dct = BitstreamGetBit(bs);
1243                                                    DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct);
1244                                            }
1245    
1246                                            if (mb->mode) {
1247                                                    mb->field_pred = BitstreamGetBit(bs);
1248                                                    DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred);
1249    
1250                                                    if (mb->field_pred) {
1251                                                            mb->field_for_top = BitstreamGetBit(bs);
1252                                                            DPRINTF(XVID_DEBUG_MB,"decp: field_for_top: %i\n", mb->field_for_top);
1253                                                            mb->field_for_bot = BitstreamGetBit(bs);
1254                                                            DPRINTF(XVID_DEBUG_MB,"decp: field_for_bot: %i\n", mb->field_for_bot);
1255                                                    }
1256                                            }
1257                                    }
1258    
1259                            } else {
1260                                    mb->mode = MODE_DIRECT_NONE_MV;
1261                                    mb->cbp = 0;
1262                            }
1263    
1264                            switch (mb->mode) {
1265                            case MODE_DIRECT:
1266                                    get_b_motion_vector(bs, &mv, 1, zeromv);
1267    
1268                            case MODE_DIRECT_NONE_MV:
1269                                    for (i = 0; i < 4; i++) {
1270                                            mb->mvs[i].x = (int32_t) ((TRB * last_mb->mvs[i].x) / TRD + mv.x);
1271                                            mb->b_mvs[i].x = (int32_t) ((mv.x == 0)
1272                                                                            ? ((TRB - TRD) * last_mb->mvs[i].x) / TRD
1273                                                                            : mb->mvs[i].x - last_mb->mvs[i].x);
1274                                            mb->mvs[i].y = (int32_t) ((TRB * last_mb->mvs[i].y) / TRD + mv.y);
1275                                            mb->b_mvs[i].y = (int32_t) ((mv.y == 0)
1276                                                                            ? ((TRB - TRD) * last_mb->mvs[i].y) / TRD
1277                                                                            : mb->mvs[i].y - last_mb->mvs[i].y);
1278                                    }
1279    
1280                                    decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
1281                                                                                                    mb, x, y, bs, 1);
1282                                    break;
1283    
1284                            case MODE_INTERPOLATE:
1285                                    get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv);
1286                                    dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
1287    
1288                                    get_b_motion_vector(bs, &mb->b_mvs[0], fcode_backward, dec->p_bmv);
1289                                    dec->p_bmv = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = mb->b_mvs[0];
1290    
1291                                    decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
1292                                                                                            mb, x, y, bs, 0);
1293                                    break;
1294    
1295                            case MODE_BACKWARD:
1296                                    get_b_motion_vector(bs, &mb->mvs[0], fcode_backward, dec->p_bmv);
1297                                    dec->p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
1298    
1299                                    decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 0);
1300                                    break;
1301    
1302                            case MODE_FORWARD:
1303                                    get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv);
1304                                    dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
1305    
1306                                    decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 1);
1307                                    break;
1308    
1309                            default:
1310                                    DPRINTF(XVID_DEBUG_ERROR,"Not supported B-frame mb_type = %i\n", mb->mode);
1311                            }
1312                    } /* End of for */
1313            }
1314    }
1315    
1316    /* perform post processing if necessary, and output the image */
1317    void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,
1318                                            xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type)
1319    {
1320            if (frame->general & (XVID_DEBLOCKY|XVID_DEBLOCKUV))    /* post process */
1321            {
1322                    /* note: image is stored to tmp */
1323                    image_copy(&dec->tmp, img, dec->edged_width, dec->height);
1324                    image_deblock(&dec->tmp, dec->edged_width,
1325                                              mbs, dec->mb_width, dec->mb_height, dec->mb_width,
1326                                              frame->general);
1327                    img = &dec->tmp;
1328            }
1329    
1330            image_output(img, dec->width, dec->height,
1331                                     dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride,
1332                                     frame->output.csp, dec->interlacing);
1333    
1334            if (stats) {
1335                    stats->type = coding2type(coding_type);
1336                    stats->data.vop.time_base = (int)dec->time_base;
1337                    stats->data.vop.time_increment = 0;     /* XXX: todo */
1338            }
1339    }
1340    
1341    
1342  int  int
1343  decoder_decode(DECODER * dec,  decoder_decode(DECODER * dec,
1344                             XVID_DEC_FRAME * frame)                                  xvid_dec_frame_t * frame, xvid_dec_stats_t * stats)
1345  {  {
1346    
1347          Bitstream bs;          Bitstream bs;
1348          uint32_t rounding;          uint32_t rounding;
1349            uint32_t reduced_resolution;
1350          uint32_t quant;          uint32_t quant;
1351          uint32_t fcode_forward;          uint32_t fcode_forward;
1352          uint32_t fcode_backward;          uint32_t fcode_backward;
1353          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
1354          uint32_t vop_type;          WARPPOINTS gmc_warp;
1355            int coding_type;
1356            int success, output, seen_something;
1357    
1358            if (XVID_VERSION_MAJOR(frame->version) != 1 || (stats && XVID_VERSION_MAJOR(stats->version) != 1))      /* v1.x.x */
1359                    return XVID_ERR_VERSION;
1360    
1361          start_global_timer();          start_global_timer();
1362    
1363          dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL;          dec->low_delay_default = (frame->general & XVID_LOWDELAY);
1364            if ((frame->general & XVID_DISCONTINUITY))
1365                    dec->frames = 0;
1366            dec->out_frm = (frame->output.csp == XVID_CSP_SLICE) ? &frame->output : NULL;
1367    
1368            if (frame->length < 0) {        /* decoder flush */
1369                    int ret;
1370                    /* if not decoding "low_delay/packed", and this isn't low_delay and
1371                            we have a reference frame, then outout the reference frame */
1372                    if (!(dec->low_delay_default && dec->packed_mode) && !dec->low_delay && dec->frames>0) {
1373                            decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);
1374                            dec->frames = 0;
1375                            ret = 0;
1376                    } else {
1377                            if (stats) stats->type = XVID_TYPE_NOTHING;
1378                            ret = XVID_ERR_END;
1379                    }
1380    
1381                    emms();
1382                    stop_global_timer();
1383                    return ret;
1384            }
1385    
1386          BitstreamInit(&bs, frame->bitstream, frame->length);          BitstreamInit(&bs, frame->bitstream, frame->length);
1387    
1388          /* add by chenm001 <chenm001@163.com> */          /* XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's */
1389          /* for support B-frame to reference last 2 frame */          if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f)
1390          dec->frames++;          {
1391          vop_type =                  image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width,
1392                  BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode_forward,                                           (uint8_t**)frame->output.plane, frame->output.stride, frame->output.csp, dec->interlacing);
1393                                                           &fcode_backward, &intra_dc_threshold);                  if (stats) stats->type = XVID_TYPE_NOTHING;
1394                    emms();
1395                    return 1;       /* one byte consumed */
1396            }
1397    
1398          dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0;  /* init pred vector to 0 */          success = 0;
1399            output = 0;
1400            seen_something = 0;
1401    
1402          switch (vop_type) {  repeat:
1403          case P_VOP:  
1404                  decoder_pframe(dec, &bs, rounding, quant, fcode_forward,          coding_type = BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,
1405                                             intra_dc_threshold);                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp);
                 break;  
1406    
1407            DPRINTF(XVID_DEBUG_HEADER, "coding_type=%i,  packed=%i,  time=%lli,  time_pp=%i,  time_bp=%i\n",
1408                                                            coding_type,    dec->packed_mode, dec->time, dec->time_pp, dec->time_bp);
1409    
1410            if (coding_type == -1) { /* nothing */
1411                    if (success) goto done;
1412                    if (stats) stats->type = XVID_TYPE_NOTHING;
1413                    emms();
1414                    return BitstreamPos(&bs)/8;
1415            }
1416    
1417            if (coding_type == -2 || coding_type == -3) {   /* vol and/or resize */
1418    
1419                    if (coding_type == -3)
1420                            decoder_resize(dec);
1421    
1422                    if (stats) {
1423                            stats->type = XVID_TYPE_VOL;
1424                            stats->data.vol.general = 0;
1425                            /*XXX: if (dec->interlacing)
1426                                    stats->data.vol.general |= ++INTERLACING; */
1427                            stats->data.vol.width = dec->width;
1428                            stats->data.vol.height = dec->height;
1429                            stats->data.vol.par = dec->aspect_ratio;
1430                            stats->data.vol.par_width = dec->par_width;
1431                            stats->data.vol.par_height = dec->par_height;
1432                            emms();
1433                            return BitstreamPos(&bs)/8;     /* number of bytes consumed */
1434                    }
1435                    goto repeat;
1436            }
1437    
1438            dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0;  /* init pred vector to 0 */
1439    
1440            /* packed_mode: special-N_VOP treament */
1441            if (dec->packed_mode && coding_type == N_VOP) {
1442                    if (dec->low_delay_default && dec->frames > 0) {
1443                            decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);
1444                            output = 1;
1445                    }
1446                    /* ignore otherwise */
1447            } else if (coding_type != B_VOP) {
1448                    switch(coding_type) {
1449          case I_VOP:          case I_VOP:
1450                  decoder_iframe(dec, &bs, quant, intra_dc_threshold);                          decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);
1451                  break;                  break;
1452          case B_VOP:                  case P_VOP :
1453                  image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);                          decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,
1454                                                    fcode_forward, intra_dc_threshold, NULL);
1455                            break;
1456                    case S_VOP :
1457                            decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,
1458                                                    fcode_forward, intra_dc_threshold, &gmc_warp);
1459                  break;                  break;
1460          case N_VOP:          case N_VOP:
1461                  /* when low_delay==0, N_VOP's should interpolate between the past and future frames */                          /* XXX: not_coded vops are not used for forward prediction */
1462                            /* we should not swap(last_mbs,mbs) */
1463                  image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);                  image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);
1464                            SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs); /* it will be swapped back */
1465                  break;                  break;
   
         default:  
                 return XVID_ERR_FAIL;  
1466          }          }
1467    
1468          frame->length = BitstreamPos(&bs) / 8;                  if (reduced_resolution) {
1469                            image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,
1470                                    (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width,
1471                                    16, 0);
1472                    }
1473    
1474          image_output(&dec->cur, dec->width, dec->height, dec->edged_width,                  /* note: for packed_mode, output is performed when the special-N_VOP is decoded */
1475                                           frame->image, frame->stride, frame->colorspace);                  if (!(dec->low_delay_default && dec->packed_mode)) {
1476                            if (dec->low_delay) {
1477                                    decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);
1478                                    output = 1;
1479                            } else if (dec->frames > 0)     { /* is the reference frame valid? */
1480                                    /* output the reference frame */
1481                                    decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);
1482                                    output = 1;
1483                            }
1484                    }
1485    
         if (vop_type == I_VOP || vop_type == P_VOP) {  
1486                  image_swap(&dec->refn[0], &dec->refn[1]);                  image_swap(&dec->refn[0], &dec->refn[1]);
1487                  image_swap(&dec->cur, &dec->refn[0]);                  image_swap(&dec->cur, &dec->refn[0]);
1488                    SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs);
1489                    dec->last_reduced_resolution = reduced_resolution;
1490                    dec->last_coding_type = coding_type;
1491    
1492                  /* swap MACROBLOCK */                  dec->frames++;
1493                  /* the Divx will not set the low_delay flage some times */                  seen_something = 1;
1494                  /* so follow code will wrong to not swap at that time */  
1495                  /* this will broken bitstream! so I'm change it, */          } else {        /* B_VOP */
1496                  /* But that is not the best way! can anyone tell me how */  
1497                  /* to do another way? */                  if (dec->low_delay) {
1498                  /* 18-07-2002   MinChen<chenm001@163.com> */                          DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n");
1499                  /*if (!dec->low_delay && vop_type == P_VOP) */                          dec->low_delay = 1;
1500                  if (vop_type == P_VOP)                  }
1501                          mb_swap(&dec->mbs, &dec->last_mbs);  
1502                    if (dec->frames < 2) {
1503                            /* attemping to decode a bvop without atleast 2 reference frames */
1504                            image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
1505                                                    "broken b-frame, mising ref frames");
1506                            stats->type = XVID_TYPE_NOTHING;
1507                    } else if (dec->time_pp <= dec->time_bp) {
1508                            /* this occurs when dx50_bvop_compatibility==0 sequences are
1509                            decoded in vfw. */
1510                            image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
1511                                                    "broken b-frame, tpp=%i tbp=%i", dec->time_pp, dec->time_bp);
1512                            stats->type = XVID_TYPE_NOTHING;
1513                    } else {
1514                            decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);
1515                            decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);
1516          }          }
1517    
1518          emms();                  output = 1;
1519                    dec->frames++;
1520            }
1521    
1522            BitstreamByteAlign(&bs);
1523    
1524            /* low_delay_default mode: repeat in packed_mode */
1525            if (dec->low_delay_default && dec->packed_mode && output == 0 && success == 0) {
1526                    success = 1;
1527                    goto repeat;
1528            }
1529    
1530    done :
1531    
1532            /* low_delay_default mode: if we've gotten here without outputting anything,
1533               then output the recently decoded frame, or print an error message  */
1534            if (dec->low_delay_default && output == 0) {
1535                    if (dec->packed_mode && seen_something) {
1536                            /* output the recently decoded frame */
1537                            decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);
1538                    } else {
1539                            image_clear(&dec->cur, dec->width, dec->height, dec->edged_width, 0, 128, 128);
1540                            image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
1541                                    "warning: nothing to output");
1542                            image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,
1543                                    "bframe decoder lag");
1544    
1545                            decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP);
1546                            if (stats) stats->type = XVID_TYPE_NOTHING;
1547                    }
1548            }
1549    
1550            emms();
1551          stop_global_timer();          stop_global_timer();
1552    
1553          return XVID_ERR_OK;          return BitstreamPos(&bs) / 8;   /* number of bytes consumed */
1554  }  }

Legend:
Removed from v.1.46  
changed lines
  Added in v.1.49.2.24

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