[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.1, Fri Mar 8 02:44:29 2002 UTC revision 1.13, Sun Apr 28 23:35:25 2002 UTC
# Line 1  Line 1 
1  /**************************************************************************  /**************************************************************************
2   *   *
3   *      XVID MPEG-4 VIDEO CODEC   *      XVID MPEG-4 VIDEO CODEC
4   *      decoder main   *  -  Decoder main module  -
5   *   *
6   *      This program is an implementation of a part of one or more MPEG-4   *      This program is an implementation of a part of one or more MPEG-4
7   *      Video tools as specified in ISO/IEC 14496-2 standard.  Those intending   *      Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
# Line 24  Line 24 
24   *   *
25   *      You should have received a copy of the GNU General Public License   *      You should have received a copy of the GNU General Public License
26   *      along with this program; if not, write to the Free Software   *      along with this program; if not, write to the Free Software
27   *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
28   *   *
29   *************************************************************************/   *************************************************************************/
30    
# Line 32  Line 32 
32   *   *
33   *      History:   *      History:
34   *   *
35     *  22.04.2002  add some B-frame decode support;  chenm001 <chenm001@163.com>
36     *  29.03.2002  interlacing fix - compensated block wasn't being used when
37     *              reconstructing blocks, thus artifacts
38     *              interlacing speedup - used transfers to re-interlace
39     *              interlaced decoding should be as fast as progressive now
40     *  26.03.2002  interlacing support - moved transfers outside decode loop
41   *      26.12.2001      decoder_mbinter: dequant/idct moved within if(coded) block   *      26.12.2001      decoder_mbinter: dequant/idct moved within if(coded) block
42   *      22.12.2001      block based interpolation   *  22.12.2001  lock based interpolation
43   *      01.12.2001      inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>   *      01.12.2001      inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>
44   *   *
45     *  $Id$
46     *
47   *************************************************************************/   *************************************************************************/
48    
49  #include <stdlib.h>  #include <stdlib.h>
50  #include <string.h>  // memset  #include <string.h>
51    
52  #include "xvid.h"  #include "xvid.h"
53  #include "portab.h"  #include "portab.h"
# Line 62  Line 70 
70    
71  #include "image/image.h"  #include "image/image.h"
72  #include "image/colorspace.h"  #include "image/colorspace.h"
73    #include "utils/mem_align.h"
74    
75  int decoder_create(XVID_DEC_PARAM * param)  int decoder_create(XVID_DEC_PARAM * param)
76  {  {
77          DECODER * dec;          DECODER * dec;
78    
79          dec = malloc(sizeof(DECODER));          dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);
80          if (dec == NULL)          if (dec == NULL)
81          {          {
82                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
# Line 85  Line 94 
94    
95          if (image_create(&dec->cur, dec->edged_width, dec->edged_height))          if (image_create(&dec->cur, dec->edged_width, dec->edged_height))
96          {          {
97                  free(dec);                  xvid_free(dec);
98                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
99          }          }
100    
101          if (image_create(&dec->refn, dec->edged_width, dec->edged_height))          if (image_create(&dec->refn[0], dec->edged_width, dec->edged_height))
102            {
103                    image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
104                    xvid_free(dec);
105                    return XVID_ERR_MEMORY;
106            }
107            // add by chenm001 <chenm001@163.com>
108            // for support B-frame to reference last 2 frame
109            if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height))
110          {          {
111                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
112                  free(dec);                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
113                    xvid_free(dec);
114                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
115          }          }
116    
117          dec->mbs = malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);          dec->mbs = xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, CACHE_LINE);
118          if (dec->mbs == NULL)          if (dec->mbs == NULL)
119          {          {
120                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
121                  free(dec);                  xvid_free(dec);
122                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
123          }          }
124    
125          init_timer();          init_timer();
         create_vlc_tables();  
