[svn] / branches / dev-api-3 / xvidcore / src / decoder.c Repository:
ViewVC logotype

Diff of /branches/dev-api-3/xvidcore/src/decoder.c

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

trunk/xvidcore/src/decoder.c revision 306, Thu Jul 18 00:07:04 2002 UTC branches/dev-api-3/xvidcore/src/decoder.c revision 667, Wed Nov 20 22:28:25 2002 UTC
# Line 55  Line 55 
55   *  22.12.2001  lock based interpolation   *  22.12.2001  lock based interpolation
56   *  01.12.2001  inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>   *  01.12.2001  inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>
57   *   *
58   *  $Id: decoder.c,v 1.31 2002-07-18 00:07:04 chenm001 Exp $   *  $Id: decoder.c,v 1.37.2.14 2002-11-20 22:28:25 Isibaar Exp $
59   *   *
60   *************************************************************************/   *************************************************************************/
61    
# Line 84  Line 84 
84  #include "prediction/mbprediction.h"  #include "prediction/mbprediction.h"
85  #include "utils/timer.h"  #include "utils/timer.h"
86  #include "utils/emms.h"  #include "utils/emms.h"
87    #include "motion/motion.h"
88    
89  #include "image/image.h"  #include "image/image.h"
90  #include "image/colorspace.h"  #include "image/colorspace.h"
91  #include "utils/mem_align.h"  #include "utils/mem_align.h"
92    
93  int  int
94  decoder_create(XVID_DEC_PARAM * param)  decoder_resize(DECODER * dec)
95  {  {
96          DECODER *dec;          /* free existing */
97    
98          dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
99          if (dec == NULL) {          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
100                  return XVID_ERR_MEMORY;          image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);
101          }          image_destroy(&dec->refh, dec->edged_width, dec->edged_height);
102          param->handle = dec;          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
103    
104          dec->width = param->width;          if (dec->last_mbs)
105          dec->height = param->height;                  xvid_free(dec->last_mbs);
106            if (dec->mbs)
107                    xvid_free(dec->mbs);
108    
109            /* realloc */
110    
111          dec->mb_width = (dec->width + 15) / 16;          dec->mb_width = (dec->width + 15) / 16;
112          dec->mb_height = (dec->height + 15) / 16;          dec->mb_height = (dec->height + 15) / 16;
113    
114          dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE;          dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE;
115          dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE;          dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE;
         dec->low_delay = 0;  
116    
117          if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) {          if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) {
118                  xvid_free(dec);                  xvid_free(dec);
# Line 120  Line 124 
124                  xvid_free(dec);                  xvid_free(dec);
125                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
126          }          }
127    
128          // add by chenm001 <chenm001@163.com>          // add by chenm001 <chenm001@163.com>
129          // for support B-frame to reference last 2 frame          // for support B-frame to reference last 2 frame
130          if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) {          if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) {
# Line 136  Line 141 
141                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
142          }          }
143    
144            if (image_create(&dec->refh, dec->edged_width, dec->edged_height)) {
145                    image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
146                    image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
147                    image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
148                    image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);
149                    xvid_free(dec);
150                    return XVID_ERR_MEMORY;
151            }
152    
153          dec->mbs =          dec->mbs =
154                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,
155                                          CACHE_LINE);                                          CACHE_LINE);
# Line 144  Line 158 
158                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
159                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
160                  image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);
161                    image_destroy(&dec->refh, dec->edged_width, dec->edged_height);
162                  xvid_free(dec);                  xvid_free(dec);
163                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
164          }          }
   
