[svn] / branches / dev-api-3 / xvidcore / src / decoder.c Repository:
ViewVC logotype

Diff of /branches/dev-api-3/xvidcore/src/decoder.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 12, Sat Mar 9 14:45:40 2002 UTC revision 133, Tue Apr 23 00:05:31 2002 UTC
# Line 12  Line 12 
12   *      editors and their companies, will have no liability for use of this   *      editors and their companies, will have no liability for use of this
13   *      software or modifications or derivatives thereof.   *      software or modifications or derivatives thereof.
14   *   *
15   *      This program is free software; you can redistribute it and/or modify   *      This program is xvid_free software; you can redistribute it and/or modify
16   *      it under the terms of the GNU General Public License as published by   *      it under the terms of the GNU General Public License as published by
17   *      the Free Software Foundation; either version 2 of the License, or   *      the xvid_free Software Foundation; either version 2 of the License, or
18   *      (at your option) any later version.   *      (at your option) any later version.
19   *   *
20   *      This program is distributed in the hope that it will be useful,   *      This program is distributed in the hope that it will be useful,
# Line 23  Line 23 
23   *      GNU General Public License for more details.   *      GNU General Public License for more details.
24   *   *
25   *      You should have received a copy of the GNU General Public License   *      You should have received a copy of the GNU General Public License
26   *      along with this program; if not, write to the Free Software   *      along with this program; if not, write to the xvid_free Software
27   *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28   *   *
29   *************************************************************************/   *************************************************************************/
# 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      block 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>
# Line 62  Line 68 
68    
69  #include "image/image.h"  #include "image/image.h"
70  #include "image/colorspace.h"  #include "image/colorspace.h"
71    #include "utils/mem_align.h"
72    
73  int decoder_create(XVID_DEC_PARAM * param)  int decoder_create(XVID_DEC_PARAM * param)
74  {  {
75          DECODER * dec;          DECODER * dec;
76    
77          dec = malloc(sizeof(DECODER));          dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);
78          if (dec == NULL)          if (dec == NULL)
79          {          {
80                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
# Line 85  Line 92 
92    
93          if (image_create(&dec->cur, dec->edged_width, dec->edged_height))          if (image_create(&dec->cur, dec->edged_width, dec->edged_height))
94          {          {
95                  free(dec);                  xvid_free(dec);
96                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
97          }          }
98    
99          if (image_create(&dec->refn, dec->edged_width, dec->edged_height))          if (image_create(&dec->refn[0], dec->edged_width, dec->edged_height))
100          {          {
101                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
102                  free(dec);                  xvid_free(dec);
103                    return XVID_ERR_MEMORY;
104            }
105            // add by chenm001 <chenm001@163.com>
106            // for support B-frame to reference last 2 frame
107            if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height))
108            {
109                    image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
110                    image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
111                    xvid_free(dec);
112                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
113          }          }
114    
115          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);
116          if (dec->mbs == NULL)          if (dec->mbs == NULL)
117          {          {
118                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
119                  free(dec);                  xvid_free(dec);
120                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
121          }          }
122    
123          init_timer();          init_timer();
         create_vlc_tables();  