126    
127          return XVID_ERR_OK;          return XVID_ERR_OK;
128  }  }
# Line 113  Line 130 
130    
131  int decoder_destroy(DECODER * dec)  int decoder_destroy(DECODER * dec)
132  {  {
133          free(dec->mbs);          xvid_free(dec->mbs);
134          image_destroy(&dec->refn, dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
135          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
136          free(dec);          xvid_free(dec);
   
         destroy_vlc_tables();  
137    
138          write_timer();          write_timer();
139          return XVID_ERR_OK;          return XVID_ERR_OK;
# Line 134  Line 149 
149    
150  // decode an intra macroblock  // decode an intra macroblock
151    
152  void decoder_mbintra(DECODER * dec, MACROBLOCK * mb, int x, int y, uint32_t acpred_flag, uint32_t cbp, Bitstream * bs, int quant, int intra_dc_threshold)  void decoder_mbintra(DECODER * dec,
153  {                       MACROBLOCK * pMB,
154          uint32_t k;                       const uint32_t x_pos,
155                         const uint32_t y_pos,
156                         const uint32_t acpred_flag,
157                         const uint32_t cbp,
158                         Bitstream * bs,
159                         const uint32_t quant,
160                         const uint32_t intra_dc_threshold)
161    {
162    
163            DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
164            DECLARE_ALIGNED_MATRIX(data,  6, 64, int16_t, CACHE_LINE);
165    
166            uint32_t stride = dec->edged_width;
167            uint32_t stride2 = stride / 2;
168            uint32_t next_block = stride * 8;
169            uint32_t i;
170            uint32_t iQuant = pMB->quant;
171            uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
172    
173            pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
174            pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
175            pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
176    
177            memset(block, 0, 6*64*sizeof(int16_t));         // clear
178    
179          for (k = 0; k < 6; k++)          for (i = 0; i < 6; i++)
180          {          {
181                  uint32_t dcscalar;                  uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
                 int16_t block[64];  
                 int16_t data[64];  
182                  int16_t predictors[8];                  int16_t predictors[8];
183                  int start_coeff;                  int start_coeff;
184    
                 dcscalar = get_dc_scaler(mb->quant, k < 4);  
   
185                  start_timer();                  start_timer();
186                  predict_acdc(dec->mbs, x, y, dec->mb_width, k, block, mb->quant, dcscalar, predictors);                  predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i, &block[i*64], iQuant, iDcScaler, predictors);
187                  if (!acpred_flag)                  if (!acpred_flag)
188                  {                  {
189                          mb->acpred_directions[k] = 0;                          pMB->acpred_directions[i] = 0;
190                  }                  }
191                  stop_prediction_timer();                  stop_prediction_timer();
192    
                 memset(block, 0, 64*sizeof(int16_t));           // clear  
   
193                  if (quant < intra_dc_threshold)                  if (quant < intra_dc_threshold)
194                  {                  {
195                          int dc_size;                          int dc_size;
196                          int dc_dif;                          int dc_dif;
197    
198                          dc_size = k < 4 ?  get_dc_size_lum(bs) : get_dc_size_chrom(bs);                          dc_size = i < 4 ?  get_dc_size_lum(bs) : get_dc_size_chrom(bs);
199                          dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0 ;                          dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0 ;
200    
201                          if (dc_size > 8)                          if (dc_size > 8)
# Line 171  Line 203 
203                                  BitstreamSkip(bs, 1);           // marker                                  BitstreamSkip(bs, 1);           // marker
204                          }                          }
205    
206                          block[0] = dc_dif;                          block[i*64 + 0] = dc_dif;
207                          start_coeff = 1;                          start_coeff = 1;
208                  }                  }
209                  else                  else
# Line 180  Line 212 
212                  }                  }
213    
214                  start_timer();                  start_timer();
215                  if (cbp & (1 << (5-k)))                 // coded                  if (cbp & (1 << (5-i)))                 // coded
216                  {                  {
217                          get_intra_block(bs, block, mb->acpred_directions[k], start_coeff);                          get_intra_block(bs, &block[i*64], pMB->acpred_directions[i], start_coeff);
218                  }                  }
219                  stop_coding_timer();                  stop_coding_timer();
220    
221                  start_timer();                  start_timer();
222                  add_acdc(mb, k, block, dcscalar, predictors);                  add_acdc(pMB, i, &block[i*64], iDcScaler, predictors);
223                  stop_prediction_timer();                  stop_prediction_timer();
224    
225                  start_timer();                  start_timer();
226                  if (dec->quant_type == 0)                  if (dec->quant_type == 0)
227                  {                  {
228                          dequant_intra(data, block, mb->quant, dcscalar);                          dequant_intra(&data[i*64], &block[i*64], iQuant, iDcScaler);
229                  }                  }
230                  else                  else
231                  {                  {
232                          dequant4_intra(data, block, mb->quant, dcscalar);                          dequant4_intra(&data[i*64], &block[i*64], iQuant, iDcScaler);
233                  }                  }
234                  stop_iquant_timer();                  stop_iquant_timer();
235    
236                  start_timer();                  start_timer();
237                  idct(data);                  idct(&data[i*64]);
238                  stop_idct_timer();                  stop_idct_timer();
   
                 start_timer();  
                 if (k < 4)  
                 {  
                         transfer_16to8copy(dec->cur.y + (16*y*dec->edged_width) + 16*x + (4*(k&2)*dec->edged_width) + 8*(k&1), data, dec->edged_width);  
                 }  
                 else if (k == 4)  
                 {  
                         transfer_16to8copy(dec->cur.u+ 8*y*(dec->edged_width/2) + 8*x, data, (dec->edged_width/2));  
239                  }                  }
240                  else    // if (k == 5)  
241            if (dec->interlacing && pMB->field_dct)
242                  {                  {
243                          transfer_16to8copy(dec->cur.v + 8*y*(dec->edged_width/2) + 8*x, data, (dec->edged_width/2));                  next_block = stride;
244                    stride *= 2;
245                  }                  }
246    
247            start_timer();
248            transfer_16to8copy(pY_Cur,                  &data[0*64], stride);
249            transfer_16to8copy(pY_Cur + 8,              &data[1*64], stride);
250            transfer_16to8copy(pY_Cur + next_block,     &data[2*64], stride);
251            transfer_16to8copy(pY_Cur + 8 + next_block, &data[3*64], stride);
252            transfer_16to8copy(pU_Cur,                  &data[4*64], stride2);
253            transfer_16to8copy(pV_Cur,                  &data[5*64], stride2);
254                  stop_transfer_timer();                  stop_transfer_timer();
255          }          }
 }  
