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

Diff of /xvidcore/src/decoder.c

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

revision 1.49.2.24, Wed Dec 10 15:07:42 2003 UTC revision 1.64, Mon Jul 26 19:32:28 2004 UTC
# Line 4  Line 4 
4   *  - Decoder Module -   *  - Decoder Module -
5   *   *
6   *  Copyright(C) 2002      MinChen <chenm001@163.com>   *  Copyright(C) 2002      MinChen <chenm001@163.com>
7   *               2002-2003 Peter Ross <pross@xvid.org>   *               2002-2004 Peter Ross <pross@xvid.org>
8   *   *
9   *  This program is free software ; you can redistribute it and/or modify   *  This program is free software ; you can redistribute it and/or modify
10   *  it under the terms of the GNU General Public License as published by   *  it under the terms of the GNU General Public License as published by
# Line 48  Line 48 
48  #include "image/interpolate8x8.h"  #include "image/interpolate8x8.h"
49  #include "image/reduced.h"  #include "image/reduced.h"
50  #include "image/font.h"  #include "image/font.h"
51    #include "image/qpel.h"
52    
53  #include "bitstream/mbcoding.h"  #include "bitstream/mbcoding.h"
54  #include "prediction/mbprediction.h"  #include "prediction/mbprediction.h"
# Line 61  Line 62 
62  #include "image/postprocessing.h"  #include "image/postprocessing.h"
63  #include "utils/mem_align.h"  #include "utils/mem_align.h"
64    
65    #ifdef ARCH_IS_IA32
66    #define interpolate16x16_quarterpel new_interpolate16x16_quarterpel
67    #define interpolate8x8_quarterpel new_interpolate8x8_quarterpel
68    #endif
69    
70  static int  static int
71  decoder_resize(DECODER * dec)  decoder_resize(DECODER * dec)
72  {  {
# Line 77  Line 83 
83                  xvid_free(dec->last_mbs);                  xvid_free(dec->last_mbs);
84          if (dec->mbs)          if (dec->mbs)
85                  xvid_free(dec->mbs);                  xvid_free(dec->mbs);
86            if (dec->qscale)
87                    xvid_free(dec->qscale);
88    
89          /* realloc */          /* realloc */
90          dec->mb_width = (dec->width + 15) / 16;          dec->mb_width = (dec->width + 15) / 16;
# Line 161  Line 169 
169    
170          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);
171    
172            /* nothing happens if that fails */
173            dec->qscale =
174                    xvid_malloc(sizeof(int) * dec->mb_width * dec->mb_height, CACHE_LINE);
175    
176            if (dec->qscale)
177                    memset(dec->qscale, 0, sizeof(int) * dec->mb_width * dec->mb_height);
178    
179          return 0;          return 0;
180  }  }
181    
# Line 200  Line 215 
215          /* image based GMC */          /* image based GMC */
216          image_null(&dec->gmc);          image_null(&dec->gmc);
217    
   