124    
125          return XVID_ERR_OK;          return XVID_ERR_OK;
126  }  }
# Line 113  Line 128 
128    
129  int decoder_destroy(DECODER * dec)  int decoder_destroy(DECODER * dec)
130  {  {
131          free(dec->mbs);          xvid_free(dec->mbs);
132          image_destroy(&dec->refn, dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
133          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
134          free(dec);          xvid_free(dec);
   
         destroy_vlc_tables();  
135    
136          write_timer();          write_timer();
137          return XVID_ERR_OK;          return XVID_ERR_OK;
# Line 134  Line 147 
147    
148  // decode an intra macroblock  // decode an intra macroblock
149    
150  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,
151  {                       MACROBLOCK * pMB,
152          uint32_t k;                       const uint32_t x_pos,
153                         const uint32_t y_pos,
154                         const uint32_t acpred_flag,
155                         const uint32_t cbp,
156                         Bitstream * bs,
157                         const uint32_t quant,
158                         const uint32_t intra_dc_threshold)
159    {
160    
161            DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
162            DECLARE_ALIGNED_MATRIX(data,  6, 64, int16_t, CACHE_LINE);
163    
164            uint32_t stride = dec->edged_width;
165            uint32_t stride2 = stride / 2;
166            uint32_t next_block = stride * 8;
167            uint32_t i;
168            uint32_t iQuant = pMB->quant;
169            uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
170    
171            pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
172            pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
173            pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
174    
175          for (k = 0; k < 6; k++)          memset(block, 0, 6*64*sizeof(int16_t));         // clear
176    
177            for (i = 0; i < 6; i++)
178          {          {
179                  uint32_t dcscalar;                  uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
                 int16_t block[64];  
                 int16_t data[64];  
180                  int16_t predictors[8];                  int16_t predictors[8];
181                  int start_coeff;                  int start_coeff;
182    
                 dcscalar = get_dc_scaler(mb->quant, k < 4);  
   
183                  start_timer();                  start_timer();
184                  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);
185                  if (!acpred_flag)                  if (!acpred_flag)
186                  {                  {
187                          mb->acpred_directions[k] = 0;                          pMB->acpred_directions[i] = 0;
188                  }                  }
189                  stop_prediction_timer();                  stop_prediction_timer();
190    
                 memset(block, 0, 64*sizeof(int16_t));           // clear  
   
191                  if (quant < intra_dc_threshold)                  if (quant < intra_dc_threshold)
192                  {                  {
193                          int dc_size;                          int dc_size;
194                          int dc_dif;                          int dc_dif;
195    
196                          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);
197                          dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0 ;                          dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0 ;
198    
199                          if (dc_size > 8)                          if (dc_size > 8)
# Line 171  Line 201 
201                                  BitstreamSkip(bs, 1);           // marker                                  BitstreamSkip(bs, 1);           // marker
202                          }                          }
203    
204                          block[0] = dc_dif;                          block[i*64 + 0] = dc_dif;
205                          start_coeff = 1;                          start_coeff = 1;
206                  }                  }
207                  else                  else
# Line 180  Line 210 
210                  }                  }
211    
212                  start_timer();                  start_timer();
213                  if (cbp & (1 << (5-k)))                 // coded                  if (cbp & (1 << (5-i)))                 // coded
214                  {                  {
215                          get_intra_block(bs, block, mb->acpred_directions[k], start_coeff);                          get_intra_block(bs, &block[i*64], pMB->acpred_directions[i], start_coeff);
216                  }                  }
217                  stop_coding_timer();                  stop_coding_timer();
218    
219                  start_timer();                  start_timer();
220                  add_acdc(mb, k, block, dcscalar, predictors);                  add_acdc(pMB, i, &block[i*64], iDcScaler, predictors);
221                  stop_prediction_timer();                  stop_prediction_timer();
222    
223                  start_timer();                  start_timer();
224                  if (dec->quant_type == 0)                  if (dec->quant_type == 0)
225                  {                  {
226                          dequant_intra(data, block, mb->quant, dcscalar);                          dequant_intra(&data[i*64], &block[i*64], iQuant, iDcScaler);
227                  }                  }
228                  else                  else
229                  {                  {
230                          dequant4_intra(data, block, mb->quant, dcscalar);                          dequant4_intra(&data[i*64], &block[i*64], iQuant, iDcScaler);
231                  }                  }
232                  stop_iquant_timer();                  stop_iquant_timer();
233    
234                  start_timer();                  start_timer();
235                  idct(data);                  idct(&data[i*64]);
236                  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);  
237                  }                  }
238                  else if (k == 4)  
239                  {          if (dec->interlacing && pMB->field_dct)
                         transfer_16to8copy(dec->cur.u+ 8*y*(dec->edged_width/2) + 8*x, data, (dec->edged_width/2));  
                 }  
                 else    // if (k == 5)  
240                  {                  {
241                          transfer_16to8copy(dec->cur.v + 8*y*(dec->edged_width/2) + 8*x, data, (dec->edged_width/2));                  next_block = stride;
242                    stride *= 2;
243                  }                  }
244    
245            start_timer();
246            transfer_16to8copy(pY_Cur,                  &data[0*64], stride);
247            transfer_16to8copy(pY_Cur + 8,              &data[1*64], stride);
248            transfer_16to8copy(pY_Cur + next_block,     &data[2*64], stride);
249            transfer_16to8copy(pY_Cur + 8 + next_block, &data[3*64], stride);
250            transfer_16to8copy(pU_Cur,                  &data[4*64], stride2);
251            transfer_16to8copy(pV_Cur,                  &data[5*64], stride2);
252                  stop_transfer_timer();                  stop_transfer_timer();
253          }          }
 }  
254    
255    
256    
# Line 234  Line 264 
264    
265  // decode an inter macroblock  // decode an inter macroblock
266    
267  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,
268  {                       const MACROBLOCK * pMB,
269          const uint32_t stride = dec->edged_width;                       const uint32_t x_pos,
270          const uint32_t stride2 = dec->edged_width / 2;                       const uint32_t y_pos,
271                         const uint32_t acpred_flag,
272                         const uint32_t cbp,
273                         Bitstream * bs,
274                         const uint32_t quant,
275                         const uint32_t rounding)
276    {
277    
278            DECLARE_ALIGNED_MATRIX(block,6, 64, int16_t, CACHE_LINE);
279            DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);
280    
281            uint32_t stride = dec->edged_width;
282            uint32_t stride2 = stride / 2;
283            uint32_t next_block = stride * 8;
284            uint32_t i;
285            uint32_t iQuant = pMB->quant;
286            uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
287          int uv_dx, uv_dy;          int uv_dx, uv_dy;
         uint32_t k;  