256    
257    
258    
# Line 234  Line 266 
266    
267  // decode an inter macroblock  // decode an inter macroblock
268    
269  void decoder_mbinter(DECODER * dec, MACROBLOCK * mb, int x, int y, uint32_t acpred_flag, uint32_t cbp, Bitstream * bs, int quant, int rounding)  void decoder_mbinter(DECODER * dec,
270  {                       const MACROBLOCK * pMB,
271          const uint32_t stride = dec->edged_width;                       const uint32_t x_pos,
272          const uint32_t stride2 = dec->edged_width / 2;                       const uint32_t y_pos,
273                         const uint32_t acpred_flag,
274                         const uint32_t cbp,
275                         Bitstream * bs,
276                         const uint32_t quant,
277                         const uint32_t rounding)
278    {
279    
280            DECLARE_ALIGNED_MATRIX(block,6, 64, int16_t, CACHE_LINE);
281            DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);
282    
283            uint32_t stride = dec->edged_width;
284            uint32_t stride2 = stride / 2;
285            uint32_t next_block = stride * 8;
286            uint32_t i;
287            uint32_t iQuant = pMB->quant;
288            uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
289          int uv_dx, uv_dy;          int uv_dx, uv_dy;
         uint32_t k;  
290    
291          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
292            pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
293            pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
294    
295            if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)
296          {          {
297                  uv_dx = mb->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
298                  uv_dy = mb->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
299    
300                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;
301                  uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;                  uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;
# Line 252  Line 303 
303          else          else
304          {          {
305                  int sum;                  int sum;
306                  sum = mb->mvs[0].x + mb->mvs[1].x + mb->mvs[2].x + mb->mvs[3].x;                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;
307                  uv_dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) );                  uv_dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) );
308    
309                  sum = mb->mvs[0].y + mb->mvs[1].y + mb->mvs[2].y + mb->mvs[3].y;                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
310                  uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) );                  uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) );
311          }          }
312    
313          start_timer();          start_timer();
314          interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x,     16*y    , mb->mvs[0].x, mb->mvs[0].y, stride,  rounding);          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos,     16*y_pos    , pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);
315          interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x + 8, 16*y    , mb->mvs[1].x, mb->mvs[1].y, stride,  rounding);          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos    , pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);
316          interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x,     16*y + 8, mb->mvs[2].x, mb->mvs[2].y, stride,  rounding);          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos,     16*y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);
317          interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x + 8, 16*y + 8, mb->mvs[3].x, mb->mvs[3].y, stride,  rounding);          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);
318          interpolate8x8_switch(dec->cur.u, dec->refn.u, 8*x, 8*y, uv_dx, uv_dy, stride2, rounding);          interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8*x_pos,      8*y_pos,      uv_dx,         uv_dy,         stride2, rounding);
319          interpolate8x8_switch(dec->cur.v, dec->refn.v, 8*x, 8*y, uv_dx, uv_dy, stride2, rounding);          interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8*x_pos,      8*y_pos,      uv_dx,         uv_dy,         stride2, rounding);
320          stop_comp_timer();          stop_comp_timer();
321    
322            for (i = 0; i < 6; i++)
         for (k = 0; k < 6; k++)  
