[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.2.6, Wed Oct 30 18:01:48 2002 UTC revision 1.37.2.20, Fri Dec 13 11:26:41 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    #include "image/font.h"
84    
85  #include "bitstream/mbcoding.h"  #include "bitstream/mbcoding.h"
86  #include "prediction/mbprediction.h"  #include "prediction/mbprediction.h"
# Line 91  Line 93 
93  #include "utils/mem_align.h"  #include "utils/mem_align.h"
94    
95  int  int
96  decoder_create(XVID_DEC_PARAM * param)  decoder_resize(DECODER * dec)
97  {  {
98          DECODER *dec;          /* free existing */
99    
100          dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
101          if (dec == NULL) {          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
102                  return XVID_ERR_MEMORY;          image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);
103          }          image_destroy(&dec->refh, dec->edged_width, dec->edged_height);
104          param->handle = dec;          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
105    
106          dec->width = param->width;          if (dec->last_mbs)
107          dec->height = param->height;                  xvid_free(dec->last_mbs);
108            if (dec->mbs)
109                    xvid_free(dec->mbs);
110    
111            /* realloc */
112    
113          dec->mb_width = (dec->width + 15) / 16;          dec->mb_width = (dec->width + 15) / 16;
114          dec->mb_height = (dec->height + 15) / 16;          dec->mb_height = (dec->height + 15) / 16;
115    
116          dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE;          dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE;
117          dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE;          dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE;
         dec->low_delay = 0;  
118    
119          if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) {          if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) {
120                  xvid_free(dec);                  xvid_free(dec);
# Line 121  Line 126 
126                  xvid_free(dec);                  xvid_free(dec);
127                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
128          }          }
129    
130          // add by chenm001 <chenm001@163.com>          // add by chenm001 <chenm001@163.com>
131          // for support B-frame to reference last 2 frame          // for support B-frame to reference last 2 frame
132          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 158  Line 164 
164                  xvid_free(dec);                  xvid_free(dec);
165                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
166          }          }
   
167          memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);          memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);
168    
169          // add by chenm001 <chenm001@163.com>          // add by chenm001 <chenm001@163.com>
# Line 179  Line 184 
184    
185          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);
186    
187            return XVID_ERR_OK;
188    }
189    
190    
191    int
192    decoder_create(XVID_DEC_PARAM * param)
193    {
194            DECODER *dec;
195    
196            dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);
197            if (dec == NULL) {
198                    return XVID_ERR_MEMORY;
199            }
200            memset(dec, 0, sizeof(DECODER));
201    
202            param->handle = dec;
203    
204            dec->width = param->width;
205            dec->height = param->height;
206    
207            image_null(&dec->cur);
208            image_null(&dec->refn[0]);
209            image_null(&dec->refn[1]);
210            image_null(&dec->refn[2]);
211            image_null(&dec->refh);
212    
213            dec->mbs = NULL;
214            dec->last_mbs = NULL;
215    
216          init_timer();          init_timer();
217    
218          // add by chenm001 <chenm001@163.com>          // add by chenm001 <chenm001@163.com>
219          // for support B-frame to save reference frame's time          // for support B-frame to save reference frame's time
220          dec->frames = -1;          dec->frames = 0;
221          dec->time = dec->time_base = dec->last_time_base = 0;          dec->time = dec->time_base = dec->last_time_base = 0;
222            dec->low_delay = 0;
223            dec->packed_mode = 0;
224    
225            dec->fixed_dimensions = (dec->width > 0 && dec->height > 0);
226    
227            if (dec->fixed_dimensions)
228                    return decoder_resize(dec);
229            else
230          return XVID_ERR_OK;          return XVID_ERR_OK;
231  }  }
232    
# Line 227  Line 268 
268                                  Bitstream * bs,                                  Bitstream * bs,
269                                  const uint32_t quant,                                  const uint32_t quant,
270                                  const uint32_t intra_dc_threshold,                                  const uint32_t intra_dc_threshold,
271                                  const unsigned int bound)                                  const unsigned int bound,
272                                    const int reduced_resolution)
273  {  {
274    
275          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
# Line 240  Line 282 
282          uint32_t iQuant = pMB->quant;          uint32_t iQuant = pMB->quant;
283          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
284    
285            if (reduced_resolution) {
286                    pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5);
287                    pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4);
288                    pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4);
289            }else{
290          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
291          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
292          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
293            }
294    
295          memset(block, 0, 6 * 64 * sizeof(int16_t));     // clear          memset(block, 0, 6 * 64 * sizeof(int16_t));     // clear
296    
# Line 303  Line 351 
351                  start_timer();                  start_timer();
352                  idct(&data[i * 64]);                  idct(&data[i * 64]);
353                  stop_idct_timer();                  stop_idct_timer();
354    
355          }          }
356    
357          if (dec->interlacing && pMB->field_dct) {          if (dec->interlacing && pMB->field_dct) {
# Line 311  Line 360 
360          }          }
361    
362          start_timer();          start_timer();
363    
364            if (reduced_resolution)
365            {
366                    next_block*=2;
367                    copy_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
368                    copy_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
369                    copy_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
370                    copy_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);
371                    copy_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
372                    copy_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
373            }else{
374          transfer_16to8copy(pY_Cur, &data[0 * 64], stride);          transfer_16to8copy(pY_Cur, &data[0 * 64], stride);
375          transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);          transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);
376          transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);          transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);
377          transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride);          transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride);
378          transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);          transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);
379          transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);          transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);
380            }
381          stop_transfer_timer();          stop_transfer_timer();
382  }  }
383    
# Line 338  Line 399 
399                                  const uint32_t cbp,                                  const uint32_t cbp,
400                                  Bitstream * bs,                                  Bitstream * bs,
401                                  const uint32_t quant,                                  const uint32_t quant,
402                                  const uint32_t rounding)                                  const uint32_t rounding,
403                                    const int reduced_resolution)
404  {  {
405    
406          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
# Line 346  Line 408 
408    
409          uint32_t stride = dec->edged_width;          uint32_t stride = dec->edged_width;
410          uint32_t stride2 = stride / 2;          uint32_t stride2 = stride / 2;
411          uint32_t next_block = stride * 8;          uint32_t next_block = stride * (reduced_resolution ? 16 : 8);
412          uint32_t i;          uint32_t i;
413          uint32_t iQuant = pMB->quant;          uint32_t iQuant = pMB->quant;
414          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
415    
416          int uv_dx, uv_dy;          int uv_dx, uv_dy;
417            VECTOR mv[4];   /* local copy of mvs */
418    
419            if (reduced_resolution) {
420                    pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5);
421                    pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4);
422                    pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4);
423                    for (i = 0; i < 4; i++) {
424                            mv[i].x = RRV_MV_SCALEUP(pMB->mvs[i].x);
425                            mv[i].y = RRV_MV_SCALEUP(pMB->mvs[i].y);
426                    }
427            }else{
428          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);          pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
429          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
430          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
431                    for (i = 0; i < 4; i++)
432                            mv[i] = pMB->mvs[i];
433            }
434    
435          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {
436                  uv_dx = pMB->mvs[0].x;                  uv_dx = mv[0].x;
437                  uv_dy = pMB->mvs[0].y;                  uv_dy = mv[0].y;
438    
439                  if (dec->quarterpel)                  if (dec->quarterpel)
440                  {                  {
441                          uv_dx = (uv_dx >> 2) + roundtab_78[uv_dx & 0x7];                          uv_dx /= 2;
442                          uv_dy = (uv_dy >> 2) + roundtab_78[uv_dy & 0x7];                          uv_dy /= 2;
443                  }                  }
444                  else {  
445                          uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];                          uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
446                          uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];                          uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
                 }  
