[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.5, Tue Mar 26 11:16:08 2002 UTC revision 1.11, Tue Apr 23 00:04:03 2002 UTC
# 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   *  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
# Line 55  Line 60 
60  #include "dct/fdct.h"  #include "dct/fdct.h"
61  #include "utils/mem_transfer.h"  #include "utils/mem_transfer.h"
62  #include "image/interpolate8x8.h"  #include "image/interpolate8x8.h"
 #include "utils/mbfunctions.h"  
63    
64  #include "bitstream/mbcoding.h"  #include "bitstream/mbcoding.h"
65  #include "prediction/mbprediction.h"  #include "prediction/mbprediction.h"
# Line 92  Line 96 
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                  xvid_free(dec);                  xvid_free(dec);
103                  return XVID_ERR_MEMORY;                  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;
113            }
114    
115          dec->mbs = xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, CACHE_LINE);          dec->mbs = xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, CACHE_LINE);
116          if (dec->mbs == NULL)          if (dec->mbs == NULL)
# Line 108  Line 121 
121          }          }
122    
123          init_timer();          init_timer();
         create_vlc_tables();  
124    
125          return XVID_ERR_OK;          return XVID_ERR_OK;
126  }  }
# Line 117  Line 129 
129  int decoder_destroy(DECODER * dec)  int decoder_destroy(DECODER * dec)
130  {  {
131          xvid_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          xvid_free(dec);          xvid_free(dec);
135    
         destroy_vlc_tables();  
   
136          write_timer();          write_timer();
137          return XVID_ERR_OK;          return XVID_ERR_OK;
138  }  }
# Line 147  Line 157 
157                                           const uint32_t quant,                                           const uint32_t quant,
158                                           const uint32_t intra_dc_threshold)                                           const uint32_t intra_dc_threshold)
159  {  {
         CACHE_ALIGN int16_t block[6][64];  
         CACHE_ALIGN int16_t data[6][64];  
160    
161          const uint32_t stride = dec->edged_width;          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;          uint32_t i;
168          uint32_t iQuant = pMB->quant;          uint32_t iQuant = pMB->quant;
169          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
170    
171      pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);      pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
172      pU_Cur = dec->cur.u + (y_pos << 3) * (stride >> 1) + (x_pos << 3);          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
173      pV_Cur = dec->cur.v + (y_pos << 3) * (stride >> 1) + (x_pos << 3);          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
174    
175          memset(block, 0, sizeof(block));                // clear          memset(block, 0, 6*64*sizeof(int16_t));         // clear
176    
177          for (i = 0; i < 6; i++)          for (i = 0; i < 6; i++)
178          {          {
# Line 168  Line 181 
181                  int start_coeff;                  int start_coeff;
182    
183                  start_timer();                  start_timer();
184                  predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i, block[i], iQuant, iDcScaler, 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                          pMB->acpred_directions[i] = 0;                          pMB->acpred_directions[i] = 0;
# Line 188  Line 201 
201                                  BitstreamSkip(bs, 1);           // marker                                  BitstreamSkip(bs, 1);           // marker
202                          }                          }
203    
204                          block[i][0] = dc_dif;                          block[i*64 + 0] = dc_dif;
205                          start_coeff = 1;                          start_coeff = 1;
206                  }                  }
207                  else                  else
# Line 199  Line 212 
212                  start_timer();                  start_timer();
213                  if (cbp & (1 << (5-i)))                 // coded                  if (cbp & (1 << (5-i)))                 // coded
214                  {                  {
215                          get_intra_block(bs, block[i], pMB->acpred_directions[i], 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(pMB, i, block[i], iDcScaler, 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[i], block[i], iQuant, iDcScaler);                          dequant_intra(&data[i*64], &block[i*64], iQuant, iDcScaler);
227                  }                  }
228                  else                  else
229                  {                  {
230                          dequant4_intra(data[i], block[i], iQuant, iDcScaler);                          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[i]);                  idct(&data[i*64]);
236                  stop_idct_timer();                  stop_idct_timer();
237          }          }
238    
         start_timer();  
239          if (dec->interlacing && pMB->field_dct)          if (dec->interlacing && pMB->field_dct)
240          {          {
241                  MBFieldToFrame(data);                  next_block = stride;
242                    stride *= 2;
243          }          }
         stop_interlacing_timer();  