165          memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);          memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);
166    
167          // add by chenm001 <chenm001@163.com>          // add by chenm001 <chenm001@163.com>
# Line 161  Line 175 
175                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
176                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
177                  image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);                  image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);
178                    image_destroy(&dec->refh, dec->edged_width, dec->edged_height);
179                  xvid_free(dec);                  xvid_free(dec);
180                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
181          }          }
182    
183          memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);          memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);
184    
185            return XVID_ERR_OK;
186    }
187    
188    
189    int
190    decoder_create(XVID_DEC_PARAM * param)
191    {
192            DECODER *dec;
193    
194            dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);
195            if (dec == NULL) {
196                    return XVID_ERR_MEMORY;
197            }
198            memset(dec, 0, sizeof(DECODER));
199    
200            param->handle = dec;
201    
202            dec->width = param->width;
203            dec->height = param->height;
204    
205            image_null(&dec->cur);
206            image_null(&dec->refn[0]);
207            image_null(&dec->refn[1]);
208            image_null(&dec->refn[2]);
209            image_null(&dec->refh);
210    
211            dec->mbs = NULL;
212            dec->last_mbs = NULL;
213    
214          init_timer();          init_timer();
215    
216          // add by chenm001 <chenm001@163.com>          // add by chenm001 <chenm001@163.com>
217          // for support B-frame to save reference frame's time          // for support B-frame to save reference frame's time
218          dec->frames = -1;          dec->frames = -1;
219          dec->time = dec->time_base = dec->last_time_base = 0;          dec->time = dec->time_base = dec->last_time_base = 0;
220            dec->low_delay = 0;
221    
222            dec->fixed_dimensions = (dec->width > 0 && dec->height > 0);
223    
224            if (dec->fixed_dimensions)
225                    return decoder_resize(dec);
226            else
227          return XVID_ERR_OK;          return XVID_ERR_OK;
228  }  }
229    
# Line 186  Line 236 
236          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
237          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
238          image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height);
239            image_destroy(&dec->refh, dec->edged_width, dec->edged_height);
240          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
241          xvid_free(dec);          xvid_free(dec);
242    
# Line 268  Line 319 
319                  start_timer();                  start_timer();
320                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       // coded
321                  {                  {
322                          get_intra_block(bs, &block[i * 64], pMB->acpred_directions[i],                          int direction = dec->alternate_vertical_scan ?
323                                                          start_coeff);                                  2 : pMB->acpred_directions[i];
324    
325                            get_intra_block(bs, &block[i * 64], direction, start_coeff);
326                  }                  }
327                  stop_coding_timer();                  stop_coding_timer();
328    
# Line 311  Line 364 
364    
365  #define SIGN(X) (((X)>0)?1:-1)  #define SIGN(X) (((X)>0)?1:-1)
366  #define ABS(X) (((X)>0)?(X):-(X))  #define ABS(X) (((X)>0)?(X):-(X))
 static const uint32_t roundtab[16] =  
         { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 };  
   
367    
368  // decode an inter macroblock  // decode an inter macroblock
369    
# Line 348  Line 398 
398                  uv_dx = pMB->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
399                  uv_dy = pMB->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
400    
401                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;                  if (dec->quarterpel)
402                  uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;                  {
403                            uv_dx /= 2;
404                            uv_dy /= 2;
405                    }
406    
407                    uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
408                    uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
409    
410                    start_timer();
411                    if(dec->quarterpel) {
412                            interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
413                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos,
414                                                                                pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);
415                    }
416                    else {
417                            interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,
418                                                                      pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);
419                            interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos,
420                                                                  pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);
421                            interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8,
422                                                                      pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);
423                            interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8,
424                                                                      pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);
425                    }
426    
427                    interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,
428                                                              uv_dx, uv_dy, stride2, rounding);
429                    interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,
430                                                              uv_dx, uv_dy, stride2, rounding);
431                    stop_comp_timer();
432    
433          } else {          } else {
434                  int sum;                  int sum;
435    
436                    if(dec->quarterpel)
437                            sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2);
438                    else
439                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;
                 uv_dx =  
                         (sum ==  
                          0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
                                                                   (ABS(sum) / 16) * 2));  
440    
441                    uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];
442    
443                    if(dec->quarterpel)
444                            sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2);
445                    else
446                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
447                  uv_dy =  
448                          (sum ==                  uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];
                          0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
                                                                   (ABS(sum) / 16) * 2));  
         }  
449    
450          start_timer();          start_timer();
451                    if(dec->quarterpel) {
452                            interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
453                                                                              dec->refh.y + 128, 16*x_pos, 16*y_pos,
454                                                                              pMB->mvs[0].x, pMB->mvs[0].y, stride,  rounding);
455                            interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
456                                                                              dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,
457                                                                              pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);
458                            interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
459                                                                              dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,
460                                                                              pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);
461                            interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64,
462                                                                              dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,
463                                                                              pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);
464                    }
465                    else {
466          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos, 16 * y_pos,          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos, 16 * y_pos,
467                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding);                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding);
468          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos + 8,                          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos,
469                                                    16 * y_pos, pMB->mvs[1].x, pMB->mvs[1].y, stride,                                                                    pMB->mvs[1].x, pMB->mvs[1].y, stride,  rounding);
470                                                    rounding);                          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8,
471          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos,                                                                    pMB->mvs[2].x, pMB->mvs[2].y, stride,  rounding);
472                                                    16 * y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride,                          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8,
473                                                    rounding);                                                                    pMB->mvs[3].x, pMB->mvs[3].y, stride,  rounding);
474          interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos + 8,                  }
475                                                    16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride,  
                                                   rounding);  
