[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.49.2.15, Tue Oct 7 13:02:35 2003 UTC revision 1.49.2.18, Wed Oct 22 09:47:52 2003 UTC
# Line 59  Line 59 
59  #include "image/colorspace.h"  #include "image/colorspace.h"
60  #include "utils/mem_align.h"  #include "utils/mem_align.h"
61    
62  int  static int
63  decoder_resize(DECODER * dec)  decoder_resize(DECODER * dec)
64  {  {
65          /* free existing */          /* free existing */
# Line 232  Line 232 
232          return 0;          return 0;
233  }  }
234    
   
   
235  static const int32_t dquant_table[4] = {  static const int32_t dquant_table[4] = {
236          -1, -2, 1, 2          -1, -2, 1, 2
237  };  };
238    
   
   
   
239  /* decode an intra macroblock */  /* decode an intra macroblock */
240  void  static void
241  decoder_mbintra(DECODER * dec,  decoder_mbintra(DECODER * dec,
242                                  MACROBLOCK * pMB,                                  MACROBLOCK * pMB,
243                                  const uint32_t x_pos,                                  const uint32_t x_pos,
# Line 365  Line 360 
360          stop_transfer_timer();          stop_transfer_timer();
361  }  }
362    
363    static void
364    decoder_mb_decode(DECODER * dec,
365                                    const uint32_t cbp,
366                                    Bitstream * bs,
367                                    uint8_t * pY_Cur,
368                                    uint8_t * pU_Cur,
369                                    uint8_t * pV_Cur,
370                                    const int reduced_resolution,
371                                    const MACROBLOCK * pMB)
372    {
373            DECLARE_ALIGNED_MATRIX(block, 1, 64, int16_t, CACHE_LINE);
374            DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);
375    
376            int stride = dec->edged_width;
377            int next_block = stride * (reduced_resolution ? 16 : 8);
378            const int stride2 = stride/2;
379            int i;
380            const uint32_t iQuant = pMB->quant;
381            const int direction = dec->alternate_vertical_scan ? 2 : 0;
382            const quant_interFuncPtr dequant = dec->quant_type == 0 ? dequant_h263_inter : dequant_mpeg_inter;
383    
384            for (i = 0; i < 6; i++) {
385    
386                    if (cbp & (1 << (5 - i))) {     /* coded */
387    
388                            memset(block, 0, 64 * sizeof(int16_t)); /* clear */
389    
390                            start_timer();
391                            get_inter_block(bs, block, direction);
392                            stop_coding_timer();
393    
394                            start_timer();
395                            dequant(&data[i * 64], block, iQuant);
396                            stop_iquant_timer();
397    
398                            start_timer();
399                            idct(&data[i * 64]);
400                            stop_idct_timer();
401                    }
402            }
403    
404            if (dec->interlacing && pMB->field_dct) {
405                    next_block = stride;
406                    stride *= 2;
407            }
408    
409            start_timer();
410            if (reduced_resolution) {
411                    if (cbp & 32)
412                            add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
413                    if (cbp & 16)
414                            add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
415                    if (cbp & 8)
416                            add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
417                    if (cbp & 4)
418                            add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);
419                    if (cbp & 2)
420                            add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
421                    if (cbp & 1)
422                            add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
423            } else {
424                    if (cbp & 32)
425                            transfer_16to8add(pY_Cur, &data[0 * 64], stride);
426                    if (cbp & 16)
427                            transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
428                    if (cbp & 8)
429                            transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
430                    if (cbp & 4)
431                            transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride);
432                    if (cbp & 2)
433                            transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
434                    if (cbp & 1)
435                            transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
436            }
437            stop_transfer_timer();
438    }
439    
440  /* decode an inter macroblock */  /* decode an inter macroblock */
441  void  static void
442  decoder_mbinter(DECODER * dec,  decoder_mbinter(DECODER * dec,
443                                  const MACROBLOCK * pMB,                                  const MACROBLOCK * pMB,
444                                  const uint32_t x_pos,                                  const uint32_t x_pos,
445                                  const uint32_t y_pos,                                  const uint32_t y_pos,
                                 const uint32_t fcode,  
446                                  const uint32_t cbp,                                  const uint32_t cbp,
447                                  Bitstream * bs,                                  Bitstream * bs,
                                 const uint32_t quant,  
448                                  const uint32_t rounding,                                  const uint32_t rounding,
449                                  const int reduced_resolution)                                  const int reduced_resolution,
450                                    const int ref)
451  {  {
   
         DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);  
         DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);  
   
452          uint32_t stride = dec->edged_width;          uint32_t stride = dec->edged_width;
453          uint32_t stride2 = stride / 2;          uint32_t stride2 = stride / 2;
         uint32_t next_block = stride * (reduced_resolution ? 16 : 8);  
454          uint32_t i;          uint32_t i;
455          uint32_t iQuant = pMB->quant;  
456          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
457    
458          int uv_dx, uv_dy;          int uv_dx, uv_dy;
# Line 411  Line 474 
474                          mv[i] = pMB->mvs[i];                          mv[i] = pMB->mvs[i];
475          }          }
476    
477          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {          start_timer();
478    
479                  uv_dx = mv[0].x / (1 + dec->quarterpel);          if (pMB->mode != MODE_INTER4V) { /* INTER, INTER_Q, NOT_CODED, FORWARD, BACKWARD */
                 uv_dy = mv[0].y / (1 + dec->quarterpel);  
480    
481                    uv_dx = mv[0].x;
482                    uv_dy = mv[0].y;
483                    if (dec->quarterpel) {
484                            uv_dx /= 2;
485                            uv_dy /= 2;
486                    }
487                  uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];                  uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
488                  uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];                  uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
489    
                 start_timer();  
490                  if (reduced_resolution)                  if (reduced_resolution)
                 {  
491                          interpolate32x32_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,                          interpolate32x32_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,
492                                                                    mv[0].x, mv[0].y, stride,  rounding);                                                                    mv[0].x, mv[0].y, stride,  rounding);
493                          interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos,                  else if (dec->quarterpel)
494                                                                    uv_dx, uv_dy, stride2, rounding);                          interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->qtmp.y, dec->qtmp.y + 64,
                         interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos,  
                                                                   uv_dx, uv_dy, stride2, rounding);  
   
                 }  
                 else  
                 {  
                         if(dec->quarterpel) {  
                                 interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->qtmp.y, dec->qtmp.y + 64,  
495                                                                                          dec->qtmp.y + 128, 16*x_pos, 16*y_pos,                                                                                          dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
496                                                                                          mv[0].x, mv[0].y, stride, rounding);                                                                                          mv[0].x, mv[0].y, stride, rounding);
497                          }                  else
498                          else {                          interpolate16x16_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos, 16*y_pos,
                                 interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,  
499                                                                            mv[0].x, mv[0].y, stride, rounding);                                                                            mv[0].x, mv[0].y, stride, rounding);
                         }  
   
                         interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,  
                                                                   uv_dx, uv_dy, stride2, rounding);  
                         interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,  
                                                                   uv_dx, uv_dy, stride2, rounding);  
                 }  
                 stop_comp_timer();  
500    
501          } else {        /* MODE_INTER4V */          } else {        /* MODE_INTER4V */
                 int sum;  
502    
503                  if(dec->quarterpel)                  if(dec->quarterpel) {
504                          sum = (mv[0].x / 2) + (mv[1].x / 2) + (mv[2].x / 2) + (mv[3].x / 2);                          uv_dx = (mv[0].x / 2) + (mv[1].x / 2) + (mv[2].x / 2) + (mv[3].x / 2);
505                  else                          uv_dy = (mv[0].y / 2) + (mv[1].y / 2) + (mv[2].y / 2) + (mv[3].y / 2);
506                          sum = mv[0].x + mv[1].x + mv[2].x + mv[3].x;                  } else {
507                            uv_dx = mv[0].x + mv[1].x + mv[2].x + mv[3].x;
508                  uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];                          uv_dy = mv[0].y + mv[1].y + mv[2].y + mv[3].y;
509                    }
                 if(dec->quarterpel)  
                         sum = (mv[0].y / 2) + (mv[1].y / 2) + (mv[2].y / 2) + (mv[3].y / 2);  
                 else  
                         sum = mv[0].y + mv[1].y + mv[2].y + mv[3].y;  
