[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.3, Thu Oct 10 12:16:00 2002 UTC revision 1.37.2.11, Tue Nov 12 15:53:36 2002 UTC
# 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 157  Line 162 
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 178  Line 182 
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 325  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 364  Line 400 
400    
401                  if (dec->quarterpel)                  if (dec->quarterpel)
402                  {                  {
403                          uv_dx = (uv_dx >> 1) | (uv_dx & 1);                          uv_dx /= 2;
404                          uv_dy = (uv_dy >> 1) | (uv_dy & 1);                          uv_dy /= 2;
405                  }                  }
406    
407                  uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;                  uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
408                  uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;                  uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
409    
410                  start_timer();                  start_timer();
411                  if(dec->quarterpel) {                  if(dec->quarterpel) {
# Line 396  Line 432 
432    
433          } else {          } else {
434                  int sum;                  int sum;
                 sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;  
435    
436                  if (dec->quarterpel)                  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                          sum /= 2;                  else
439                  }                          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                  sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;                  uv_dx = (sum >> 3) + roundtab_76[sum & 0xf];
442    
443                  if (dec->quarterpel)                  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                          sum /= 2;                  else
446                  }                          sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
447    
448                  uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2));                  uv_dy = (sum >> 3) + roundtab_76[sum & 0xf];
449    
450                  start_timer();                  start_timer();
451                  if(dec->quarterpel) {                  if(dec->quarterpel) {
# Line 497  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 519  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 557  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)                  if(dec->out_frm)
606                    output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,dec->mb_width);                    output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,dec->mb_width);
   
607          }          }
608    
609  }  }
# Line 609  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;
# Line 644  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 661  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++;                                  cp_mb++;
728                                  mcbpc = get_mcbpc_inter(bs);                                  mcbpc = get_mcbpc_inter(bs);
# Line 677  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 715  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 747  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 791  Line 871 
871                                                                   dec->refn[0].v +                                                                   dec->refn[0].v +
872                                                                   (8 * y) * dec->edged_width / 2 + (8 * x),                                                                   (8 * y) * dec->edged_width / 2 + (8 * x),
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) {                                  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);                                    output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb);
879                                    cp_mb = 0;                                    cp_mb = 0;
# Line 964  Line 1046 
1046          stop_transfer_timer();          stop_transfer_timer();
1047  }  }
1048    
   
