[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.37, Wed Sep 4 03:23:23 2002 UTC revision 1.37.2.18, Tue Dec 10 11:13:50 2002 UTC
# Line 79  Line 79 
79  #include "dct/fdct.h"  #include "dct/fdct.h"
80  #include "utils/mem_transfer.h"  #include "utils/mem_transfer.h"
81  #include "image/interpolate8x8.h"  #include "image/interpolate8x8.h"
82    #include "image/reduced.h"
83    
84  #include "bitstream/mbcoding.h"  #include "bitstream/mbcoding.h"
85  #include "prediction/mbprediction.h"  #include "prediction/mbprediction.h"
86  #include "utils/timer.h"  #include "utils/timer.h"
87  #include "utils/emms.h"  #include "utils/emms.h"
88    #include "motion/motion.h"
89    
90  #include "image/image.h"  #include "image/image.h"
91  #include "image/colorspace.h"  #include "image/colorspace.h"
92  #include "utils/mem_align.h"  #include "utils/mem_align.h"
93    
94  int  int
95  decoder_create(XVID_DEC_PARAM * param)  decoder_resize(DECODER * dec)
96  {  {
97          DECODER *dec;          /* free existing */
98    
99          dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
100          if (dec == NULL) {          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
101                  return XVID_ERR_MEMORY;          image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);
102          }          image_destroy(&dec->refh, dec->edged_width, dec->edged_height);
103          param->handle = dec;          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
104    
105          dec->width = param->width;          if (dec->last_mbs)
106          dec->height = param->height;                  xvid_free(dec->last_mbs);
107            if (dec->mbs)
108                    xvid_free(dec->mbs);
109    
110            /* realloc */
111    
112          dec->mb_width = (dec->width + 15) / 16;          dec->mb_width = (dec->width + 15) / 16;
113          dec->mb_height = (dec->height + 15) / 16;          dec->mb_height = (dec->height + 15) / 16;
114    
115          dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE;          dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE;
116          dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE;          dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE;
         dec->low_delay = 0;  
117    
118          if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) {          if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) {
119                  xvid_free(dec);                  xvid_free(dec);
# Line 120  Line 125 
125                  xvid_free(dec);                  xvid_free(dec);
126                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
127          }          }
128    
129          // add by chenm001 <chenm001@163.com>          // add by chenm001 <chenm001@163.com>
130          // for support B-frame to reference last 2 frame          // for support B-frame to reference last 2 frame
131          if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) {          if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) {
# Line 136  Line 142 
142                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
143          }          }
144    
145            if (image_create(&dec->refh, dec->edged_width, dec->edged_height)) {
146                    image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
147                    image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
148                    image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
149                    image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);
150                    xvid_free(dec);
151                    return XVID_ERR_MEMORY;
152            }
153    
154          dec->mbs =          dec->mbs =
155                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,
156                                          CACHE_LINE);                                          CACHE_LINE);
# Line 144  Line 159 
159                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
160                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
161                  image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);
162                    image_destroy(&dec->refh, dec->edged_width, dec->edged_height);
163                  xvid_free(dec);                  xvid_free(dec);
164                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
165          }          }
   
166          memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);          memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);
167    
168          // add by chenm001 <chenm001@163.com>          // add by chenm001 <chenm001@163.com>
# Line 161  Line 176 
176                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
177                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
178                  image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);
179                    image_destroy(&dec->refh, dec->edged_width, dec->edged_height);
180                  xvid_free(dec);                  xvid_free(dec);
181                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
182          }          }
183    
184          memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);          memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);
185    
186            return XVID_ERR_OK;
187    }
188    
189    
190    int
191    decoder_create(XVID_DEC_PARAM * param)
192    {
193            DECODER *dec;
194    
195            dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);
196            if (dec == NULL) {
197                    return XVID_ERR_MEMORY;
198            }
199            memset(dec, 0, sizeof(DECODER));
200    
201            param->handle = dec;
202    
203            dec->width = param->width;
204            dec->height = param->height;
205    
206            image_null(&dec->cur);
207            image_null(&dec->refn[0]);
208            image_null(&dec->refn[1]);
209            image_null(&dec->refn[2]);
210            image_null(&dec->refh);
211    
212            dec->mbs = NULL;
213            dec->last_mbs = NULL;
214    
215          init_timer();          init_timer();
216    
217          // add by chenm001 <chenm001@163.com>          // add by chenm001 <chenm001@163.com>
218          // for support B-frame to save reference frame's time          // for support B-frame to save reference frame's time
219          dec->frames = -1;          dec->frames = -1;
220          dec->time = dec->time_base = dec->last_time_base = 0;          dec->time = dec->time_base = dec->last_time_base = 0;
221            dec->low_delay = 0;
222            dec->packed_mode = 0;
223    
224            dec->fixed_dimensions = (dec->width > 0 && dec->height > 0);
225    
226            if (dec->fixed_dimensions)
227                    return decoder_resize(dec);
228            else
229          return XVID_ERR_OK;          return XVID_ERR_OK;
230  }  }
231    
# Line 186  Line 238 
238          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
239          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
240          image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);
241            image_destroy(&dec->refh, dec->edged_width, dec->edged_height);
242          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
243          xvid_free(dec);          xvid_free(dec);
244    
# Line 214  Line 267 
267                                  Bitstream * bs,                                  Bitstream * bs,
268                                  const uint32_t quant,                                  const uint32_t quant,
269                                  const uint32_t intra_dc_threshold,                                  const uint32_t intra_dc_threshold,
270                                  const unsigned int bound)                                  const unsigned int bound,
271                                    const int reduced_resolution)
272  {  {
273    
274          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
# Line 227  Line 281 
281          uint32_t iQuant = pMB->quant;          uint32_t iQuant = pMB->quant;
282          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
283    
284            if (reduced_resolution) {
285                    pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5);
286                    pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4);
287                    pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4);
288            }else{
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) * stride2 + (x_pos << 3);          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);          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
292            }
293    
294          memset(block, 0, 6 * 64 * sizeof(int16_t));     // clear          memset(block, 0, 6 * 64 * sizeof(int16_t));     // clear
295    
# Line 268  Line 328 
328                  start_timer();                  start_timer();
329                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       // coded
330                  {                  {
331                          get_intra_block(bs, &block[i * 64], pMB->acpred_directions[i],                          int direction = dec->alternate_vertical_scan ?
332                                                          start_coeff);                                  2 : pMB->acpred_directions[i];
333    
334                            get_intra_block(bs, &block[i * 64], direction, start_coeff);
335                  }                  }
336                  stop_coding_timer();                  stop_coding_timer();
337    
# Line 288  Line 350 
350                  start_timer();                  start_timer();
351                  idct(&data[i * 64]);                  idct(&data[i * 64]);
352                  stop_idct_timer();                  stop_idct_timer();
353    
354          }          }
355    
356          if (dec->interlacing && pMB->field_dct) {          if (dec->interlacing && pMB->field_dct) {
# Line 296  Line 359 
359          }          }
360    
361          start_timer();          start_timer();
362    
363            if (reduced_resolution)
364            {
365                    next_block*=2;
366                    copy_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
367                    copy_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
368                    copy_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
369                    copy_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);
370                    copy_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
371                    copy_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
372            }else{
373          transfer_16to8copy(pY_Cur, &data[0 * 64], stride);          transfer_16to8copy(pY_Cur, &data[0 * 64], stride);
374          transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);          transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);
375          transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);          transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);
376          transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride);          transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride);
377          transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);          transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);
378          transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);          transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);
379            }
380          stop_transfer_timer();          stop_transfer_timer();
381  }  }
382    
# Line 311  Line 386 
386    
387  #define SIGN(X) (((X)>0)?1:-1)  #define SIGN(X) (((X)>0)?1:-1)
388  #define ABS(X) (((X)>0)?(X):-(X))  #define ABS(X) (((X)>0)?(X):-(X))
 static const uint32_t roundtab[16] =  
         { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 };  
   