510    
511                  uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];                  uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf];
512                    uv_dy = (uv_dy >> 3) + roundtab_76[uv_dy & 0xf];
513    
514                  start_timer();                  if (reduced_resolution) {
                 if (reduced_resolution)  
                 {  
515                          interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,                          interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,
516                                                                    mv[0].x, mv[0].y, stride,  rounding);                                                                    mv[0].x, mv[0].y, stride,  rounding);
517                          interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos + 16, 32*y_pos,                          interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos + 16, 32*y_pos,
# Line 482  Line 525 
525                          interpolate16x16_switch(dec->cur.v, dec->refn[0].v , 16 * x_pos, 16 * y_pos,                          interpolate16x16_switch(dec->cur.v, dec->refn[0].v , 16 * x_pos, 16 * y_pos,
526                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
527    
528                          /* set_block(pY_Cur, stride, 32, 32, 127); */                  } else if (dec->quarterpel) {
                 }  
                 else  
                 {  
                         if(dec->quarterpel) {  
529                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
530                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos,                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
531                                                                                    mv[0].x, mv[0].y, stride,  rounding);                                                                                    mv[0].x, mv[0].y, stride,  rounding);
# Line 499  Line 538 
538                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
539                                                                                    dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8,                                                                                    dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8,
540                                                                                    mv[3].x, mv[3].y, stride,  rounding);                                                                                    mv[3].x, mv[3].y, stride,  rounding);
541                          }                  } else {
                         else {  
542                                  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,
543                                                                            mv[0].x, mv[0].y, stride,  rounding);                                                                            mv[0].x, mv[0].y, stride,  rounding);
544                                  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,
# Line 510  Line 548 
548                                  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,
549                                                                            mv[3].x, mv[3].y, stride,  rounding);                                                                            mv[3].x, mv[3].y, stride,  rounding);
550                          }                          }
551            }
552    
553                          interpolate8x8_switch(dec->cur.u, dec->refn[0].u , 8 * x_pos, 8 * y_pos,          /* chroma */
554            if (reduced_resolution) {
555                    interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos,
556                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
557                          interpolate8x8_switch(dec->cur.v, dec->refn[0].v , 8 * x_pos, 8 * y_pos,                  interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos,
558                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
                 }  
                 stop_comp_timer();  
         }  
   
         for (i = 0; i < 6; i++) {  
                 int direction = dec->alternate_vertical_scan ? 2 : 0;  
   
                 if (cbp & (1 << (5 - i)))       /* coded */  
                 {  
                         memset(&block[i * 64], 0, 64 * sizeof(int16_t));        /* clear */  
   
                         start_timer();  
                         get_inter_block(bs, &block[i * 64], direction);  
                         stop_coding_timer();  
   
                         start_timer();  
                         if (dec->quant_type == 0) {  
                                 dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant);  
559                          } else {                          } else {
560                                  dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant);                  interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos,
561                          }                                                                  uv_dx, uv_dy, stride2, rounding);
562                          stop_iquant_timer();                  interpolate8x8_switch(dec->cur.v, dec->refn[ref].v, 8 * x_pos, 8 * y_pos,
563                                                                    uv_dx, uv_dy, stride2, rounding);
                         start_timer();  
                         idct(&data[i * 64]);  
                         stop_idct_timer();  
                 }  
564          }          }
565    
566          if (dec->interlacing && pMB->field_dct) {          stop_comp_timer();
                 next_block = stride;  
                 stride *= 2;  
         }  
567    
568          start_timer();          if (cbp)
569          if (reduced_resolution)                  decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur,
570          {                                                          reduced_resolution, pMB);
                 if (cbp & 32)  
                         add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);  
                 if (cbp & 16)  
                         add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);  
                 if (cbp & 8)  
                         add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);  
                 if (cbp & 4)  
                         add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);  
                 if (cbp & 2)  
                         add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);  
                 if (cbp & 1)  
                         add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);  
         }  
         else  
         {  
                 if (cbp & 32)  
                         transfer_16to8add(pY_Cur, &data[0 * 64], stride);  
                 if (cbp & 16)  
                         transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);  
                 if (cbp & 8)  
                         transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);  
                 if (cbp & 4)  
                         transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride);  
                 if (cbp & 2)  
                         transfer_16to8add(pU_Cur, &data[4 * 64], stride2);  
                 if (cbp & 1)  
                         transfer_16to8add(pV_Cur, &data[5 * 64], stride2);  
         }  
         stop_transfer_timer();  
571  }  }
572    
   
573  static void  static void
574  decoder_mbgmc(DECODER * dec,  decoder_mbgmc(DECODER * dec,
575                                  MACROBLOCK * const pMB,                                  MACROBLOCK * const pMB,
# Line 592  Line 578 
578                                  const uint32_t fcode,                                  const uint32_t fcode,
579                                  const uint32_t cbp,                                  const uint32_t cbp,
580                                  Bitstream * bs,                                  Bitstream * bs,
581                                  const uint32_t quant,                                  const uint32_t rounding)
                                 const uint32_t rounding,  
                                 const int reduced_resolution)   /* no reduced res support */  
582  {  {
   
         DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);  
         DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);  
   
583          const uint32_t stride = dec->edged_width;          const uint32_t stride = dec->edged_width;
584          const uint32_t stride2 = stride / 2;          const uint32_t stride2 = stride / 2;
585          const uint32_t next_block = stride * (reduced_resolution ? 16 : 8);  
         uint32_t i;  
         const uint32_t iQuant = pMB->quant;  
586          uint8_t *const pY_Cur=dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);          uint8_t *const pY_Cur=dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
587          uint8_t *const pU_Cur=dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);          uint8_t *const pU_Cur=dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
588          uint8_t *const pV_Cur=dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);          uint8_t *const pV_Cur=dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
589    
590            NEW_GMC_DATA * gmc_data = &dec->new_gmc_data;
591    
592          pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;          pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
593    
594          start_timer();          start_timer();
595    
596  /* this is where the calculations are done */  /* this is where the calculations are done */
597    
         {       NEW_GMC_DATA * gmc_data = &dec->new_gmc_data;  
   
598                          gmc_data->predict_16x16(gmc_data,                          gmc_data->predict_16x16(gmc_data,
599                                          dec->cur.y + y_pos*16*stride + x_pos*16, dec->refn[0].y,                                          dec->cur.y + y_pos*16*stride + x_pos*16, dec->refn[0].y,
600                                          stride, stride, x_pos, y_pos, rounding);                                          stride, stride, x_pos, y_pos, rounding);
# Line 630  Line 608 
608    
609                  pMB->amv.x = gmc_sanitize(pMB->amv.x, dec->quarterpel, fcode);                  pMB->amv.x = gmc_sanitize(pMB->amv.x, dec->quarterpel, fcode);
610                  pMB->amv.y = gmc_sanitize(pMB->amv.y, dec->quarterpel, fcode);                  pMB->amv.y = gmc_sanitize(pMB->amv.y, dec->quarterpel, fcode);
         }  
         pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;  
   
 /*  
         transfer16x16_copy(pY_Cur, dec->gmc.y + (y_pos << 4)*stride + (x_pos  << 4), stride);  
         transfer8x8_copy(pU_Cur, dec->gmc.u + (y_pos << 3)*stride2 + (x_pos  << 3), stride2);  
         transfer8x8_copy(pV_Cur, dec->gmc.v + (y_pos << 3)*stride2 + (x_pos << 3), stride2);  
 */  