447    
448                  start_timer();                  start_timer();
449                    if (reduced_resolution)
450                    {
451                            interpolate32x32_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,
452                                                                      mv[0].x, mv[0].y, stride,  rounding);
453                            interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos,
454                                                                      uv_dx, uv_dy, stride2, rounding);
455                            interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos,
456                                                                      uv_dx, uv_dy, stride2, rounding);
457    
458                    }
459                    else
460                    {
461                  if(dec->quarterpel) {                  if(dec->quarterpel) {
462                          interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                          interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
463                                                                              dec->refh.y + 128, 16*x_pos, 16*y_pos,                                                                              dec->refh.y + 128, 16*x_pos, 16*y_pos,
464                                                                              pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);                                                                                          mv[0].x, mv[0].y, stride,  rounding);
465                  }                  }
466                  else {                  else {
467                          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,                                  interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,
468                                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);                                                                            mv[0].x, mv[0].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);  
                         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);  
                         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);  
469                  }                  }
470    
471                  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,
472                                                            uv_dx, uv_dy, stride2, rounding);                                                            uv_dx, uv_dy, stride2, rounding);
473                  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,
474                                                            uv_dx, uv_dy, stride2, rounding);                                                            uv_dx, uv_dy, stride2, rounding);
475                    }
476                  stop_comp_timer();                  stop_comp_timer();
477    
478          } else {          } else {        /* MODE_INTER4V */
479                  int sum;                  int sum;
480    
481                  if(dec->quarterpel)                  if(dec->quarterpel)
482                          sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2);                          sum = (mv[0].x / 2) + (mv[1].x / 2) + (mv[2].x / 2) + (mv[3].x / 2);
483                  else                  else
484                          sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;                          sum = mv[0].x + mv[1].x + mv[2].x + mv[3].x;
485    
486                  uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];                  uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];
487    
488                  if(dec->quarterpel)                  if(dec->quarterpel)
489                          sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2);                          sum = (mv[0].y / 2) + (mv[1].y / 2) + (mv[2].y / 2) + (mv[3].y / 2);
490                  else                  else
491                          sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;                          sum = mv[0].y + mv[1].y + mv[2].y + mv[3].y;
492    
493                  uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];                  uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];
494    
495                  start_timer();                  start_timer();
496                    if (reduced_resolution)
497                    {
498                            interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,
499                                                                      mv[0].x, mv[0].y, stride,  rounding);
500                            interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos + 16, 32*y_pos,
501                                                                      mv[1].x, mv[1].y, stride,  rounding);
502                            interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos + 16,
503                                                                      mv[2].x, mv[2].y, stride,  rounding);
504                            interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos + 16, 32*y_pos + 16,
505                                                                      mv[3].x, mv[3].y, stride,  rounding);
506                            interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos,
507                                                                      uv_dx, uv_dy, stride2, rounding);
508                            interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos,
509                                                                      uv_dx, uv_dy, stride2, rounding);
510    
511                            // set_block(pY_Cur, stride, 32, 32, 127);
512                    }
513                    else
514                    {
515                  if(dec->quarterpel) {                  if(dec->quarterpel) {
516                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
517                                                                            dec->refh.y + 128, 16*x_pos, 16*y_pos,                                                                            dec->refh.y + 128, 16*x_pos, 16*y_pos,
518                                                                            pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);                                                                                    mv[0].x, mv[0].y, stride,  rounding);
519                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
520                                                                            dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,                                                                            dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,
521                                                                            pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);                                                                                    mv[1].x, mv[1].y, stride,  rounding);
522                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
523                                                                            dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,                                                                            dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,
524                                                                            pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);                                                                                    mv[2].x, mv[2].y, stride,  rounding);
525                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
526                                                                            dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,                                                                            dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,
527                                                                            pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);                                                                                    mv[3].x, mv[3].y, stride,  rounding);
528                  }                  }
529                  else {                  else {
530                          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,
531                                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);                                                                            mv[0].x, mv[0].y, stride,  rounding);
532                          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,
533                                                                    pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);                                                                            mv[1].x, mv[1].y, stride,  rounding);
534                          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,
535                                                                    pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);                                                                            mv[2].x, mv[2].y, stride,  rounding);
536                          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,
537                                                                    pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);                                                                            mv[3].x, mv[3].y, stride,  rounding);
538                  }                  }
539    
540                  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,
541                                                            uv_dx, uv_dy, stride2, rounding);                                                            uv_dx, uv_dy, stride2, rounding);
542                  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,
543                                                            uv_dx, uv_dy, stride2, rounding);                                                            uv_dx, uv_dy, stride2, rounding);
544                    }
545                  stop_comp_timer();                  stop_comp_timer();
546          }          }
547    
# Line 474  Line 576 
576          }          }
577    
578          start_timer();          start_timer();
579            if (reduced_resolution)
580            {
581                    if (cbp & 32)
582                            add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
583                    if (cbp & 16)
584                            add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
585                    if (cbp & 8)
586                            add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
587                    if (cbp & 4)
588                            add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);
589                    if (cbp & 2)
590                            add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
591                    if (cbp & 1)
592                            add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
593            }
594            else
595            {
596          if (cbp & 32)          if (cbp & 32)
597                  transfer_16to8add(pY_Cur, &data[0 * 64], stride);                  transfer_16to8add(pY_Cur, &data[0 * 64], stride);
598          if (cbp & 16)          if (cbp & 16)
# Line 486  Line 605 
605                  transfer_16to8add(pU_Cur, &data[4 * 64], stride2);                  transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
606          if (cbp & 1)          if (cbp & 1)
607                  transfer_16to8add(pV_Cur, &data[5 * 64], stride2);                  transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
608            }
609          stop_transfer_timer();          stop_transfer_timer();
610  }  }
611    
# Line 493  Line 613 
613  void  void
614  decoder_iframe(DECODER * dec,  decoder_iframe(DECODER * dec,
615                             Bitstream * bs,                             Bitstream * bs,
616                               int reduced_resolution,
617                             int quant,                             int quant,
618                             int intra_dc_threshold)                             int intra_dc_threshold)
619  {  {
620          uint32_t bound;          uint32_t bound;
621          uint32_t x, y;          uint32_t x, y;
622            int mb_width = dec->mb_width;
623            int mb_height = dec->mb_height;
624    
625            if (reduced_resolution)
626            {
627                    mb_width = (dec->width + 31) / 32;
628                    mb_height = (dec->height + 31) / 32;
629            }
630    
631          bound = 0;          bound = 0;
632    
633          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < mb_height; y++) {
634                  for (x = 0; x < dec->mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
635                          MACROBLOCK *mb;                          MACROBLOCK *mb;
636                          uint32_t mcbpc;                          uint32_t mcbpc;
637                          uint32_t cbpc;                          uint32_t cbpc;
# Line 515  Line 644 
644    
645                          if (check_resync_marker(bs, 0))                          if (check_resync_marker(bs, 0))
646                          {                          {
647                                  bound = read_video_packet_header(bs, 0, &quant);                                  bound = read_video_packet_header(bs, dec, 0,
648                                  x = bound % dec->mb_width;                                                          &quant, NULL, NULL, &intra_dc_threshold);
649                                  y = bound / dec->mb_width;                                  x = bound % mb_width;
650                                    y = bound / mb_width;
651                          }                          }
652                          mb = &dec->mbs[y * dec->mb_width + x];                          mb = &dec->mbs[y * dec->mb_width + x];
653    
# Line 552  Line 682 
682                          }                          }
683    
684                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
685                                                          intra_dc_threshold, bound);                                                          intra_dc_threshold, bound, reduced_resolution);
686    
687                  }                  }
688                  if(dec->out_frm)                  if(dec->out_frm)
689                    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);
   
