[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.25, Fri Jan 3 16:25:14 2003 UTC revision 1.49, Wed Feb 19 21:59:30 2003 UTC
# Line 1  Line 1 
1  /**************************************************************************  /*****************************************************************************
2   *   *
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  -  Decoder main module  -   *  - Decoder Module -
5   *   *
6   *  This program is an implementation of a part of one or more MPEG-4   *  This file is part of XviD, a free MPEG-4 video encoder/decoder
  *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending  
  *  to use this software module in hardware or software products are  
  *  advised that its use may infringe existing patents or copyrights, and  
  *  any such use would be at such party's own risk.  The original  
  *  developer of this software module and his/her company, and subsequent  
  *  editors and their companies, will have no liability for use of this  
  *  software or modifications or derivatives thereof.  
7   *   *
8   *  This program is free software; you can redistribute it and/or modify   *  This program is free software; you can redistribute it and/or modify
9   *  it under the terms of the GNU General Public License as published by   *  it under the terms of the GNU General Public License as published by
# Line 26  Line 19 
19   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
20   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21   *   *
  *************************************************************************/  
   
 /**************************************************************************  
  *  
  *  History:  
  *  
  *  15.07.2002  fix a bug in B-frame decode at DIRECT mode  
  *              MinChen <chenm001@163.com>  
  *  10.07.2002  added BFRAMES_DEC_DEBUG support  
  *              Fix a little bug for low_delay flage  
  *              MinChen <chenm001@163.com>  
  *  28.06.2002  added basic resync support to iframe/pframe_decode()  
  *  22.06.2002  added primative N_VOP support  
  *                              #define BFRAMES_DEC now enables Minchen's bframe decoder  
  *  08.05.2002  add low_delay support for B_VOP decode  
  *              MinChen <chenm001@163.com>  
  *  05.05.2002  fix some B-frame decode problem  
  *  02.05.2002  add B-frame decode support(have some problem);  
  *              MinChen <chenm001@163.com>  
  *  22.04.2002  add some B-frame decode support;  chenm001 <chenm001@163.com>  
  *  29.03.2002  interlacing fix - compensated block wasn't being used when  
  *              reconstructing blocks, thus artifacts  
  *              interlacing speedup - used transfers to re-interlace  
  *              interlaced decoding should be as fast as progressive now  
  *  26.03.2002  interlacing support - moved transfers outside decode loop  
  *  26.12.2001  decoder_mbinter: dequant/idct moved within if(coded) block  
  *  22.12.2001  lock based interpolation  
  *  01.12.2001  inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>  
  *  
22   *  $Id$   *  $Id$
23   *   *
24   *************************************************************************/   ****************************************************************************/
25    
26    #include <stdio.h>
27  #include <stdlib.h>  #include <stdlib.h>
28  #include <string.h>  #include <string.h>
29    
# Line 68  Line 33 
33    
34  #include "xvid.h"  #include "xvid.h"
35  #include "portab.h"  #include "portab.h"
36    #include "global.h"
37    
38  #include "decoder.h"  #include "decoder.h"
39  #include "bitstream/bitstream.h"  #include "bitstream/bitstream.h"
# Line 96  Line 62 
62  decoder_resize(DECODER * dec)  decoder_resize(DECODER * dec)
63  {  {
64          /* free existing */          /* free existing */
   
65          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
66          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
67          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
68          image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);          image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
69          image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);          image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);
70    
71            image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);
72    
73          if (dec->last_mbs)          if (dec->last_mbs)
74                  xvid_free(dec->last_mbs);                  xvid_free(dec->last_mbs);
75          if (dec->mbs)          if (dec->mbs)
76                  xvid_free(dec->mbs);                  xvid_free(dec->mbs);
77    
78          /* realloc */          /* realloc */
   
79          dec->mb_width = (dec->width + 15) / 16;          dec->mb_width = (dec->width + 15) / 16;
80          dec->mb_height = (dec->height + 15) / 16;          dec->mb_height = (dec->height + 15) / 16;
81    
# Line 127  Line 93 
93                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
94          }          }
95    
96          // add by chenm001 <chenm001@163.com>          /* Support B-frame to reference last 2 frame */
         // for support B-frame to reference last 2 frame  