611    
612            pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
613    
614          stop_transfer_timer();          stop_transfer_timer();
615    
616          if (!cbp) return;          if (cbp)
617                    decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, 0, pMB);
         for (i = 0; i < 6; i++) {  
                 int direction = dec->alternate_vertical_scan ? 2 : 0;  
   
                 if (cbp & (1 << (5 - i)))       /* coded */  
                 {  
                         memset(&block[i * 64], 0, 64 * sizeof(int16_t));        /* clear */  
   
                         start_timer();  
                         get_inter_block(bs, &block[i * 64], direction);  
                         stop_coding_timer();  
   
                         start_timer();  
                         if (dec->quant_type == 0) {  
                                 dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant);  
                         } else {  
                                 dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant);  
                         }  
                         stop_iquant_timer();  
   
                         start_timer();  
                         idct(&data[i * 64]);  
                         stop_idct_timer();  
                 }  
         }  
618    
 /* interlace + GMC is this possible ??? */  
 /*  
   if (dec->interlacing && pMB->field_dct) {  
           next_block = stride;  
           stride *= 2;  
   }  
 */  
         start_timer();  
         if (cbp & 32)  
                 transfer_16to8add(pY_Cur, &data[0 * 64], stride);  
         if (cbp & 16)  
                 transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);  
         if (cbp & 8)  
                 transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);  
         if (cbp & 4)  
                 transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride);  
         if (cbp & 2)  
                 transfer_16to8add(pU_Cur, &data[4 * 64], stride2);  
         if (cbp & 1)  
                 transfer_16to8add(pV_Cur, &data[5 * 64], stride2);  
         stop_transfer_timer();  
619  }  }
620    
621    
622  void  static void
623  decoder_iframe(DECODER * dec,  decoder_iframe(DECODER * dec,
624                             Bitstream * bs,                             Bitstream * bs,
625                             int reduced_resolution,                             int reduced_resolution,
# Line 705  Line 631 
631          uint32_t mb_width = dec->mb_width;          uint32_t mb_width = dec->mb_width;
632          uint32_t mb_height = dec->mb_height;          uint32_t mb_height = dec->mb_height;
633    
634          if (reduced_resolution)          if (reduced_resolution) {
         {  
635                  mb_width = (dec->width + 31) / 32;                  mb_width = (dec->width + 31) / 32;
636                  mb_height = (dec->height + 31) / 32;                  mb_height = (dec->height + 31) / 32;
637          }          }
# Line 775  Line 700 
700  }  }
701    
702    
703  void  static void
704  get_motion_vector(DECODER * dec,  get_motion_vector(DECODER * dec,
705                                    Bitstream * bs,                                    Bitstream * bs,
706                                    int x,                                    int x,
# Line 786  Line 711 
711                                    const int bound)                                    const int bound)
712  {  {
713    
714          int scale_fac = 1 << (fcode - 1);          const int scale_fac = 1 << (fcode - 1);
715          int high = (32 * scale_fac) - 1;          const int high = (32 * scale_fac) - 1;
716          int low = ((-32) * scale_fac);          const int low = ((-32) * scale_fac);
717          int range = (64 * scale_fac);          const int range = (64 * scale_fac);
718    
719          VECTOR pmv;          const VECTOR pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k);
720          VECTOR mv;          VECTOR mv;
721    
         pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k);  
   
722          mv.x = get_mv(bs, fcode);          mv.x = get_mv(bs, fcode);
723          mv.y = get_mv(bs, fcode);          mv.y = get_mv(bs, fcode);
724    
# Line 820  Line 743 
743          ret_mv->y = mv.y;          ret_mv->y = mv.y;
744  }  }
745    
   
   
   
   
746  /* for P_VOP set gmc_warp to NULL */  /* for P_VOP set gmc_warp to NULL */
747  void  static void
748  decoder_pframe(DECODER * dec,  decoder_pframe(DECODER * dec,
749                             Bitstream * bs,                             Bitstream * bs,
750                             int rounding,                             int rounding,
# Line 835  Line 754 
754                             int intra_dc_threshold,                             int intra_dc_threshold,
755                             const WARPPOINTS *const gmc_warp)                             const WARPPOINTS *const gmc_warp)
756  {  {
   
757          uint32_t x, y;          uint32_t x, y;
758          uint32_t bound;          uint32_t bound;
759          int cp_mb, st_mb;          int cp_mb, st_mb;
760          uint32_t mb_width = dec->mb_width;          uint32_t mb_width = dec->mb_width;
761          uint32_t mb_height = dec->mb_height;          uint32_t mb_height = dec->mb_height;
762    
763          if (reduced_resolution)          if (reduced_resolution) {
         {  
764                  mb_width = (dec->width + 31) / 32;                  mb_width = (dec->width + 31) / 32;
765                  mb_height = (dec->height + 31) / 32;                  mb_height = (dec->height + 31) / 32;
766          }          }
# Line 853  Line 770 
770                                     dec->width, dec->height);                                     dec->width, dec->height);
771          stop_edges_timer();          stop_edges_timer();
772    
773          if (gmc_warp)          if (gmc_warp) {
         {  
   
774                  /* accuracy:  0==1/2, 1=1/4, 2=1/8, 3=1/16 */                  /* accuracy:  0==1/2, 1=1/4, 2=1/8, 3=1/16 */
 /*              {  
                         fprintf(stderr,"GMC parameters acc=%d(-> 1/%d), %d pts!!!\n",  
                                 dec->sprite_warping_accuracy,(2<<dec->sprite_warping_accuracy),  
                                 dec->sprite_warping_points);  
                 }*/  
   
775                  generate_GMCparameters( dec->sprite_warping_points,                  generate_GMCparameters( dec->sprite_warping_points,
776                                  dec->sprite_warping_accuracy, gmc_warp,                                  dec->sprite_warping_accuracy, gmc_warp,
777                                  dec->width, dec->height, &dec->new_gmc_data);                                  dec->width, dec->height, &dec->new_gmc_data);
# Line 881  Line 790 
790                          while (BitstreamShowBits(bs, 10) == 1)                          while (BitstreamShowBits(bs, 10) == 1)
791                                  BitstreamSkip(bs, 10);                                  BitstreamSkip(bs, 10);
792    
793                          if (check_resync_marker(bs, fcode - 1))                          if (check_resync_marker(bs, fcode - 1)) {
                         {  
794                                  bound = read_video_packet_header(bs, dec, fcode - 1,                                  bound = read_video_packet_header(bs, dec, fcode - 1,
795                                          &quant, &fcode, NULL, &intra_dc_threshold);                                          &quant, &fcode, NULL, &intra_dc_threshold);
796                                  x = bound % mb_width;                                  x = bound % mb_width;
# Line 892  Line 800 
800    
801                          DPRINTF(XVID_DEBUG_MB, "macroblock (%i,%i) %08x\n", x, y, BitstreamShowBits(bs, 32));                          DPRINTF(XVID_DEBUG_MB, "macroblock (%i,%i) %08x\n", x, y, BitstreamShowBits(bs, 32));
802    
803                          /* if (!(dec->mb_skip[y*dec->mb_width + x]=BitstreamGetBit(bs))) */ /* not_coded */                          if (!(BitstreamGetBit(bs)))     { /* block _is_ coded */
804                          if (!(BitstreamGetBit(bs)))     /* block _is_ coded */                                  uint32_t mcbpc, cbpc, cbpy, cbp;
805                          {                                  uint32_t intra, acpred_flag = 0;
                                 uint32_t mcbpc;  
                                 uint32_t cbpc;  
                                 uint32_t acpred_flag;  
                                 uint32_t cbpy;  
                                 uint32_t cbp;  
                                 uint32_t intra;  
806                                  int mcsel = 0;          /* mcsel: '0'=local motion, '1'=GMC */                                  int mcsel = 0;          /* mcsel: '0'=local motion, '1'=GMC */
807    
808                                  cp_mb++;                                  cp_mb++;
# Line 910  Line 812 
812    
813                                  DPRINTF(XVID_DEBUG_MB, "mode %i\n", mb->mode);                                  DPRINTF(XVID_DEBUG_MB, "mode %i\n", mb->mode);
814                                  DPRINTF(XVID_DEBUG_MB, "cbpc %i\n", cbpc);                                  DPRINTF(XVID_DEBUG_MB, "cbpc %i\n", cbpc);
                                 acpred_flag = 0;  
815    
816                                  intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q);                                  intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q);
817    
818                                  if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q))                                  if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q))
819                                          mcsel = BitstreamGetBit(bs);                                          mcsel = BitstreamGetBit(bs);
820                                    else if (intra)
                                 if (intra)  