690          }          }
691    
692  }  }
# Line 568  Line 698 
698                                    int x,                                    int x,
699                                    int y,                                    int y,
700                                    int k,                                    int k,
701                                    VECTOR * mv,                                    VECTOR * ret_mv,
702                                    int fcode,                                    int fcode,
703                                    const int bound)                                    const int bound)
704  {  {
# Line 579  Line 709 
709          int range = (64 * scale_fac);          int range = (64 * scale_fac);
710    
711          VECTOR pmv;          VECTOR pmv;
712          int mv_x, mv_y;          VECTOR mv;
713    
714          pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k);          pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k);
715    
716          mv_x = get_mv(bs, fcode);          mv.x = get_mv(bs, fcode);
717          mv_y = get_mv(bs, fcode);          mv.y = get_mv(bs, fcode);
718    
719          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);
720    
721          mv_x += pmv.x;          mv.x += pmv.x;
722          mv_y += pmv.y;          mv.y += pmv.y;
723    
724          if (mv_x < low) {          if (mv.x < low) {
725                  mv_x += range;                  mv.x += range;
726          } else if (mv_x > high) {          } else if (mv.x > high) {
727                  mv_x -= range;                  mv.x -= range;
728          }          }
729    
730          if (mv_y < low) {          if (mv.y < low) {
731                  mv_y += range;                  mv.y += range;
732          } else if (mv_y > high) {          } else if (mv.y > high) {
733                  mv_y -= range;                  mv.y -= range;
734          }          }
735    
736          mv->x = mv_x;          ret_mv->x = mv.x;
737          mv->y = mv_y;          ret_mv->y = mv.y;
738    }
739    
740    
741    
742    static __inline int gmc_sanitize(int value, int quarterpel, int fcode)
743    {
744            int length = 1 << (fcode+4);
745    
746            if (quarterpel) value *= 2;
747    
748            if (value < -length)
749                    return -length;
750            else if (value >= length)
751                    return length-1;
752            else return value;
753  }  }
754    
755    
756    /* for P_VOP set gmc_mv to NULL */
757  void  void
758  decoder_pframe(DECODER * dec,  decoder_pframe(DECODER * dec,
759                             Bitstream * bs,                             Bitstream * bs,
760                             int rounding,                             int rounding,
761                               int reduced_resolution,
762                             int quant,                             int quant,
763                             int fcode,                             int fcode,
764                             int intra_dc_threshold)                             int intra_dc_threshold,
765                               VECTOR * gmc_mv)
766  {  {
767    
768          uint32_t x, y;          uint32_t x, y;
769          uint32_t bound;          uint32_t bound;
770          int cp_mb, st_mb;          int cp_mb, st_mb;
771            int mb_width = dec->mb_width;
772            int mb_height = dec->mb_height;
773    
774            if (reduced_resolution)
775            {
776                    mb_width = (dec->width + 31) / 32;
777                    mb_height = (dec->height + 31) / 32;
778            }
779    
780          start_timer();          start_timer();
781          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
# Line 629  Line 784 
784    
785          bound = 0;          bound = 0;
786    
787          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < mb_height; y++) {
788                  cp_mb = st_mb = 0;                  cp_mb = st_mb = 0;
789                  for (x = 0; x < dec->mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
790                          MACROBLOCK *mb;                          MACROBLOCK *mb;
791    
792                          // skip stuffing                          // skip stuffing
# Line 640  Line 795 
795    
796                          if (check_resync_marker(bs, fcode - 1))                          if (check_resync_marker(bs, fcode - 1))
797                          {                          {
798                                  bound = read_video_packet_header(bs, fcode - 1, &quant);                                  bound = read_video_packet_header(bs, dec, fcode - 1,
799                                  x = bound % dec->mb_width;                                          &quant, &fcode, NULL, &intra_dc_threshold);
800                                  y = bound / dec->mb_width;                                  x = bound % mb_width;
801                                    y = bound / mb_width;
802                          }                          }
803                          mb = &dec->mbs[y * dec->mb_width + x];                          mb = &dec->mbs[y * dec->mb_width + x];
804    
# Line 657  Line 813 
813                                  uint32_t cbpy;                                  uint32_t cbpy;
814                                  uint32_t cbp;                                  uint32_t cbp;
815                                  uint32_t intra;                                  uint32_t intra;
816                                    int mcsel = 0;          // mcsel: '0'=local motion, '1'=GMC
817    
818                                  cp_mb++;                                  cp_mb++;
819                                  mcbpc = get_mcbpc_inter(bs);                                  mcbpc = get_mcbpc_inter(bs);
# Line 673  Line 830 
830                                          acpred_flag = BitstreamGetBit(bs);                                          acpred_flag = BitstreamGetBit(bs);
831                                  }                                  }
832    
833                                    if (gmc_mv && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q))
834                                    {
835                                            mcsel = BitstreamGetBit(bs);
836                                    }
837    
838                                  cbpy = get_cbpy(bs, intra);                                  cbpy = get_cbpy(bs, intra);
839                                  DPRINTF(DPRINTF_MB, "cbpy %i", cbpy);                                  DPRINTF(DPRINTF_MB, "cbpy %i", cbpy);
840    
# Line 711  Line 873 
873                                  }                                  }
874    
875                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
876                                          if (dec->interlacing && mb->field_pred) {  
877                                            if (mcsel)
878                                            {
879                                                    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);
880                                                    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);
881    
882                                            } else if (dec->interlacing && mb->field_pred) {
883                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],
884                                                                                    fcode, bound);                                                                                    fcode, bound);
885                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1],
# Line 737  Line 905 
905                                          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 =
906                                                  0;                                                  0;
907                                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,                                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
908                                                                          intra_dc_threshold, bound);                                                                          intra_dc_threshold, bound, reduced_resolution);
909                                          continue;                                          continue;
910                                  }                                  }
911    
912                                  decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant,                                  decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant,
913                                                                  rounding);                                                                  rounding, reduced_resolution);
914                          } else                          // not coded  
915                            }
916                            else if (gmc_mv)        /* not coded S_VOP macroblock */
917                          {                          {
918                                  mb->mode = MODE_NOT_CODED;                                  mb->mode = MODE_NOT_CODED;
919                                    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);
920                                    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);
921                                    decoder_mbinter(dec, mb, x, y, 0, 0, bs, quant, rounding, reduced_resolution);
922                            }
923                            else    /* not coded P_VOP macroblock */
924                            {
925                                    mb->mode = MODE_NOT_CODED;
926    
927                                  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;
928                                  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;
   
929                                  // copy macroblock directly from ref to cur                                  // copy macroblock directly from ref to cur
930    
931                                  start_timer();                                  start_timer();
932    
933                                  transfer8x8_copy(dec->cur.y + (16 * y) * dec->edged_width +                                  if (reduced_resolution)
934                                                                   (16 * x),                                  {
935                                                                   dec->refn[0].y + (16 * y) * dec->edged_width +                                          transfer32x32_copy(dec->cur.y + (32*y)*dec->edged_width + (32*x),
936                                                                   (16 * x), dec->edged_width);                                                                           dec->refn[0].y + (32*y)*dec->edged_width + (32*x),
937                                                                             dec->edged_width);
938                                  transfer8x8_copy(dec->cur.y + (16 * y) * dec->edged_width +  
939                                                                   (16 * x + 8),                                          transfer16x16_copy(dec->cur.u + (16*y)*dec->edged_width/2 + (16*x),
940                                                                   dec->refn[0].y + (16 * y) * dec->edged_width +                                                                          dec->refn[0].u + (16*y)*dec->edged_width/2 + (16*x),
                                                                  (16 * x + 8), dec->edged_width);  
   
                                 transfer8x8_copy(dec->cur.y + (16 * y + 8) * dec->edged_width +  
                                                                  (16 * x),  
                                                                  dec->refn[0].y + (16 * y +  
                                                                                                    8) * dec->edged_width +  
                                                                  (16 * x), dec->edged_width);  
   
                                 transfer8x8_copy(dec->cur.y + (16 * y + 8) * dec->edged_width +  
                                                                  (16 * x + 8),  
                                                                  dec->refn[0].y + (16 * y +  
                                                                                                    8) * dec->edged_width +  
                                                                  (16 * x + 8), dec->edged_width);  
   
                                 transfer8x8_copy(dec->cur.u + (8 * y) * dec->edged_width / 2 +  
                                                                  (8 * x),  
                                                                  dec->refn[0].u +  
                                                                  (8 * y) * dec->edged_width / 2 + (8 * x),  
941                                                                   dec->edged_width / 2);                                                                   dec->edged_width / 2);
942    
943                                  transfer8x8_copy(dec->cur.v + (8 * y) * dec->edged_width / 2 +                                          transfer16x16_copy(dec->cur.v + (16*y)*dec->edged_width/2 + (16*x),
944                                                                   (8 * x),                                                                           dec->refn[0].v + (16*y)*dec->edged_width/2 + (16*x),
                                                                  dec->refn[0].v +  
                                                                  (8 * y) * dec->edged_width / 2 + (8 * x),  
945                                                                   dec->edged_width / 2);                                                                   dec->edged_width / 2);
946                                    }
947                                    else
948                                    {
949                                            transfer16x16_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x),
950                                                                             dec->refn[0].y + (16*y)*dec->edged_width + (16*x),
951                                                                             dec->edged_width);
952    
953                                            transfer8x8_copy(dec->cur.u + (8*y)*dec->edged_width/2 + (8*x),
954                                                                            dec->refn[0].u + (8*y)*dec->edged_width/2 + (8*x),
955                                                                            dec->edged_width/2);
956    
957                                            transfer8x8_copy(dec->cur.v + (8*y)*dec->edged_width/2 + (8*x),
958                                                                             dec->refn[0].v + (8*y)*dec->edged_width/2 + (8*x),
959                                                                             dec->edged_width/2);
960                                    }
961    
962                                  stop_transfer_timer();                                  stop_transfer_timer();
963    
964                                  if(dec->out_frm && cp_mb > 0) {                                  if(dec->out_frm && cp_mb > 0) {
965                                    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);
966                                    cp_mb = 0;                                    cp_mb = 0;
# Line 878  Line 1052 
1052                  uv_dx = pMB->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
1053                  uv_dy = pMB->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
1054    
1055                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;                  if (dec->quarterpel)
1056                  uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;                  {
1057                            uv_dx /= 2;
1058                            uv_dy /= 2;
1059                    }
1060    
1061                    uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
1062                    uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
1063          } else {          } else {
1064                  int sum;                  int sum;
1065    
1066                    if(dec->quarterpel)
1067                            sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2);
1068                    else
1069                  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));  
1070    
1071                    uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];
1072    
1073                    if(dec->quarterpel)
1074                            sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2);
1075                    else
1076                  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;
1077                  uv_dy =  
1078                          (sum ==                  uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];
                          0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
                                                                   (ABS(sum) / 16) * 2));  