476          interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,
477                                                    uv_dx, uv_dy, stride2, rounding);                                                    uv_dx, uv_dy, stride2, rounding);
478          interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,
479                                                    uv_dx, uv_dy, stride2, rounding);                                                    uv_dx, uv_dy, stride2, rounding);
480          stop_comp_timer();          stop_comp_timer();
481            }
482    
483          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
484                    int direction = dec->alternate_vertical_scan ? 2 : 0;
485    
486                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       // coded
487                  {                  {
488                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
489    
490                          start_timer();                          start_timer();
491                          get_inter_block(bs, &block[i * 64]);                          get_inter_block(bs, &block[i * 64], direction);
492                          stop_coding_timer();                          stop_coding_timer();
493    
494                          start_timer();                          start_timer();
# Line 432  Line 530 
530  void  void
531  decoder_iframe(DECODER * dec,  decoder_iframe(DECODER * dec,
532                             Bitstream * bs,                             Bitstream * bs,
533                               int reduced_resolution,
534                             int quant,                             int quant,
535                             int intra_dc_threshold)                             int intra_dc_threshold)
536  {  {
537          uint32_t bound;          uint32_t bound;
538          uint32_t x, y;          uint32_t x, y;
539            int mb_width = dec->mb_width;
540            int mb_height = dec->mb_height;
541    
542            if (reduced_resolution)
543            {
544                    mb_width /= 2;
545                    mb_height /= 2;
546            }
547    
548          bound = 0;          bound = 0;
549    
550          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < mb_height; y++) {
551                  for (x = 0; x < dec->mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
552                          MACROBLOCK *mb;                          MACROBLOCK *mb;
553                          uint32_t mcbpc;                          uint32_t mcbpc;
554                          uint32_t cbpc;                          uint32_t cbpc;
# Line 454  Line 561 
561    
562                          if (check_resync_marker(bs, 0))                          if (check_resync_marker(bs, 0))
563                          {                          {
564                                  bound = read_video_packet_header(bs, 0, &quant);                                  bound = read_video_packet_header(bs, dec, 0,
565                                                            &quant, NULL, NULL, &intra_dc_threshold);
566                                  x = bound % dec->mb_width;                                  x = bound % dec->mb_width;
567                                  y = bound / dec->mb_width;                                  y = bound / dec->mb_width;
568                          }                          }
# Line 492  Line 600 
600    
601                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
602                                                          intra_dc_threshold, bound);                                                          intra_dc_threshold, bound);
603    
604                  }                  }
605                    if(dec->out_frm)
606                      output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,dec->mb_width);
607          }          }
608    
609  }  }
# Line 541  Line 652 
652    
653          mv->x = mv_x;          mv->x = mv_x;
654          mv->y = mv_y;          mv->y = mv_y;
655    }
656    
657    
658    
659    static __inline int gmc_sanitize(int value, int quarterpel, int fcode)
660    {
661            int length = 1 << (fcode+4);
662    
663            if (quarterpel) value *= 2;
664    
665            if (value < -length)
666                    return -length;
667            else if (value >= length)
668                    return length-1;
669            else return value;
670  }  }
671    
672    
673    /* for P_VOP set gmc_mv to NULL */
674  void  void
675  decoder_pframe(DECODER * dec,  decoder_pframe(DECODER * dec,
676                             Bitstream * bs,                             Bitstream * bs,
677                             int rounding,                             int rounding,
678                               int reduced_resolution,
679                             int quant,                             int quant,
680                             int fcode,                             int fcode,
681                             int intra_dc_threshold)                             int intra_dc_threshold,
682                               VECTOR * gmc_mv)
683  {  {
684    
685          uint32_t x, y;          uint32_t x, y;
686          uint32_t bound;          uint32_t bound;
687            int cp_mb, st_mb;
688    
689          start_timer();          start_timer();
690          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
691                                     dec->width, dec->height, dec->interlacing);                                     dec->width, dec->height);
692          stop_edges_timer();          stop_edges_timer();
693    
694          bound = 0;          bound = 0;
695    
696          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < dec->mb_height; y++) {
697                    cp_mb = st_mb = 0;
698                  for (x = 0; x < dec->mb_width; x++) {                  for (x = 0; x < dec->mb_width; x++) {
699                          MACROBLOCK *mb;                          MACROBLOCK *mb;
700    
# Line 574  Line 704 
704    
705                          if (check_resync_marker(bs, fcode - 1))                          if (check_resync_marker(bs, fcode - 1))
706                          {                          {
707                                  bound = read_video_packet_header(bs, fcode - 1, &quant);                                  bound = read_video_packet_header(bs, dec, fcode - 1,
708                                            &quant, &fcode, NULL, &intra_dc_threshold);
709                                  x = bound % dec->mb_width;                                  x = bound % dec->mb_width;
710                                  y = bound / dec->mb_width;                                  y = bound / dec->mb_width;
711                          }                          }
# Line 591  Line 722 
722                                  uint32_t cbpy;                                  uint32_t cbpy;
723                                  uint32_t cbp;                                  uint32_t cbp;
724                                  uint32_t intra;                                  uint32_t intra;
725                                    int mcsel = 0;          // mcsel: '0'=local motion, '1'=GMC
726    
727                                    cp_mb++;
728                                  mcbpc = get_mcbpc_inter(bs);                                  mcbpc = get_mcbpc_inter(bs);
729                                  mb->mode = mcbpc & 7;                                  mb->mode = mcbpc & 7;
730                                  cbpc = (mcbpc >> 4);                                  cbpc = (mcbpc >> 4);
# Line 606  Line 739 
739                                          acpred_flag = BitstreamGetBit(bs);                                          acpred_flag = BitstreamGetBit(bs);
740                                  }                                  }
741    
742                                    if (gmc_mv && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q))
743                                    {
744                                            mcsel = BitstreamGetBit(bs);
745                                    }
746    
747                                  cbpy = get_cbpy(bs, intra);                                  cbpy = get_cbpy(bs, intra);
748                                  DPRINTF(DPRINTF_MB, "cbpy %i", cbpy);                                  DPRINTF(DPRINTF_MB, "cbpy %i", cbpy);
749    
# Line 625  Line 763 
763                                  mb->quant = quant;                                  mb->quant = quant;
764    
765                                  if (dec->interlacing) {                                  if (dec->interlacing) {
766                                            if (cbp || intra) {
767                                          mb->field_dct = BitstreamGetBit(bs);                                          mb->field_dct = BitstreamGetBit(bs);
768                                          DEBUG1("decp: field_dct: ", mb->field_dct);                                          DEBUG1("decp: field_dct: ", mb->field_dct);
769                                            }
770    
771                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
772                                                  mb->field_pred = BitstreamGetBit(bs);                                                  mb->field_pred = BitstreamGetBit(bs);
# Line 642  Line 782 
782                                  }                                  }
783    
784                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
785                                          if (dec->interlacing && mb->field_pred) {  
786                                            if (mcsel)
787                                            {
788                                                    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);
789                                                    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);
790    
791                                            } else if (dec->interlacing && mb->field_pred) {
792                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],
793                                                                                    fcode, bound);                                                                                    fcode, bound);
794                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1],
# Line 655  Line 801 
801                                                  mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =                                                  mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =
802                                                          mb->mvs[0].y;                                                          mb->mvs[0].y;
803                                          }                                          }
804                                  } else if (mb->mode ==                                  } else if (mb->mode == MODE_INTER4V ) {
805                                                     MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */ ) {  
806                                          get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound);                                          get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound);
807                                          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);
808                                          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);
# Line 674  Line 820 
820    
821                                  decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant,                                  decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant,
822                                                                  rounding);                                                                  rounding);
823                          } else                          // not coded  
824                            }
825                            else if (gmc_mv)        /* not coded S_VOP macroblock */
826                            {
827                                    mb->mode = MODE_NOT_CODED;
828                                    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);
829                                    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);
830                                    decoder_mbinter(dec, mb, x, y, 0, 0, bs, quant, rounding);
831                            }
832                            else    /* not coded P_VOP macroblock */
833                          {                          {
                                 //DEBUG2("P-frame MB at (X,Y)=",x,y);  
834                                  mb->mode = MODE_NOT_CODED;                                  mb->mode = MODE_NOT_CODED;
835                                  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;
836                                  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;
   
837                                  // copy macroblock directly from ref to cur                                  // copy macroblock directly from ref to cur
838    
839                                  start_timer();                                  start_timer();
# Line 720  Line 873 
873                                                                   dec->edged_width / 2);                                                                   dec->edged_width / 2);
874    
875                                  stop_transfer_timer();                                  stop_transfer_timer();
876    
877                                    if(dec->out_frm && cp_mb > 0) {
878                                      output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb);
879                                      cp_mb = 0;
880                          }                          }
881                                    st_mb = x+1;
882                  }                  }
883          }          }
884                    if(dec->out_frm && cp_mb > 0)
885                      output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb);
886            }
887  }  }
888    
889    
# Line 804  Line 965 
965                  uv_dx = pMB->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
966                  uv_dy = pMB->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
967    
968                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;                  if (dec->quarterpel)
969                  uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;                  {
970                            uv_dx /= 2;
971                            uv_dy /= 2;
972                    }
973    
974                    uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
975                    uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
976          } else {          } else {
977                  int sum;                  int sum;
978    
979                    if(dec->quarterpel)
980                            sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2);
981                    else
982                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;
                 uv_dx =  
                         (sum ==  
                          0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
                                                                   (ABS(sum) / 16) * 2));  