389    
390  // decode an inter macroblock  // decode an inter macroblock
391    
# Line 326  Line 398 
398                                  const uint32_t cbp,                                  const uint32_t cbp,
399                                  Bitstream * bs,                                  Bitstream * bs,
400                                  const uint32_t quant,                                  const uint32_t quant,
401                                  const uint32_t rounding)                                  const uint32_t rounding,
402                                    const int reduced_resolution)
403  {  {
404    
405          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
# Line 334  Line 407 
407    
408          uint32_t stride = dec->edged_width;          uint32_t stride = dec->edged_width;
409          uint32_t stride2 = stride / 2;          uint32_t stride2 = stride / 2;
410          uint32_t next_block = stride * 8;          uint32_t next_block = stride * (reduced_resolution ? 16 : 8);
411          uint32_t i;          uint32_t i;
412          uint32_t iQuant = pMB->quant;          uint32_t iQuant = pMB->quant;
413          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
414    
415          int uv_dx, uv_dy;          int uv_dx, uv_dy;
416            VECTOR mv[4];   /* local copy of mvs */
417    
418            if (reduced_resolution) {
419                    pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5);
420                    pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4);
421                    pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4);
422                    for (i = 0; i < 4; i++) {
423                            mv[i].x = RRV_MV_SCALEUP(pMB->mvs[i].x);
424                            mv[i].y = RRV_MV_SCALEUP(pMB->mvs[i].y);
425                    }
426            }else{
427          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
428          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
429          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
430                    for (i = 0; i < 4; i++)
431                            mv[i] = pMB->mvs[i];
432            }
433    
434          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {
435                  uv_dx = pMB->mvs[0].x;                  uv_dx = mv[0].x;
436                  uv_dy = pMB->mvs[0].y;                  uv_dy = mv[0].y;
437    
438                  if (dec->quarterpel)                  if (dec->quarterpel)
439                  {                  {
440                          uv_dx = (uv_dx >> 1) | (uv_dx & 1);                          uv_dx /= 2;
441                          uv_dy = (uv_dy >> 1) | (uv_dy & 1);                          uv_dy /= 2;
442                  }                  }
443    
444                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;                  uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
445                  uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;                  uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
         } else {  
                 int sum;  
                 sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;  
446    
447                  if (dec->quarterpel)                  start_timer();
448                    if (reduced_resolution)
449                    {
450                            interpolate32x32_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,
451                                                                      mv[0].x, mv[0].y, stride,  rounding);
452                            interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos,
453                                                                      uv_dx, uv_dy, stride2, rounding);
454                            interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos,
455                                                                      uv_dx, uv_dy, stride2, rounding);
456    
457                    }
458                    else
459                  {                  {
460                          sum /= 2;                          if(dec->quarterpel) {
461                                    interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
462                                                                                            dec->refh.y + 128, 16*x_pos, 16*y_pos,
463                                                                                            mv[0].x, mv[0].y, stride,  rounding);
464                            }
465                            else {
466                                    interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,
467                                                                              mv[0].x, mv[0].y, stride,  rounding);
468                  }                  }
469    
470                  uv_dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2));                          interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,
471                                                                      uv_dx, uv_dy, stride2, rounding);
472                            interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,
473                                                                      uv_dx, uv_dy, stride2, rounding);
474                    }
475                    stop_comp_timer();
476    
477                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;          } else {        /* MODE_INTER4V */
478                    int sum;
479    
480                  if (dec->quarterpel)                  if (dec->quarterpel)
481                  {                          sum = (mv[0].x / 2) + (mv[1].x / 2) + (mv[2].x / 2) + (mv[3].x / 2);
482                          sum /= 2;                  else
483                  }                          sum = mv[0].x + mv[1].x + mv[2].x + mv[3].x;
484    
485                  uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2));                  uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];
486          }  
487                    if(dec->quarterpel)
488                            sum = (mv[0].y / 2) + (mv[1].y / 2) + (mv[2].y / 2) + (mv[3].y / 2);
489                    else
490                            sum = mv[0].y + mv[1].y + mv[2].y + mv[3].y;
491    
492                    uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];
493    
494          start_timer();          start_timer();
495                    if (reduced_resolution)
496                    {
497                            interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,
498                                                                      mv[0].x, mv[0].y, stride,  rounding);
499                            interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos + 16, 32*y_pos,
500                                                                      mv[1].x, mv[1].y, stride,  rounding);
501                            interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos + 16,
502                                                                      mv[2].x, mv[2].y, stride,  rounding);
503                            interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos + 16, 32*y_pos + 16,
504                                                                      mv[3].x, mv[3].y, stride,  rounding);
505                            interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos,
506                                                                      uv_dx, uv_dy, stride2, rounding);
507                            interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos,
508                                                                      uv_dx, uv_dy, stride2, rounding);
509    
510                            // set_block(pY_Cur, stride, 32, 32, 127);
511                    }
512                    else
513                    {
514          if(dec->quarterpel) {          if(dec->quarterpel) {
515                  DEBUG("QUARTERPEL");                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
516                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,                                                                                    dec->refh.y + 128, 16*x_pos, 16*y_pos,
517                                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);                                                                                    mv[0].x, mv[0].y, stride,  rounding);
518                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos,                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
519                                                                    pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);                                                                                    dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,
520                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8,                                                                                    mv[1].x, mv[1].y, stride,  rounding);
521                                                                    pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
522                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8,                                                                                    dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,
523                                                                    pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);                                                                                    mv[2].x, mv[2].y, stride,  rounding);
524                                    interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
525                                                                                      dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,
526                                                                                      mv[3].x, mv[3].y, stride,  rounding);
527          }          }
528          else {          else {
529                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,
530                                                            pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);                                                                            mv[0].x, mv[0].y, stride,  rounding);
531                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos,                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos,
532                                                            pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);                                                                            mv[1].x, mv[1].y, stride,  rounding);
533                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8,                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8,
534                                                            pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);                                                                            mv[2].x, mv[2].y, stride,  rounding);
535                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8,                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8,
536                                                            pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);                                                                            mv[3].x, mv[3].y, stride,  rounding);
537          }          }
538    
539          interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,
540                                                    uv_dx, uv_dy, stride2, rounding);                                                    uv_dx, uv_dy, stride2, rounding);
541          interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,
542                                                    uv_dx, uv_dy, stride2, rounding);                                                    uv_dx, uv_dy, stride2, rounding);
543                    }
544          stop_comp_timer();          stop_comp_timer();
545            }
546    
547          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
548                    int direction = dec->alternate_vertical_scan ? 2 : 0;
549    
550                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       // coded
551                  {                  {
552                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
553    
554                          start_timer();                          start_timer();
555                          get_inter_block(bs, &block[i * 64]);                          get_inter_block(bs, &block[i * 64], direction);
556                          stop_coding_timer();                          stop_coding_timer();
557    
558                          start_timer();                          start_timer();
# Line 435  Line 575 
575          }          }
576    
577          start_timer();          start_timer();
578            if (reduced_resolution)
579            {
580                    if (cbp & 32)
581                            add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
582                    if (cbp & 16)
583                            add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
584                    if (cbp & 8)
585                            add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
586                    if (cbp & 4)
587                            add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);
588                    if (cbp & 2)
589                            add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
590                    if (cbp & 1)
591                            add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
592            }
593            else
594            {
595          if (cbp & 32)          if (cbp & 32)
596                  transfer_16to8add(pY_Cur, &data[0 * 64], stride);                  transfer_16to8add(pY_Cur, &data[0 * 64], stride);
597          if (cbp & 16)          if (cbp & 16)
# Line 447  Line 604 
604                  transfer_16to8add(pU_Cur, &data[4 * 64], stride2);                  transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
605          if (cbp & 1)          if (cbp & 1)
606                  transfer_16to8add(pV_Cur, &data[5 * 64], stride2);                  transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
607            }
608          stop_transfer_timer();          stop_transfer_timer();
609  }  }
610    
# Line 454  Line 612 
612  void  void
613  decoder_iframe(DECODER * dec,  decoder_iframe(DECODER * dec,
614                             Bitstream * bs,                             Bitstream * bs,
615                               int reduced_resolution,
616                             int quant,                             int quant,
617                             int intra_dc_threshold)                             int intra_dc_threshold)
618  {  {
619          uint32_t bound;          uint32_t bound;
620          uint32_t x, y;          uint32_t x, y;
621            int mb_width = dec->mb_width;
622            int mb_height = dec->mb_height;
623    
624            if (reduced_resolution)
625            {
626                    mb_width = (dec->width + 31) / 32;
627                    mb_height = (dec->height + 31) / 32;
628            }
629    
630          bound = 0;          bound = 0;
631    
632          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < mb_height; y++) {
633                  for (x = 0; x < dec->mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
634                          MACROBLOCK *mb;                          MACROBLOCK *mb;
635                          uint32_t mcbpc;                          uint32_t mcbpc;
636                          uint32_t cbpc;                          uint32_t cbpc;
# Line 476  Line 643 
643    
644                          if (check_resync_marker(bs, 0))                          if (check_resync_marker(bs, 0))
645                          {                          {
646                                  bound = read_video_packet_header(bs, 0, &quant);                                  bound = read_video_packet_header(bs, dec, 0,
647                                  x = bound % dec->mb_width;                                                          &quant, NULL, NULL, &intra_dc_threshold);
648                                  y = bound / dec->mb_width;                                  x = bound % mb_width;
649                                    y = bound / mb_width;
650                          }                          }
651                          mb = &dec->mbs[y * dec->mb_width + x];                          mb = &dec->mbs[y * dec->mb_width + x];
652    
# Line 513  Line 681 
681                          }                          }
682    
683                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
684                                                          intra_dc_threshold, bound);                                                          intra_dc_threshold, bound, reduced_resolution);
685    
686                  }                  }
687                  if(dec->out_frm)                  if(dec->out_frm)
688                    output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,dec->mb_width);                    output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,mb_width);
   