1079          }          }
1080    
1081          start_timer();          start_timer();
1082            if(dec->quarterpel) {
1083                    interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->refh.y, dec->refh.y + 64,
1084                                                                        dec->refh.y + 128, 16*x_pos, 16*y_pos,
1085                                                                        pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1086            }
1087            else {
1088          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,
1089                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1090          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,
1091                                                    16 * y_pos, pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);                                                        pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
1092          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,
1093                                                    16 * y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride,                                                            pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
1094                                                    0);                  interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos + 8,
1095          interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos + 8,                                                            pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);
1096                                                    16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride,          }
1097                                                    0);  
1098          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,
1099                                                    uv_dx, uv_dy, stride2, 0);                                                    uv_dx, uv_dy, stride2, 0);
1100          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 993  Line 1181 
1181                  uv_dx = pMB->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
1182                  uv_dy = pMB->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
1183    
                 uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;  
                 uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;  
   
1184                  b_uv_dx = pMB->b_mvs[0].x;                  b_uv_dx = pMB->b_mvs[0].x;
1185                  b_uv_dy = pMB->b_mvs[0].y;                  b_uv_dy = pMB->b_mvs[0].y;
1186    
1187                  b_uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;                  if (dec->quarterpel)
1188                  b_uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;                  {
1189                            uv_dx /= 2;
1190                            uv_dy /= 2;
1191    
1192                            b_uv_dx /= 2;
1193                            b_uv_dy /= 2;
1194                    }
1195    
1196                    uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
1197                    uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
1198    
1199                    b_uv_dx = (b_uv_dx >> 1) + roundtab_79[b_uv_dx & 0x3];
1200                    b_uv_dy = (b_uv_dy >> 1) + roundtab_79[b_uv_dy & 0x3];
1201          } else {          } else {
1202                  int sum;                  int sum;
1203    
1204                    if(dec->quarterpel)
1205                            sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2);
1206                    else
1207                  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));  
1208    
1209                    uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];
1210    
1211                    if(dec->quarterpel)
1212                            sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2);
1213                    else
1214                  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;
1215                  uv_dy =  
1216                          (sum ==                  uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];
1217                           0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
1218                                                                    (ABS(sum) / 16) * 2));  
1219                    if(dec->quarterpel)
1220                  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);
1221                          pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x +                  else
1222                          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;
1223                  b_uv_dx =  
1224                          (sum ==                  b_uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];
1225                           0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
1226                                                                    (ABS(sum) / 16) * 2));                  if(dec->quarterpel)
1227                            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);
1228                  sum =                  else
1229                          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;
1230                          pMB->b_mvs[3].y;  
1231                  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));  
1232          }          }
1233    
1234    
1235          start_timer();          start_timer();
1236            if(dec->quarterpel) {
1237                    if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q))
1238                            interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1239                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos,
1240                                                                                pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1241                    else {
1242                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1243                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos,
1244                                                                                pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1245                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1246                                                                                dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,
1247                                                                                pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
1248                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1249                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,
1250                                                                                pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
1251                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1252                                                                                dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,
1253                                                                                pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);
1254                    }
1255            }
1256            else {
1257          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,
1258                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1259          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 1044  Line 1263 
1263          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8,          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8,
1264                                                    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,
1265                                                    0);                                                    0);
1266            }
1267    
1268          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,
1269                                                    uv_dy, stride2, 0);                                                    uv_dy, stride2, 0);
1270          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,
1271                                                    uv_dy, stride2, 0);                                                    uv_dy, stride2, 0);
1272    
1273    
1274            if(dec->quarterpel) {
1275                    if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q))
1276                            interpolate16x16_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1277                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos,
1278                                                                                pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1279                    else {
1280                            interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1281                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos,
1282                                                                                pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1283                            interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1284                                                                                dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,
1285                                                                                pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0);
1286                            interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1287                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,
1288                                                                                pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0);
1289                            interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1290                                                                                dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,
1291                                                                                pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0);
1292                    }
1293            }
1294            else {
1295          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,
1296                                                    pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);                                                    pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1297          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 1061  Line 1303 
1303          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,
1304                                                    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,
1305                                                    stride, 0);                                                    stride, 0);
1306            }
1307    
1308          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,
1309                                                    b_uv_dx, b_uv_dy, stride2, 0);                                                    b_uv_dx, b_uv_dy, stride2, 0);
1310          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,
# Line 1069  Line 1313 
1313          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1314                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1315                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos,                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos,
1316                                                  stride, 0);                                                  stride, 1, 8);
1317    
1318          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1319                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1320                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8,                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8,
1321                                                  stride, 0);                                                  stride, 1, 8);
1322    
1323          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1324                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1325                                                  dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos,                                                  dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1326                                                  stride, 0);                                                  stride, 1, 8);
1327    
1328          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1329                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1330                                                  dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,                                                  dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1331                                                  stride, 0);                                                  stride, 1, 8);
1332    
1333          interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,          interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1334                                                  dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1335                                                  dec->refn[2].u + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->refn[2].u + (8 * y_pos * stride2) + 8 * x_pos,
1336                                                  stride2, 0);                                                  stride2, 1, 8);
1337    
1338          interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,          interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1339                                                  dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1340                                                  dec->refn[2].v + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->refn[2].v + (8 * y_pos * stride2) + 8 * x_pos,
1341                                                  stride2, 0);                                                  stride2, 1, 8);
1342    
1343          stop_comp_timer();          stop_comp_timer();
1344    
# Line 1362  Line 1606 
1606          *mb2 = temp;          *mb2 = temp;
1607  }  }
1608    
1609    
1610  int  int
1611  decoder_decode(DECODER * dec,  decoder_decode(DECODER * dec,
1612                             XVID_DEC_FRAME * frame)                             XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats)
1613  {  {
1614    
1615          Bitstream bs;          Bitstream bs;
1616          uint32_t rounding;          uint32_t rounding;
1617            uint32_t reduced_resolution;
1618          uint32_t quant;          uint32_t quant;
1619          uint32_t fcode_forward;          uint32_t fcode_forward;
1620          uint32_t fcode_backward;          uint32_t fcode_backward;
1621          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
1622            VECTOR gmc_mv[5];
1623          uint32_t vop_type;          uint32_t vop_type;
1624            int success = 0;
1625            int output = 0;
1626            int seen_something = 0;
1627    
1628          start_global_timer();          start_global_timer();
1629    
1630            dec->low_delay_default = (frame->general & XVID_DEC_LOWDELAY);
1631    
1632          dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL;          dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL;
1633    
1634          BitstreamInit(&bs, frame->bitstream, frame->length);          BitstreamInit(&bs, frame->bitstream, frame->length);
1635    
1636          if(BitstreamShowBits(&bs, 8) == 0x7f)          // XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's
1637            if(frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f)
1638            {
1639                    if (stats)
1640                            stats->notify = XVID_DEC_VOP;
1641                    frame->length = 1;
1642                    image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width,
1643                                             frame->image, frame->stride, frame->colorspace, dec->interlacing);
1644                    emms();
1645                  return XVID_ERR_OK;                  return XVID_ERR_OK;
1646            }
1647    
1648    start:
1649          // add by chenm001 <chenm001@163.com>          // add by chenm001 <chenm001@163.com>
1650          // for support B-frame to reference last 2 frame          // for support B-frame to reference last 2 frame
1651          dec->frames++;  
1652    xxx:
1653          vop_type =          vop_type =
1654                  BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode_forward,                  BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,
1655                                                           &fcode_backward, &intra_dc_threshold);                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, gmc_mv);
1656    
1657            DPRINTF(DPRINTF_HEADER, "vop_type=%i,  packed=%i,  time=%i,  time_pp=%i,  time_bp=%i",
1658                                                            vop_type,       dec->packed_mode, dec->time, dec->time_pp, dec->time_bp);
1659    
1660            if (vop_type == - 1)
1661            {
1662                    if (success) goto done;
1663                    return XVID_ERR_FAIL;
1664            }
1665    
1666            if (vop_type == -2 || vop_type == -3)
1667            {
1668                    if (vop_type == -3)
1669                            decoder_resize(dec);
1670    
1671                    if (stats)
1672                    {
1673                            stats->notify = XVID_DEC_VOL;
1674                            stats->data.vol.general = 0;
1675                            if (dec->interlacing)
1676                                    stats->data.vol.general |= XVID_INTERLACING;
1677                            stats->data.vol.width = dec->width;
1678                            stats->data.vol.height = dec->height;
1679                            stats->data.vol.aspect_ratio = dec->aspect_ratio;
1680                            stats->data.vol.par_width = dec->par_width;
1681                            stats->data.vol.par_height = dec->par_height;
1682                            frame->length = BitstreamPos(&bs) / 8;
1683                            return XVID_ERR_OK;
1684                    }
1685                    goto xxx;
1686            }
1687    
1688          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
1689    
         switch (vop_type) {  
         case P_VOP:  
                 decoder_pframe(dec, &bs, rounding, quant, fcode_forward,  
                                            intra_dc_threshold);  
 #ifdef BFRAMES_DEC  
                 DEBUG1("P_VOP  Time=", dec->time);  
 #endif  
                 break;  
1690    
1691            /* packed_mode: special-N_VOP treament */
1692            if (dec->packed_mode && vop_type == N_VOP)
1693            {
1694                    if (dec->low_delay_default)
1695                    {
1696                            image_output(&dec->refn[0], dec->width, dec->height,
1697                                                     dec->edged_width, frame->image, frame->stride,
1698                                                     frame->colorspace, dec->interlacing);
1699                            output = 1;
1700                    }
1701                    /* ignore otherwise */
1702            }
1703            else if (vop_type != B_VOP)
1704            {
1705                    switch(vop_type)
1706                    {
1707          case I_VOP:          case I_VOP:
1708                  decoder_iframe(dec, &bs, quant, intra_dc_threshold);                          decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);
 #ifdef BFRAMES_DEC  
                 DEBUG1("I_VOP  Time=", dec->time);  
 #endif  
1709                  break;                  break;
1710                    case P_VOP :
1711          case B_VOP:                          decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,
1712  #ifdef BFRAMES_DEC                                                  fcode_forward, intra_dc_threshold, NULL);
                 if (dec->time_pp > dec->time_bp) {  
                         DEBUG1("B_VOP  Time=", dec->time);  
                         decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);  
                 } else {  
                         DEBUG("broken B-frame!");  
                 }  
 #else  
                 image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);  
 #endif  