983    
984                    uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];
985    
986                    if(dec->quarterpel)
987                            sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2);
988                    else
989                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
990                  uv_dy =  
991                          (sum ==                  uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];
                          0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
                                                                   (ABS(sum) / 16) * 2));  
992          }          }
993    
994          start_timer();          start_timer();
995            if(dec->quarterpel) {
996                    interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->refh.y, dec->refh.y + 64,
997                                                                        dec->refh.y + 128, 16*x_pos, 16*y_pos,
998                                                                        pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
999            }
1000            else {
1001          interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos, 16 * y_pos,          interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos, 16 * y_pos,
1002                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1003          interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos + 8,                  interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos,
1004                                                    16 * y_pos, pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);                                                        pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
1005          interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos,                  interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos, 16*y_pos + 8,
1006                                                    16 * y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride,                                                            pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
1007                                                    0);                  interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos + 8,
1008          interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos + 8,                                                            pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);
1009                                                    16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride,          }
1010                                                    0);  
1011          interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos,
1012                                                    uv_dx, uv_dy, stride2, 0);                                                    uv_dx, uv_dy, stride2, 0);
1013          interpolate8x8_switch(dec->cur.v, dec->refn[ref].v, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->cur.v, dec->refn[ref].v, 8 * x_pos, 8 * y_pos,
# Line 840  Line 1015 
1015          stop_comp_timer();          stop_comp_timer();
1016    
1017          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
1018                    int direction = dec->alternate_vertical_scan ? 2 : 0;
1019    
1020                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       // coded
1021                  {                  {
1022                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
1023    
1024                          start_timer();                          start_timer();
1025                          get_inter_block(bs, &block[i * 64]);                          get_inter_block(bs, &block[i * 64], direction);
1026                          stop_coding_timer();                          stop_coding_timer();
1027    
1028                          start_timer();                          start_timer();
# Line 883  Line 1060 
1060          stop_transfer_timer();          stop_transfer_timer();
1061  }  }
1062    
   
1063  // add by MinChen <chenm001@163.com>  // add by MinChen <chenm001@163.com>
1064  // decode an B-frame direct &  inter macroblock  // decode an B-frame direct &  inter macroblock
1065  void  void
# Line 918  Line 1094 
1094                  uv_dx = pMB->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
1095                  uv_dy = pMB->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
1096    
                 uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;  
                 uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;  
   
1097                  b_uv_dx = pMB->b_mvs[0].x;                  b_uv_dx = pMB->b_mvs[0].x;
1098                  b_uv_dy = pMB->b_mvs[0].y;                  b_uv_dy = pMB->b_mvs[0].y;
1099    
1100                  b_uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;                  if (dec->quarterpel)
1101                  b_uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;                  {
1102                            uv_dx /= 2;
1103                            uv_dy /= 2;
1104    
1105                            b_uv_dx /= 2;
1106                            b_uv_dy /= 2;
1107                    }
1108    
1109                    uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
1110                    uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
1111    
1112                    b_uv_dx = (b_uv_dx >> 1) + roundtab_79[b_uv_dx & 0x3];
1113                    b_uv_dy = (b_uv_dy >> 1) + roundtab_79[b_uv_dy & 0x3];
1114          } else {          } else {
1115                  int sum;                  int sum;
1116    
1117                    if(dec->quarterpel)
1118                            sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2);
1119                    else
1120                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;                  sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;
                 uv_dx =  
                         (sum ==  
                          0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
                                                                   (ABS(sum) / 16) * 2));  