689          }          }
690    
691  }  }
# Line 529  Line 697 
697                                    int x,                                    int x,
698                                    int y,                                    int y,
699                                    int k,                                    int k,
700                                    VECTOR * mv,                                    VECTOR * ret_mv,
701                                    int fcode,                                    int fcode,
702                                    const int bound)                                    const int bound)
703  {  {
# Line 540  Line 708 
708          int range = (64 * scale_fac);          int range = (64 * scale_fac);
709    
710          VECTOR pmv;          VECTOR pmv;
711          int mv_x, mv_y;          VECTOR mv;
712    
713          pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k);          pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k);
714    
715          mv_x = get_mv(bs, fcode);          mv.x = get_mv(bs, fcode);
716          mv_y = get_mv(bs, fcode);          mv.y = get_mv(bs, fcode);
717    
718          DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i)", mv_x, mv_y, pmv.x, pmv.y);          DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i)", mv.x, mv.y, pmv.x, pmv.y);
719    
720          mv_x += pmv.x;          mv.x += pmv.x;
721          mv_y += pmv.y;          mv.y += pmv.y;
722    
723          if (mv_x < low) {          if (mv.x < low) {
724                  mv_x += range;                  mv.x += range;
725          } else if (mv_x > high) {          } else if (mv.x > high) {
726                  mv_x -= range;                  mv.x -= range;
727          }          }
728    
729          if (mv_y < low) {          if (mv.y < low) {
730                  mv_y += range;                  mv.y += range;
731          } else if (mv_y > high) {          } else if (mv.y > high) {
732                  mv_y -= range;                  mv.y -= range;
733            }
734    
735            ret_mv->x = mv.x;
736            ret_mv->y = mv.y;
737          }          }
738    
         mv->x = mv_x;  
         mv->y = mv_y;  