218          dec->mbs = NULL;          dec->mbs = NULL;
219          dec->last_mbs = NULL;          dec->last_mbs = NULL;
220            dec->qscale = NULL;
221    
222          init_timer();          init_timer();
223            init_postproc(&dec->postproc);
224          init_mpeg_matrix(dec->mpeg_quant_matrices);          init_mpeg_matrix(dec->mpeg_quant_matrices);
225    
226          /* For B-frame support (used to save reference frame's time */          /* For B-frame support (used to save reference frame's time */
# Line 212  Line 228 
228          dec->time = dec->time_base = dec->last_time_base = 0;          dec->time = dec->time_base = dec->last_time_base = 0;
229          dec->low_delay = 0;          dec->low_delay = 0;
230          dec->packed_mode = 0;          dec->packed_mode = 0;
231            dec->time_inc_resolution = 1; /* until VOL header says otherwise */
232    
233          dec->fixed_dimensions = (dec->width > 0 && dec->height > 0);          dec->fixed_dimensions = (dec->width > 0 && dec->height > 0);
234    
# Line 227  Line 244 
244  {  {
245          xvid_free(dec->last_mbs);          xvid_free(dec->last_mbs);
246          xvid_free(dec->mbs);          xvid_free(dec->mbs);
247            xvid_free(dec->qscale);
248    
249          /* image based GMC */          /* image based GMC */
250          image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);          image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);
# Line 327  Line 345 
345                  stop_coding_timer();                  stop_coding_timer();
346    
347                  start_timer();                  start_timer();
348                  add_acdc(pMB, i, &block[i * 64], iDcScaler, predictors);                  add_acdc(pMB, i, &block[i * 64], iDcScaler, predictors, dec->bs_version);
349                  stop_prediction_timer();                  stop_prediction_timer();
350    
351                  start_timer();                  start_timer();
# Line 378  Line 396 
396                                  uint8_t * pY_Cur,                                  uint8_t * pY_Cur,
397                                  uint8_t * pU_Cur,                                  uint8_t * pU_Cur,
398                                  uint8_t * pV_Cur,                                  uint8_t * pV_Cur,
399                                  const int reduced_resolution,                                  int reduced_resolution,
400                                  const MACROBLOCK * pMB)                                  const MACROBLOCK * pMB)
401  {  {
402          DECLARE_ALIGNED_MATRIX(block, 1, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(data, 1, 64, int16_t, CACHE_LINE);
         DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);  
403    
404          int stride = dec->edged_width;          int stride = dec->edged_width;
405          int next_block = stride * (reduced_resolution ? 16 : 8);          int next_block = stride * (reduced_resolution ? 16 : 8);
         const int stride2 = stride/2;  
406          int i;          int i;
407          const uint32_t iQuant = pMB->quant;          const uint32_t iQuant = pMB->quant;
408          const int direction = dec->alternate_vertical_scan ? 2 : 0;          const int direction = dec->alternate_vertical_scan ? 2 : 0;
409          const quant_interFuncPtr dequant = dec->quant_type == 0 ? dequant_h263_inter : dequant_mpeg_inter;          typedef void (*get_inter_block_function_t)(
410                            Bitstream * bs,
411                            int16_t * block,
412                            int direction,
413                            const int quant,
414                            const uint16_t *matrix);
415            typedef void (*add_residual_function_t)(
416                            uint8_t *predicted_block,
417                            const int16_t *residual,
418                            int stride);
419    
420            const get_inter_block_function_t get_inter_block = (dec->quant_type == 0)
421                    ? (get_inter_block_function_t)get_inter_block_h263
422                    : (get_inter_block_function_t)get_inter_block_mpeg;
423    
424            const add_residual_function_t add_residual = (reduced_resolution)
425                    ? (add_residual_function_t)add_upsampled_8x8_16to8
426                    : (add_residual_function_t)transfer_16to8add;
427    
428          for (i = 0; i < 6; i++) {          uint8_t *dst[6];
429            int strides[6];
430    
                 if (cbp & (1 << (5 - i))) {     /* coded */  
431    
432                          memset(block, 0, 64 * sizeof(int16_t)); /* clear */          if (dec->interlacing && pMB->field_dct) {
433                    next_block = stride;
434                    stride *= 2;
435            }
436    
437                          start_timer();          reduced_resolution = !!reduced_resolution;
438                          get_inter_block(bs, block, direction);          dst[0] = pY_Cur;
439                          stop_coding_timer();          dst[2] = pY_Cur + next_block;
440            dst[1] = dst[0] + (8<<reduced_resolution);
441            dst[3] = dst[2] + (8<<reduced_resolution);
442            dst[4] = pU_Cur;
443            dst[5] = pV_Cur;
444            strides[0] = strides[1] = strides[2] = strides[3] = stride;
445            strides[4] = stride/2;
446            strides[5] = stride/2;
447    
448            for (i = 0; i < 6; i++) {
449                    /* Process only coded blocks */
450                    if (cbp & (1 << (5 - i))) {
451    
452                            /* Clear the block */
453                            memset(&data[0], 0, 64*sizeof(int16_t));
454    
455                            /* Decode coeffs and dequantize on the fly */
456                          start_timer();                          start_timer();
457                          dequant(&data[i * 64], block, iQuant, dec->mpeg_quant_matrices);                          get_inter_block(bs, &data[0], direction, iQuant, get_inter_matrix(dec->mpeg_quant_matrices));
458                          stop_iquant_timer();                          stop_coding_timer();
459    
460                            /* iDCT */
461                          start_timer();                          start_timer();
462                          idct(&data[i * 64]);                          idct(&data[0]);
463                          stop_idct_timer();                          stop_idct_timer();
                 }  
         }  
   
         if (dec->interlacing && pMB->field_dct) {  
                 next_block = stride;  
                 stride *= 2;  
         }  
464    
465                            /* Add this residual to the predicted block */
466          start_timer();          start_timer();
467          if (reduced_resolution) {                          add_residual(dst[i], &data[0], strides[i]);
                 if (cbp & 32)  
                         add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);  
                 if (cbp & 16)  
                         add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);  
                 if (cbp & 8)  
                         add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);  
                 if (cbp & 4)  
                         add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);  
                 if (cbp & 2)  
                         add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);  
                 if (cbp & 1)  
                         add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);  
         } else {  
                 if (cbp & 32)  
                         transfer_16to8add(pY_Cur, &data[0 * 64], stride);  
                 if (cbp & 16)  
                         transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);  
                 if (cbp & 8)  
                         transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);  
                 if (cbp & 4)  
                         transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride);  
                 if (cbp & 2)  
                         transfer_16to8add(pU_Cur, &data[4 * 64], stride2);  
                 if (cbp & 1)  
                         transfer_16to8add(pV_Cur, &data[5 * 64], stride2);  
         }  