1121    
1122                    uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];
1123    
1124                    if(dec->quarterpel)
1125                            sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2);
1126                    else
1127                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
1128                  uv_dy =  
1129                          (sum ==                  uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];
1130                           0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
1131                                                                    (ABS(sum) / 16) * 2));  
1132                    if(dec->quarterpel)
1133                  sum =                          sum = (pMB->b_mvs[0].x / 2) + (pMB->b_mvs[1].x / 2) + (pMB->b_mvs[2].x / 2) + (pMB->b_mvs[3].x / 2);
1134                          pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x +                  else
1135                          pMB->b_mvs[3].x;                          sum = pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + pMB->b_mvs[3].x;
1136                  b_uv_dx =  
1137                          (sum ==                  b_uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];
1138                           0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
1139                                                                    (ABS(sum) / 16) * 2));                  if(dec->quarterpel)
1140                            sum = (pMB->b_mvs[0].y / 2) + (pMB->b_mvs[1].y / 2) + (pMB->b_mvs[2].y / 2) + (pMB->b_mvs[3].y / 2);
1141                  sum =                  else
1142                          pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y +                          sum = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y;
1143                          pMB->b_mvs[3].y;  
1144                  b_uv_dy =                  b_uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];
                         (sum ==  
                          0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] +  
                                                                   (ABS(sum) / 16) * 2));  