739    
740    
741    static __inline int gmc_sanitize(int value, int quarterpel, int fcode)
742    {
743            int length = 1 << (fcode+4);
744    
745            if (quarterpel) value *= 2;
746    
747            if (value < -length)
748                    return -length;
749            else if (value >= length)
750                    return length-1;
751            else return value;
752  }  }
753    
754    
755    /* for P_VOP set gmc_mv to NULL */
756  void  void
757  decoder_pframe(DECODER * dec,  decoder_pframe(DECODER * dec,
758                             Bitstream * bs,                             Bitstream * bs,
759                             int rounding,                             int rounding,
760                               int reduced_resolution,
761                             int quant,                             int quant,
762                             int fcode,                             int fcode,
763                             int intra_dc_threshold)                             int intra_dc_threshold,
764                               VECTOR * gmc_mv)
765  {  {
766    
767          uint32_t x, y;          uint32_t x, y;
768          uint32_t bound;          uint32_t bound;
769          int cp_mb, st_mb;          int cp_mb, st_mb;
770            int mb_width = dec->mb_width;
771            int mb_height = dec->mb_height;
772    
773            if (reduced_resolution)
774            {
775                    mb_width = (dec->width + 31) / 32;
776                    mb_height = (dec->height + 31) / 32;
777            }
778    
779          start_timer();          start_timer();
780          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
781                                     dec->width, dec->height, dec->interlacing);                                     dec->width, dec->height);
782          stop_edges_timer();          stop_edges_timer();
783    
784          bound = 0;          bound = 0;
785    
786          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < mb_height; y++) {
787                  cp_mb = st_mb = 0;                  cp_mb = st_mb = 0;
788                  for (x = 0; x < dec->mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
789                          MACROBLOCK *mb;                          MACROBLOCK *mb;
790    
791                          // skip stuffing                          // skip stuffing
# Line 601  Line 794 
794    
795                          if (check_resync_marker(bs, fcode - 1))                          if (check_resync_marker(bs, fcode - 1))
796                          {                          {
797                                  bound = read_video_packet_header(bs, fcode - 1, &quant);                                  bound = read_video_packet_header(bs, dec, fcode - 1,
798                                  x = bound % dec->mb_width;                                          &quant, &fcode, NULL, &intra_dc_threshold);
799                                  y = bound / dec->mb_width;                                  x = bound % mb_width;
800                                    y = bound / mb_width;
801                          }                          }
802                          mb = &dec->mbs[y * dec->mb_width + x];                          mb = &dec->mbs[y * dec->mb_width + x];
803    
# Line 618  Line 812 
812                                  uint32_t cbpy;                                  uint32_t cbpy;
813                                  uint32_t cbp;                                  uint32_t cbp;
814                                  uint32_t intra;                                  uint32_t intra;
815                                    int mcsel = 0;          // mcsel: '0'=local motion, '1'=GMC
816    
817                                  cp_mb++;                                  cp_mb++;
818                                  mcbpc = get_mcbpc_inter(bs);                                  mcbpc = get_mcbpc_inter(bs);
# Line 634  Line 829 
829                                          acpred_flag = BitstreamGetBit(bs);                                          acpred_flag = BitstreamGetBit(bs);
830                                  }                                  }
831    
832                                    if (gmc_mv && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q))
833                                    {
834                                            mcsel = BitstreamGetBit(bs);
835                                    }
836    
837                                  cbpy = get_cbpy(bs, intra);                                  cbpy = get_cbpy(bs, intra);
838                                  DPRINTF(DPRINTF_MB, "cbpy %i", cbpy);                                  DPRINTF(DPRINTF_MB, "cbpy %i", cbpy);
839    
# Line 672  Line 872 
872                                  }                                  }
873    
874                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
875                                          if (dec->interlacing && mb->field_pred) {  
876                                            if (mcsel)
877                                            {
878                                                    mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = gmc_sanitize(gmc_mv[0].x, dec->quarterpel, fcode);
879                                                    mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = gmc_sanitize(gmc_mv[0].y, dec->quarterpel, fcode);
880    
881                                            } else if (dec->interlacing && mb->field_pred) {
882                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],
883                                                                                    fcode, bound);                                                                                    fcode, bound);
884                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1],
# Line 698  Line 904 
904                                          mb->mvs[0].y = 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 =
905                                                  0;                                                  0;
906                                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,                                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
907                                                                          intra_dc_threshold, bound);                                                                          intra_dc_threshold, bound, reduced_resolution);
908                                          continue;                                          continue;
909                                  }                                  }
910    
911                                  decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant,                                  decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant,
912                                                                  rounding);                                                                  rounding, reduced_resolution);
913                          } else                          // not coded  
914                            }
915                            else if (gmc_mv)        /* not coded S_VOP macroblock */
916                          {                          {
                                 DEBUG2("P-frame MB at (X,Y)=",x,y);  
917                                  mb->mode = MODE_NOT_CODED;                                  mb->mode = MODE_NOT_CODED;
918                                    mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = gmc_sanitize(gmc_mv[0].x, dec->quarterpel, fcode);
919                                    mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = gmc_sanitize(gmc_mv[0].y, dec->quarterpel, fcode);
920                                    decoder_mbinter(dec, mb, x, y, 0, 0, bs, quant, rounding, reduced_resolution);
921                            }
922                            else    /* not coded P_VOP macroblock */
923                            {
924                                    mb->mode = MODE_NOT_CODED;
925    
926                                  mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0;                                  mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0;
927                                  mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0;                                  mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0;
   
928                                  // copy macroblock directly from ref to cur                                  // copy macroblock directly from ref to cur
929    
930                                  start_timer();                                  start_timer();
931    
932                                  transfer8x8_copy(dec->cur.y + (16 * y) * dec->edged_width +                                  if (reduced_resolution)
933                                                                   (16 * x),                                  {
934                                                                   dec->refn[0].y + (16 * y) * dec->edged_width +                                          transfer32x32_copy(dec->cur.y + (32*y)*dec->edged_width + (32*x),
935                                                                   (16 * x), dec->edged_width);                                                                           dec->refn[0].y + (32*y)*dec->edged_width + (32*x),
936                                                                             dec->edged_width);
937                                  transfer8x8_copy(dec->cur.y + (16 * y) * dec->edged_width +  
938                                                                   (16 * x + 8),                                          transfer16x16_copy(dec->cur.u + (16*y)*dec->edged_width/2 + (16*x),
939                                                                   dec->refn[0].y + (16 * y) * dec->edged_width +                                                                          dec->refn[0].u + (16*y)*dec->edged_width/2 + (16*x),
940                                                                   (16 * x + 8), dec->edged_width);                                                                          dec->edged_width/2);
941    
942                                  transfer8x8_copy(dec->cur.y + (16 * y + 8) * dec->edged_width +                                          transfer16x16_copy(dec->cur.v + (16*y)*dec->edged_width/2 + (16*x),
943                                                                   (16 * x),                                                                           dec->refn[0].v + (16*y)*dec->edged_width/2 + (16*x),
944                                                                   dec->refn[0].y + (16 * y +                                                                           dec->edged_width/2);
945                                                                                                     8) * dec->edged_width +                                  }
946                                                                   (16 * x), dec->edged_width);                                  else
947                                    {
948                                  transfer8x8_copy(dec->cur.y + (16 * y + 8) * dec->edged_width +                                          transfer16x16_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x),
949                                                                   (16 * x + 8),                                                                           dec->refn[0].y + (16*y)*dec->edged_width + (16*x),
950                                                                   dec->refn[0].y + (16 * y +                                                                           dec->edged_width);
951                                                                                                     8) * dec->edged_width +  
952                                                                   (16 * x + 8), dec->edged_width);                                          transfer8x8_copy(dec->cur.u + (8*y)*dec->edged_width/2 + (8*x),
953                                                                            dec->refn[0].u + (8*y)*dec->edged_width/2 + (8*x),
                                 transfer8x8_copy(dec->cur.u + (8 * y) * dec->edged_width / 2 +  
                                                                  (8 * x),  
                                                                  dec->refn[0].u +  
                                                                  (8 * y) * dec->edged_width / 2 + (8 * x),  
954                                                                   dec->edged_width / 2);                                                                   dec->edged_width / 2);
955    
956                                  transfer8x8_copy(dec->cur.v + (8 * y) * dec->edged_width / 2 +                                          transfer8x8_copy(dec->cur.v + (8*y)*dec->edged_width/2 + (8*x),
957                                                                   (8 * x),                                                                           dec->refn[0].v + (8*y)*dec->edged_width/2 + (8*x),
                                                                  dec->refn[0].v +  
                                                                  (8 * y) * dec->edged_width / 2 + (8 * x),  
958                                                                   dec->edged_width / 2);                                                                   dec->edged_width / 2);
959                                    }
960    
961                                  stop_transfer_timer();                                  stop_transfer_timer();
962    
963                                  if(dec->out_frm && cp_mb > 0) {                                  if(dec->out_frm && cp_mb > 0) {
964                                    output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb);                                    output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb);
965                                    cp_mb = 0;                                    cp_mb = 0;
# Line 840  Line 1051 
1051                  uv_dx = pMB->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
1052                  uv_dy = pMB->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
1053    
1054                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;                  if (dec->quarterpel)
1055                  uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;                  {
1056                            uv_dx /= 2;
1057                            uv_dy /= 2;
1058                    }
1059    
1060                    uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
1061                    uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
1062          } else {          } else {
1063                  int sum;                  int sum;
1064    
1065                    if(dec->quarterpel)
1066                            sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2);
1067                    else
1068                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;
                 uv_dx =  
                         (sum ==  
                          0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
                                                                   (ABS(sum) / 16) * 2));  