1049  // add by MinChen <chenm001@163.com>  // add by MinChen <chenm001@163.com>
1050  // decode an B-frame direct &  inter macroblock  // decode an B-frame direct &  inter macroblock
1051  void  void
# Line 1082  Line 1163 
1163                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8,                                                  dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8,
1164                                                  stride, 0);                                                  stride, 0);
1165    
1166          interpolate8x8_avg2(dec->cur.y + (16 * (y_pos + 8) * stride) + 16 * x_pos,          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1167                                                  dec->cur.y + (16 * (y_pos + 8) * stride) + 16 * x_pos,                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1168                                                  dec->refn[2].y + (16 * (y_pos + 8) * stride) + 16 * x_pos,                                                  dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1169                                                  stride, 0);                                                  stride, 0);
1170    
1171          interpolate8x8_avg2(dec->cur.y + (16 * (y_pos + 8) * stride) + 16 * x_pos + 8,          interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1172                                                  dec->cur.y + (16 * (y_pos + 8) * stride) + 16 * x_pos + 8,                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1173                                                  dec->refn[2].y + (16 * (y_pos + 8) * stride) + 16 * x_pos + 8,                                                  dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1174                                                  stride, 0);                                                  stride, 0);
1175    
1176          interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride) + 8 * x_pos,          interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1177                                                  dec->cur.u + (8 * y_pos * stride) + 8 * x_pos,                                                  dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1178                                                  dec->refn[2].u + (8 * y_pos * stride) + 8 * x_pos,                                                  dec->refn[2].u + (8 * y_pos * stride2) + 8 * x_pos,
1179                                                  stride2, 0);                                                  stride2, 0);
1180    
1181          interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride) + 8 * x_pos,          interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1182                                                  dec->cur.v + (8 * y_pos * stride) + 8 * x_pos,                                                  dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1183                                                  dec->refn[2].v + (8 * y_pos * stride) + 8 * x_pos,                                                  dec->refn[2].v + (8 * y_pos * stride2) + 8 * x_pos,
1184                                                  stride2, 0);                                                  stride2, 0);
1185    
1186          stop_comp_timer();          stop_comp_timer();
# Line 1370  Line 1451 
1451    
1452  int  int
1453  decoder_decode(DECODER * dec,  decoder_decode(DECODER * dec,
1454                             XVID_DEC_FRAME * frame)                             XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats)
1455  {  {
1456    
1457          Bitstream bs;          Bitstream bs;
1458          uint32_t rounding;          uint32_t rounding;
1459            uint32_t reduced_resolution;
1460          uint32_t quant;          uint32_t quant;
1461          uint32_t fcode_forward;          uint32_t fcode_forward;
1462          uint32_t fcode_backward;          uint32_t fcode_backward;
1463          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
1464            VECTOR gmc_mv[5];
1465          uint32_t vop_type;          uint32_t vop_type;
1466    
1467          start_global_timer();          start_global_timer();
# Line 1387  Line 1470 
1470    
1471          BitstreamInit(&bs, frame->bitstream, frame->length);          BitstreamInit(&bs, frame->bitstream, frame->length);
1472    
1473            // XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's
1474            if(frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f)
1475            {
1476                    if (stats)
1477                            stats->notify = XVID_DEC_VOP;
1478                    frame->length = 1;
1479                    image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width,
1480                                             frame->image, frame->stride, frame->colorspace, dec->interlacing);
1481                    emms();
1482                    return XVID_ERR_OK;
1483            }
1484    
1485    start:
1486          // add by chenm001 <chenm001@163.com>          // add by chenm001 <chenm001@163.com>
1487          // for support B-frame to reference last 2 frame          // for support B-frame to reference last 2 frame
1488          dec->frames++;          dec->frames++;
1489    
1490    xxx:
1491          vop_type =          vop_type =
1492                  BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode_forward,                  BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,
1493                                                           &fcode_backward, &intra_dc_threshold);                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, gmc_mv);
1494    
1495            DPRINTF(DPRINTF_HEADER, "vop_type=%i", vop_type);
1496    
1497            if (vop_type == -2 || vop_type == -3)
1498            {
1499                    if (vop_type == -3)
1500                            decoder_resize(dec);
1501    
1502                    if (stats)
1503                    {
1504                            stats->notify = XVID_DEC_VOL;
1505                            stats->data.vol.general = 0;
1506                            if (dec->interlacing)
1507                                    stats->data.vol.general |= XVID_INTERLACING;
1508                            stats->data.vol.width = dec->width;
1509                            stats->data.vol.height = dec->height;
1510                            stats->data.vol.aspect_ratio = dec->aspect_ratio;
1511                            stats->data.vol.par_width = dec->par_width;
1512                            stats->data.vol.par_height = dec->par_height;
1513                            frame->length = BitstreamPos(&bs) / 8;
1514                            return XVID_ERR_OK;
1515                    }
1516                    goto xxx;
1517            }
1518    
1519          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
1520    
1521          switch (vop_type) {          switch (vop_type) {
1522          case P_VOP:          case P_VOP:
1523                  decoder_pframe(dec, &bs, rounding, quant, fcode_forward,                  decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,
1524                                             intra_dc_threshold);                                                  fcode_forward, intra_dc_threshold, NULL);
1525  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1526                  DEBUG1("P_VOP  Time=", dec->time);                  DEBUG1("P_VOP  Time=", dec->time);
1527  #endif  #endif
1528                  break;                  break;
1529    
1530          case I_VOP:          case I_VOP:
1531                  decoder_iframe(dec, &bs, quant, intra_dc_threshold);                  decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);
1532  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1533                  DEBUG1("I_VOP  Time=", dec->time);                  DEBUG1("I_VOP  Time=", dec->time);
1534  #endif  #endif
# Line 1425  Line 1547 
1547  #endif  #endif
1548                  break;                  break;
1549    
1550            case S_VOP :
1551                    decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,
1552                                                    fcode_forward, intra_dc_threshold, gmc_mv);
1553                    break;
1554    
1555          case N_VOP:                             // vop not coded          case N_VOP:                             // vop not coded
1556                  // 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
1557                  image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);                  image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);
1558    #ifdef BFRAMES_DEC
1559                    DEBUG1("N_VOP  Time=", dec->time);
1560    #endif
1561                  break;                  break;
1562    
1563          default:          default:
1564                    if (stats)
1565                            stats->notify = 0;
1566                  return XVID_ERR_FAIL;                  return XVID_ERR_FAIL;
1567          }          }
1568    
1569  #ifdef BFRAMES_DEC_DEBUG          BitstreamByteAlign(&bs);
         if (frame->length != BitstreamPos(&bs) / 8){  
                 DEBUG2("InLen/UseLen",frame->length, BitstreamPos(&bs) / 8);  
         }  
 #endif  
         frame->length = BitstreamPos(&bs) / 8;  
   