821                                          acpred_flag = BitstreamGetBit(bs);                                          acpred_flag = BitstreamGetBit(bs);
822    
823                                  cbpy = get_cbpy(bs, intra);                                  cbpy = get_cbpy(bs, intra);
# Line 958  Line 858 
858                                  }                                  }
859    
860                                  if (mcsel) {                                  if (mcsel) {
861                                          decoder_mbgmc(dec, mb, x, y, fcode, cbp, bs, quant,                                          decoder_mbgmc(dec, mb, x, y, fcode, cbp, bs, rounding);
                                                                 rounding, reduced_resolution);  
862                                          continue;                                          continue;
863    
864                                  } else if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                  } else if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
865    
866                                          if (dec->interlacing && mb->field_pred) {                                          if (dec->interlacing && mb->field_pred) {
867                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound);
868                                                                                    fcode, bound);                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1], fcode, bound);
                                                 get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1],  
                                                                                   fcode, bound);  
869                                          } else {                                          } else {
870                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound);
                                                                                   fcode, bound);  
871                                                  mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0];                                                  mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0];
872                                          }                                          }
873                                  } else if (mb->mode == MODE_INTER4V ) {                                  } else if (mb->mode == MODE_INTER4V ) {
   
874                                          get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound);                                          get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound);
875                                          get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode, bound);                                          get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode, bound);
876                                          get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode, bound);                                          get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode, bound);
877                                          get_motion_vector(dec, bs, x, y, 3, &mb->mvs[3], fcode, bound);                                          get_motion_vector(dec, bs, x, y, 3, &mb->mvs[3], fcode, bound);
878                                  } else                  /* MODE_INTRA, MODE_INTRA_Q */                                  } else {                /* MODE_INTRA, MODE_INTRA_Q */
879                                  {                                          mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0;
880                                          mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x =                                          mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =     0;
                                                 0;  
                                         mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =  
                                                 0;  
881                                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,                                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
882                                                                          intra_dc_threshold, bound, reduced_resolution);                                                                          intra_dc_threshold, bound, reduced_resolution);
883                                          continue;                                          continue;
884                                  }                                  }
885    
886                                  decoder_mbinter(dec, mb, x, y, fcode, cbp, bs, quant,                                  decoder_mbinter(dec, mb, x, y, cbp, bs,
887                                                                  rounding, reduced_resolution);                                                                  rounding, reduced_resolution, 0);
888    
889                          }                          } else if (gmc_warp) {  /* a not coded S(GMC)-VOP macroblock */
                         else if (gmc_warp)      /* a not coded S(GMC)-VOP macroblock */  
                         {  
890                                  mb->mode = MODE_NOT_CODED_GMC;                                  mb->mode = MODE_NOT_CODED_GMC;
891                                    decoder_mbgmc(dec, mb, x, y, fcode, 0x00, bs, rounding);
                                 start_timer();  
   
                                 decoder_mbgmc(dec, mb, x, y, fcode, 0x00, bs, quant,  
                                                                 rounding, reduced_resolution);  
   
                                 stop_transfer_timer();  
892    
893                                  if(dec->out_frm && cp_mb > 0) {                                  if(dec->out_frm && cp_mb > 0) {
894                                    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);
895                                    cp_mb = 0;                                    cp_mb = 0;
896                                  }                                  }
897                                  st_mb = x+1;                                  st_mb = x+1;
898                          }                          } else {        /* not coded P_VOP macroblock */
                         else    /* not coded P_VOP macroblock */  
                         {  
899                                  mb->mode = MODE_NOT_CODED;                                  mb->mode = MODE_NOT_CODED;
900    
901                                  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;
902                                  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;
                                 /* copy macroblock directly from ref to cur */  
   
                                 start_timer();  
903    
904                                  if (reduced_resolution)                                  decoder_mbinter(dec, mb, x, y, 0, bs,
905                                  {                                                                  rounding, reduced_resolution, 0);
                                         transfer32x32_copy(dec->cur.y + (32*y)*dec->edged_width + (32*x),  
                                                                          dec->refn[0].y + (32*y)*dec->edged_width + (32*x),  
                                                                          dec->edged_width);  
   
                                         transfer16x16_copy(dec->cur.u + (16*y)*dec->edged_width/2 + (16*x),  
                                                                         dec->refn[0].u + (16*y)*dec->edged_width/2 + (16*x),  
                                                                         dec->edged_width/2);  
   
                                         transfer16x16_copy(dec->cur.v + (16*y)*dec->edged_width/2 + (16*x),  
                                                                          dec->refn[0].v + (16*y)*dec->edged_width/2 + (16*x),  
                                                                          dec->edged_width/2);  
                                 }  
                                 else  
                                 {  
                                         transfer16x16_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x),  
                                                                          dec->refn[0].y + (16*y)*dec->edged_width + (16*x),  
                                                                          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),  
                                                                         dec->edged_width/2);  
   
                                         transfer8x8_copy(dec->cur.v + (8*y)*dec->edged_width/2 + (8*x),  
                                                                          dec->refn[0].v + (8*y)*dec->edged_width/2 + (8*x),  
                                                                          dec->edged_width/2);  
                                 }  
   
                                 stop_transfer_timer();  