1145          }          }
1146    
1147    
1148          start_timer();          start_timer();
1149            if(dec->quarterpel) {
1150                    if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q))
1151                            interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1152                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos,
1153                                                                                pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1154                    else {
1155                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1156                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos,
1157                                                                                pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1158                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1159                                                                                dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,
1160                                                                                pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
1161                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1162                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,
1163                                                                                pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
1164                            interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64,
1165                                                                                dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,
1166                                                                                pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);
1167                    }
1168            }
1169            else {
1170          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos,          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos,
1171                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);                                                    pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
1172          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, 16 * y_pos,          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, 16 * y_pos,
# Line 969  Line 1176 
1176          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8,          interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8,
1177                                                    16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride,                                                    16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride,
1178                                                    0);                                                    0);
1179            }
1180    
1181          interpolate8x8_switch(dec->cur.u, forward.u, 8 * x_pos, 8 * y_pos, uv_dx,          interpolate8x8_switch(dec->cur.u, forward.u, 8 * x_pos, 8 * y_pos, uv_dx,
1182                                                    uv_dy, stride2, 0);                                                    uv_dy, stride2, 0);
1183          interpolate8x8_switch(dec->cur.v, forward.v, 8 * x_pos, 8 * y_pos, uv_dx,          interpolate8x8_switch(dec->cur.v, forward.v, 8 * x_pos, 8 * y_pos, uv_dx,
1184                                                    uv_dy, stride2, 0);                                                    uv_dy, stride2, 0);
1185    
1186    
1187            if(dec->quarterpel) {
1188                    if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q))
1189                            interpolate16x16_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1190                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos,
1191                                                                                pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1192                    else {
1193                            interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1194                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos,
1195                                                                                pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1196                            interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1197                                                                                dec->refh.y + 128, 16*x_pos + 8, 16*y_pos,
1198                                                                                pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0);
1199                            interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1200                                                                                dec->refh.y + 128, 16*x_pos, 16*y_pos + 8,
1201                                                                                pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0);
1202                            interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64,
1203                                                                                dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8,
1204                                                                                pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0);
1205                    }
1206            }
1207            else {
1208          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos, 16 * y_pos,          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos, 16 * y_pos,
1209                                                    pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);                                                    pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
1210          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,
# Line 986  Line 1216 
1216          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,          interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8,
1217                                                    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,
1218                                                    stride, 0);                                                    stride, 0);
1219            }
1220    
1221          interpolate8x8_switch(dec->refn[2].u, backward.u, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->refn[2].u, backward.u, 8 * x_pos, 8 * y_pos,
1222                                                    b_uv_dx, b_uv_dy, stride2, 0);                                                    b_uv_dx, b_uv_dy, stride2, 0);
1223          interpolate8x8_switch(dec->refn[2].v, backward.v, 8 * x_pos, 8 * y_pos,          interpolate8x8_switch(dec->refn[2].v, backward.v, 8 * x_pos, 8 * y_pos,
1224                                                    b_uv_dx, b_uv_dy, stride2, 0);                                                    b_uv_dx, b_uv_dy, stride2, 0);
1225    
1226          interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos, 16 * y_pos,          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1227                                           stride);                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1228          interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos + 8, 16 * y_pos,                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos,
1229                                           stride);                                                  stride, 1, 8);
1230          interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos, 16 * y_pos + 8,  
1231                                           stride);          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1232          interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos + 8,                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1233                                           16 * y_pos + 8, stride);                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8,
1234          interpolate8x8_c(dec->cur.u, dec->refn[2].u, 8 * x_pos, 8 * y_pos,                                                  stride, 1, 8);
1235                                           stride2);  
1236          interpolate8x8_c(dec->cur.v, dec->refn[2].v, 8 * x_pos, 8 * y_pos,          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1237                                           stride2);                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1238                                                    dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1239                                                    stride, 1, 8);
1240    
1241            interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1242                                                    dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1243                                                    dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1244                                                    stride, 1, 8);
1245    
1246            interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1247                                                    dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1248                                                    dec->refn[2].u + (8 * y_pos * stride2) + 8 * x_pos,
1249                                                    stride2, 1, 8);
1250    
1251            interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1252                                                    dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1253                                                    dec->refn[2].v + (8 * y_pos * stride2) + 8 * x_pos,
1254                                                    stride2, 1, 8);
1255    
1256          stop_comp_timer();          stop_comp_timer();
1257    
1258          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
1259                    int direction = dec->alternate_vertical_scan ? 2 : 0;
1260    
1261                  if (cbp & (1 << (5 - i)))       // coded                  if (cbp & (1 << (5 - i)))       // coded
1262                  {                  {
1263                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear                          memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
1264    
1265                          start_timer();                          start_timer();
1266                          get_inter_block(bs, &block[i * 64]);                          get_inter_block(bs, &block[i * 64], direction);
1267                          stop_coding_timer();                          stop_coding_timer();
1268    
1269                          start_timer();                          start_timer();
# Line 1106  Line 1358 
1358    
1359          start_timer();          start_timer();
1360          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
1361                                     dec->width, dec->height, dec->interlacing);                                     dec->width, dec->height);
1362          image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height,
1363                                     dec->width, dec->height, dec->interlacing);                                     dec->width, dec->height);
1364          stop_edges_timer();          stop_edges_timer();
1365    
1366  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
# Line 1176  Line 1428 
1428  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
1429          BFRAME_DEBUG          BFRAME_DEBUG
1430  #endif  #endif
1431    
1432                          switch (mb->mb_type) {                          switch (mb->mb_type) {
1433                          case MODE_DIRECT:                          case MODE_DIRECT:
1434                                  get_b_motion_vector(dec, bs, x, y, &mv, 1, zeromv);                                  get_b_motion_vector(dec, bs, x, y, &mv, 1, zeromv);
1435    
1436                          case MODE_DIRECT_NONE_MV:                          case MODE_DIRECT_NONE_MV:
1437                                  {                               // Because this file is a C file not C++ so I use '{' to define var                                  {
1438                                          const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp;                                          const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp;
1439                                          int i;                                          int i;
1440    
# Line 1241  Line 1494 
1494                                  break;                                  break;
1495    
1496                          default:                          default:
1497                                  //DEBUG1("Not support B-frame mb_type =", mb->mb_type);                                  DEBUG1("Not support B-frame mb_type =", mb->mb_type);
                                 ;  
1498                          }                          }
1499    
1500                  }                                               // end of FOR                  }                                               // end of FOR
# Line 1269  Line 1521 
1521    
1522  int  int
1523  decoder_decode(DECODER * dec,  decoder_decode(DECODER * dec,
1524                             XVID_DEC_FRAME * frame)                             XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats)
1525  {  {
1526    
1527          Bitstream bs;          Bitstream bs;
1528          uint32_t rounding;          uint32_t rounding;
1529            uint32_t reduced_resolution;
1530          uint32_t quant;          uint32_t quant;
1531          uint32_t fcode_forward;          uint32_t fcode_forward;
1532          uint32_t fcode_backward;          uint32_t fcode_backward;
1533          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
1534            VECTOR gmc_mv[5];
1535          uint32_t vop_type;          uint32_t vop_type;
1536            int success = 0;
1537    
1538          start_global_timer();          start_global_timer();
1539    
1540            dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL;
1541    
1542          BitstreamInit(&bs, frame->bitstream, frame->length);          BitstreamInit(&bs, frame->bitstream, frame->length);
1543    
1544            // XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's
1545            if(frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f)
1546            {
1547                    if (stats)
1548                            stats->notify = XVID_DEC_VOP;
1549                    frame->length = 1;
1550                    image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width,
1551                                             frame->image, frame->stride, frame->colorspace, dec->interlacing);
1552                    emms();
1553                    return XVID_ERR_OK;
1554            }
1555    
1556    start:
1557          // add by chenm001 <chenm001@163.com>          // add by chenm001 <chenm001@163.com>
1558          // for support B-frame to reference last 2 frame          // for support B-frame to reference last 2 frame
1559          dec->frames++;          dec->frames++;
1560    
1561    xxx:
1562          vop_type =          vop_type =
1563                  BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode_forward,                  BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,
1564                                                           &fcode_backward, &intra_dc_threshold);                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, gmc_mv);
1565    
1566            DPRINTF(DPRINTF_HEADER, "vop_type=%i", vop_type);
1567    
1568            if (vop_type == -1 && success)
1569                    goto done;
1570    
1571            if (vop_type == -2 || vop_type == -3)
1572            {
1573                    if (vop_type == -3)
1574                            decoder_resize(dec);
1575    
1576                    if (stats)
1577                    {
1578                            stats->notify = XVID_DEC_VOL;
1579                            stats->data.vol.general = 0;
1580                            if (dec->interlacing)
1581                                    stats->data.vol.general |= XVID_INTERLACING;
1582                            stats->data.vol.width = dec->width;
1583                            stats->data.vol.height = dec->height;
1584                            stats->data.vol.aspect_ratio = dec->aspect_ratio;
1585                            stats->data.vol.par_width = dec->par_width;
1586                            stats->data.vol.par_height = dec->par_height;
1587                            frame->length = BitstreamPos(&bs) / 8;
1588                            return XVID_ERR_OK;
1589                    }
1590                    goto xxx;
1591            }
1592    
1593          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
1594    
1595          switch (vop_type) {          switch (vop_type) {
1596          case P_VOP:          case P_VOP:
1597                  decoder_pframe(dec, &bs, rounding, quant, fcode_forward,                  decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,
1598                                             intra_dc_threshold);                                                  fcode_forward, intra_dc_threshold, NULL);
1599  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1600                  DEBUG1("P_VOP  Time=", dec->time);                  DEBUG1("P_VOP  Time=", dec->time);
1601  #endif  #endif
1602                  break;                  break;
1603    
1604          case I_VOP:          case I_VOP:
1605                  decoder_iframe(dec, &bs, quant, intra_dc_threshold);                  decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);
1606  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1607                  DEBUG1("I_VOP  Time=", dec->time);                  DEBUG1("I_VOP  Time=", dec->time);
1608  #endif  #endif
# Line 1322  Line 1621 
1621  #endif  #endif
1622                  break;                  break;
1623    
1624            case S_VOP :
1625                    decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,
1626                                                    fcode_forward, intra_dc_threshold, gmc_mv);
1627                    break;
1628    
1629          case N_VOP:                             // vop not coded          case N_VOP:                             // vop not coded
1630                  // when low_delay==0, N_VOP's should interpolate between the past and future frames                  // when low_delay==0, N_VOP's should interpolate between the past and future frames
1631                  image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);                  image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);
1632    #ifdef BFRAMES_DEC
1633                    DEBUG1("N_VOP  Time=", dec->time);
1634    #endif
1635                  break;                  break;
1636    
1637          default:          default:
1638                  return XVID_ERR_FAIL;                  if (stats)
1639          }                          stats->notify = 0;
1640    
1641  #ifdef BFRAMES_DEC_DEBUG                  emms();
1642          if (frame->length != BitstreamPos(&bs) / 8){                  return XVID_ERR_FAIL;
                 DEBUG2("InLen/UseLen",frame->length, BitstreamPos(&bs) / 8);  
1643          }          }
 #endif  
         frame->length = BitstreamPos(&bs) / 8;  
