[cvs] / xvidcore / src / decoder.c Repository:
ViewVC logotype

Diff of /xvidcore/src/decoder.c

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

revision 1.37.2.20, Fri Dec 13 11:26:41 2002 UTC revision 1.37.2.28, Sat Jan 11 20:37:46 2003 UTC
# Line 59  Line 59 
59   *   *
60   *************************************************************************/   *************************************************************************/
61    
62    #include <stdio.h>
63  #include <stdlib.h>  #include <stdlib.h>
64  #include <string.h>  #include <string.h>
65    
# Line 68  Line 69 
69    
70  #include "xvid.h"  #include "xvid.h"
71  #include "portab.h"  #include "portab.h"
72    #include "global.h"
73    
74  #include "decoder.h"  #include "decoder.h"
75  #include "bitstream/bitstream.h"  #include "bitstream/bitstream.h"
# Line 97  Line 99 
99  {  {
100          /* free existing */          /* free existing */
101    
102            image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
103          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
104          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
105          image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);          image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
106          image_destroy(&dec->refh, dec->edged_width, dec->edged_height);          image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);
107          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);  
108            image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);
109    
110          if (dec->last_mbs)          if (dec->last_mbs)
111                  xvid_free(dec->last_mbs);                  xvid_free(dec->last_mbs);
# Line 135  Line 139 
139                  xvid_free(dec);                  xvid_free(dec);
140                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
141          }          }
142          if (image_create(&dec->refn[2], dec->edged_width, dec->edged_height)) {          if (image_create(&dec->tmp, dec->edged_width, dec->edged_height)) {
143                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
144                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
145                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
# Line 143  Line 147 
147                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
148          }          }
149    
150          if (image_create(&dec->refh, dec->edged_width, dec->edged_height)) {          if (image_create(&dec->qtmp, dec->edged_width, dec->edged_height)) {
151                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
152                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
153                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
154                  image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);                  image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
155                    xvid_free(dec);
156                    return XVID_ERR_MEMORY;
157            }
158    
159            if (image_create(&dec->gmc, dec->edged_width, dec->edged_height)) {
160                    image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);
161                    image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
162                    image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
163                    image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
164                    image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
165                  xvid_free(dec);                  xvid_free(dec);
166                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
167          }          }
# Line 159  Line 173 
173                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
174                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
175                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
176                  image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);                  image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
177                  image_destroy(&dec->refh, dec->edged_width, dec->edged_height);                  image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);
178                  xvid_free(dec);                  xvid_free(dec);
179                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
180          }          }
# Line 176  Line 190 
190                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
191                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
192                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
193                  image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);                  image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
194                  image_destroy(&dec->refh, dec->edged_width, dec->edged_height);                  image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);
195                  xvid_free(dec);                  xvid_free(dec);
196                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
197          }          }
# Line 207  Line 221 
221          image_null(&dec->cur);          image_null(&dec->cur);
222          image_null(&dec->refn[0]);          image_null(&dec->refn[0]);
223          image_null(&dec->refn[1]);          image_null(&dec->refn[1]);
224          image_null(&dec->refn[2]);          image_null(&dec->tmp);
225          image_null(&dec->refh);          image_null(&dec->qtmp);
226    
227    /* image based GMC */
228            image_null(&dec->gmc);
229    
230    
231          dec->mbs = NULL;          dec->mbs = NULL;
232          dec->last_mbs = NULL;          dec->last_mbs = NULL;
# Line 236  Line 254 
254  {  {
255          xvid_free(dec->last_mbs);          xvid_free(dec->last_mbs);
256          xvid_free(dec->mbs);          xvid_free(dec->mbs);
257    
258            image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);          /* image based GMC */
259    
260          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
261          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
262          image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);          image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
263          image_destroy(&dec->refh, dec->edged_width, dec->edged_height);          image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);
264          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
265          xvid_free(dec);          xvid_free(dec);
266    
# Line 384  Line 405 
405    
406    
407    
   
 #define SIGN(X) (((X)>0)?1:-1)  
 #define ABS(X) (((X)>0)?(X):-(X))  
   