1069    
1070                    uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];
1071    
1072                    if(dec->quarterpel)
1073                            sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2);
1074                    else
1075                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
1076                  uv_dy =  
1077                          (sum ==                  uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];
                          0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
                                                                   (ABS(sum) / 16) * 2));  
1078          }          }
1079    
1080          start_timer();          start_timer();
1081            if(dec->quarterpel) {
1082                    interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->refh.y, dec->refh.y + 64,
1083                                                                        dec->refh.y + 128, 16*x_pos, 16*y_pos,
1084                                                                        pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1085            }
1086            else {
1087          interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos, 16 * y_pos,          interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos, 16 * y_pos,
1088                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1089          interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos + 8,                  interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos,
1090                                                    16 * y_pos, pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);                                                        pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
1091          interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos,                  interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos, 16*y_pos + 8,
1092                                                    16 * y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride,                                                            pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
1093                                                    0);                  interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos + 8,
1094          interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos + 8,                                                            pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);
1095                                                    16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride,          }
1096                                                    0);  
1097          interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos,
1098                                                    uv_dx, uv_dy, stride2, 0);                                                    uv_dx, uv_dy, stride2, 0);
1099          interpolate8x8_switch(dec->cur.v, dec->refn[ref].v, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->cur.v, dec->refn[ref].v, 8 * x_pos, 8 * y_pos,
# Line 876  Line 1101 
1101          stop_comp_timer();          stop_comp_timer();
1102    
1103          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
1104                    int direction = dec->alternate_vertical_scan ? 2 : 0;
1105    
1106                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       // coded
1107                  {                  {
1108                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
1109    
1110                          start_timer();                          start_timer();
1111                          get_inter_block(bs, &block[i * 64]);                          get_inter_block(bs, &block[i * 64], direction);
1112                          stop_coding_timer();                          stop_coding_timer();
1113    
1114                          start_timer();                          start_timer();
# Line 919  Line 1146 
1146          stop_transfer_timer();          stop_transfer_timer();
1147  }  }
1148    
   
1149  // add by MinChen <chenm001@163.com>  // add by MinChen <chenm001@163.com>
1150  // decode an B-frame direct &  inter macroblock  // decode an B-frame direct &  inter macroblock
1151  void  void
# Line 954  Line 1180 
1180                  uv_dx = pMB->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
1181                  uv_dy = pMB->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
1182    
                 uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;  
                 uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;  
   
1183                  b_uv_dx = pMB->b_mvs[0].x;                  b_uv_dx = pMB->b_mvs[0].x;
1184                  b_uv_dy = pMB->b_mvs[0].y;                  b_uv_dy = pMB->b_mvs[0].y;
1185    
1186                  b_uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;                  if (dec->quarterpel)
1187                  b_uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;                  {
1188                            uv_dx /= 2;
1189                            uv_dy /= 2;
1190    
1191                            b_uv_dx /= 2;
1192                            b_uv_dy /= 2;
1193                    }
1194    
1195                    uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
1196                    uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
1197    
1198                    b_uv_dx = (b_uv_dx >> 1) + roundtab_79[b_uv_dx & 0x3];
1199                    b_uv_dy = (b_uv_dy >> 1) + roundtab_79[b_uv_dy & 0x3];
1200          } else {          } else {
1201                  int sum;                  int sum;
1202    
1203                    if(dec->quarterpel)
1204                            sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2);
1205                    else
1206                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;
                 uv_dx =  
                         (sum ==  
                          0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
                                                                   (ABS(sum) / 16) * 2));  