468          stop_transfer_timer();          stop_transfer_timer();
469  }  }
470            }
471    }
472    
473  /* decode an inter macroblock */  /* decode an inter macroblock */
474  static void  static void
# Line 485  Line 507 
507                          mv[i] = pMB->mvs[i];                          mv[i] = pMB->mvs[i];
508          }          }
509    
510            for (i = 0; i < 4; i++) {
511                    /* clip to valid range */
512                    int border = (int)(dec->mb_width - x_pos) << (5 + dec->quarterpel);
513                    if (mv[i].x > border) {
514                            DPRINTF(XVID_DEBUG_MV, "mv.x > max -- %d > %d, MB %d, %d", mv[i].x, border, x_pos, y_pos);
515                            mv[i].x = border;
516                    } else {
517                            border = (-(int)x_pos-1) << (5 + dec->quarterpel);
518                            if (mv[i].x < border) {
519                                    DPRINTF(XVID_DEBUG_MV, "mv.x < min -- %d < %d, MB %d, %d", mv[i].x, border, x_pos, y_pos);
520                                    mv[i].x = border;
521                            }
522                    }
523    
524                    border = (int)(dec->mb_height - y_pos) << (5 + dec->quarterpel);
525                    if (mv[i].y >  border) {
526                            DPRINTF(XVID_DEBUG_MV, "mv.y > max -- %d > %d, MB %d, %d", mv[i].y, border, x_pos, y_pos);
527                            mv[i].y = border;
528                    } else {
529                            border = (-(int)y_pos-1) << (5 + dec->quarterpel);
530                            if (mv[i].y < border) {
531                                    DPRINTF(XVID_DEBUG_MV, "mv.y < min -- %d < %d, MB %d, %d", mv[i].y, border, x_pos, y_pos);
532                                    mv[i].y = border;
533                            }
534                    }
535            }
536    
537          start_timer();          start_timer();
538    
539          if (pMB->mode != MODE_INTER4V) { /* INTER, INTER_Q, NOT_CODED, FORWARD, BACKWARD */          if (pMB->mode != MODE_INTER4V) { /* INTER, INTER_Q, NOT_CODED, FORWARD, BACKWARD */
# Line 776  Line 825 
825                  mb_height = (dec->height + 31) / 32;                  mb_height = (dec->height + 31) / 32;
826          }          }
827    
828            if (!dec->is_edged[0]) {
829          start_timer();          start_timer();
830          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
831                                          dec->width, dec->height);                                                  dec->width, dec->height, dec->bs_version);
832                    dec->is_edged[0] = 1;
833          stop_edges_timer();          stop_edges_timer();
834            }
835    
836          if (gmc_warp) {          if (gmc_warp) {
837                  /* accuracy: 0==1/2, 1=1/4, 2=1/8, 3=1/16 */                  /* accuracy: 0==1/2, 1=1/4, 2=1/8, 3=1/16 */
# Line 850  Line 902 
902                                  mb->quant = quant;                                  mb->quant = quant;
903    
904                                  if (dec->interlacing) {                                  if (dec->interlacing) {
905                                          if ((cbp || intra) && !mcsel) {                                          if (cbp || intra) {
906                                                  mb->field_dct = BitstreamGetBit(bs);                                                  mb->field_dct = BitstreamGetBit(bs);
907                                                  DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct);                                                  DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct);
908                                          }                                          }
909    
910                                          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                          if ((mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) && !mcsel) {
911                                                  mb->field_pred = BitstreamGetBit(bs);                                                  mb->field_pred = BitstreamGetBit(bs);
912                                                  DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred);                                                  DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred);
913    
# Line 899  Line 951 
951    
952                          } else if (gmc_warp) {  /* a not coded S(GMC)-VOP macroblock */                          } else if (gmc_warp) {  /* a not coded S(GMC)-VOP macroblock */
953                                  mb->mode = MODE_NOT_CODED_GMC;                                  mb->mode = MODE_NOT_CODED_GMC;
954                                    mb->quant = quant;
955                                  decoder_mbgmc(dec, mb, x, y, fcode, 0x00, bs, rounding);                                  decoder_mbgmc(dec, mb, x, y, fcode, 0x00, bs, rounding);
956    
957                                  if(dec->out_frm && cp_mb > 0) {                                  if(dec->out_frm && cp_mb > 0) {
# Line 908  Line 961 
961                                  st_mb = x+1;                                  st_mb = x+1;
962                          } else {        /* not coded P_VOP macroblock */                          } else {        /* not coded P_VOP macroblock */
963                                  mb->mode = MODE_NOT_CODED;                                  mb->mode = MODE_NOT_CODED;
964                                    mb->quant = quant;
965    
966                                  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;
967                                  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;
# Line 934  Line 988 
988  get_b_motion_vector(Bitstream * bs,  get_b_motion_vector(Bitstream * bs,
989                                          VECTOR * mv,                                          VECTOR * mv,
990                                          int fcode,                                          int fcode,
991                                          const VECTOR pmv)                                          const VECTOR pmv,
992                                            const DECODER * const dec,
993                                            const int x, const int y)
994  {  {
995          const int scale_fac = 1 << (fcode - 1);          const int scale_fac = 1 << (fcode - 1);
996          const int high = (32 * scale_fac) - 1;          const int high = (32 * scale_fac) - 1;
# Line 986  Line 1042 
1042          if (!direct) {          if (!direct) {
1043                  uv_dx = pMB->mvs[0].x;                  uv_dx = pMB->mvs[0].x;
1044                  uv_dy = pMB->mvs[0].y;                  uv_dy = pMB->mvs[0].y;
   
1045                  b_uv_dx = pMB->b_mvs[0].x;                  b_uv_dx = pMB->b_mvs[0].x;
1046                  b_uv_dy = pMB->b_mvs[0].y;                  b_uv_dy = pMB->b_mvs[0].y;
1047    
# Line 999  Line 1054 
1054    
1055                  uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];                  uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
1056                  uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];                  uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
   
1057                  b_uv_dx = (b_uv_dx >> 1) + roundtab_79[b_uv_dx & 0x3];                  b_uv_dx = (b_uv_dx >> 1) + roundtab_79[b_uv_dx & 0x3];
1058                  b_uv_dy = (b_uv_dy >> 1) + roundtab_79[b_uv_dy & 0x3];                  b_uv_dy = (b_uv_dy >> 1) + roundtab_79[b_uv_dy & 0x3];
1059    
1060          } else {          } else {
                 if(dec->quarterpel) {  
                         uv_dx = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2);  
                         uv_dy = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2);  
                         b_uv_dx = (pMB->b_mvs[0].x / 2) + (pMB->b_mvs[1].x / 2) + (pMB->b_mvs[2].x / 2) + (pMB->b_mvs[3].x / 2);  
                         b_uv_dy = (pMB->b_mvs[0].y / 2) + (pMB->b_mvs[1].y / 2) + (pMB->b_mvs[2].y / 2) + (pMB->b_mvs[3].y / 2);  
                 } else {  
1061                          uv_dx = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;                          uv_dx = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;
1062                          uv_dy = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;                          uv_dy = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
1063                          b_uv_dx = pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + pMB->b_mvs[3].x;                          b_uv_dx = pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + pMB->b_mvs[3].x;
1064                          b_uv_dy = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y;                          b_uv_dy = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y;
1065    
1066                    if (dec->quarterpel) {
1067                            uv_dx /= 2;
1068                            uv_dy /= 2;
1069                            b_uv_dx /= 2;
1070                            b_uv_dy /= 2;
1071                  }                  }
1072    
1073                  uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf];                  uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf];
# Line 1049  Line 1103 
1103                                                          pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);                                                          pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
1104                  interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos + 8,                  interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos + 8,
1105                                                          pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);                                                          pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
1106                  interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8,                  interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, 16 * y_pos + 8,
1107                                                          16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);                                                          pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);
1108          }          }
1109    
1110          interpolate8x8_switch(dec->cur.u, forward.u, 8 * x_pos, 8 * y_pos, uv_dx,          interpolate8x8_switch(dec->cur.u, forward.u, 8 * x_pos, 8 * y_pos, uv_dx,
# Line 1097  Line 1151 
1151          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1152                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos,
1153                                                  dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos,                                                  dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos,
1154                                                  stride, 1, 8);                                                  stride, 0, 8);
1155    
1156          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,          interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1157                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,                                                  dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1158                                                  dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos + 8,                                                  dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos + 8,
1159                                                  stride, 1, 8);                                                  stride, 0, 8);
1160    
1161          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,
1162                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1163                                                  dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,                                                  dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
1164                                                  stride, 1, 8);                                                  stride, 0, 8);
1165    
1166          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,
1167                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,                                                  dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1168                                                  dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,                                                  dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
1169                                                  stride, 1, 8);                                                  stride, 0, 8);
1170    
1171          interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,          interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1172                                                  dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos,
1173                                                  dec->tmp.u + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->tmp.u + (8 * y_pos * stride2) + 8 * x_pos,
1174                                                  stride2, 1, 8);                                                  stride2, 0, 8);
1175    
1176          interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,          interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1177                                                  dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos,
1178                                                  dec->tmp.v + (8 * y_pos * stride2) + 8 * x_pos,                                                  dec->tmp.v + (8 * y_pos * stride2) + 8 * x_pos,
1179                                                  stride2, 1, 8);                                                  stride2, 0, 8);
1180    
1181          stop_comp_timer();          stop_comp_timer();
1182    
# Line 1172  Line 1226 
1226          uint32_t x, y;          uint32_t x, y;
1227          VECTOR mv;          VECTOR mv;
1228          const VECTOR zeromv = {0,0};          const VECTOR zeromv = {0,0};
         const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp;  