408  // decode an inter macroblock  // decode an inter macroblock
409    
410  void  void
# Line 433  Line 450 
450          }          }
451    
452          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {
                 uv_dx = mv[0].x;  
                 uv_dy = mv[0].y;  
453    
454                  if (dec->quarterpel)                  uv_dx = mv[0].x / (1 + dec->quarterpel);
455                  {                  uv_dy = mv[0].y / (1 + dec->quarterpel);
                         uv_dx /= 2;  
                         uv_dy /= 2;  
                 }  
456    
457                  uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];                  uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
458                  uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];                  uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
# Line 459  Line 471 
471                  else                  else
472                  {                  {
473                          if(dec->quarterpel) {                          if(dec->quarterpel) {
474                                  interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                                  interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->qtmp.y, dec->qtmp.y + 64,
475                                                                                          dec->refh.y + 128, 16*x_pos, 16*y_pos,                                                                                          dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
476                                                                                          mv[0].x, mv[0].y, stride,  rounding);                                                                                          mv[0].x, mv[0].y, stride,  rounding);
477                          }                          }
478                          else {                          else {
# Line 513  Line 525 
525                  else                  else
526                  {                  {
527                          if(dec->quarterpel) {                          if(dec->quarterpel) {
528                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
529                                                                                    dec->refh.y + 128, 16*x_pos, 16*y_pos,                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
530                                                                                    mv[0].x, mv[0].y, stride,  rounding);                                                                                    mv[0].x, mv[0].y, stride,  rounding);
531                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
532                                                                                    dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,                                                                                    dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos,
533                                                                                    mv[1].x, mv[1].y, stride,  rounding);                                                                                    mv[1].x, mv[1].y, stride,  rounding);
534                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
535                                                                                    dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8,
536                                                                                    mv[2].x, mv[2].y, stride,  rounding);                                                                                    mv[2].x, mv[2].y, stride,  rounding);
537                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
538                                                                                    dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,                                                                                    dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8,
539                                                                                    mv[3].x, mv[3].y, stride,  rounding);                                                                                    mv[3].x, mv[3].y, stride,  rounding);
540                          }                          }
541                          else {                          else {
# Line 610  Line 622 
622  }  }
623    
624    
625    static void
626    decoder_mbgmc(DECODER * dec,
627                                    MACROBLOCK * const pMB,
628                                    const uint32_t x_pos,
629                                    const uint32_t y_pos,
630                                    const uint32_t acpred_flag,
631                                    const uint32_t cbp,
632                                    Bitstream * bs,
633                                    const uint32_t quant,
634                                    const uint32_t rounding,
635                                    const int reduced_resolution)   /* no reduced res support */
636    {
637    
638            DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
639            DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);
640    
641            const uint32_t stride = dec->edged_width;
642            const uint32_t stride2 = stride / 2;
643            const uint32_t next_block = stride * (reduced_resolution ? 16 : 8);
644            uint32_t i;
645            const uint32_t iQuant = pMB->quant;
646            uint8_t *const pY_Cur=dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
647            uint8_t *const pU_Cur=dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
648            uint8_t *const pV_Cur=dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
649    
650            pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
651    
652            start_timer();
653            transfer16x16_copy(pY_Cur, dec->gmc.y + (y_pos << 4)*stride + (x_pos  << 4), stride);
654            transfer8x8_copy(pU_Cur, dec->gmc.u + (y_pos << 3)*stride2 + (x_pos  << 3), stride2);
655            transfer8x8_copy(pV_Cur, dec->gmc.v + (y_pos << 3)*stride2 + (x_pos << 3), stride2);
656            stop_transfer_timer();
657    
658            if (!cbp) return;
659    
660            for (i = 0; i < 6; i++) {
661                    int direction = dec->alternate_vertical_scan ? 2 : 0;
662    
663                    if (cbp & (1 << (5 - i)))       // coded
664                    {
665                            memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
666    
667                            start_timer();
668                            get_inter_block(bs, &block[i * 64], direction);
669                            stop_coding_timer();
670    
671                            start_timer();
672                            if (dec->quant_type == 0) {
673                                    dequant_inter(&data[i * 64], &block[i * 64], iQuant);
674                            } else {
675                                    dequant4_inter(&data[i * 64], &block[i * 64], iQuant);
676                            }
677                            stop_iquant_timer();
678    
679                            start_timer();
680                            idct(&data[i * 64]);
681                            stop_idct_timer();
682                    }
683            }
684    
685    /* interlace + GMC is this possible ??? */
686    /*      if (dec->interlacing && pMB->field_dct) {
687                    next_block = stride;
688                    stride *= 2;
689            }
690    */
691            start_timer();
692            if (cbp & 32)
693                    transfer_16to8add(pY_Cur, &data[0 * 64], stride);
694            if (cbp & 16)
695                    transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
696            if (cbp & 8)
697                    transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
698            if (cbp & 4)
699                    transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride);
700            if (cbp & 2)
701                    transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
702            if (cbp & 1)
703                    transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
704            stop_transfer_timer();
705    }
706    
707    
708  void  void
709  decoder_iframe(DECODER * dec,  decoder_iframe(DECODER * dec,
710                             Bitstream * bs,                             Bitstream * bs,
# Line 619  Line 714 
714  {  {
715          uint32_t bound;          uint32_t bound;
716          uint32_t x, y;          uint32_t x, y;
717          int mb_width = dec->mb_width;          uint32_t mb_width = dec->mb_width;
718          int mb_height = dec->mb_height;          uint32_t mb_height = dec->mb_height;
719    
720          if (reduced_resolution)          if (reduced_resolution)
721          {          {
# Line 678  Line 773 
773    
774                          if (dec->interlacing) {                          if (dec->interlacing) {
775                                  mb->field_dct = BitstreamGetBit(bs);                                  mb->field_dct = BitstreamGetBit(bs);
776                                  DEBUG1("deci: field_dct: ", mb->field_dct);                                  DPRINTF(DPRINTF_MB,"deci: field_dct: %i", mb->field_dct);
777                          }                          }
778    
779                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
# Line 716  Line 811 
811          mv.x = get_mv(bs, fcode);          mv.x = get_mv(bs, fcode);
812          mv.y = get_mv(bs, fcode);          mv.y = get_mv(bs, fcode);
813    
814          DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i)", mv.x, mv.y, pmv.x, pmv.y);          DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)", mv.x, mv.y, pmv.x, pmv.y, mv.x+pmv.x, mv.y+pmv.y);
815    
816          mv.x += pmv.x;          mv.x += pmv.x;
817          mv.y += pmv.y;          mv.y += pmv.y;
# Line 753  Line 848 
848  }  }
849    
850    
851  /* for P_VOP set gmc_mv to NULL */  /* for P_VOP set gmc_warp to NULL */
852  void  void
853  decoder_pframe(DECODER * dec,  decoder_pframe(DECODER * dec,
854                             Bitstream * bs,                             Bitstream * bs,
# Line 762  Line 857 
857                             int quant,                             int quant,
858                             int fcode,                             int fcode,
859                             int intra_dc_threshold,                             int intra_dc_threshold,
860                             VECTOR * gmc_mv)                             const WARPPOINTS *const gmc_warp)
861  {  {
862    
863          uint32_t x, y;          uint32_t x, y;
864          uint32_t bound;          uint32_t bound;
865          int cp_mb, st_mb;          int cp_mb, st_mb;
866          int mb_width = dec->mb_width;          uint32_t mb_width = dec->mb_width;
867          int mb_height = dec->mb_height;          uint32_t mb_height = dec->mb_height;
868    
869            static int framecount=0;
870          if (reduced_resolution)          if (reduced_resolution)
871          {          {
872                  mb_width = (dec->width + 31) / 32;                  mb_width = (dec->width + 31) / 32;
# Line 782  Line 878 
878                                     dec->width, dec->height);                                     dec->width, dec->height);
879          stop_edges_timer();          stop_edges_timer();
880    
881            if (gmc_warp)
882            {
883    
884                    // accuracy:  0==1/2, 1=1/4, 2=1/8, 3=1/16
885                    if ( (dec->sprite_warping_accuracy != 3) || (dec->sprite_warping_points != 2) )
886                    {
887                            fprintf(stderr,"Wrong GMC parameters acc=%d(-> 1/%d), %d!!!\n",
888                                    dec->sprite_warping_accuracy,(2<<dec->sprite_warping_accuracy),
889                                    dec->sprite_warping_points);
890                    }
891    
892                    generate_GMCparameters( dec->sprite_warping_points,
893                                    (2 << dec->sprite_warping_accuracy), gmc_warp,
894                                    dec->width, dec->height, &dec->gmc_data);
895    
896                    generate_GMCimage(&dec->gmc_data, &dec->refn[0],
897                                            mb_width, mb_height,
898                                            dec->edged_width, dec->edged_width/2,
899                                            fcode, dec->quarterpel, 0,
900                                            rounding, dec->mbs, &dec->gmc);
901    
902            }
903    
904          bound = 0;          bound = 0;
905    
906          for (y = 0; y < mb_height; y++) {          for (y = 0; y < mb_height; y++) {
# Line 805  Line 924 
924                          DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32));                          DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32));
925    
926                          //if (!(dec->mb_skip[y*dec->mb_width + x]=BitstreamGetBit(bs)))         // not_coded                          //if (!(dec->mb_skip[y*dec->mb_width + x]=BitstreamGetBit(bs)))         // not_coded
927                          if (!(BitstreamGetBit(bs)))     // not_coded                          if (!(BitstreamGetBit(bs)))     // block _is_ coded
928                          {                          {
929                                  uint32_t mcbpc;                                  uint32_t mcbpc;
930                                  uint32_t cbpc;                                  uint32_t cbpc;
# Line 830  Line 949 
949                                          acpred_flag = BitstreamGetBit(bs);                                          acpred_flag = BitstreamGetBit(bs);
950                                  }                                  }
951    
952                                  if (gmc_mv && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q))                                  if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q))
953                                  {                                  {
954                                          mcsel = BitstreamGetBit(bs);                                          mcsel = BitstreamGetBit(bs);
955                                  }                                  }
956    
957                                  cbpy = get_cbpy(bs, intra);                                  cbpy = get_cbpy(bs, intra);
958                                  DPRINTF(DPRINTF_MB, "cbpy %i", cbpy);                                  DPRINTF(DPRINTF_MB, "cbpy %i  mcsel %i ", cbpy,mcsel);
959    
960                                  cbp = (cbpy << 2) | cbpc;                                  cbp = (cbpy << 2) | cbpc;
961    
# Line 856  Line 975 
975                                  if (dec->interlacing) {                                  if (dec->interlacing) {
976                                          if (cbp || intra) {                                          if (cbp || intra) {
977                                                  mb->field_dct = BitstreamGetBit(bs);                                                  mb->field_dct = BitstreamGetBit(bs);
978                                                  DEBUG1("decp: field_dct: ", mb->field_dct);                                                  DPRINTF(DPRINTF_MB,"decp: field_dct: %i", mb->field_dct);
979                                          }                                          }
980    
981                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
982                                                  mb->field_pred = BitstreamGetBit(bs);                                                  mb->field_pred = BitstreamGetBit(bs);
983                                                  DEBUG1("decp: field_pred: ", mb->field_pred);                                                  DPRINTF(DPRINTF_MB, "decp: field_pred: %i", mb->field_pred);
984    
985                                                  if (mb->field_pred) {                                                  if (mb->field_pred) {
986                                                          mb->field_for_top = BitstreamGetBit(bs);                                                          mb->field_for_top = BitstreamGetBit(bs);
987                                                          DEBUG1("decp: field_for_top: ", mb->field_for_top);                                                          DPRINTF(DPRINTF_MB,"decp: field_for_top: %i", mb->field_for_top);
988                                                          mb->field_for_bot = BitstreamGetBit(bs);                                                          mb->field_for_bot = BitstreamGetBit(bs);
989                                                          DEBUG1("decp: field_for_bot: ", mb->field_for_bot);                                                          DPRINTF(DPRINTF_MB,"decp: field_for_bot: %i", mb->field_for_bot);
990                                                  }                                                  }
991                                          }                                          }
992                                  }                                  }
993    
994                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                  if (mcsel) {
995                                            decoder_mbgmc(dec, mb, x, y, 0, cbp, bs, quant,
996                                                                    rounding, reduced_resolution);
997                                            continue;
998    
999                                          if (mcsel)                                  } else if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
                                         {  
                                                 mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = gmc_sanitize(gmc_mv[0].x, dec->quarterpel, fcode);  
                                                 mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = gmc_sanitize(gmc_mv[0].y, dec->quarterpel, fcode);  
1000    
1001                                          } else if (dec->interlacing && mb->field_pred) {                                          if (dec->interlacing && mb->field_pred) {
1002                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],
1003                                                                                    fcode, bound);                                                                                    fcode, bound);
1004                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1],
# Line 887  Line 1006 
1006                                          } else {                                          } else {
1007                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],
1008                                                                                    fcode, bound);                                                                                    fcode, bound);
1009                                                  mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x =                                                  mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0];
                                                         mb->mvs[0].x;  
                                                 mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =  
                                                         mb->mvs[0].y;  