906    
907                                  if(dec->out_frm && cp_mb > 0) {                                  if(dec->out_frm && cp_mb > 0) {
908                                    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);
# Line 1060  Line 911 
911                                  st_mb = x+1;                                  st_mb = x+1;
912                          }                          }
913                  }                  }
914    
915                  if(dec->out_frm && cp_mb > 0)                  if(dec->out_frm && cp_mb > 0)
916                    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);
917          }          }
# Line 1067  Line 919 
919    
920    
921  /* decode B-frame motion vector */  /* decode B-frame motion vector */
922  void  static void
923  get_b_motion_vector(DECODER * dec,  get_b_motion_vector(Bitstream * bs,
                                         Bitstream * bs,  
                                         int x,  
                                         int y,  
924                                          VECTOR * mv,                                          VECTOR * mv,
925                                          int fcode,                                          int fcode,
926                                          const VECTOR pmv)                                          const VECTOR pmv)
927  {  {
928          int scale_fac = 1 << (fcode - 1);          const int scale_fac = 1 << (fcode - 1);
929          int high = (32 * scale_fac) - 1;          const int high = (32 * scale_fac) - 1;
930          int low = ((-32) * scale_fac);          const int low = ((-32) * scale_fac);
931          int range = (64 * scale_fac);          const int range = (64 * scale_fac);
   
         int mv_x, mv_y;  
         int pmv_x, pmv_y;  
932    
933          pmv_x = pmv.x;          int mv_x = get_mv(bs, fcode);
934          pmv_y = pmv.y;          int mv_y = get_mv(bs, fcode);
935    
936          mv_x = get_mv(bs, fcode);          mv_x += pmv.x;
937          mv_y = get_mv(bs, fcode);          mv_y += pmv.y;
938    
939          mv_x += pmv_x;          if (mv_x < low)
         mv_y += pmv_y;  
   
         if (mv_x < low) {  
940                  mv_x += range;                  mv_x += range;
941          } else if (mv_x > high) {          else if (mv_x > high)
942                  mv_x -= range;                  mv_x -= range;
         }  
943    
944          if (mv_y < low) {          if (mv_y < low)
945                  mv_y += range;                  mv_y += range;
946          } else if (mv_y > high) {          else if (mv_y > high)
947                  mv_y -= range;                  mv_y -= range;
         }  
948    
949          mv->x = mv_x;          mv->x = mv_x;
950          mv->y = mv_y;          mv->y = mv_y;
951  }  }
952    
953    /* decode an B-frame direct & interpolate macroblock */
954  /* decode an B-frame forward & backward inter macroblock */  static void
 void  
 decoder_bf_mbinter(DECODER * dec,  
                                    const MACROBLOCK * pMB,  
                                    const uint32_t x_pos,  
                                    const uint32_t y_pos,  
                                    const uint32_t cbp,  
                                    Bitstream * bs,  
                                    const uint32_t quant,  
                                    const uint8_t ref)  
 {  
   
         DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);  
         DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);  
   
         uint32_t stride = dec->edged_width;  
         uint32_t stride2 = stride / 2;  
         uint32_t next_block = stride * 8;  
         uint32_t i;  
         uint32_t iQuant = pMB->quant;  
         uint8_t *pY_Cur, *pU_Cur, *pV_Cur;  
         int uv_dx, uv_dy;  
   
         pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);  
         pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);  
         pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);  
   
   
         if (!(pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) {  
                 uv_dx = pMB->mvs[0].x;  
                 uv_dy = pMB->mvs[0].y;  
   
                 if (dec->quarterpel)  
                 {  
                         uv_dx /= 2;  
                         uv_dy /= 2;  
                 }  
   
                 uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];  
                 uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];  
         } else {  
                 int sum;  
   
                 if(dec->quarterpel)  
                         sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2);  
                 else  
                         sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;  
   
                 uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];  
   
                 if(dec->quarterpel)  
                         sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2);  
                 else  
                         sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;  
   
                 uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];  
         }  
   
         start_timer();  
         if(dec->quarterpel) {  
                 interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->qtmp.y, dec->qtmp.y + 64,  
                                                                     dec->qtmp.y + 128, 16*x_pos, 16*y_pos,  
                                                                     pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);  
         }  
         else {  
                 interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos, 16*y_pos,  
                                                           pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);  
                 interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos,  
                                                       pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);  
                 interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos, 16*y_pos + 8,  
                                                           pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);  
                 interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos + 8,  
                                                           pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);  
         }  
   
         interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos,  
                                                   uv_dx, uv_dy, stride2, 0);  
         interpolate8x8_switch(dec->cur.v, dec->refn[ref].v, 8 * x_pos, 8 * y_pos,  
                                                   uv_dx, uv_dy, stride2, 0);  
         stop_comp_timer();  
   
         for (i = 0; i < 6; i++) {  
                 int direction = dec->alternate_vertical_scan ? 2 : 0;  
   
                 if (cbp & (1 << (5 - i)))       /* coded */  
                 {  
                         memset(&block[i * 64], 0, 64 * sizeof(int16_t));        /* clear */  
   
                         start_timer();  
                         get_inter_block(bs, &block[i * 64], direction);  
                         stop_coding_timer();  
   
                         start_timer();  
                         if (dec->quant_type == 0) {  
                                 dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant);  
                         } else {  
                                 dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant);  
                         }  
                         stop_iquant_timer();  
   
                         start_timer();  
                         idct(&data[i * 64]);  
                         stop_idct_timer();  
                 }  
         }  
   
         if (dec->interlacing && pMB->field_dct) {  
                 next_block = stride;  
                 stride *= 2;  
         }  
   
         start_timer();  
         if (cbp & 32)  
                 transfer_16to8add(pY_Cur, &data[0 * 64], stride);  
         if (cbp & 16)  
                 transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);  
         if (cbp & 8)  
                 transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);  
         if (cbp & 4)  
                 transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride);  
         if (cbp & 2)  
                 transfer_16to8add(pU_Cur, &data[4 * 64], stride2);  
         if (cbp & 1)  
                 transfer_16to8add(pV_Cur, &data[5 * 64], stride2);  
         stop_transfer_timer();  
 }  
   
 /* decode an B-frame direct &  inter macroblock */  
 void  
955  decoder_bf_interpolate_mbinter(DECODER * dec,  decoder_bf_interpolate_mbinter(DECODER * dec,
956                                                             IMAGE forward,                                                             IMAGE forward,
957                                                             IMAGE backward,                                                             IMAGE backward,
958                                                             const MACROBLOCK * pMB,                                                             const MACROBLOCK * pMB,
959                                                             const uint32_t x_pos,                                                             const uint32_t x_pos,
960                                                             const uint32_t y_pos,                                                             const uint32_t y_pos,
961                                                             Bitstream * bs)                                                                  Bitstream * bs,
962                                                                    const int direct)
963  {  {
   
         DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);  
         DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);  
   
964          uint32_t stride = dec->edged_width;          uint32_t stride = dec->edged_width;
965          uint32_t stride2 = stride / 2;          uint32_t stride2 = stride / 2;
         uint32_t next_block = stride * 8;  
         uint32_t iQuant = pMB->quant;  
966          int uv_dx, uv_dy;          int uv_dx, uv_dy;
967          int b_uv_dx, b_uv_dy;          int b_uv_dx, b_uv_dy;
         uint32_t i;  
968          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
969      const uint32_t cbp = pMB->cbp;      const uint32_t cbp = pMB->cbp;
970    
# Line 1265  Line 972 
972          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);          pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
973          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);          pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
974    
975            if (!direct) {
         if ((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) {  
976                  uv_dx = pMB->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
977                  uv_dy = pMB->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
978    
979                  b_uv_dx = pMB->b_mvs[0].x;                  b_uv_dx = pMB->b_mvs[0].x;
980                  b_uv_dy = pMB->b_mvs[0].y;                  b_uv_dy = pMB->b_mvs[0].y;
981    
982                  if (dec->quarterpel)                  if (dec->quarterpel) {
                 {  
983                          uv_dx /= 2;                          uv_dx /= 2;
984                          uv_dy /= 2;                          uv_dy /= 2;
   
985                          b_uv_dx /= 2;                          b_uv_dx /= 2;
986                          b_uv_dy /= 2;                          b_uv_dy /= 2;
987                  }                  }
# Line 1287  Line 991 
991    
992                  b_uv_dx = (b_uv_dx >> 1) + roundtab_79[b_uv_dx & 0x3];                  b_uv_dx = (b_uv_dx >> 1) + roundtab_79[b_uv_dx & 0x3];
993                  b_uv_dy = (b_uv_dy >> 1) + roundtab_79[b_uv_dy & 0x3];                  b_uv_dy = (b_uv_dy >> 1) + roundtab_79[b_uv_dy & 0x3];
         } else {  
                 int sum;  
   
                 if(dec->quarterpel)  
                         sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2);  
                 else  
                         sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;  
   
                 uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];  
994    
995                  if(dec->quarterpel)          } else {
996                          sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2);                  if(dec->quarterpel) {
997                  else                          uv_dx = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2);
998                          sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;                          uv_dy = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2);
999                            b_uv_dx = (pMB->b_mvs[0].x / 2) + (pMB->b_mvs[1].x / 2) + (pMB->b_mvs[2].x / 2) + (pMB->b_mvs[3].x / 2);
1000                  uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];                          b_uv_dy = (pMB->b_mvs[0].y / 2) + (pMB->b_mvs[1].y / 2) + (pMB->b_mvs[2].y / 2) + (pMB->b_mvs[3].y / 2);
1001                    } else {
1002                            uv_dx = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;
1003                  if(dec->quarterpel)                          uv_dy = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
1004                          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);                          b_uv_dx = pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + pMB->b_mvs[3].x;
1005                  else                          b_uv_dy = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y;
                         sum = pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + pMB->b_mvs[3].x;  
   
                 b_uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];  
   
                 if(dec->quarterpel)  
                         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);  
                 else  
                         sum = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y;  
   
                 b_uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];  