97          if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) {          if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) {
98                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
99                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
# Line 152  Line 117 
117                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
118          }          }
119    
120            if (image_create(&dec->gmc, dec->edged_width, dec->edged_height)) {
121                    image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);
122                    image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
123                    image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
124                    image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
125                    image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
126                    xvid_free(dec);
127                    return XVID_ERR_MEMORY;
128            }
129    
130          dec->mbs =          dec->mbs =
131                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,
132                                          CACHE_LINE);                                          CACHE_LINE);
# Line 166  Line 141 
141          }          }
142          memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);          memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);
143    
144          // add by chenm001 <chenm001@163.com>          /* For skip MB flag */
         // for skip MB flag  
145          dec->last_mbs =          dec->last_mbs =
146                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,
147                                          CACHE_LINE);                                          CACHE_LINE);
# Line 210  Line 184 
184          image_null(&dec->tmp);          image_null(&dec->tmp);
185          image_null(&dec->qtmp);          image_null(&dec->qtmp);
186    
187            /* image based GMC */
188            image_null(&dec->gmc);
189    
190    
191          dec->mbs = NULL;          dec->mbs = NULL;
192          dec->last_mbs = NULL;          dec->last_mbs = NULL;
193    
194          init_timer();          init_timer();
195    
196          // add by chenm001 <chenm001@163.com>          /* For B-frame support (used to save reference frame's time */
         // for support B-frame to save reference frame's time  
197          dec->frames = 0;          dec->frames = 0;
198          dec->time = dec->time_base = dec->last_time_base = 0;          dec->time = dec->time_base = dec->last_time_base = 0;
199          dec->low_delay = 0;          dec->low_delay = 0;
# Line 236  Line 213 
213  {  {
214          xvid_free(dec->last_mbs);          xvid_free(dec->last_mbs);
215          xvid_free(dec->mbs);          xvid_free(dec->mbs);
216    
217            /* image based GMC */
218            image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);
219    
220          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
221          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
222          image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);          image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
# Line 256  Line 237 
237    
238    
239    
240  // decode an intra macroblock  /* decode an intra macroblock */
   