1010                                          }                                          }
1011                                  } else if (mb->mode == MODE_INTER4V ) {                                  } else if (mb->mode == MODE_INTER4V ) {
1012    
# Line 909  Line 1025 
1025                                          continue;                                          continue;
1026                                  }                                  }
1027    
1028                                  decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant,                                  decoder_mbinter(dec, mb, x, y, 0, cbp, bs, quant,
1029                                                                  rounding, reduced_resolution);                                                                  rounding, reduced_resolution);
1030    
1031                          }                          }
1032                          else if (gmc_mv)        /* not coded S_VOP macroblock */                          else if (gmc_warp)      /* a not coded S(GMC)-VOP macroblock */
1033                          {                          {
1034                                  mb->mode = MODE_NOT_CODED;                                  mb->mode = MODE_NOT_CODED_GMC;
1035                                  mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = gmc_sanitize(gmc_mv[0].x, dec->quarterpel, fcode);  
1036                                  mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = gmc_sanitize(gmc_mv[0].y, dec->quarterpel, fcode);                                  start_timer();
1037                                  decoder_mbinter(dec, mb, x, y, 0, 0, bs, quant, rounding, reduced_resolution);  
1038                                    decoder_mbgmc(dec, mb, x, y, 0, 0x00, bs, quant,
1039                                                                    rounding, reduced_resolution);
1040    
1041                                    stop_transfer_timer();
1042    
1043                                    if(dec->out_frm && cp_mb > 0) {
1044                                      output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb);
1045                                      cp_mb = 0;
1046                                    }
1047                                    st_mb = x+1;
1048                          }                          }
1049                          else    /* not coded P_VOP macroblock */                          else    /* not coded P_VOP macroblock */
1050                          {                          {
# Line 1080  Line 1206 
1206    
1207          start_timer();          start_timer();
1208          if(dec->quarterpel) {          if(dec->quarterpel) {
1209                  interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->refh.y, dec->refh.y + 64,                  interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->qtmp.y, dec->qtmp.y + 64,
1210                                                                      dec->refh.y + 128, 16*x_pos, 16*y_pos,                                                                      dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
1211                                                                      pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);                                                                      pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1212          }          }
1213          else {          else {
# Line 1235  Line 1361 
1361          start_timer();          start_timer();
1362          if(dec->quarterpel) {          if(dec->quarterpel) {
1363                  if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q))                  if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q))
1364                          interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,                          interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64,
1365                                                                              dec->refh.y + 128, 16*x_pos, 16*y_pos,                                                                              dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
1366                                                                              pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);                                                                              pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1367                  else {                  else {
1368                          interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,                          interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64,
1369                                                                              dec->refh.y + 128, 16*x_pos, 16*y_pos,                                                                              dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
1370                                                                              pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);                                                                              pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1371                          interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,                          interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64,
1372                                                                              dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,                                                                              dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos,
1373                                                                              pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);                                                                              pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
1374                          interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,                          interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64,
1375                                                                              dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,                                                                              dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8,
1376                                                                              pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);                                                                              pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
1377                          interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,                          interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64,
1378                                                                              dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,                                                                              dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8,
1379                                                                              pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);                                                                              pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);
1380                  }                  }
1381          }          }
# Line 1273  Line 1399 
1399    
1400          if(dec->quarterpel) {          if(dec->quarterpel) {
1401                  if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q))                  if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q))
1402                          interpolate16x16_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,                          interpolate16x16_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64,
1403                                                                              dec->refh.y + 128, 16*x_pos, 16*y_pos,                                                                              dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
1404                                                                              pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);                                                                              pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1405                  else {                  else {
1406                          interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,                          interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64,
1407                                                                              dec->refh.y + 128, 16*x_pos, 16*y_pos,                                                                              dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
1408                                                                              pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);                                                                              pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1409                          interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,                          interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64,
1410                                                                              dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,                                                                              dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos,
1411                                                                              pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0);                                                                              pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0);
1412                          interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,                          interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64,
1413                                                                              dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,                                                                              dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8,
1414                                                                              pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0);                                                                              pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0);
1415                          interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,                          interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64,
1416                                                                              dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,                                                                              dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8,
1417                                                                              pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0);                                                                              pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0);
1418                  }                  }
1419          }          }
1420          else {          else {
1421                  interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos, 16 * y_pos,                  interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos, 16 * y_pos,
1422                                                            pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);                                                            pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1423                  interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,                  interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8,
1424                                                            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,
1425                                                            0);                                                            0);
1426                  interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos,                  interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos,
1427                                                            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,
1428                                                            stride, 0);                                                            stride, 0);
1429                  interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,                  interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8,
1430                                                            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,
1431                                                            stride, 0);                                                            stride, 0);
1432          }          }
1433    
1434          interpolate8x8_switch(dec->refn[2].u, backward.u, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->tmp.u, backward.u, 8 * x_pos, 8 * y_pos,
1435                                                    b_uv_dx, b_uv_dy, stride2, 0);                                                    b_uv_dx, b_uv_dy, stride2, 0);
1436          interpolate8x8_switch(dec->refn[2].v, backward.v, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->tmp.v, backward.v, 8 * x_pos, 8 * y_pos,
1437                                                    b_uv_dx, b_uv_dy, stride2, 0);                                                    b_uv_dx, b_uv_dy, stride2, 0);
1438    
1439          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1440                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1441                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos,                                                  dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos,
1442                                                  stride, 1, 8);                                                  stride, 1, 8);
1443    
1444          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1445                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1446                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8,                                                  dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1447                                                  stride, 1, 8);                                                  stride, 1, 8);
1448    
1449          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1450                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1451                                                  dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos,                                                  dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1452                                                  stride, 1, 8);                                                  stride, 1, 8);
1453    
1454          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1455                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1456                                                  dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,                                                  dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1457                                                  stride, 1, 8);                                                  stride, 1, 8);
1458    
1459          interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,          interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1460                                                  dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1461                                                  dec->refn[2].u + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->tmp.u + (8 * y_pos * stride2) + 8 * x_pos,
1462                                                  stride2, 1, 8);                                                  stride2, 1, 8);
1463    
1464          interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,          interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1465                                                  dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1466                                                  dec->refn[2].v + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->tmp.v + (8 * y_pos * stride2) + 8 * x_pos,
1467                                                  stride2, 1, 8);                                                  stride2, 1, 8);
1468    
1469          stop_comp_timer();          stop_comp_timer();
# Line 1467  Line 1593 
1593                          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] =
1594                          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;
1595    
1596                          // the last P_VOP is skip macroblock ?                          // skip if the co-located P_VOP macroblock is not coded
1597                            // if not codec in co-located S_VOP macroblock is _not_ automatically skipped
1598    
1599                          if (last_mb->mode == MODE_NOT_CODED) {                          if (last_mb->mode == MODE_NOT_CODED) {
1600                                  //DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y);                                  //DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y);
1601                                  mb->cbp = 0;                                  mb->cbp = 0;
# Line 1581  Line 1709 
1709                                  break;                                  break;
1710    
1711                          default:                          default:
1712                                  DEBUG1("Not support B-frame mb_type =", mb->mb_type);                                  DPRINTF(DPRINTF_ERROR,"Not support B-frame mb_type = %i", mb->mb_type);
1713                          }                          }
1714    
1715                  }                                               // end of FOR                  }                                               // end of FOR
# Line 1607  Line 1735 
1735  }  }
1736    
1737    
1738    /* perform post processing if necessary, and output the image */
1739    void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,
1740                                            const XVID_DEC_FRAME * frame, int pp_disable)
1741    {
1742    
1743            if ((frame->general & (XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV)) && !pp_disable)   /* post process */
1744            {
1745                    /* note: image is stored to tmp */
1746                    image_copy(&dec->tmp, img, dec->edged_width, dec->height);
1747                    image_deblock_rrv(&dec->tmp, dec->edged_width,
1748                                                    mbs, dec->mb_width, dec->mb_height, dec->mb_width,
1749                                                    8, frame->general);
1750                    img = &dec->tmp;
1751            }
1752    
1753            image_output(img, dec->width, dec->height,
1754                                     dec->edged_width, frame->image, frame->stride,
1755                                     frame->colorspace, dec->interlacing);
1756    }
1757    
1758    
1759  int  int
1760  decoder_decode(DECODER * dec,  decoder_decode(DECODER * dec,
1761                             XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats)                             XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats)
# Line 1619  Line 1768 
1768          uint32_t fcode_forward;          uint32_t fcode_forward;
1769          uint32_t fcode_backward;          uint32_t fcode_backward;
1770          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
1771          VECTOR gmc_mv[5];          WARPPOINTS gmc_warp;
1772          uint32_t vop_type;          uint32_t vop_type;
1773          int success = 0;          int success = 0;
1774          int output = 0;          int output = 0;
# Line 1628  Line 1777 
1777          start_global_timer();          start_global_timer();
1778    
1779          dec->low_delay_default = (frame->general & XVID_DEC_LOWDELAY);          dec->low_delay_default = (frame->general & XVID_DEC_LOWDELAY);
   