1207    
1208                    uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];
1209    
1210                    if(dec->quarterpel)
1211                            sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2);
1212                    else
1213                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
1214                  uv_dy =  
1215                          (sum ==                  uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];
1216                           0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
1217                                                                    (ABS(sum) / 16) * 2));  
1218                    if(dec->quarterpel)
1219                  sum =                          sum = (pMB->b_mvs[0].x / 2) + (pMB->b_mvs[1].x / 2) + (pMB->b_mvs[2].x / 2) + (pMB->b_mvs[3].x / 2);
1220                          pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x +                  else
1221                          pMB->b_mvs[3].x;                          sum = pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + pMB->b_mvs[3].x;
1222                  b_uv_dx =  
1223                          (sum ==                  b_uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];
1224                           0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
1225                                                                    (ABS(sum) / 16) * 2));                  if(dec->quarterpel)
1226                            sum = (pMB->b_mvs[0].y / 2) + (pMB->b_mvs[1].y / 2) + (pMB->b_mvs[2].y / 2) + (pMB->b_mvs[3].y / 2);
1227                  sum =                  else
1228                          pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y +                          sum = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y;
1229                          pMB->b_mvs[3].y;  
1230                  b_uv_dy =                  b_uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];
                         (sum ==  
                          0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
                                                                   (ABS(sum) / 16) * 2));  