1006          }          }
1007    
1008                    uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf];
1009                    uv_dy = (uv_dy >> 3) + roundtab_76[uv_dy & 0xf];
1010                    b_uv_dx = (b_uv_dx >> 3) + roundtab_76[b_uv_dx & 0xf];
1011                    b_uv_dy = (b_uv_dy >> 3) + roundtab_76[b_uv_dy & 0xf];
1012            }
1013    
1014          start_timer();          start_timer();
1015          if(dec->quarterpel) {          if(dec->quarterpel) {
1016                  if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q))                  if(!direct) {
1017                          interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64,                          interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64,
1018                                                                              dec->qtmp.y + 128, 16*x_pos, 16*y_pos,                                                                              dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
1019                                                                              pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);                                                                              pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1020                  else {                  } else {
1021                          interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64,                          interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64,
1022                                                                              dec->qtmp.y + 128, 16*x_pos, 16*y_pos,                                                                              dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
1023                                                                              pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);                                                                              pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
# Line 1341  Line 1031 
1031                                                                              dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8,                                                                              dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8,
1032                                                                              pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);                                                                              pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);
1033                  }                  }
1034          }          } else {
         else {  
1035                  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,
1036                                                            pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);                                                            pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1037                  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 1350  Line 1039 
1039                  interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos + 8,                  interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos + 8,
1040                                                            pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);                                                            pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
1041                  interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8,                  interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8,
1042                                                            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, 0);
                                                           0);  
1043          }          }
1044    
1045          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,
# Line 1361  Line 1049 
1049    
1050    
1051          if(dec->quarterpel) {          if(dec->quarterpel) {
1052                  if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q))                  if(!direct) {
1053                          interpolate16x16_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64,                          interpolate16x16_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64,
1054                                                                              dec->qtmp.y + 128, 16*x_pos, 16*y_pos,                                                                              dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
1055                                                                              pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);                                                                              pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1056                  else {                  } else {
1057                          interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64,                          interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64,
1058                                                                              dec->qtmp.y + 128, 16*x_pos, 16*y_pos,                                                                              dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
1059                                                                              pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);                                                                              pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
# Line 1379  Line 1067 
1067                                                                              dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8,                                                                              dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8,
1068                                                                              pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0);                                                                              pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0);
1069                  }                  }
1070          }          } else {
         else {  
1071                  interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos, 16 * y_pos,                  interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos, 16 * y_pos,
1072                                                            pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);                                                            pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1073                  interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8,                  interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8,
1074                                                            16 * y_pos, pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride,                                                          16 * y_pos, pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0);
                                                           0);  
1075                  interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos,                  interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos,
1076                                                            16 * y_pos + 8, pMB->b_mvs[2].x, pMB->b_mvs[2].y,                                                          16 * y_pos + 8, pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0);
                                                           stride, 0);  
1077                  interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8,                  interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8,
1078                                                            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, stride, 0);
                                                           stride, 0);  
1079          }          }
1080    
1081          interpolate8x8_switch(dec->tmp.u, backward.u, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->tmp.u, backward.u, 8 * x_pos, 8 * y_pos,
# Line 1431  Line 1115 
1115    
1116          stop_comp_timer();          stop_comp_timer();
1117    
1118          for (i = 0; i < 6; i++) {          if (cbp)
1119                  int direction = dec->alternate_vertical_scan ? 2 : 0;                  decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, 0, pMB);
   
                 if (cbp & (1 << (5 - i)))       /* coded */  
                 {  
                         memset(&block[i * 64], 0, 64 * sizeof(int16_t));        /* clear */  
   
                         start_timer();  
                         get_inter_block(bs, &block[i * 64], direction);  
                         stop_coding_timer();  
   
                         start_timer();  
                         if (dec->quant_type == 0) {  
                                 dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant);  
                         } else {  
                                 dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant);  
                         }  
                         stop_iquant_timer();  
   
                         start_timer();  
                         idct(&data[i * 64]);  
                         stop_idct_timer();  
                 }  
         }  
   
         if (dec->interlacing && pMB->field_dct) {  
                 next_block = stride;  
                 stride *= 2;  
         }  
   
         start_timer();  
         if (cbp & 32)  
                 transfer_16to8add(pY_Cur, &data[0 * 64], stride);  
         if (cbp & 16)  
                 transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);  
         if (cbp & 8)  
                 transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);  
         if (cbp & 4)  
                 transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride);  
         if (cbp & 2)  
                 transfer_16to8add(pU_Cur, &data[4 * 64], stride2);  
         if (cbp & 1)  
                 transfer_16to8add(pV_Cur, &data[5 * 64], stride2);  
         stop_transfer_timer();  
1120  }  }
1121    
   
1122  /* for decode B-frame dbquant */  /* for decode B-frame dbquant */
1123  int32_t __inline  static __inline int32_t
1124  get_dbquant(Bitstream * bs)  get_dbquant(Bitstream * bs)
1125  {  {
1126          if (!BitstreamGetBit(bs))      /*  '0' */          if (!BitstreamGetBit(bs))      /*  '0' */
# Line 1491  Line 1132 
1132  }  }
1133    
1134  /*  /*
1135   * For decode B-frame mb_type   * decode B-frame mb_type
1136   * bit   ret_value   * bit   ret_value
1137   * 1        0   * 1        0
1138   * 01       1   * 01       1
1139   * 001      2   * 001      2
1140   * 0001     3   * 0001     3
1141   */   */
1142  int32_t __inline  static int32_t __inline
1143  get_mbtype(Bitstream * bs)  get_mbtype(Bitstream * bs)
1144  {  {
1145          int32_t mb_type;          int32_t mb_type;
1146    
1147          for (mb_type = 0; mb_type <= 3; mb_type++) {          for (mb_type = 0; mb_type <= 3; mb_type++)
1148                  if (BitstreamGetBit(bs))                  if (BitstreamGetBit(bs))
                         break;  
         }  
   
         if (mb_type <= 3)  
1149                  return (mb_type);                  return (mb_type);
1150          else  
1151                  return (-1);          return -1;
1152  }  }
1153    
1154  void  static void
1155  decoder_bframe(DECODER * dec,  decoder_bframe(DECODER * dec,
1156                             Bitstream * bs,                             Bitstream * bs,
1157                             int quant,                             int quant,
# Line 1524  Line 1161 
1161          uint32_t x, y;          uint32_t x, y;
1162          VECTOR mv;          VECTOR mv;
1163          const VECTOR zeromv = {0,0};          const VECTOR zeromv = {0,0};
1164            const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp;
1165            int i;
1166    
1167  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
1168          FILE *fp;          FILE *fp;
1169          static char first=0;          static char first=0;
1170  #define BFRAME_DEBUG    if (!first && fp){ \  #define BFRAME_DEBUG
1171                  fprintf(fp,"Y=%3d   X=%3d   MB=%2d   CBP=%02X\n",y,x,mb->mb_type,mb->cbp); \          if (!first && fp) { \
1172                    fprintf(fp,"Y=%3d   X=%3d   MB=%2d   CBP=%02X\n",y,x,mb->mode,mb->cbp); \
1173          }          }
1174  #endif  #endif
1175    
# Line 1555  Line 1196 
1196                          mv =                          mv =
1197                          mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] =                          mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] =
1198                          mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv;                          mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv;
1199                            mb->quant = quant;
1200    
1201                          /*                          /*
1202                           * skip if the co-located P_VOP macroblock is not coded                           * skip if the co-located P_VOP macroblock is not coded
# Line 1563  Line 1205 
1205                           */                           */
1206    
1207                          if (last_mb->mode == MODE_NOT_CODED) {                          if (last_mb->mode == MODE_NOT_CODED) {
                                 /* DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); */  
1208                                  mb->cbp = 0;                                  mb->cbp = 0;
1209  #ifdef BFRAMES_DEC_DEBUG                                  mb->mode = MODE_FORWARD;
1210                                  mb->mb_type = MODE_NOT_CODED;                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 1);
         BFRAME_DEBUG  
 #endif  
                                 mb->mb_type = MODE_FORWARD;  
                                 mb->quant = last_mb->quant;  
                                 /*  
                                   mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x;  
                                   mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y;  
                                 */  
   
                                 decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, mb->quant, 1);  