1780          dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL;          dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL;
1781    
1782            if ((frame->general & XVID_DEC_DISCONTINUITY))
1783                    dec->frames = 0;
1784    
1785            if (frame->length < 0)  /* decoder flush */
1786            {
1787                    /* if  not decoding "low_delay/packed", and this isn't low_delay and
1788                        we have a reference frame, then outout the reference frame */
1789                    if (!(dec->low_delay_default && dec->packed_mode) && !dec->low_delay && dec->frames>0)
1790                    {
1791                            decoder_output(dec, &dec->refn[0], dec->mbs, frame, dec->last_reduced_resolution);
1792                            output = 1;
1793                    }
1794    
1795                    frame->length = 0;
1796                    if (stats)
1797                    {
1798                            stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING;
1799                            stats->data.vop.time_base = (int)dec->time_base;
1800                            stats->data.vop.time_increment = 0;     //XXX: todo
1801                    }
1802    
1803                    emms();
1804    
1805                    stop_global_timer();
1806                    return XVID_ERR_OK;
1807            }
1808    
1809          BitstreamInit(&bs, frame->bitstream, frame->length);          BitstreamInit(&bs, frame->bitstream, frame->length);
1810    
1811          // XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's          // XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's
1812          if(frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f)          if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f)
1813          {          {
1814                  if (stats)                  if (stats)
1815                          stats->notify = XVID_DEC_VOP;                          stats->notify = XVID_DEC_VOP;
# Line 1645  Line 1820 
1820                  return XVID_ERR_OK;                  return XVID_ERR_OK;
1821          }          }
1822    
1823  start:  repeat:
         // add by chenm001 <chenm001@163.com>  
         // for support B-frame to reference last 2 frame  