1644    
1645            BitstreamByteAlign(&bs);
1646    
1647  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1648          // test if no B_VOP          // test if no B_VOP
1649          if (dec->low_delay) {          if (dec->low_delay || dec->frames == 0 || ((dec->packed_mode) && !(frame->length > BitstreamPos(&bs) / 8))) {
1650  #endif  #endif
1651          image_output(&dec->cur, dec->width, dec->height, dec->edged_width,          image_output(&dec->cur, dec->width, dec->height, dec->edged_width,
1652                                           frame->image, frame->stride, frame->colorspace);                                           frame->image, frame->stride, frame->colorspace, dec->interlacing);
1653    
1654  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1655          } else {          } else {
1656                  if (dec->frames >= 0) {                  if (dec->frames >= 1 && !(dec->packed_mode)) {
1657                          start_timer();                          start_timer();
1658                          if ((vop_type == I_VOP || vop_type == P_VOP)) {                          if ((vop_type == I_VOP || vop_type == P_VOP || vop_type == S_VOP)) {
1659                                  image_output(&dec->refn[0], dec->width, dec->height,                                  image_output(&dec->refn[0], dec->width, dec->height,
1660                                                           dec->edged_width, frame->image, frame->stride,                                                           dec->edged_width, frame->image, frame->stride,
1661                                                           frame->colorspace);                                                           frame->colorspace, dec->interlacing);
1662                          } else if (vop_type == B_VOP) {                          } else if (vop_type == B_VOP) {
1663                                  image_output(&dec->cur, dec->width, dec->height,                                  image_output(&dec->cur, dec->width, dec->height,
1664                                                           dec->edged_width, frame->image, frame->stride,                                                           dec->edged_width, frame->image, frame->stride,
1665                                                           frame->colorspace);                                                           frame->colorspace, dec->interlacing);
1666                          }                          }
1667                          stop_conv_timer();                          stop_conv_timer();
1668                  }                  }
1669          }          }
1670  #endif  #endif
1671    
1672          if (vop_type == I_VOP || vop_type == P_VOP) {          if (vop_type == I_VOP || vop_type == P_VOP || vop_type == S_VOP) {
1673                  image_swap(&dec->refn[0], &dec->refn[1]);                  image_swap(&dec->refn[0], &dec->refn[1]);
1674                  image_swap(&dec->cur, &dec->refn[0]);                  image_swap(&dec->cur, &dec->refn[0]);
1675    
# Line 1380  Line 1685 
1685                          mb_swap(&dec->mbs, &dec->last_mbs);                          mb_swap(&dec->mbs, &dec->last_mbs);
1686          }          }
1687    
1688            success = 1;
1689    
1690            if (frame->length > BitstreamPos(&bs) / 8)      // multiple vops packed together
1691                    goto start;
1692    
1693    done :
1694    
1695            frame->length = BitstreamPos(&bs) / 8;
1696    
1697            if (stats)
1698            {
1699                    stats->notify = XVID_DEC_VOP;
1700                    stats->data.vop.time_base = (int)dec->time_base;
1701                    stats->data.vop.time_increment = 0;     //XXX: todo
1702            }
1703    
1704          emms();          emms();
1705    
1706          stop_global_timer();          stop_global_timer();

Legend:
Removed from v.306  
changed lines
  Added in v.667

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