1229          int i;          int i;
1230    
1231            if (!dec->is_edged[0]) {
1232          start_timer();          start_timer();
1233          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
1234                                          dec->width, dec->height);                                                  dec->width, dec->height, dec->bs_version);
1235                    dec->is_edged[0] = 1;
1236                    stop_edges_timer();
1237            }
1238    
1239            if (!dec->is_edged[1]) {
1240                    start_timer();
1241          image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height,
1242                                          dec->width, dec->height);                                                  dec->width, dec->height, dec->bs_version);
1243                    dec->is_edged[1] = 1;
1244          stop_edges_timer();          stop_edges_timer();
1245            }
1246    
1247          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < dec->mb_height; y++) {
1248                  /* Initialize Pred Motion Vector */                  /* Initialize Pred Motion Vector */
# Line 1263  Line 1325 
1325    
1326                          switch (mb->mode) {                          switch (mb->mode) {
1327                          case MODE_DIRECT:                          case MODE_DIRECT:
1328                                  get_b_motion_vector(bs, &mv, 1, zeromv);                                  get_b_motion_vector(bs, &mv, 1, zeromv, dec, x, y);
1329    
1330                          case MODE_DIRECT_NONE_MV:                          case MODE_DIRECT_NONE_MV:
1331                                  for (i = 0; i < 4; i++) {                                  for (i = 0; i < 4; i++) {
1332                                          mb->mvs[i].x = (int32_t) ((TRB * last_mb->mvs[i].x) / TRD + mv.x);                                          mb->mvs[i].x = last_mb->mvs[i].x*dec->time_bp/dec->time_pp + mv.x;
1333                                          mb->b_mvs[i].x = (int32_t) ((mv.x == 0)                                          mb->mvs[i].y = last_mb->mvs[i].y*dec->time_bp/dec->time_pp + mv.y;
1334                                                                          ? ((TRB - TRD) * last_mb->mvs[i].x) / TRD  
1335                                                                          : mb->mvs[i].x - last_mb->mvs[i].x);                                          mb->b_mvs[i].x = (mv.x)
1336                                          mb->mvs[i].y = (int32_t) ((TRB * last_mb->mvs[i].y) / TRD + mv.y);                                                  ?  mb->mvs[i].x - last_mb->mvs[i].x
1337                                          mb->b_mvs[i].y = (int32_t) ((mv.y == 0)                                                  : last_mb->mvs[i].x*(dec->time_bp - dec->time_pp)/dec->time_pp;
1338                                                                          ? ((TRB - TRD) * last_mb->mvs[i].y) / TRD                                          mb->b_mvs[i].y = (mv.y)
1339                                                                          : mb->mvs[i].y - last_mb->mvs[i].y);                                                  ? mb->mvs[i].y - last_mb->mvs[i].y
1340                                                    : last_mb->mvs[i].y*(dec->time_bp - dec->time_pp)/dec->time_pp;
1341                                  }                                  }
1342    
1343                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
# Line 1282  Line 1345 
1345                                  break;                                  break;
1346    
1347                          case MODE_INTERPOLATE:                          case MODE_INTERPOLATE:
1348                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv);                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv, dec, x, y);
1349                                  dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];                                  dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
1350    
1351                                  get_b_motion_vector(bs, &mb->b_mvs[0], fcode_backward, dec->p_bmv);                                  get_b_motion_vector(bs, &mb->b_mvs[0], fcode_backward, dec->p_bmv, dec, x, y);
1352                                  dec->p_bmv = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = mb->b_mvs[0];                                  dec->p_bmv = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = mb->b_mvs[0];
1353    
1354                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],                                  decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0],
# Line 1293  Line 1356 
1356                                  break;                                  break;
1357    
1358                          case MODE_BACKWARD:                          case MODE_BACKWARD:
1359                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_backward, dec->p_bmv);                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_backward, dec->p_bmv, dec, x, y);
1360                                  dec->p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];                                  dec->p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
1361    
1362                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 0);                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 0);
1363                                  break;                                  break;
1364    
1365                          case MODE_FORWARD:                          case MODE_FORWARD:
1366                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv);                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv, dec, x, y);
1367                                  dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];                                  dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] =     mb->mvs[0];
1368    
1369                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 1);                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 1);
# Line 1315  Line 1378 
1378    
1379  /* perform post processing if necessary, and output the image */  /* perform post processing if necessary, and output the image */
1380  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,
1381                                          xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type)                                          xvid_dec_frame_t * frame, xvid_dec_stats_t * stats,
1382                                            int coding_type, int quant)
1383  {  {
1384          if (frame->general & (XVID_DEBLOCKY|XVID_DEBLOCKUV))    /* post process */          const int brightness = XVID_VERSION_MINOR(frame->version) >= 1 ? frame->brightness : 0;
1385    
1386            if (dec->cartoon_mode)
1387                    frame->general &= ~XVID_FILMEFFECT;
1388    
1389            if ((frame->general & (XVID_DEBLOCKY|XVID_DEBLOCKUV|XVID_FILMEFFECT) || brightness!=0)
1390                    && mbs != NULL) /* post process */
1391          {          {
1392                  /* note: image is stored to tmp */                  /* note: image is stored to tmp */
1393                  image_copy(&dec->tmp, img, dec->edged_width, dec->height);                  image_copy(&dec->tmp, img, dec->edged_width, dec->height);
1394                  image_deblock(&dec->tmp, dec->edged_width,                  image_postproc(&dec->postproc, &dec->tmp, dec->edged_width,
1395                                            mbs, dec->mb_width, dec->mb_height, dec->mb_width,                                            mbs, dec->mb_width, dec->mb_height, dec->mb_width,
1396                                            frame->general);                                             frame->general, brightness, dec->frames, (coding_type == B_VOP));
1397                  img = &dec->tmp;                  img = &dec->tmp;
1398          }          }
1399    
# Line 1335  Line 1405 
1405                  stats->type = coding2type(coding_type);                  stats->type = coding2type(coding_type);
1406                  stats->data.vop.time_base = (int)dec->time_base;                  stats->data.vop.time_base = (int)dec->time_base;
1407                  stats->data.vop.time_increment = 0;     /* XXX: todo */                  stats->data.vop.time_increment = 0;     /* XXX: todo */
1408                    stats->data.vop.qscale_stride = dec->mb_width;
1409                    stats->data.vop.qscale = dec->qscale;
1410                    if (stats->data.vop.qscale != NULL && mbs != NULL) {
1411                            int i;
1412                            for (i = 0; i < dec->mb_width*dec->mb_height; i++)
1413                                    stats->data.vop.qscale[i] = mbs[i].quant;
1414                    } else
1415                            stats->data.vop.qscale = NULL;
1416          }          }
1417  }  }
1418    
# Line 1347  Line 1425 
1425          Bitstream bs;          Bitstream bs;
1426          uint32_t rounding;          uint32_t rounding;
1427          uint32_t reduced_resolution;          uint32_t reduced_resolution;
1428          uint32_t quant;          uint32_t quant = 2;
1429          uint32_t fcode_forward;          uint32_t fcode_forward;
1430          uint32_t fcode_backward;          uint32_t fcode_backward;
1431          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
# Line 1370  Line 1448 
1448                  /* if not decoding "low_delay/packed", and this isn't low_delay and                  /* if not decoding "low_delay/packed", and this isn't low_delay and
1449                          we have a reference frame, then outout the reference frame */                          we have a reference frame, then outout the reference frame */
1450                  if (!(dec->low_delay_default && dec->packed_mode) && !dec->low_delay && dec->frames>0) {                  if (!(dec->low_delay_default && dec->packed_mode) && !dec->low_delay && dec->frames>0) {
1451                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant);
1452                          dec->frames = 0;                          dec->frames = 0;
1453                          ret = 0;                          ret = 0;
1454                  } else {                  } else {
# Line 1435  Line 1513 
1513                  goto repeat;                  goto repeat;
1514          }          }
1515    
1516            if(dec->frames == 0 && coding_type != I_VOP) {
1517                    /* 1st frame is not an i-vop */
1518                    goto repeat;
1519            }
1520    
1521          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 */
1522    
1523          /* packed_mode: special-N_VOP treament */          /* packed_mode: special-N_VOP treament */
1524          if (dec->packed_mode && coding_type == N_VOP) {          if (dec->packed_mode && coding_type == N_VOP) {
1525                  if (dec->low_delay_default && dec->frames > 0) {                  if (dec->low_delay_default && dec->frames > 0) {
1526                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant);
1527                          output = 1;                          output = 1;
1528                  }                  }
1529                  /* ignore otherwise */                  /* ignore otherwise */
# Line 1474  Line 1557 
1557                  /* note: for packed_mode, output is performed when the special-N_VOP is decoded */                  /* note: for packed_mode, output is performed when the special-N_VOP is decoded */
1558                  if (!(dec->low_delay_default && dec->packed_mode)) {                  if (!(dec->low_delay_default && dec->packed_mode)) {
1559                          if (dec->low_delay) {                          if (dec->low_delay) {
1560                                  decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);                                  decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type, quant);
1561                                  output = 1;                                  output = 1;
1562                          } else if (dec->frames > 0)     { /* is the reference frame valid? */                          } else if (dec->frames > 0)     { /* is the reference frame valid? */
1563                                  /* output the reference frame */                                  /* output the reference frame */
1564                                  decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);                                  decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant);
1565                                  output = 1;                                  output = 1;
1566                          }                          }
1567                  }                  }
1568    
1569                  image_swap(&dec->refn[0], &dec->refn[1]);                  image_swap(&dec->refn[0], &dec->refn[1]);
1570                    dec->is_edged[1] = dec->is_edged[0];
1571                  image_swap(&dec->cur, &dec->refn[0]);                  image_swap(&dec->cur, &dec->refn[0]);
1572                    dec->is_edged[0] = 0;
1573                  SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs);                  SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs);
1574                  dec->last_reduced_resolution = reduced_resolution;                  dec->last_reduced_resolution = reduced_resolution;
1575                  dec->last_coding_type = coding_type;                  dec->last_coding_type = coding_type;
# Line 1496  Line 1581 
1581    
1582                  if (dec->low_delay) {                  if (dec->low_delay) {
1583                          DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n");                          DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n");
1584                          dec->low_delay = 1;                          dec->low_delay = 0;
1585                  }                  }
1586    
1587                  if (dec->frames < 2) {                  if (dec->frames < 2) {
1588                          /* attemping to decode a bvop without atleast 2 reference frames */                          /* attemping to decode a bvop without atleast 2 reference frames */
1589                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
1590                                                  "broken b-frame, mising ref frames");                                                  "broken b-frame, mising ref frames");
1591                          stats->type = XVID_TYPE_NOTHING;                          if (stats) stats->type = XVID_TYPE_NOTHING;
1592                  } else if (dec->time_pp <= dec->time_bp) {                  } else if (dec->time_pp <= dec->time_bp) {
1593                          /* this occurs when dx50_bvop_compatibility==0 sequences are                          /* this occurs when dx50_bvop_compatibility==0 sequences are
1594                          decoded in vfw. */                          decoded in vfw. */
1595                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
1596                                                  "broken b-frame, tpp=%i tbp=%i", dec->time_pp, dec->time_bp);                                                  "broken b-frame, tpp=%i tbp=%i", dec->time_pp, dec->time_bp);
1597                          stats->type = XVID_TYPE_NOTHING;                          if (stats) stats->type = XVID_TYPE_NOTHING;
1598                  } else {                  } else {
1599                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);
1600                          decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);                          decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type, quant);
1601                  }                  }
1602    
1603                  output = 1;                  output = 1;
1604                  dec->frames++;                  dec->frames++;
1605          }          }
1606    
1607    #if 0 /* Avoids to read to much data because of 32bit reads in our BS functions */
1608          BitstreamByteAlign(&bs);          BitstreamByteAlign(&bs);
1609    #endif
1610    
1611          /* low_delay_default mode: repeat in packed_mode */          /* low_delay_default mode: repeat in packed_mode */
1612          if (dec->low_delay_default && dec->packed_mode && output == 0 && success == 0) {          if (dec->low_delay_default && dec->packed_mode && output == 0 && success == 0) {
# Line 1534  Line 1621 
1621          if (dec->low_delay_default && output == 0) {          if (dec->low_delay_default && output == 0) {
1622                  if (dec->packed_mode && seen_something) {                  if (dec->packed_mode && seen_something) {
1623                          /* output the recently decoded frame */                          /* output the recently decoded frame */
1624                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant);
1625                  } else {                  } else {
1626                          image_clear(&dec->cur, dec->width, dec->height, dec->edged_width, 0, 128, 128);                          image_clear(&dec->cur, dec->width, dec->height, dec->edged_width, 0, 128, 128);
1627                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
# Line 1542  Line 1629 
1629                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,
1630                                  "bframe decoder lag");                                  "bframe decoder lag");
1631    
1632                          decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP);                          decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP, quant);
1633                          if (stats) stats->type = XVID_TYPE_NOTHING;                          if (stats) stats->type = XVID_TYPE_NOTHING;
1634                  }                  }
1635          }          }
# Line 1550  Line 1637 
1637          emms();          emms();
1638          stop_global_timer();          stop_global_timer();
1639    
1640          return BitstreamPos(&bs) / 8;   /* number of bytes consumed */          return (BitstreamPos(&bs) + 7) / 8;     /* number of bytes consumed */
1641  }  }

Legend:
Removed from v.1.49.2.24  
changed lines
  Added in v.1.64

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