1824    
1825  xxx:          vop_type =      BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,
1826          vop_type =                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp);
                 BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,  
                         &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, gmc_mv);  
1827    
1828          DPRINTF(DPRINTF_HEADER, "vop_type=%i,  packed=%i,  time=%i,  time_pp=%i,  time_bp=%i",          DPRINTF(DPRINTF_HEADER, "vop_type=%i,  packed=%i,  time=%lli,  time_pp=%i,  time_bp=%i",
1829                                                          vop_type,       dec->packed_mode, dec->time, dec->time_pp, dec->time_bp);                                                          vop_type,       dec->packed_mode, dec->time, dec->time_pp, dec->time_bp);
1830    
1831          if (vop_type == - 1)          if (vop_type == - 1)
1832          {          {
1833                  if (success) goto done;                  if (success) goto done;
1834                    emms();
1835                  return XVID_ERR_FAIL;                  return XVID_ERR_FAIL;
1836          }          }
1837    
# Line 1680  Line 1852 
1852                          stats->data.vol.par_width = dec->par_width;                          stats->data.vol.par_width = dec->par_width;
1853                          stats->data.vol.par_height = dec->par_height;                          stats->data.vol.par_height = dec->par_height;
1854                          frame->length = BitstreamPos(&bs) / 8;                          frame->length = BitstreamPos(&bs) / 8;
1855                            emms();
1856                          return XVID_ERR_OK;                          return XVID_ERR_OK;
1857                  }                  }
1858                  goto xxx;                  goto repeat;
1859          }          }
1860    
1861          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
# Line 1691  Line 1864 
1864          /* packed_mode: special-N_VOP treament */          /* packed_mode: special-N_VOP treament */
1865          if (dec->packed_mode && vop_type == N_VOP)          if (dec->packed_mode && vop_type == N_VOP)
1866          {          {
1867                  if (dec->low_delay_default)                  if (dec->low_delay_default && dec->frames > 0)
1868                  {                  {
1869                          image_output(&dec->refn[0], dec->width, dec->height,                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution);
                                                  dec->edged_width, frame->image, frame->stride,  
                                                  frame->colorspace, dec->interlacing);  
1870                          output = 1;                          output = 1;
1871                  }                  }
1872                  /* ignore otherwise */                  /* ignore otherwise */
# Line 1713  Line 1884 
1884                          break;                          break;
1885                  case S_VOP :                  case S_VOP :
1886                          decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,                          decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,
1887                                                  fcode_forward, intra_dc_threshold, gmc_mv);                                                  fcode_forward, intra_dc_threshold, &gmc_warp);
1888                          break;                          break;
1889                  case N_VOP :                  case N_VOP :
1890                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);
# Line 1723  Line 1894 
1894                  if (reduced_resolution)                  if (reduced_resolution)
1895                  {                  {
1896                          image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,                          image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,
1897                                  (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width);                                  (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width,
1898                                    16, XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV);
1899                  }                  }
1900    
1901                  /* 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 */
# Line 1731  Line 1903 
1903                  {                  {
1904                          if (dec->low_delay)                          if (dec->low_delay)
1905                          {                          {
1906                                  image_output(&dec->cur, dec->width, dec->height,                                  decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution);
                                                          dec->edged_width, frame->image, frame->stride,  
                                                          frame->colorspace, dec->interlacing);  
1907                                  output = 1;                                  output = 1;
1908                          }                          }
1909                          else if (dec->frames > 0)       /* is the reference frame valid? */                          else if (dec->frames > 0)       /* is the reference frame valid? */
1910                          {                          {
1911                                  image_output(&dec->refn[0], dec->width, dec->height,                                  /* output the reference frame */
1912                                                           dec->edged_width, frame->image, frame->stride,                                  decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution);
                                                          frame->colorspace, dec->interlacing);  
1913                                  output = 1;                                  output = 1;
1914                          }                          }
1915                  }                  }
# Line 1748  Line 1917 
1917                  image_swap(&dec->refn[0], &dec->refn[1]);                  image_swap(&dec->refn[0], &dec->refn[1]);
1918                  image_swap(&dec->cur, &dec->refn[0]);                  image_swap(&dec->cur, &dec->refn[0]);
1919                  mb_swap(&dec->mbs, &dec->last_mbs);                  mb_swap(&dec->mbs, &dec->last_mbs);
1920                    dec->last_reduced_resolution = reduced_resolution;
1921    
1922                  dec->frames++;                  dec->frames++;
1923                  seen_something = 1;                  seen_something = 1;
# Line 1760  Line 1930 
1930                          dec->low_delay = 1;                          dec->low_delay = 1;
1931                  }                  }
1932    
1933                  if (dec->time_pp <= dec->time_bp) {                  if (dec->frames < 2)
1934                    {
1935                            /* attemping to decode a bvop without atleast 2 reference frames */
1936                            image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
1937                                                    "broken b-frame, mising ref frames");
1938                    }else if (dec->time_pp <= dec->time_bp) {
1939                          /* this occurs when dx50_bvop_compatibility==0 sequences are                          /* this occurs when dx50_bvop_compatibility==0 sequences are
1940                          decoded in vfw. */                          decoded in vfw. */
1941                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
# Line 1769  Line 1944 
1944                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);
1945                  }                  }
1946    
1947                  image_output(&dec->cur, dec->width, dec->height,                  decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution);
                                          dec->edged_width, frame->image, frame->stride,  
                                          frame->colorspace, dec->interlacing);  