1231          }          }
1232    
1233    
1234          start_timer();          start_timer();
1235            if(dec->quarterpel) {
1236                    if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q))
1237                            interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1238                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos,
1239                                                                                pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1240                    else {
1241                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1242                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos,
1243                                                                                pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1244                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1245                                                                                dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,
1246                                                                                pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
1247                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1248                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,
1249                                                                                pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
1250                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1251                                                                                dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,
1252                                                                                pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);
1253                    }
1254            }
1255            else {
1256          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos,          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos,
1257                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1258          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, 16 * y_pos,          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, 16 * y_pos,
# Line 1005  Line 1262 
1262          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8,          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8,
1263                                                    16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride,                                                    16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride,
1264                                                    0);                                                    0);
1265            }
1266    
1267          interpolate8x8_switch(dec->cur.u, forward.u, 8 * x_pos, 8 * y_pos, uv_dx,          interpolate8x8_switch(dec->cur.u, forward.u, 8 * x_pos, 8 * y_pos, uv_dx,
1268                                                    uv_dy, stride2, 0);                                                    uv_dy, stride2, 0);
1269          interpolate8x8_switch(dec->cur.v, forward.v, 8 * x_pos, 8 * y_pos, uv_dx,          interpolate8x8_switch(dec->cur.v, forward.v, 8 * x_pos, 8 * y_pos, uv_dx,
1270                                                    uv_dy, stride2, 0);                                                    uv_dy, stride2, 0);
1271    
1272    
1273            if(dec->quarterpel) {
1274                    if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q))
1275                            interpolate16x16_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1276                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos,
1277                                                                                pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1278                    else {
1279                            interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1280                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos,
1281                                                                                pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1282                            interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1283                                                                                dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,
1284                                                                                pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0);
1285                            interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1286                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,
1287                                                                                pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0);
1288                            interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1289                                                                                dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,
1290                                                                                pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0);
1291                    }
1292            }
1293            else {
1294          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos, 16 * y_pos,          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos, 16 * y_pos,
1295                                                    pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);                                                    pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1296          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,
# Line 1022  Line 1302 
1302          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,
1303                                                    16 * y_pos + 8, pMB->b_mvs[3].x, pMB->b_mvs[3].y,                                                    16 * y_pos + 8, pMB->b_mvs[3].x, pMB->b_mvs[3].y,
1304                                                    stride, 0);                                                    stride, 0);
1305            }
1306    
1307          interpolate8x8_switch(dec->refn[2].u, backward.u, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->refn[2].u, backward.u, 8 * x_pos, 8 * y_pos,
1308                                                    b_uv_dx, b_uv_dy, stride2, 0);                                                    b_uv_dx, b_uv_dy, stride2, 0);
1309          interpolate8x8_switch(dec->refn[2].v, backward.v, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->refn[2].v, backward.v, 8 * x_pos, 8 * y_pos,
1310                                                    b_uv_dx, b_uv_dy, stride2, 0);                                                    b_uv_dx, b_uv_dy, stride2, 0);
1311    
1312          interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos, 16 * y_pos,          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1313                                           stride);                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1314          interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos + 8, 16 * y_pos,                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos,
1315                                           stride);                                                  stride, 1, 8);
1316          interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos, 16 * y_pos + 8,  
1317                                           stride);          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1318          interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos + 8,                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1319                                           16 * y_pos + 8, stride);                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8,
1320          interpolate8x8_c(dec->cur.u, dec->refn[2].u, 8 * x_pos, 8 * y_pos,                                                  stride, 1, 8);
1321                                           stride2);  
1322          interpolate8x8_c(dec->cur.v, dec->refn[2].v, 8 * x_pos, 8 * y_pos,          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1323                                           stride2);                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1324                                                    dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1325                                                    stride, 1, 8);
1326    
1327            interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1328                                                    dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1329                                                    dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1330                                                    stride, 1, 8);
1331    
1332            interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1333                                                    dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1334                                                    dec->refn[2].u + (8 * y_pos * stride2) + 8 * x_pos,
1335                                                    stride2, 1, 8);
1336    
1337            interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1338                                                    dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1339                                                    dec->refn[2].v + (8 * y_pos * stride2) + 8 * x_pos,
1340                                                    stride2, 1, 8);
1341    
1342          stop_comp_timer();          stop_comp_timer();
1343    
1344          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
1345                    int direction = dec->alternate_vertical_scan ? 2 : 0;
1346    
1347                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       // coded
1348                  {                  {
1349                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
1350    
1351                          start_timer();                          start_timer();
1352                          get_inter_block(bs, &block[i * 64]);                          get_inter_block(bs, &block[i * 64], direction);
1353                          stop_coding_timer();                          stop_coding_timer();
1354    
1355                          start_timer();                          start_timer();
# Line 1142  Line 1444 
1444    
1445          start_timer();          start_timer();
1446          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
1447                                     dec->width, dec->height, dec->interlacing);                                     dec->width, dec->height);
1448          image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height,
1449                                     dec->width, dec->height, dec->interlacing);                                     dec->width, dec->height);
1450          stop_edges_timer();          stop_edges_timer();
1451    
1452  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
# Line 1305  Line 1607 
1607    
1608  int  int
1609  decoder_decode(DECODER * dec,  decoder_decode(DECODER * dec,
1610                             XVID_DEC_FRAME * frame)                             XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats)
1611  {  {
1612    
1613          Bitstream bs;          Bitstream bs;
1614          uint32_t rounding;          uint32_t rounding;
1615            uint32_t reduced_resolution;
1616          uint32_t quant;          uint32_t quant;
1617          uint32_t fcode_forward;          uint32_t fcode_forward;
1618          uint32_t fcode_backward;          uint32_t fcode_backward;
1619          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
1620            VECTOR gmc_mv[5];
1621          uint32_t vop_type;          uint32_t vop_type;
1622            int success = 0;
1623    
1624          start_global_timer();          start_global_timer();
1625    
# Line 1322  Line 1627 
1627    
1628          BitstreamInit(&bs, frame->bitstream, frame->length);          BitstreamInit(&bs, frame->bitstream, frame->length);
1629    
1630            // XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's
1631            if(frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f)
1632            {
1633                    if (stats)
1634                            stats->notify = XVID_DEC_VOP;
1635                    frame->length = 1;
1636                    image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width,
1637                                             frame->image, frame->stride, frame->colorspace, dec->interlacing);
1638                    emms();
1639                    return XVID_ERR_OK;
1640            }
1641    
1642    start:
1643          // add by chenm001 <chenm001@163.com>          // add by chenm001 <chenm001@163.com>
1644          // for support B-frame to reference last 2 frame          // for support B-frame to reference last 2 frame
1645          dec->frames++;          dec->frames++;
1646    
1647    xxx:
1648          vop_type =          vop_type =
1649                  BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode_forward,                  BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,
1650                                                           &fcode_backward, &intra_dc_threshold);                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, gmc_mv);
1651    
1652            //DPRINTF(DPRINTF_HEADER, "vop_type=%i", vop_type);
1653    
1654            if (vop_type == -1 && success)
1655                    goto done;
1656    
1657            if (vop_type == -2 || vop_type == -3)
1658            {
1659                    if (vop_type == -3)
1660                            decoder_resize(dec);
1661    
1662                    if (stats)
1663                    {
1664                            stats->notify = XVID_DEC_VOL;
1665                            stats->data.vol.general = 0;
1666                            if (dec->interlacing)
1667                                    stats->data.vol.general |= XVID_INTERLACING;
1668                            stats->data.vol.width = dec->width;
1669                            stats->data.vol.height = dec->height;
1670                            stats->data.vol.aspect_ratio = dec->aspect_ratio;
1671                            stats->data.vol.par_width = dec->par_width;
1672                            stats->data.vol.par_height = dec->par_height;
1673                            frame->length = BitstreamPos(&bs) / 8;
1674                            return XVID_ERR_OK;
1675                    }
1676                    goto xxx;
1677            }
1678    
1679          dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0;  // init pred vector to 0          dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0;  // init pred vector to 0
1680    
1681          switch (vop_type) {          switch (vop_type) {
1682          case P_VOP:          case P_VOP:
1683                  decoder_pframe(dec, &bs, rounding, quant, fcode_forward,                  decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,
1684                                             intra_dc_threshold);                                                  fcode_forward, intra_dc_threshold, NULL);
1685  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1686                  DEBUG1("P_VOP  Time=", dec->time);                  DEBUG1("P_VOP  Time=", dec->time);
1687  #endif  #endif
1688                  break;                  break;
1689    
1690          case I_VOP:          case I_VOP:
1691                  decoder_iframe(dec, &bs, quant, intra_dc_threshold);                  decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);
1692  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1693                  DEBUG1("I_VOP  Time=", dec->time);                  DEBUG1("I_VOP  Time=", dec->time);
1694  #endif  #endif
# Line 1360  Line 1707 
1707  #endif  #endif
1708                  break;                  break;
1709    
1710            case S_VOP :
1711                    decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,
1712                                                    fcode_forward, intra_dc_threshold, gmc_mv);
1713                    break;
1714    
1715          case N_VOP:                             // vop not coded          case N_VOP:                             // vop not coded
1716                  // when low_delay==0, N_VOP's should interpolate between the past and future frames                  // when low_delay==0, N_VOP's should interpolate between the past and future frames
1717                  image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);                  image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);
1718    #ifdef BFRAMES_DEC
1719                    DEBUG1("N_VOP  Time=", dec->time);
1720    #endif
1721                  break;                  break;
1722    
1723          default:          default:
1724                    if (stats)
1725                            stats->notify = 0;
1726    
1727                    emms();
1728                  return XVID_ERR_FAIL;                  return XVID_ERR_FAIL;
1729          }          }
1730    
1731  #ifdef BFRAMES_DEC_DEBUG  
1732          if (frame->length != BitstreamPos(&bs) / 8){          if (reduced_resolution)
1733                  DEBUG2("InLen/UseLen",frame->length, BitstreamPos(&bs) / 8);          {
1734                    image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,
1735                            (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width);
1736          }          }
 #endif  
         frame->length = BitstreamPos(&bs) / 8;  