244    
245          start_timer();          start_timer();
246          transfer_16to8copy(pY_Cur, data[0], stride);          transfer_16to8copy(pY_Cur,                  &data[0*64], stride);
247          transfer_16to8copy(pY_Cur + 8, data[1], stride);          transfer_16to8copy(pY_Cur + 8,              &data[1*64], stride);
248          transfer_16to8copy(pY_Cur + 8 * stride, data[2], stride);          transfer_16to8copy(pY_Cur + next_block,     &data[2*64], stride);
249          transfer_16to8copy(pY_Cur + 8 + 8 * stride, data[3], stride);          transfer_16to8copy(pY_Cur + 8 + next_block, &data[3*64], stride);
250          transfer_16to8copy(pU_Cur, data[4], stride / 2);          transfer_16to8copy(pU_Cur,                  &data[4*64], stride2);
251          transfer_16to8copy(pV_Cur, data[5], stride / 2);          transfer_16to8copy(pV_Cur,                  &data[5*64], stride2);
252          stop_transfer_timer();          stop_transfer_timer();
253  }  }
254    
# Line 262  Line 274 
274                                           const uint32_t quant,                                           const uint32_t quant,
275                                           const uint32_t rounding)                                           const uint32_t rounding)
276  {  {
         CACHE_ALIGN int16_t block[6][64];  
         CACHE_ALIGN int16_t data[6][64];  
277    
278          const uint32_t stride = dec->edged_width;          DECLARE_ALIGNED_MATRIX(block,6, 64, int16_t, CACHE_LINE);
279          const uint32_t stride2 = dec->edged_width / 2;          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;      uint32_t i;
285      uint32_t iQuant = pMB->quant;      uint32_t iQuant = pMB->quant;
286          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
287          int uv_dx, uv_dy;          int uv_dx, uv_dy;
288    
289      pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);      pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
290      pU_Cur = dec->cur.u + (y_pos << 3) * (stride >> 1) + (x_pos << 3);          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
291      pV_Cur = dec->cur.v + (y_pos << 3) * (stride >> 1) + (x_pos << 3);          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
292    
293          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)
294          {          {
# Line 295  Line 309 
309          }          }
310    
311          start_timer();          start_timer();
312          interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x_pos,     16*y_pos    , pMB->mvs[0].x, pMB->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_pos + 8, 16*y_pos    , pMB->mvs[1].x, pMB->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_pos,     16*y_pos + 8, pMB->mvs[2].x, pMB->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_pos + 8, 16*y_pos + 8, pMB->mvs[3].x, pMB->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_pos,      8*y_pos,      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_pos,      8*y_pos,      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 (i = 0; i < 6; i++)
321          {          {
322                  if (cbp & (1 << (5-i)))                 // coded                  if (cbp & (1 << (5-i)))                 // coded
323                  {                  {
324                          memset(block[i], 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[i]);                          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[i], block[i], iQuant);                                  dequant_inter(&data[i*64], &block[i*64], iQuant);
334                          }                          }
335                          else                          else
336                          {                          {
337                                  dequant4_inter(data[i], block[i], iQuant);                                  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[i]);                          idct(&data[i*64]);
343                          stop_idct_timer();                          stop_idct_timer();
344                  }                  }
345          }          }
346    
347          start_timer();          if (dec->interlacing && pMB->field_dct)
         if (pMB->field_dct)  
348          {          {
349                  MBFieldToFrame(data);                  next_block = stride;
350                    stride *= 2;
351          }          }
         stop_interlacing_timer();  
352    
353          start_timer();          start_timer();
354          if (cbp & 32)          if (cbp & 32)
355                  transfer_16to8add(pY_Cur, data[0], stride);                  transfer_16to8add(pY_Cur,                  &data[0*64], stride);
356          if (cbp & 16)          if (cbp & 16)
357                  transfer_16to8add(pY_Cur + 8, data[1], stride);                  transfer_16to8add(pY_Cur + 8,              &data[1*64], stride);
358          if (cbp & 8)          if (cbp & 8)
359                  transfer_16to8add(pY_Cur + 8 * stride, data[2], stride);                  transfer_16to8add(pY_Cur + next_block,     &data[2*64], stride);
360          if (cbp & 4)          if (cbp & 4)
361                  transfer_16to8add(pY_Cur + 8 + 8 * stride, data[3], stride);                  transfer_16to8add(pY_Cur + 8 + next_block, &data[3*64], stride);
362          if (cbp & 2)          if (cbp & 2)
363                  transfer_16to8add(pU_Cur, data[4], stride / 2);                  transfer_16to8add(pU_Cur,                  &data[4*64], stride2);
364          if (cbp & 1)          if (cbp & 1)
365                  transfer_16to8add(pV_Cur, data[5], stride / 2);                  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 408  Line 422 
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 462  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, dec->interlacing);          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 583  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 614  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 657  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.1.5  
changed lines
  Added in v.1.11

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