241  void  void
242  decoder_mbintra(DECODER * dec,  decoder_mbintra(DECODER * dec,
243                                  MACROBLOCK * pMB,                                  MACROBLOCK * pMB,
# Line 292  Line 272 
272                  pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);                  pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
273          }          }
274    
275          memset(block, 0, 6 * 64 * sizeof(int16_t));     // clear          memset(block, 0, 6 * 64 * sizeof(int16_t));     /* clear */
276    
277          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
278                  uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);                  uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
# Line 315  Line 295 
295                          dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0;                          dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0;
296    
297                          if (dc_size > 8) {                          if (dc_size > 8) {
298                                  BitstreamSkip(bs, 1);   // marker                                  BitstreamSkip(bs, 1);   /* marker */
299                          }                          }
300    
301                          block[i * 64 + 0] = dc_dif;                          block[i * 64 + 0] = dc_dif;
# Line 327  Line 307 
307                  }                  }
308    
309                  start_timer();                  start_timer();
310                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       /* coded */
311                  {                  {
312                          int direction = dec->alternate_vertical_scan ?                          int direction = dec->alternate_vertical_scan ?
313                                  2 : pMB->acpred_directions[i];                                  2 : pMB->acpred_directions[i];
# Line 384  Line 364 
364    
365    
366    
367    /* decode an inter macroblock */
 #define SIGN(X) (((X)>0)?1:-1)  
 #define ABS(X) (((X)>0)?(X):-(X))  
   
 // decode an inter macroblock  
   
368  void  void
369  decoder_mbinter(DECODER * dec,  decoder_mbinter(DECODER * dec,
370                                  const MACROBLOCK * pMB,                                  const MACROBLOCK * pMB,
371                                  const uint32_t x_pos,                                  const uint32_t x_pos,
372                                  const uint32_t y_pos,                                  const uint32_t y_pos,
373                                  const uint32_t acpred_flag,                                  const uint32_t fcode,
374                                  const uint32_t cbp,                                  const uint32_t cbp,
375                                  Bitstream * bs,                                  Bitstream * bs,
376                                  const uint32_t quant,                                  const uint32_t quant,
# Line 433  Line 408 
408          }          }
409    
410          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;  
411    
412                  if (dec->quarterpel)                  uv_dx = mv[0].x / (1 + dec->quarterpel);
413                  {                  uv_dy = mv[0].y / (1 + dec->quarterpel);
                         uv_dx /= 2;  
                         uv_dy /= 2;  
                 }  
414    
415                  uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];                  uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
416                  uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];                  uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
# Line 508  Line 478 
478                          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,
479                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
480    
481                          // set_block(pY_Cur, stride, 32, 32, 127);                          /* set_block(pY_Cur, stride, 32, 32, 127); */
482                  }                  }
483                  else                  else
484                  {                  {
# Line 548  Line 518 
518          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
519                  int direction = dec->alternate_vertical_scan ? 2 : 0;                  int direction = dec->alternate_vertical_scan ? 2 : 0;
520    
521                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       /* coded */
522                  {                  {
523                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        /* clear */
524    
525                          start_timer();                          start_timer();
526                          get_inter_block(bs, &block[i * 64], direction);                          get_inter_block(bs, &block[i * 64], direction);
# Line 609  Line 579 
579          stop_transfer_timer();          stop_transfer_timer();
580  }  }
581    
582    static __inline int gmc_sanitize(int value, int quarterpel, int fcode)
583    {
584            int length = 1 << (fcode+4);
585    
586    /*      if (quarterpel) value *= 2; */
587    
588            if (value < -length)
589                    return -length;
590            else if (value >= length)
591                    return length-1;
592            else return value;
593    }
594    
595    
596    static void
597    decoder_mbgmc(DECODER * dec,
598                                    MACROBLOCK * const pMB,
599                                    const uint32_t x_pos,
600                                    const uint32_t y_pos,
601                                    const uint32_t fcode,
602                                    const uint32_t cbp,
603                                    Bitstream * bs,
604                                    const uint32_t quant,
605                                    const uint32_t rounding,
606                                    const int reduced_resolution)   /* no reduced res support */
607    {
608    
609            DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
610            DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);
611    
612            const uint32_t stride = dec->edged_width;
613            const uint32_t stride2 = stride / 2;
614            const uint32_t next_block = stride * (reduced_resolution ? 16 : 8);
615            uint32_t i;
616            const uint32_t iQuant = pMB->quant;
617            uint8_t *const pY_Cur=dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
618            uint8_t *const pU_Cur=dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
619            uint8_t *const pV_Cur=dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
620    
621            pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
622    
623            start_timer();
624    
625    /* this is where the calculations are done */
626    
627            {
628                    pMB->amv = generate_GMCimageMB(&dec->gmc_data, &dec->refn[0], x_pos, y_pos,
629                                            stride, stride2, dec->quarterpel, rounding, &dec->cur);
630    
631                    pMB->amv.x = gmc_sanitize(pMB->amv.x, dec->quarterpel, fcode);
632                    pMB->amv.y = gmc_sanitize(pMB->amv.y, dec->quarterpel, fcode);
633            }
634            pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
635    
636    /*
637            transfer16x16_copy(pY_Cur, dec->gmc.y + (y_pos << 4)*stride + (x_pos  << 4), stride);
638            transfer8x8_copy(pU_Cur, dec->gmc.u + (y_pos << 3)*stride2 + (x_pos  << 3), stride2);
639            transfer8x8_copy(pV_Cur, dec->gmc.v + (y_pos << 3)*stride2 + (x_pos << 3), stride2);
640    */
641    
642    
643            stop_transfer_timer();
644    
645            if (!cbp) return;
646    
647            for (i = 0; i < 6; i++) {
648                    int direction = dec->alternate_vertical_scan ? 2 : 0;
649    
650                    if (cbp & (1 << (5 - i)))       /* coded */
651                    {
652                            memset(&block[i * 64], 0, 64 * sizeof(int16_t));        /* clear */
653    
654                            start_timer();
655                            get_inter_block(bs, &block[i * 64], direction);
656                            stop_coding_timer();
657    
658                            start_timer();
659                            if (dec->quant_type == 0) {
660                                    dequant_inter(&data[i * 64], &block[i * 64], iQuant);
661                            } else {
662                                    dequant4_inter(&data[i * 64], &block[i * 64], iQuant);
663                            }
664                            stop_iquant_timer();
665    
666                            start_timer();
667                            idct(&data[i * 64]);
668                            stop_idct_timer();
669                    }
670            }
671    
672    /* interlace + GMC is this possible ??? */
673    /*
674      if (dec->interlacing && pMB->field_dct) {
675              next_block = stride;
676              stride *= 2;
677      }
678    */
679            start_timer();
680            if (cbp & 32)
681                    transfer_16to8add(pY_Cur, &data[0 * 64], stride);
682            if (cbp & 16)
683                    transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
684            if (cbp & 8)
685                    transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
686            if (cbp & 4)
687                    transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride);
688            if (cbp & 2)
689                    transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
690            if (cbp & 1)
691                    transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
692            stop_transfer_timer();
693    }
694    
695    
696  void  void
697  decoder_iframe(DECODER * dec,  decoder_iframe(DECODER * dec,
# Line 716  Line 799 
799          mv.x = get_mv(bs, fcode);          mv.x = get_mv(bs, fcode);
800          mv.y = get_mv(bs, fcode);          mv.y = get_mv(bs, fcode);
801    
802          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);
803    
804          mv.x += pmv.x;          mv.x += pmv.x;
805          mv.y += pmv.y;          mv.y += pmv.y;
# Line 739  Line 822 
822    
823    
824    
 static __inline int gmc_sanitize(int value, int quarterpel, int fcode)  
 {  
         int length = 1 << (fcode+4);  
   
         if (quarterpel) value *= 2;  
   
         if (value < -length)  
                 return -length;  
         else if (value >= length)  
                 return length-1;  
         else return value;  
 }  
825    
826    
827  /* for P_VOP set gmc_mv to NULL */  /* for P_VOP set gmc_warp to NULL */
828  void  void
829  decoder_pframe(DECODER * dec,  decoder_pframe(DECODER * dec,
830                             Bitstream * bs,                             Bitstream * bs,
# Line 762  Line 833 
833                             int quant,                             int quant,
834                             int fcode,                             int fcode,
835                             int intra_dc_threshold,                             int intra_dc_threshold,
836                             VECTOR * gmc_mv)                             const WARPPOINTS *const gmc_warp)
837  {  {
838    
839          uint32_t x, y;          uint32_t x, y;
# Line 782  Line 853 
853                                     dec->width, dec->height);                                     dec->width, dec->height);
854          stop_edges_timer();          stop_edges_timer();
855    
856            if (gmc_warp)
857            {
858    
859                    /* accuracy:  0==1/2, 1=1/4, 2=1/8, 3=1/16 */
860                    if ( (dec->sprite_warping_accuracy != 3) || (dec->sprite_warping_points != 2) )
861                    {
862                            fprintf(stderr,"Wrong GMC parameters acc=%d(-> 1/%d), %d!!!\n",
863                                    dec->sprite_warping_accuracy,(2<<dec->sprite_warping_accuracy),
864                                    dec->sprite_warping_points);
865                    }
866    
867                    generate_GMCparameters( dec->sprite_warping_points,
868                                    (2 << dec->sprite_warping_accuracy), gmc_warp,
869                                    dec->width, dec->height, &dec->gmc_data);
870    
871    /* image warping is done block-based  in decoder_mbgmc(), now */
872    /*
873            generate_GMCimage(&dec->gmc_data, &dec->refn[0],
874                                            mb_width, mb_height,
875                                            dec->edged_width, dec->edged_width/2,
876                                            fcode, dec->quarterpel, 0,
877                                            rounding, dec->mbs, &dec->gmc);
878    */
879            }
880    
881          bound = 0;          bound = 0;
882    
883          for (y = 0; y < mb_height; y++) {          for (y = 0; y < mb_height; y++) {
# Line 789  Line 885 
885                  for (x = 0; x < mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
886                          MACROBLOCK *mb;                          MACROBLOCK *mb;
887    
888                          // skip stuffing                          /* skip stuffing */
889                          while (BitstreamShowBits(bs, 10) == 1)                          while (BitstreamShowBits(bs, 10) == 1)
890                                  BitstreamSkip(bs, 10);                                  BitstreamSkip(bs, 10);
891    
# Line 804  Line 900 
900    
901                          DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32));                          DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32));
902    
903                          //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 */
904                          if (!(BitstreamGetBit(bs)))     // not_coded                          if (!(BitstreamGetBit(bs)))     /* block _is_ coded */
905                          {                          {
906                                  uint32_t mcbpc;                                  uint32_t mcbpc;
907                                  uint32_t cbpc;                                  uint32_t cbpc;
# Line 813  Line 909 
909                                  uint32_t cbpy;                                  uint32_t cbpy;
910                                  uint32_t cbp;                                  uint32_t cbp;
911                                  uint32_t intra;                                  uint32_t intra;
912                                  int mcsel = 0;          // mcsel: '0'=local motion, '1'=GMC                                  int mcsel = 0;          /* mcsel: '0'=local motion, '1'=GMC */
913    
914                                  cp_mb++;                                  cp_mb++;
915                                  mcbpc = get_mcbpc_inter(bs);                                  mcbpc = get_mcbpc_inter(bs);
# Line 830  Line 926 
926                                          acpred_flag = BitstreamGetBit(bs);                                          acpred_flag = BitstreamGetBit(bs);
927                                  }                                  }
928    
929                                  if (gmc_mv && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q))                                  if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q))
930                                  {                                  {
931                                          mcsel = BitstreamGetBit(bs);                                          mcsel = BitstreamGetBit(bs);
932                                  }                                  }
933    
934                                  cbpy = get_cbpy(bs, intra);                                  cbpy = get_cbpy(bs, intra);
935                                  DPRINTF(DPRINTF_MB, "cbpy %i", cbpy);                                  DPRINTF(DPRINTF_MB, "cbpy %i  mcsel %i ", cbpy,mcsel);
936    
937                                  cbp = (cbpy << 2) | cbpc;                                  cbp = (cbpy << 2) | cbpc;
938    
# Line 872  Line 968 
968                                          }                                          }
969                                  }                                  }
970    
971                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                  if (mcsel) {
972                                            decoder_mbgmc(dec, mb, x, y, fcode, cbp, bs, quant,
973                                                                    rounding, reduced_resolution);
974                                            continue;
975    
976                                          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);  
977    
978                                          } else if (dec->interlacing && mb->field_pred) {                                          if (dec->interlacing && mb->field_pred) {
979                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],
980                                                                                    fcode, bound);                                                                                    fcode, bound);
981                                                  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 983 
983                                          } else {                                          } else {
984                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],
985                                                                                    fcode, bound);                                                                                    fcode, bound);
986                                                  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;  
987                                          }                                          }
988                                  } else if (mb->mode == MODE_INTER4V ) {                                  } else if (mb->mode == MODE_INTER4V ) {
989    
# Line 898  Line 991 
991                                          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);
992                                          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);
993                                          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);
994                                  } else                  // MODE_INTRA, MODE_INTRA_Q                                  } else                  /* MODE_INTRA, MODE_INTRA_Q */
995                                  {                                  {
996                                          mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x =                                          mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x =
997                                                  0;                                                  0;
# Line 909  Line 1002 
1002                                          continue;                                          continue;
1003                                  }                                  }
1004    
1005                                  decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant,                                  decoder_mbinter(dec, mb, x, y, fcode, cbp, bs, quant,
1006                                                                  rounding, reduced_resolution);                                                                  rounding, reduced_resolution);
1007    
1008                          }                          }
1009                          else if (gmc_mv)        /* not coded S_VOP macroblock */                          else if (gmc_warp)      /* a not coded S(GMC)-VOP macroblock */
1010                          {                          {
1011                                  mb->mode = MODE_NOT_CODED_GMC;                                  mb->mode = MODE_NOT_CODED_GMC;
1012                                  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);  
1013                                  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();
1014                                  decoder_mbinter(dec, mb, x, y, 0, 0, bs, quant, rounding, reduced_resolution);  
1015                                    decoder_mbgmc(dec, mb, x, y, fcode, 0x00, bs, quant,
1016                                                                    rounding, reduced_resolution);
1017    
1018                                    stop_transfer_timer();
1019    
1020                                    if(dec->out_frm && cp_mb > 0) {
1021                                      output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb);
1022                                      cp_mb = 0;
1023                                    }
1024                                    st_mb = x+1;
1025                          }                          }
1026                          else    /* not coded P_VOP macroblock */                          else    /* not coded P_VOP macroblock */
1027                          {                          {
# Line 926  Line 1029 
1029    
1030                                  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;
1031                                  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;
1032                                  // copy macroblock directly from ref to cur                                  /* copy macroblock directly from ref to cur */
1033    
1034                                  start_timer();                                  start_timer();
1035    
# Line 974  Line 1077 
1077  }  }
1078    
1079    
1080  // add by MinChen <chenm001@163.com>  /* decode B-frame motion vector */
 // decode B-frame motion vector  