1737    
1738            BitstreamByteAlign(&bs);
1739    
1740  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1741          // test if no B_VOP          // test if no B_VOP
1742          if (dec->low_delay || dec->frames == 0) {          if (dec->low_delay || dec->frames == 0 || ((dec->packed_mode) && !(frame->length > BitstreamPos(&bs) / 8))) {
1743  #endif  #endif
1744          image_output(&dec->cur, dec->width, dec->height, dec->edged_width,          image_output(&dec->cur, dec->width, dec->height, dec->edged_width,
1745                                           frame->image, frame->stride, frame->colorspace);                                           frame->image, frame->stride, frame->colorspace, dec->interlacing);
1746    
1747  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1748          } else {          } else {
1749                  if (dec->frames >= 1) {                  if (dec->frames >= 1 && !(dec->packed_mode)) {
1750                          start_timer();                          start_timer();
1751                          if ((vop_type == I_VOP || vop_type == P_VOP)) {                          if ((vop_type == I_VOP || vop_type == P_VOP || vop_type == S_VOP)) {
1752                                  image_output(&dec->refn[0], dec->width, dec->height,                                  image_output(&dec->refn[0], dec->width, dec->height,
1753                                                           dec->edged_width, frame->image, frame->stride,                                                           dec->edged_width, frame->image, frame->stride,
1754                                                           frame->colorspace);                                                           frame->colorspace, dec->interlacing);
1755                          } else if (vop_type == B_VOP) {                          } else if (vop_type == B_VOP) {
1756                                  image_output(&dec->cur, dec->width, dec->height,                                  image_output(&dec->cur, dec->width, dec->height,
1757                                                           dec->edged_width, frame->image, frame->stride,                                                           dec->edged_width, frame->image, frame->stride,
1758                                                           frame->colorspace);                                                           frame->colorspace, dec->interlacing);
1759                          }                          }
1760                          stop_conv_timer();                          stop_conv_timer();
1761                  }                  }
1762          }          }
1763  #endif  #endif
1764    
1765          if (vop_type == I_VOP || vop_type == P_VOP) {          if (vop_type == I_VOP || vop_type == P_VOP || vop_type == S_VOP) {
1766                  image_swap(&dec->refn[0], &dec->refn[1]);                  image_swap(&dec->refn[0], &dec->refn[1]);
1767                  image_swap(&dec->cur, &dec->refn[0]);                  image_swap(&dec->cur, &dec->refn[0]);
1768    
# Line 1418  Line 1778 
1778                          mb_swap(&dec->mbs, &dec->last_mbs);                          mb_swap(&dec->mbs, &dec->last_mbs);
1779          }          }
1780    
1781    
1782            if (success == 0 && dec->packed_mode)
1783            {
1784                    success = 1;
1785            //      if (frame->length > BitstreamPos(&bs) / 8)      // multiple vops packed together
1786                    goto start;
1787            }
1788    
1789    done :
1790    
1791            frame->length = BitstreamPos(&bs) / 8;
1792    
1793            if (stats)
1794            {
1795                    stats->notify = XVID_DEC_VOP;
1796                    stats->data.vop.time_base = (int)dec->time_base;
1797                    stats->data.vop.time_increment = 0;     //XXX: todo
1798            }
1799    
1800          emms();          emms();
1801    
1802          stop_global_timer();          stop_global_timer();

Legend:
Removed from v.1.37  
changed lines
  Added in v.1.37.2.18

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