1211                                  continue;                                  continue;
1212                          }                          }
1213    
1214                          if (!BitstreamGetBit(bs)) {     /* modb=='0' */                          if (!BitstreamGetBit(bs)) {     /* modb=='0' */
1215                                  const uint8_t modb2 = BitstreamGetBit(bs);                                  const uint8_t modb2 = BitstreamGetBit(bs);
1216    
1217                                  mb->mb_type = get_mbtype(bs);                                  mb->mode = get_mbtype(bs);
1218    
1219                                  if (!modb2) {   /* modb=='00' */                                  if (!modb2)             /* modb=='00' */
1220                                          mb->cbp = BitstreamGetBits(bs, 6);                                          mb->cbp = BitstreamGetBits(bs, 6);
1221                                  } else {                                  else
1222                                          mb->cbp = 0;                                          mb->cbp = 0;
                                 }  
                                 if (mb->mb_type && mb->cbp) {  
                                         quant += get_dbquant(bs);  
1223    
1224                                          if (quant > 31) {                                  if (mb->mode && mb->cbp) {
1225                                            quant += get_dbquant(bs);
1226                                            if (quant > 31)
1227                                                  quant = 31;                                                  quant = 31;
1228                                          } else if (quant < 1) {                                          else if (quant < 1)
1229                                                  quant = 1;                                                  quant = 1;
1230                                          }                                          }
1231                                  }                                  mb->quant = quant;
1232    
1233                                  if (dec->interlacing) {                                  if (dec->interlacing) {
1234                                          if (mb->cbp) {                                          if (mb->cbp) {
# Line 1606  Line 1236 
1236                                                  DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct);                                                  DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct);
1237                                          }                                          }
1238    
1239                                          if (mb->mb_type) {                                          if (mb->mode) {
1240                                                  mb->field_pred = BitstreamGetBit(bs);                                                  mb->field_pred = BitstreamGetBit(bs);
1241                                                  DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred);                                                  DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred);
1242    
# Line 1620  Line 1250 
1250                                  }                                  }
1251    
1252                          } else {                          } else {
1253                                  mb->mb_type = MODE_DIRECT_NONE_MV;                                  mb->mode = MODE_DIRECT_NONE_MV;
1254                                  mb->cbp = 0;                                  mb->cbp = 0;
1255                          }                          }
1256    
1257                          mb->quant = quant;                          switch (mb->mode) {
                         mb->mode = MODE_INTER4V;  
                         /* DEBUG1("Switch bm_type=",mb->mb_type); */  
   
 #ifdef BFRAMES_DEC_DEBUG  
         BFRAME_DEBUG  
 #endif  
   
                         switch (mb->mb_type) {  
1258                          case MODE_DIRECT:                          case MODE_DIRECT:
1259                                  get_b_motion_vector(dec, bs, x, y, &mv, 1, zeromv);                                  get_b_motion_vector(bs, &mv, 1, zeromv);
1260    
1261                          case MODE_DIRECT_NONE_MV:                          case MODE_DIRECT_NONE_MV:
                                 {  
                                         const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp;  
                                         int i;  
   
1262                                          for (i = 0; i < 4; i++) {                                          for (i = 0; i < 4; i++) {
1263                                                  mb->mvs[i].x = (int32_t) ((TRB * last_mb->mvs[i].x)                                          mb->mvs[i].x = (int32_t) ((TRB * last_mb->mvs[i].x) / TRD + mv.x);
                                                                       / TRD + mv.x);  
1264                                                  mb->b_mvs[i].x = (int32_t) ((mv.x == 0)                                                  mb->b_mvs[i].x = (int32_t) ((mv.x == 0)
1265                                                                                  ? ((TRB - TRD) * last_mb->mvs[i].x)                                                                          ? ((TRB - TRD) * last_mb->mvs[i].x) / TRD
                                                                                   / TRD  
1266                                                                                  : mb->mvs[i].x - last_mb->mvs[i].x);                                                                                  : mb->mvs[i].x - last_mb->mvs[i].x);
1267                                                  mb->mvs[i].y = (int32_t) ((TRB * last_mb->mvs[i].y)                                          mb->mvs[i].y = (int32_t) ((TRB * last_mb->mvs[i].y) / TRD + mv.y);
                                                                       / TRD + mv.y);  
1268                                                  mb->b_mvs[i].y = (int32_t) ((mv.y == 0)                                                  mb->b_mvs[i].y = (int32_t) ((mv.y == 0)
1269                                                                                  ? ((TRB - TRD) * last_mb->mvs[i].y)                                                                          ? ((TRB - TRD) * last_mb->mvs[i].y) / TRD
                                                                                   / TRD  
1270                                                                              : mb->mvs[i].y - last_mb->mvs[i].y);                                                                              : mb->mvs[i].y - last_mb->mvs[i].y);
1271                                          }                                          }
1272                                          /* DEBUG("B-frame Direct!\n"); */  
                                 }  
1273                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
1274                                                                                             mb, x, y, bs);                                                                                                  mb, x, y, bs, 1);
1275                                  break;                                  break;
1276    
1277                          case MODE_INTERPOLATE:                          case MODE_INTERPOLATE:
1278                                  get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_forward,                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv);
                                                                         dec->p_fmv);  
1279                                  dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];                                  dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
1280    
1281                                  get_b_motion_vector(dec, bs, x, y, &mb->b_mvs[0],                                  get_b_motion_vector(bs, &mb->b_mvs[0], fcode_backward, dec->p_bmv);
1282                                                                          fcode_backward, dec->p_bmv);                                  dec->p_bmv = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = mb->b_mvs[0];
                                 dec->p_bmv = mb->b_mvs[1] = mb->b_mvs[2] =  
                                         mb->b_mvs[3] = mb->b_mvs[0];  
1283    
1284                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
1285                                                                                             mb, x, y, bs);                                                                                          mb, x, y, bs, 0);
                                 /* DEBUG("B-frame Bidir!\n"); */  
1286                                  break;                                  break;
1287    
1288                          case MODE_BACKWARD:                          case MODE_BACKWARD:
1289                                  get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_backward,                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_backward, dec->p_bmv);
                                                                         dec->p_bmv);  
1290                                  dec->p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];                                  dec->p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
1291    
1292                                  mb->mode = MODE_INTER;                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 0);
                                 decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0);  
                                 /* DEBUG("B-frame Backward!\n"); */  
1293                                  break;                                  break;
1294    
1295                          case MODE_FORWARD:                          case MODE_FORWARD:
1296                                  get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_forward,                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv);
                                                                         dec->p_fmv);  
1297                                  dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];                                  dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
1298    
1299                                  mb->mode = MODE_INTER;                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 1);
                                 decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1);  
                                 /* DEBUG("B-frame Forward!\n"); */  