1081  void  void
1082  get_b_motion_vector(DECODER * dec,  get_b_motion_vector(DECODER * dec,
1083                                          Bitstream * bs,                                          Bitstream * bs,
# Line 1019  Line 1121 
1121  }  }
1122    
1123    
1124  // add by MinChen <chenm001@163.com>  /* decode an B-frame forward & backward inter macroblock */
 // decode an B-frame forward & backward inter macroblock  
1125  void  void
1126  decoder_bf_mbinter(DECODER * dec,  decoder_bf_mbinter(DECODER * dec,
1127                                     const MACROBLOCK * pMB,                                     const MACROBLOCK * pMB,
# Line 1104  Line 1205 
1205          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
1206                  int direction = dec->alternate_vertical_scan ? 2 : 0;                  int direction = dec->alternate_vertical_scan ? 2 : 0;
1207    
1208                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       /* coded */
1209                  {                  {
1210                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        /* clear */
1211    
1212                          start_timer();                          start_timer();
1213                          get_inter_block(bs, &block[i * 64], direction);                          get_inter_block(bs, &block[i * 64], direction);
# Line 1147  Line 1248 
1248          stop_transfer_timer();          stop_transfer_timer();
1249  }  }
1250    
1251  // add by MinChen <chenm001@163.com>  /* decode an B-frame direct &  inter macroblock */
 // decode an B-frame direct &  inter macroblock  
1252  void  void
1253  decoder_bf_interpolate_mbinter(DECODER * dec,  decoder_bf_interpolate_mbinter(DECODER * dec,
1254                                                             IMAGE forward,                                                             IMAGE forward,
# Line 1345  Line 1445 
1445          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
1446                  int direction = dec->alternate_vertical_scan ? 2 : 0;                  int direction = dec->alternate_vertical_scan ? 2 : 0;
1447    
1448                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       /* coded */
1449                  {                  {
1450                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        /* clear */
1451    
1452                          start_timer();                          start_timer();
1453                          get_inter_block(bs, &block[i * 64], direction);                          get_inter_block(bs, &block[i * 64], direction);
# Line 1389  Line 1489 
1489  }  }
1490    
1491    
1492  // add by MinChen <chenm001@163.com>  /* for decode B-frame dbquant */
 // for decode B-frame dbquant  
1493  int32_t __inline  int32_t __inline
1494  get_dbquant(Bitstream * bs)  get_dbquant(Bitstream * bs)
1495  {  {
1496          if (!BitstreamGetBit(bs))       // '0'          if (!BitstreamGetBit(bs))      /*  '0' */
1497                  return (0);                  return (0);
1498          else if (!BitstreamGetBit(bs))  // '10'          else if (!BitstreamGetBit(bs)) /* '10' */
1499                  return (-2);                  return (-2);
1500          else          else                           /* '11' */
1501                  return (2);                             // '11'                  return (2);
1502  }  }
1503    
1504  // add by MinChen <chenm001@163.com>  /*
1505  // for decode B-frame mb_type   * For decode B-frame mb_type
1506  // bit   ret_value   * bit   ret_value
1507  // 1        0   * 1        0
1508  // 01       1   * 01       1
1509  // 001      2   * 001      2
1510  // 0001     3   * 0001     3
1511     */
1512  int32_t __inline  int32_t __inline
1513  get_mbtype(Bitstream * bs)  get_mbtype(Bitstream * bs)
1514  {  {
# Line 1457  Line 1557 
1557  #endif  #endif
1558    
1559          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < dec->mb_height; y++) {
1560                  // Initialize Pred Motion Vector                  /* Initialize Pred Motion Vector */
1561                  dec->p_fmv = dec->p_bmv = zeromv;                  dec->p_fmv = dec->p_bmv = zeromv;
1562                  for (x = 0; x < dec->mb_width; x++) {                  for (x = 0; x < dec->mb_width; x++) {
1563                          MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x];                          MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x];
# Line 1467  Line 1567 
1567                          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] =
1568                          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;
1569    
1570                          // skip if the co-located P_VOP macroblock is not coded                          /*
1571                          // note: gmc+not_coded isn't skipped                           * skip if the co-located P_VOP macroblock is not coded
1572                             * if not codec in co-located S_VOP macroblock is _not_
1573                             * automatically skipped
1574                             */
1575    
1576                          if (last_mb->mode == MODE_NOT_CODED) {                          if (last_mb->mode == MODE_NOT_CODED) {
1577                                  //DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y);                                  /* DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); */
1578                                  mb->cbp = 0;                                  mb->cbp = 0;
1579  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
1580                                  mb->mb_type = MODE_NOT_CODED;                                  mb->mb_type = MODE_NOT_CODED;
# Line 1479  Line 1582 
1582  #endif  #endif
1583                                  mb->mb_type = MODE_FORWARD;                                  mb->mb_type = MODE_FORWARD;
1584                                  mb->quant = last_mb->quant;                                  mb->quant = last_mb->quant;
1585                                  //mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x;                                  /*
1586                                  //mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y;                                    mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x;
1587                                      mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y;
1588                                    */
1589    
1590                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, mb->quant, 1);                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, mb->quant, 1);
1591                                  continue;                                  continue;
1592                          }                          }
1593    
1594                          if (!BitstreamGetBit(bs)) {     // modb=='0'                          if (!BitstreamGetBit(bs)) {     /* modb=='0' */
1595                                  const uint8_t modb2 = BitstreamGetBit(bs);                                  const uint8_t modb2 = BitstreamGetBit(bs);
1596    
1597                                  mb->mb_type = get_mbtype(bs);                                  mb->mb_type = get_mbtype(bs);
1598    
1599                                  if (!modb2) {   // modb=='00'                                  if (!modb2) {   /* modb=='00' */
1600                                          mb->cbp = BitstreamGetBits(bs, 6);                                          mb->cbp = BitstreamGetBits(bs, 6);
1601                                  } else {                                  } else {
1602                                          mb->cbp = 0;                                          mb->cbp = 0;
# Line 1512  Line 1617 
1617    
1618                          mb->quant = quant;                          mb->quant = quant;
1619                          mb->mode = MODE_INTER4V;                          mb->mode = MODE_INTER4V;
1620                          //DEBUG1("Switch bm_type=",mb->mb_type);                          /* DEBUG1("Switch bm_type=",mb->mb_type); */
1621    
1622  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
1623          BFRAME_DEBUG          BFRAME_DEBUG
# Line 1541  Line 1646 
1646                                                                                    / TRD                                                                                    / TRD
1647                                                                              : mb->mvs[i].y - last_mb->mvs[i].y);                                                                              : mb->mvs[i].y - last_mb->mvs[i].y);
1648                                          }                                          }
1649                                          //DEBUG("B-frame Direct!\n");                                          /* DEBUG("B-frame Direct!\n"); */
1650                                  }                                  }
1651                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
1652                                                                                             mb, x, y, bs);                                                                                             mb, x, y, bs);
# Line 1559  Line 1664 
1664    
1665                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
1666                                                                                             mb, x, y, bs);                                                                                             mb, x, y, bs);
1667                                  //DEBUG("B-frame Bidir!\n");                                  /* DEBUG("B-frame Bidir!\n"); */
1668                                  break;                                  break;
1669    
1670                          case MODE_BACKWARD:                          case MODE_BACKWARD:
# Line 1569  Line 1674 
1674    
1675                                  mb->mode = MODE_INTER;                                  mb->mode = MODE_INTER;
1676                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0);                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0);
1677                                  //DEBUG("B-frame Backward!\n");                                  /* DEBUG("B-frame Backward!\n"); */
1678                                  break;                                  break;
1679    
1680                          case MODE_FORWARD:                          case MODE_FORWARD:
# Line 1579  Line 1684 
1684    
1685                                  mb->mode = MODE_INTER;                                  mb->mode = MODE_INTER;
1686                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1);                                  decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1);
1687                                  //DEBUG("B-frame Forward!\n");                                  /* DEBUG("B-frame Forward!\n"); */
1688                                  break;                                  break;
1689    
1690                          default:                          default:
1691                                  DPRINTF(DPRINTF_ERROR,"Not support B-frame mb_type = %i", mb->mb_type);                                  DPRINTF(DPRINTF_ERROR,"Not support B-frame mb_type = %i", mb->mb_type);
1692                          }                          }
1693                    } /* End of for */
                 }                                               // end of FOR  