288    
289          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
290            pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
291            pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
292    
293            if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)
294          {          {
295                  uv_dx = mb->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
296                  uv_dy = mb->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
297    
298                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;
299                  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 301 
301          else          else
302          {          {
303                  int sum;                  int sum;
304                  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;
305                  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) );
306    
307                  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;
308                  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) );
309          }          }
310    
311          start_timer();          start_timer();
312          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);
313          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);
314          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);
315          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);
316          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);
317          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);
318          stop_comp_timer();          stop_comp_timer();
319    
320            for (i = 0; i < 6; i++)
         for (k = 0; k < 6; k++)  
321          {          {
322                  int16_t block[64];                  if (cbp & (1 << (5-i)))                 // coded
                 int16_t data[64];  
   
                 if (cbp & (1 << (5-k)))                 // coded  
323                  {                  {
324                          memset(block, 0, 64 * sizeof(int16_t));         // clear                          memset(&block[i*64], 0, 64 * sizeof(int16_t));          // clear
325    
326                          start_timer();                          start_timer();
327                          get_inter_block(bs, block);                          get_inter_block(bs, &block[i*64]);
328                          stop_coding_timer();                          stop_coding_timer();
329    
330                          start_timer();                          start_timer();
331                          if (dec->quant_type == 0)                          if (dec->quant_type == 0)
332                          {                          {
333                                  dequant_inter(data, block, mb->quant);                                  dequant_inter(&data[i*64], &block[i*64], iQuant);
334                          }                          }
335                          else                          else
336                          {                          {
337                                  dequant4_inter(data, block, mb->quant);                                  dequant4_inter(&data[i*64], &block[i*64], iQuant);
338                          }                          }
339                          stop_iquant_timer();                          stop_iquant_timer();
340    
341                          start_timer();                          start_timer();
342                          idct(data);                          idct(&data[i*64]);
343                          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);  
344                          }                          }
                         else if (k == 4)  
                         {  
                                 transfer_16to8add(dec->cur.u + 8*y*stride2 + 8*x, data, stride2);  
345                          }                          }
346                          else // k == 5  
347            if (dec->interlacing && pMB->field_dct)
348                          {                          {
349                                  transfer_16to8add(dec->cur.v + 8*y*stride2 + 8*x, data, stride2);                  next_block = stride;
350                    stride *= 2;
351                          }                          }
352    
353            start_timer();
354            if (cbp & 32)
355                    transfer_16to8add(pY_Cur,                  &data[0*64], stride);
356            if (cbp & 16)
357                    transfer_16to8add(pY_Cur + 8,              &data[1*64], stride);
358            if (cbp & 8)
359                    transfer_16to8add(pY_Cur + next_block,     &data[2*64], stride);
360            if (cbp & 4)
361                    transfer_16to8add(pY_Cur + 8 + next_block, &data[3*64], stride);
362            if (cbp & 2)
363                    transfer_16to8add(pU_Cur,                  &data[4*64], stride2);
364            if (cbp & 1)
365                    transfer_16to8add(pV_Cur,                  &data[5*64], stride2);
366                          stop_transfer_timer();                          stop_transfer_timer();
367                  }                  }
         }  
 }  
   