323          {          {
324                  int16_t block[64];                  if (cbp & (1 << (5-i)))                 // coded
                 int16_t data[64];  
   
                 if (cbp & (1 << (5-k)))                 // coded  
325                  {                  {
326                          memset(block, 0, 64 * sizeof(int16_t));         // clear                          memset(&block[i*64], 0, 64 * sizeof(int16_t));          // clear
327    
328                          start_timer();                          start_timer();
329                          get_inter_block(bs, block);                          get_inter_block(bs, &block[i*64]);
330                          stop_coding_timer();                          stop_coding_timer();
331    
332                          start_timer();                          start_timer();
333                          if (dec->quant_type == 0)                          if (dec->quant_type == 0)
334                          {                          {
335                                  dequant_inter(data, block, mb->quant);                                  dequant_inter(&data[i*64], &block[i*64], iQuant);
336                          }                          }
337                          else                          else
338                          {                          {
339                                  dequant4_inter(data, block, mb->quant);                                  dequant4_inter(&data[i*64], &block[i*64], iQuant);
340                          }                          }
341                          stop_iquant_timer();                          stop_iquant_timer();
342    
343                          start_timer();                          start_timer();
344                          idct(data);                          idct(&data[i*64]);
345                          stop_idct_timer();                          stop_idct_timer();
   
                         start_timer();  
                         if (k < 4)  
                         {  
                                 transfer_16to8add(dec->cur.y + (16*y + 4*(k&2))*stride + 16*x + 8*(k&1), data, stride);  
346                          }                          }
                         else if (k == 4)  
                         {  
                                 transfer_16to8add(dec->cur.u + 8*y*stride2 + 8*x, data, stride2);  
347                          }                          }
348                          else // k == 5  
349            if (dec->interlacing && pMB->field_dct)
350                          {                          {
351                                  transfer_16to8add(dec->cur.v + 8*y*stride2 + 8*x, data, stride2);                  next_block = stride;
352                    stride *= 2;
353                          }                          }
354    
355            start_timer();
356            if (cbp & 32)
357                    transfer_16to8add(pY_Cur,                  &data[0*64], stride);
358            if (cbp & 16)
359                    transfer_16to8add(pY_Cur + 8,              &data[1*64], stride);
360            if (cbp & 8)
361                    transfer_16to8add(pY_Cur + next_block,     &data[2*64], stride);
362            if (cbp & 4)
363                    transfer_16to8add(pY_Cur + 8 + next_block, &data[3*64], stride);
364            if (cbp & 2)
365                    transfer_16to8add(pU_Cur,                  &data[4*64], stride2);
366            if (cbp & 1)
367                    transfer_16to8add(pV_Cur,                  &data[5*64], stride2);
368                          stop_transfer_timer();                          stop_transfer_timer();
369                  }                  }
         }  
 }  
   