1694          }          }
1695    
1696  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
1697          if (!first){          if (!first){
1698                  first=1;                  first=1;
# Line 1597  Line 1702 
1702  #endif  #endif
1703  }  }
1704    
1705  // swap two MACROBLOCK array  /* swap two MACROBLOCK array */
1706  void  void
1707  mb_swap(MACROBLOCK ** mb1,  mb_swap(MACROBLOCK ** mb1,
1708                  MACROBLOCK ** mb2)                  MACROBLOCK ** mb2)
# Line 1642  Line 1747 
1747          uint32_t fcode_forward;          uint32_t fcode_forward;
1748          uint32_t fcode_backward;          uint32_t fcode_backward;
1749          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
1750          VECTOR gmc_mv[5];          WARPPOINTS gmc_warp;
1751          uint32_t vop_type;          int vop_type;
1752          int success = 0;          int success = 0;
1753          int output = 0;          int output = 0;
1754          int seen_something = 0;          int seen_something = 0;
# Line 1671  Line 1776 
1776                  {                  {
1777                          stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING;                          stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING;
1778                          stats->data.vop.time_base = (int)dec->time_base;                          stats->data.vop.time_base = (int)dec->time_base;
1779                          stats->data.vop.time_increment = 0;     //XXX: todo                          stats->data.vop.time_increment = 0;     /* XXX: todo */
1780                  }                  }
1781    
1782                  emms();                  emms();
# Line 1682  Line 1787 
1787    
1788          BitstreamInit(&bs, frame->bitstream, frame->length);          BitstreamInit(&bs, frame->bitstream, frame->length);
1789    
1790          // XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's          /* XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's */
1791          if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f)          if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f)
1792          {          {
1793                  if (stats)                  if (stats)
# Line 1697  Line 1802 
1802  repeat:  repeat:
1803    
1804          vop_type =      BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,          vop_type =      BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,
1805                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, gmc_mv);                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp);
1806    
1807          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",
1808                                                          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);
1809    
1810          if (vop_type == - 1)          if (vop_type == - 1)
# Line 1732  Line 1837 
1837                  goto repeat;                  goto repeat;
1838          }          }
1839    
1840          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 */
1841    
1842    
1843          /* packed_mode: special-N_VOP treament */          /* packed_mode: special-N_VOP treament */
# Line 1758  Line 1863 
1863                          break;                          break;
1864                  case S_VOP :                  case S_VOP :
1865                          decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,                          decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,
1866                                                  fcode_forward, intra_dc_threshold, gmc_mv);                                                  fcode_forward, intra_dc_threshold, &gmc_warp);
1867                          break;                          break;
1868                  case N_VOP :                  case N_VOP :
1869                          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 1862  Line 1967 
1967          {          {
1968                  stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING;                  stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING;
1969                  stats->data.vop.time_base = (int)dec->time_base;                  stats->data.vop.time_base = (int)dec->time_base;
1970                  stats->data.vop.time_increment = 0;     //XXX: todo                  stats->data.vop.time_increment = 0;     /* XXX: todo */
1971          }          }
1972    
1973          emms();          emms();

Legend:
Removed from v.1.37.2.25  
changed lines
  Added in v.1.49

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