1713                  break;                  break;
1714                    case S_VOP :
1715          case N_VOP:                             // vop not coded                          decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,
1716                  // when low_delay==0, N_VOP's should interpolate between the past and future frames                                                  fcode_forward, intra_dc_threshold, gmc_mv);
1717                            break;
1718                    case N_VOP :
1719                  image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);                  image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);
 #ifdef BFRAMES_DEC  
                 DEBUG1("N_VOP  Time=", dec->time);  
 #endif  
1720                  break;                  break;
1721                    }
1722    
1723          default:                  if (reduced_resolution)
1724                  return XVID_ERR_FAIL;                  {
1725                            image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,
1726                                    (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width);
1727          }          }
1728    
1729  #ifdef BFRAMES_DEC_DEBUG                  /* note: for packed_mode, output is performed when the special-N_VOP is decoded */
1730          if (frame->length != BitstreamPos(&bs) / 8){                  if (!(dec->low_delay_default && dec->packed_mode))
1731                  DEBUG2("InLen/UseLen",frame->length, BitstreamPos(&bs) / 8);                  {
1732                            if (dec->low_delay)
1733                            {
1734                                    image_output(&dec->cur, dec->width, dec->height,
1735                                                             dec->edged_width, frame->image, frame->stride,
1736                                                             frame->colorspace, dec->interlacing);
1737                                    output = 1;
1738                            }
1739                            else if (dec->frames > 0)       /* is the reference frame valid? */
1740                            {
1741                                    image_output(&dec->refn[0], dec->width, dec->height,
1742                                                             dec->edged_width, frame->image, frame->stride,
1743                                                             frame->colorspace, dec->interlacing);
1744                                    output = 1;
1745                            }
1746          }          }
 #endif  
         frame->length = BitstreamPos(&bs) / 8;  