1948                  output = 1;                  output = 1;
1949                  dec->frames++;                  dec->frames++;
1950          }          }
1951    
         emms();  
   
1952          BitstreamByteAlign(&bs);          BitstreamByteAlign(&bs);
1953    
1954          /* low_delay_default mode: repeat in packed_mode */          /* low_delay_default mode: repeat in packed_mode */
1955          if (dec->low_delay_default && dec->packed_mode && output == 0 && success == 0)          if (dec->low_delay_default && dec->packed_mode && output == 0 && success == 0)
1956          {          {
1957                  success = 1;                  success = 1;
1958                  goto start;                  goto repeat;
1959          }          }
1960    
1961  done :  done :
# Line 1796  Line 1967 
1967                  if (dec->packed_mode && seen_something)                  if (dec->packed_mode && seen_something)
1968                  {                  {
1969                          /* output the recently decoded frame */                          /* output the recently decoded frame */
1970                          image_output(&dec->refn[0], dec->width, dec->height,                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution);
1971                                                           dec->edged_width, frame->image, frame->stride,                          output = 1;
                                                          frame->colorspace, dec->interlacing);  
1972                  }                  }
1973                  else                  else
1974                  {                  {
1975                            image_clear(&dec->cur, dec->width, dec->height, dec->edged_width, 0, 128, 128);
1976                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
1977                                  "warning: nothing to output");                                  "warning: nothing to output");
1978                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,
1979                                  "bframe decoder lag");                                  "bframe decoder lag");
1980    
1981                          image_output(&dec->cur, dec->width, dec->height,                          decoder_output(dec, &dec->cur, NULL, frame, 1 /*disable pp*/);
                                                          dec->edged_width, frame->image, frame->stride,  
                                                          frame->colorspace, dec->interlacing);  
1982                  }                  }
                 output = 1;  
1983          }          }
1984    
1985          frame->length = BitstreamPos(&bs) / 8;          frame->length = BitstreamPos(&bs) / 8;

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

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