370    
371    
372  void decoder_iframe(DECODER * dec, Bitstream * bs, int quant, int intra_dc_threshold)  void decoder_iframe(DECODER * dec, Bitstream * bs, int quant, int intra_dc_threshold)
373  {  {
374    
375          uint32_t x, y;          uint32_t x, y;
376    
377          for (y = 0; y < dec->mb_height; y++)          for (y = 0; y < dec->mb_height; y++)
# Line 362  Line 415 
415                          }                          }
416                          mb->quant = quant;                          mb->quant = quant;
417    
418                            if (dec->interlacing)
419                            {
420                                    mb->field_dct = BitstreamGetBit(bs);
421                                    DEBUG1("deci: field_dct: ", mb->field_dct);
422                            }
423    
424                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, intra_dc_threshold);                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, intra_dc_threshold);
425                  }                  }
426          }          }
427    
428  }  }
429    
430    
431  void get_motion_vector(DECODER *dec, Bitstream *bs, int x, int y, int k, VECTOR * mv, int fcode)  void get_motion_vector(DECODER *dec, Bitstream *bs, int x, int y, int k, VECTOR * mv, int fcode)
432  {  {
433    
434          int scale_fac = 1 << (fcode - 1);          int scale_fac = 1 << (fcode - 1);
435          int high = (32 * scale_fac) - 1;          int high = (32 * scale_fac) - 1;
436          int low = ((-32) * scale_fac);          int low = ((-32) * scale_fac);
437          int range = (64 * scale_fac);          int range = (64 * scale_fac);
438    
439          VECTOR pmv[4];          VECTOR pmv[4];
440          uint32_t psad[4];          int32_t psad[4];
441    
442          int mv_x, mv_y;          int mv_x, mv_y;
443          int pmv_x, pmv_y;          int pmv_x, pmv_y;
# Line 420  Line 480 
480    
481  void decoder_pframe(DECODER * dec, Bitstream * bs, int rounding, int quant, int fcode, int intra_dc_threshold)  void decoder_pframe(DECODER * dec, Bitstream * bs, int rounding, int quant, int fcode, int intra_dc_threshold)
482  {  {
         uint32_t x, y;  
483    
484          image_swap(&dec->cur, &dec->refn);          uint32_t x, y;
485    
486          start_timer();          start_timer();
487          image_setedges(&dec->refn, dec->edged_width, dec->edged_height, dec->width, dec->height);          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, dec->width, dec->height, dec->interlacing);
488          stop_edges_timer();          stop_edges_timer();
489    
490          for (y = 0; y < dec->mb_height; y++)          for (y = 0; y < dec->mb_height; y++)
# Line 446  Line 505 
505                                  mcbpc = get_mcbpc_inter(bs);                                  mcbpc = get_mcbpc_inter(bs);
506                                  mb->mode = mcbpc & 7;                                  mb->mode = mcbpc & 7;
507                                  cbpc = (mcbpc >> 4);                                  cbpc = (mcbpc >> 4);
508                                    acpred_flag = 0;
509    
510                                  intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q);                                  intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q);
511    
# Line 477  Line 537 
537                                  }                                  }
538                                  mb->quant = quant;                                  mb->quant = quant;
539    
540                                    if (dec->interlacing)
541                                    {
542                                            mb->field_dct = BitstreamGetBit(bs);
543                                            DEBUG1("decp: field_dct: ", mb->field_dct);
544    
545                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)
546                                  {                                  {
547                                                    mb->field_pred = BitstreamGetBit(bs);
548                                                    DEBUG1("decp: field_pred: ", mb->field_pred);
549    
550                                                    if (mb->field_pred)
551                                                    {
552                                                            mb->field_for_top = BitstreamGetBit(bs);
553                                                            DEBUG1("decp: field_for_top: ", mb->field_for_top);
554                                                            mb->field_for_bot = BitstreamGetBit(bs);
555                                                            DEBUG1("decp: field_for_bot: ", mb->field_for_bot);
556                                                    }
557                                            }
558                                    }
559    
560                                    if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)
561                                    {
562                                            if (dec->interlacing && mb->field_pred)
563                                            {
564                                                    get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode);
565                                                    get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1], fcode);
566                                            }
567                                            else
568                                            {
569                                          get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode);                                          get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode);
570                                          mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x;                                          mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x;
571                                          mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y;                                          mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y;
572                                  }                                  }
573                                    }
574                                  else if (mb->mode == MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */)                                  else if (mb->mode == MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */)
575                                  {                                  {
576                                          get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode);                                          get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode);
# Line 513  Line 600 
600                                  start_timer();                                  start_timer();
601    
602                                  transfer8x8_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x),                                  transfer8x8_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x),
603                                                                  dec->refn.y + (16*y)*dec->edged_width + (16*x),                                                   dec->refn[0].y + (16*y)*dec->edged_width + (16*x),
604                                                                  dec->edged_width);                                                                  dec->edged_width);
605    
606                                  transfer8x8_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x+8),                                  transfer8x8_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x+8),
607                                                                  dec->refn.y + (16*y)*dec->edged_width + (16*x+8),                                                   dec->refn[0].y + (16*y)*dec->edged_width + (16*x+8),
608                                                                  dec->edged_width);                                                                  dec->edged_width);
609    
610                                  transfer8x8_copy(dec->cur.y + (16*y+8)*dec->edged_width + (16*x),                                  transfer8x8_copy(dec->cur.y + (16*y+8)*dec->edged_width + (16*x),
611                                                                  dec->refn.y + (16*y+8)*dec->edged_width + (16*x),                                                   dec->refn[0].y + (16*y+8)*dec->edged_width + (16*x),
612                                                                  dec->edged_width);                                                                  dec->edged_width);
613    
614                                  transfer8x8_copy(dec->cur.y + (16*y+8)*dec->edged_width + (16*x+8),                                  transfer8x8_copy(dec->cur.y + (16*y+8)*dec->edged_width + (16*x+8),
615                                                                  dec->refn.y + (16*y+8)*dec->edged_width + (16*x+8),                                                   dec->refn[0].y + (16*y+8)*dec->edged_width + (16*x+8),
616                                                                  dec->edged_width);                                                                  dec->edged_width);
617    
618                                  transfer8x8_copy(dec->cur.u + (8*y)*dec->edged_width/2 + (8*x),                                  transfer8x8_copy(dec->cur.u + (8*y)*dec->edged_width/2 + (8*x),
619                                                                  dec->refn.u + (8*y)*dec->edged_width/2 + (8*x),                                                   dec->refn[0].u + (8*y)*dec->edged_width/2 + (8*x),
620                                                                  dec->edged_width/2);                                                                  dec->edged_width/2);
621    
622                                  transfer8x8_copy(dec->cur.v + (8*y)*dec->edged_width/2 + (8*x),                                  transfer8x8_copy(dec->cur.v + (8*y)*dec->edged_width/2 + (8*x),
623                                                                  dec->refn.v + (8*y)*dec->edged_width/2 + (8*x),                                                   dec->refn[0].v + (8*y)*dec->edged_width/2 + (8*x),
624                                                                  dec->edged_width/2);                                                                  dec->edged_width/2);
625    
626                                  stop_transfer_timer();                                  stop_transfer_timer();
# Line 544  Line 631 
631    
632  int decoder_decode(DECODER * dec, XVID_DEC_FRAME * frame)  int decoder_decode(DECODER * dec, XVID_DEC_FRAME * frame)
633  {  {
634    
635          Bitstream bs;          Bitstream bs;
636          uint32_t rounding;          uint32_t rounding;
637          uint32_t quant;          uint32_t quant;
638          uint32_t fcode;          uint32_t fcode;
639          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
640            uint32_t vop_type;
641    
642          start_global_timer();          start_global_timer();
643    
644          BitstreamInit(&bs, frame->bitstream, frame->length);          BitstreamInit(&bs, frame->bitstream, frame->length);
645    
646          switch (BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode, &intra_dc_threshold))          // add by chenm001 <chenm001@163.com>
647            // for support B-frame to reference last 2 frame
648            vop_type=BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode, &intra_dc_threshold);
649    
650            if (vop_type==I_VOP || vop_type==P_VOP){
651                    image_swap(&dec->refn[0], &dec->refn[1]);
652                    image_swap(&dec->cur, &dec->refn[0]);
653            }
654    
655            switch (vop_type)
656          {          {
657          case P_VOP :          case P_VOP :
658                  decoder_pframe(dec, &bs, rounding, quant, fcode, intra_dc_threshold);                  decoder_pframe(dec, &bs, rounding, quant, fcode, intra_dc_threshold);
# Line 587  Line 685 
685          stop_global_timer();          stop_global_timer();
686    
687          return XVID_ERR_OK;          return XVID_ERR_OK;
688    
689  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.13

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