368    
369    
370  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)
371  {  {
372    
373          uint32_t x, y;          uint32_t x, y;
374    
375          for (y = 0; y < dec->mb_height; y++)          for (y = 0; y < dec->mb_height; y++)
# Line 362  Line 413 
413                          }                          }
414                          mb->quant = quant;                          mb->quant = quant;
415    
416                            if (dec->interlacing)
417                            {
418                                    mb->field_dct = BitstreamGetBit(bs);
419                                    DEBUG1("deci: field_dct: ", mb->field_dct);
420                            }
421    
422                          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);
423                  }                  }
424          }          }
425    
426  }  }
427    
428    
429  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)
430  {  {
431    
432          int scale_fac = 1 << (fcode - 1);          int scale_fac = 1 << (fcode - 1);
433          int high = (32 * scale_fac) - 1;          int high = (32 * scale_fac) - 1;
434          int low = ((-32) * scale_fac);          int low = ((-32) * scale_fac);
# Line 420  Line 478 
478    
479  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)
480  {  {
         uint32_t x, y;  
481    
482          image_swap(&dec->cur, &dec->refn);          uint32_t x, y;
483    
484          start_timer();          start_timer();
485          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);
486          stop_edges_timer();          stop_edges_timer();
487    
488          for (y = 0; y < dec->mb_height; y++)          for (y = 0; y < dec->mb_height; y++)
# Line 478  Line 535 
535                                  }                                  }
536                                  mb->quant = quant;                                  mb->quant = quant;
537    
538                                    if (dec->interlacing)
539                                    {
540                                            mb->field_dct = BitstreamGetBit(bs);
541                                            DEBUG1("decp: field_dct: ", mb->field_dct);
542    
543                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)
544                                  {                                  {
545                                                    mb->field_pred = BitstreamGetBit(bs);
546                                                    DEBUG1("decp: field_pred: ", mb->field_pred);
547    
548                                                    if (mb->field_pred)
549                                                    {
550                                                            mb->field_for_top = BitstreamGetBit(bs);
551                                                            DEBUG1("decp: field_for_top: ", mb->field_for_top);
552                                                            mb->field_for_bot = BitstreamGetBit(bs);
553                                                            DEBUG1("decp: field_for_bot: ", mb->field_for_bot);
554                                                    }
555                                            }
556                                    }
557    
558                                    if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)
559                                    {
560                                            if (dec->interlacing && mb->field_pred)
561                                            {
562                                                    get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode);
563                                                    get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1], fcode);
564                                            }
565                                            else
566                                            {
567                                          get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode);                                          get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode);
568                                          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;
569                                          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;
570                                  }                                  }
571                                    }
572                                  else if (mb->mode == MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */)                                  else if (mb->mode == MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */)
573                                  {                                  {
574                                          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 514  Line 598 
598                                  start_timer();                                  start_timer();
599    
600                                  transfer8x8_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x),                                  transfer8x8_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x),
601                                                                  dec->refn.y + (16*y)*dec->edged_width + (16*x),                                                   dec->refn[0].y + (16*y)*dec->edged_width + (16*x),
602                                                                  dec->edged_width);                                                                  dec->edged_width);
603    
604                                  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),
605                                                                  dec->refn.y + (16*y)*dec->edged_width + (16*x+8),                                                   dec->refn[0].y + (16*y)*dec->edged_width + (16*x+8),
606                                                                  dec->edged_width);                                                                  dec->edged_width);
607    
608                                  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),
609                                                                  dec->refn.y + (16*y+8)*dec->edged_width + (16*x),                                                   dec->refn[0].y + (16*y+8)*dec->edged_width + (16*x),
610                                                                  dec->edged_width);                                                                  dec->edged_width);
611    
612                                  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),
613                                                                  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),
614                                                                  dec->edged_width);                                                                  dec->edged_width);
615    
616                                  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),
617                                                                  dec->refn.u + (8*y)*dec->edged_width/2 + (8*x),                                                   dec->refn[0].u + (8*y)*dec->edged_width/2 + (8*x),
618                                                                  dec->edged_width/2);                                                                  dec->edged_width/2);
619    
620                                  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),
621                                                                  dec->refn.v + (8*y)*dec->edged_width/2 + (8*x),                                                   dec->refn[0].v + (8*y)*dec->edged_width/2 + (8*x),
622                                                                  dec->edged_width/2);                                                                  dec->edged_width/2);
623    
624                                  stop_transfer_timer();                                  stop_transfer_timer();
# Line 545  Line 629 
629    
630  int decoder_decode(DECODER * dec, XVID_DEC_FRAME * frame)  int decoder_decode(DECODER * dec, XVID_DEC_FRAME * frame)
631  {  {
632    
633          Bitstream bs;          Bitstream bs;
634          uint32_t rounding;          uint32_t rounding;
635          uint32_t quant;          uint32_t quant;
636          uint32_t fcode;          uint32_t fcode;
637          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
638            uint32_t vop_type;
639    
640          start_global_timer();          start_global_timer();
641    
642          BitstreamInit(&bs, frame->bitstream, frame->length);          BitstreamInit(&bs, frame->bitstream, frame->length);
643    
644          switch (BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode, &intra_dc_threshold))          // add by chenm001 <chenm001@163.com>
645            // for support B-frame to reference last 2 frame
646            vop_type=BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode, &intra_dc_threshold);
647    
648            if (vop_type==I_VOP || vop_type==P_VOP){
649                    image_swap(&dec->refn[0], &dec->refn[1]);
650                    image_swap(&dec->cur, &dec->refn[0]);
651            }
652    
653            switch (vop_type)
654          {          {
655          case P_VOP :          case P_VOP :
656                  decoder_pframe(dec, &bs, rounding, quant, fcode, intra_dc_threshold);                  decoder_pframe(dec, &bs, rounding, quant, fcode, intra_dc_threshold);
# Line 588  Line 683 
683          stop_global_timer();          stop_global_timer();
684    
685          return XVID_ERR_OK;          return XVID_ERR_OK;
686    
687  }  }

Legend:
Removed from v.12  
changed lines
  Added in v.133

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