1300                                  break;                                  break;
1301    
1302                          default:                          default:
1303                                  DPRINTF(XVID_DEBUG_ERROR,"Not support B-frame mb_type = %i\n", mb->mb_type);                                  DPRINTF(XVID_DEBUG_ERROR,"Not supported B-frame mb_type = %i\n", mb->mode);
1304                          }                          }
1305                  } /* End of for */                  } /* End of for */
1306          }          }
# Line 1711  Line 1314 
1314  #endif  #endif
1315  }  }
1316    
   
   
1317  /* perform post processing if necessary, and output the image */  /* perform post processing if necessary, and output the image */
1318  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,
1319                                          xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type)                                          xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type)
1320  {  {
   
   
1321          image_output(img, dec->width, dec->height,          image_output(img, dec->width, dec->height,
1322                                   dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride,                                   dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride,
1323                                   frame->output.csp, dec->interlacing);                                   frame->output.csp, dec->interlacing);
1324    
1325          if (stats)          if (stats) {
         {  
1326                  stats->type = coding2type(coding_type);                  stats->type = coding2type(coding_type);
1327                  stats->data.vop.time_base = (int)dec->time_base;                  stats->data.vop.time_base = (int)dec->time_base;
1328                  stats->data.vop.time_increment = 0;     /* XXX: todo */                  stats->data.vop.time_increment = 0;     /* XXX: todo */
# Line 1758  Line 1356 
1356                  dec->frames = 0;                  dec->frames = 0;
1357          dec->out_frm = (frame->output.csp == XVID_CSP_SLICE) ? &frame->output : NULL;          dec->out_frm = (frame->output.csp == XVID_CSP_SLICE) ? &frame->output : NULL;
1358    
1359          if (frame->length < 0)  /* decoder flush */          if (frame->length < 0) {        /* decoder flush */
         {  
1360          int ret;          int ret;
1361                  /* if  not decoding "low_delay/packed", and this isn't low_delay and                  /* if  not decoding "low_delay/packed", and this isn't low_delay and
1362                      we have a reference frame, then outout the reference frame */                      we have a reference frame, then outout the reference frame */
# Line 1801  Line 1398 
1398          DPRINTF(XVID_DEBUG_HEADER, "coding_type=%i,  packed=%i,  time=%lli,  time_pp=%i,  time_bp=%i\n",          DPRINTF(XVID_DEBUG_HEADER, "coding_type=%i,  packed=%i,  time=%lli,  time_pp=%i,  time_bp=%i\n",
1399                                                          coding_type,    dec->packed_mode, dec->time, dec->time_pp, dec->time_bp);                                                          coding_type,    dec->packed_mode, dec->time, dec->time_pp, dec->time_bp);
1400    
1401          if (coding_type == -1) /* nothing */          if (coding_type == -1) { /* nothing */
         {  
1402                  if (success) goto done;                  if (success) goto done;
1403          if (stats) stats->type = XVID_TYPE_NOTHING;          if (stats) stats->type = XVID_TYPE_NOTHING;
1404                  emms();                  emms();
1405          return BitstreamPos(&bs)/8;          return BitstreamPos(&bs)/8;
1406          }          }
1407    
1408          if (coding_type == -2 || coding_type == -3)   /* vol and/or resize */          if (coding_type == -2 || coding_type == -3) {   /* vol and/or resize */
1409          {  
1410                  if (coding_type == -3)                  if (coding_type == -3)
1411                          decoder_resize(dec);                          decoder_resize(dec);
1412    
1413                  if (stats)                  if (stats) {
                 {  
1414                          stats->type = XVID_TYPE_VOL;                          stats->type = XVID_TYPE_VOL;
1415                          stats->data.vol.general = 0;                          stats->data.vol.general = 0;
1416                          /*XXX: if (dec->interlacing)                          /*XXX: if (dec->interlacing)
# Line 1834  Line 1429 
1429          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 */
1430    
1431          /* packed_mode: special-N_VOP treament */          /* packed_mode: special-N_VOP treament */
1432          if (dec->packed_mode && coding_type == N_VOP)          if (dec->packed_mode && coding_type == N_VOP) {
1433          {                  if (dec->low_delay_default && dec->frames > 0) {
                 if (dec->low_delay_default && dec->frames > 0)  
                 {  
1434                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);
1435                          output = 1;                          output = 1;
1436                  }                  }
1437                  /* ignore otherwise */                  /* ignore otherwise */
1438          }          } else if (coding_type != B_VOP) {
1439          else if (coding_type != B_VOP)                  switch(coding_type) {
         {  
                 switch(coding_type)  
                 {  
1440                  case I_VOP :                  case I_VOP :
1441                          decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);                          decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);
1442                          break;                          break;
# Line 1865  Line 1455 
1455                          break;                          break;
1456                  }                  }
1457    
1458                  if (reduced_resolution)                  if (reduced_resolution) {
                 {  
1459                          image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,                          image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,
1460                                  (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width,                                  (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width,
1461                                  16, 0);                                  16, 0);
1462                  }                  }
1463    
1464                  /* note: for packed_mode, output is performed when the special-N_VOP is decoded */                  /* note: for packed_mode, output is performed when the special-N_VOP is decoded */
1465                  if (!(dec->low_delay_default && dec->packed_mode))                  if (!(dec->low_delay_default && dec->packed_mode)) {
1466                  {                          if (dec->low_delay) {
                         if (dec->low_delay)  
                         {  
1467                                  decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);                                  decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);
1468                                  output = 1;                                  output = 1;
1469                          }                          } else if (dec->frames > 0)     { /* is the reference frame valid? */
                         else if (dec->frames > 0)       /* is the reference frame valid? */  
                         {  
1470                                  /* output the reference frame */                                  /* output the reference frame */
1471                                  decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);                                  decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);
1472                                  output = 1;                                  output = 1;
# Line 1899  Line 1484 
1484    
1485          }else{  /* B_VOP */          }else{  /* B_VOP */
1486    
1487                  if (dec->low_delay)                  if (dec->low_delay) {
                 {  
1488                          DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n");                          DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n");
1489                          dec->low_delay = 1;                          dec->low_delay = 1;
1490                  }                  }
1491    
1492                  if (dec->frames < 2)                  if (dec->frames < 2) {
                 {  
1493                          /* attemping to decode a bvop without atleast 2 reference frames */                          /* attemping to decode a bvop without atleast 2 reference frames */
1494                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
1495                                                  "broken b-frame, mising ref frames");                                                  "broken b-frame, mising ref frames");
# Line 1927  Line 1510 
1510          BitstreamByteAlign(&bs);          BitstreamByteAlign(&bs);
1511    
1512          /* low_delay_default mode: repeat in packed_mode */          /* low_delay_default mode: repeat in packed_mode */
1513          if (dec->low_delay_default && dec->packed_mode && output == 0 && success == 0)          if (dec->low_delay_default && dec->packed_mode && output == 0 && success == 0) {
         {  
1514                  success = 1;                  success = 1;
1515                  goto repeat;                  goto repeat;
1516          }          }
# Line 1937  Line 1519 
1519    
1520          /* low_delay_default mode: if we've gotten here without outputting anything,          /* low_delay_default mode: if we've gotten here without outputting anything,
1521             then output the recently decoded frame, or print an error message  */             then output the recently decoded frame, or print an error message  */
1522          if (dec->low_delay_default && output == 0)          if (dec->low_delay_default && output == 0) {
1523          {                  if (dec->packed_mode && seen_something) {
                 if (dec->packed_mode && seen_something)  
                 {  
1524                          /* output the recently decoded frame */                          /* output the recently decoded frame */
1525                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);
1526                  }                  } else {
                 else  
                 {  
1527                          image_clear(&dec->cur, dec->width, dec->height, dec->edged_width, 0, 128, 128);                          image_clear(&dec->cur, dec->width, dec->height, dec->edged_width, 0, 128, 128);
1528                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
1529                                  "warning: nothing to output");                                  "warning: nothing to output");
# Line 1954  Line 1532 
1532    
1533                          decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP);                          decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP);
1534                          if (stats) stats->type = XVID_TYPE_NOTHING;                          if (stats) stats->type = XVID_TYPE_NOTHING;
   
1535                  }                  }
1536          }          }
1537    

Legend:
Removed from v.1.49.2.15  
changed lines
  Added in v.1.49.2.18

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