1570    
1571  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1572          // test if no B_VOP          // test if no B_VOP
1573          if (dec->low_delay || dec->frames == 0) {          if (dec->low_delay || dec->frames == 0 || ((dec->packed_mode) && !(frame->length > BitstreamPos(&bs) / 8))) {
1574  #endif  #endif
1575          image_output(&dec->cur, dec->width, dec->height, dec->edged_width,          image_output(&dec->cur, dec->width, dec->height, dec->edged_width,
1576                                           frame->image, frame->stride, frame->colorspace);                                           frame->image, frame->stride, frame->colorspace, dec->interlacing);
1577    
1578  #ifdef BFRAMES_DEC  #ifdef BFRAMES_DEC
1579          } else {          } else {
1580                  if (dec->frames >= 1) {                  if (dec->frames >= 1 && !(dec->packed_mode)) {
1581                          start_timer();                          start_timer();
1582                          if ((vop_type == I_VOP || vop_type == P_VOP)) {                          if ((vop_type == I_VOP || vop_type == P_VOP || vop_type == S_VOP)) {
1583                                  image_output(&dec->refn[0], dec->width, dec->height,                                  image_output(&dec->refn[0], dec->width, dec->height,
1584                                                           dec->edged_width, frame->image, frame->stride,                                                           dec->edged_width, frame->image, frame->stride,
1585                                                           frame->colorspace);                                                           frame->colorspace, dec->interlacing);
1586                          } else if (vop_type == B_VOP) {                          } else if (vop_type == B_VOP) {
1587                                  image_output(&dec->cur, dec->width, dec->height,                                  image_output(&dec->cur, dec->width, dec->height,
1588                                                           dec->edged_width, frame->image, frame->stride,                                                           dec->edged_width, frame->image, frame->stride,
1589                                                           frame->colorspace);                                                           frame->colorspace, dec->interlacing);
1590                          }                          }
1591                          stop_conv_timer();                          stop_conv_timer();
1592                  }                  }
1593          }          }
1594  #endif  #endif
1595    
1596          if (vop_type == I_VOP || vop_type == P_VOP) {          if (vop_type == I_VOP || vop_type == P_VOP || vop_type == S_VOP) {
1597                  image_swap(&dec->refn[0], &dec->refn[1]);                  image_swap(&dec->refn[0], &dec->refn[1]);
1598                  image_swap(&dec->cur, &dec->refn[0]);                  image_swap(&dec->cur, &dec->refn[0]);
1599    
# Line 1483  Line 1609 
1609                          mb_swap(&dec->mbs, &dec->last_mbs);                          mb_swap(&dec->mbs, &dec->last_mbs);
1610          }          }
1611    
1612            if (frame->length > BitstreamPos(&bs) / 8)      // multiple vops packed together
1613                    goto start;
1614    
1615            frame->length = BitstreamPos(&bs) / 8;
1616    
1617            if (stats)
1618            {
1619                    stats->notify = XVID_DEC_VOP;
1620                    stats->data.vop.time_base = (int)dec->time_base;
1621                    stats->data.vop.time_increment = 0;     //XXX: todo
1622            }
1623    
1624          emms();          emms();
1625    
1626          stop_global_timer();          stop_global_timer();

Legend:
Removed from v.1.37.2.3  
changed lines
  Added in v.1.37.2.11

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