1747    
1748                    image_swap(&dec->refn[0], &dec->refn[1]);
1749                    image_swap(&dec->cur, &dec->refn[0]);
1750                    mb_swap(&dec->mbs, &dec->last_mbs);
1751    
1752  #ifdef BFRAMES_DEC                  dec->frames++;
1753          // test if no B_VOP                  seen_something = 1;
         if (dec->low_delay || dec->frames == 0) {  
 #endif  
         image_output(&dec->cur, dec->width, dec->height, dec->edged_width,  
                                          frame->image, frame->stride, frame->colorspace);  
1754    
1755  #ifdef BFRAMES_DEC          }else{  /* B_VOP */
1756    
1757                    if (dec->low_delay)
1758                    {
1759                            DPRINTF(DPRINTF_ERROR, "warning: bvop found in low_delay==1 stream");
1760                            dec->low_delay = 1;
1761                    }
1762    
1763                    if (dec->time_pp <= dec->time_bp) {
1764                            /* this occurs when dx50_bvop_compatibility==0 sequences are
1765                            decoded in vfw. */
1766                            image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
1767                                                    "broken b-frame, tpp=%i tbp=%i", dec->time_pp, dec->time_bp);
1768          } else {          } else {
1769                  if (dec->frames >= 1) {                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);
1770                          start_timer();                  }
1771                          if ((vop_type == I_VOP || vop_type == P_VOP)) {  
1772                    image_output(&dec->cur, dec->width, dec->height,
1773                                             dec->edged_width, frame->image, frame->stride,
1774                                             frame->colorspace, dec->interlacing);
1775                    output = 1;
1776                    dec->frames++;
1777            }
1778    
1779            emms();
1780    
1781            BitstreamByteAlign(&bs);
1782    
1783            /* low_delay_default mode: repeat in packed_mode */
1784            if (dec->low_delay_default && dec->packed_mode && output == 0 && success == 0)
1785            {
1786                    success = 1;
1787                    goto start;
1788            }
1789    
1790    done :
1791    
1792            /* low_delay_default mode: if we've gotten here without outputting anything,
1793               then output the recently decoded frame, or print an error message  */
1794            if (dec->low_delay_default && output == 0)
1795            {
1796                    if (dec->packed_mode && seen_something)
1797                    {
1798                            /* output the recently decoded frame */
1799                                  image_output(&dec->refn[0], dec->width, dec->height,                                  image_output(&dec->refn[0], dec->width, dec->height,
1800                                                           dec->edged_width, frame->image, frame->stride,                                                           dec->edged_width, frame->image, frame->stride,
1801                                                           frame->colorspace);                                                           frame->colorspace, dec->interlacing);
1802                          } else if (vop_type == B_VOP) {                  }
1803                    else
1804                    {
1805                            image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
1806                                    "warning: nothing to output");
1807                            image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,
1808                                    "bframe decoder lag");
1809    
1810                                  image_output(&dec->cur, dec->width, dec->height,                                  image_output(&dec->cur, dec->width, dec->height,
1811                                                           dec->edged_width, frame->image, frame->stride,                                                           dec->edged_width, frame->image, frame->stride,
1812                                                           frame->colorspace);                                                           frame->colorspace, dec->interlacing);
1813                          }                          }
1814                          stop_conv_timer();                  output = 1;
1815                  }                  }
         }  
 #endif  
1816    
1817          if (vop_type == I_VOP || vop_type == P_VOP) {          frame->length = BitstreamPos(&bs) / 8;
                 image_swap(&dec->refn[0], &dec->refn[1]);  
                 image_swap(&dec->cur, &dec->refn[0]);  
1818    
1819                  // swap MACROBLOCK          if (stats)
1820                  // the Divx will not set the low_delay flage some times          {
1821                  // so follow code will wrong to not swap at that time                  stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING;
1822                  // this will broken bitstream! so I'm change it,                  stats->data.vop.time_base = (int)dec->time_base;
1823                  // But that is not the best way! can anyone tell me how                  stats->data.vop.time_increment = 0;     //XXX: todo
                 // to do another way?  
                 // 18-07-2002   MinChen<chenm001@163.com>  
                 //if (!dec->low_delay && vop_type == P_VOP)  
                 if (vop_type == P_VOP)  
                         mb_swap(&dec->mbs, &dec->last_mbs);  
1824          }          }
1825    
1826          emms();          emms();

Legend:
Removed from v.1.37.2.6  
changed lines
  Added in v.1.37.2.20

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