[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.66, Sun Aug 15 11:28:38 2004 UTC revision 1.71, Mon May 23 09:29:43 2005 UTC
# Line 46  Line 46 
46  #include "dct/fdct.h"  #include "dct/fdct.h"
47  #include "utils/mem_transfer.h"  #include "utils/mem_transfer.h"
48  #include "image/interpolate8x8.h"  #include "image/interpolate8x8.h"
 #include "image/reduced.h"  
49  #include "image/font.h"  #include "image/font.h"
50  #include "image/qpel.h"  #include "image/qpel.h"
51    
# Line 74  Line 73 
73    
74          image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);          image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);
75    
76          if (dec->last_mbs)    image_null(&dec->cur);
77      image_null(&dec->refn[0]);
78      image_null(&dec->refn[1]);
79      image_null(&dec->tmp);
80      image_null(&dec->qtmp);
81      image_null(&dec->gmc);
82    
83    
84                  xvid_free(dec->last_mbs);                  xvid_free(dec->last_mbs);
         if (dec->mbs)  
85                  xvid_free(dec->mbs);                  xvid_free(dec->mbs);
         if (dec->qscale)  
86                  xvid_free(dec->qscale);                  xvid_free(dec->qscale);
87      dec->last_mbs = NULL;
88      dec->mbs = NULL;
89      dec->qscale = NULL;
90    
91          /* realloc */          /* realloc */
92          dec->mb_width = (dec->width + 15) / 16;          dec->mb_width = (dec->width + 15) / 16;
# Line 88  Line 95 
95          dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE;          dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE;
96          dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE;          dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE;
97    
98          if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) {          if (   image_create(&dec->cur, dec->edged_width, dec->edged_height)
99                  xvid_free(dec);              || image_create(&dec->refn[0], dec->edged_width, dec->edged_height)
100                  return XVID_ERR_MEMORY;              || image_create(&dec->refn[1], dec->edged_width, dec->edged_height)         /* Support B-frame to reference last 2 frame */
101          }              || image_create(&dec->tmp, dec->edged_width, dec->edged_height)
102                || image_create(&dec->qtmp, dec->edged_width, dec->edged_height)
103          if (image_create(&dec->refn[0], dec->edged_width, dec->edged_height)) {        || image_create(&dec->gmc, dec->edged_width, dec->edged_height) )
104                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);      goto memory_error;
                 xvid_free(dec);  
                 return XVID_ERR_MEMORY;  
         }  
   
         /* Support B-frame to reference last 2 frame */  
         if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) {  
                 image_destroy(&dec->cur, dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);  
                 xvid_free(dec);  
                 return XVID_ERR_MEMORY;  
         }  
         if (image_create(&dec->tmp, dec->edged_width, dec->edged_height)) {  
                 image_destroy(&dec->cur, dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);  
                 xvid_free(dec);  
                 return XVID_ERR_MEMORY;  
         }  
   
         if (image_create(&dec->qtmp, dec->edged_width, dec->edged_height)) {  
                 image_destroy(&dec->cur, dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);  
                 xvid_free(dec);  
                 return XVID_ERR_MEMORY;  
         }  
   
         if (image_create(&dec->gmc, dec->edged_width, dec->edged_height)) {  
                 image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->cur, dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);  
                 xvid_free(dec);  
                 return XVID_ERR_MEMORY;  
         }  
105    
106          dec->mbs =          dec->mbs =
107                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,
108                                          CACHE_LINE);                                          CACHE_LINE);
109          if (dec->mbs == NULL) {          if (dec->mbs == NULL)
110                  image_destroy(&dec->cur, dec->edged_width, dec->edged_height);            goto memory_error;
                 image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);  
                 xvid_free(dec);  
                 return XVID_ERR_MEMORY;  
         }  
111          memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);          memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);
112    
113          /* For skip MB flag */          /* For skip MB flag */
114          dec->last_mbs =          dec->last_mbs =
115                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,
116                                          CACHE_LINE);                                          CACHE_LINE);
117          if (dec->last_mbs == NULL) {          if (dec->last_mbs == NULL)
118                  xvid_free(dec->mbs);            goto memory_error;
                 image_destroy(&dec->cur, dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);  
                 image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);  
                 xvid_free(dec);  
                 return XVID_ERR_MEMORY;  
         }  
   
119          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);
120    
121          /* nothing happens if that fails */          /* nothing happens if that fails */
# Line 172  Line 126 
126                  memset(dec->qscale, 0, sizeof(int) * dec->mb_width * dec->mb_height);                  memset(dec->qscale, 0, sizeof(int) * dec->mb_width * dec->mb_height);
127    
128          return 0;          return 0;
129    
130    memory_error:
131            /* Most structures were deallocated / nullifieded, so it should be safe */
132            /* decoder_destroy(dec) minus the write_timer */
133      xvid_free(dec->mbs);
134      image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
135      image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
136      image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
137      image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
138      image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);
139    
140      xvid_free(dec);
141      return XVID_ERR_MEMORY;
142  }  }
143    
144    
# Line 271  Line 238 
238                                  Bitstream * bs,                                  Bitstream * bs,
239                                  const uint32_t quant,                                  const uint32_t quant,
240                                  const uint32_t intra_dc_threshold,                                  const uint32_t intra_dc_threshold,
241                                  const unsigned int bound,                                  const unsigned int bound)
                                 const int reduced_resolution)  
242  {  {
243    
244          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
# Line 285  Line 251 
251          uint32_t iQuant = pMB->quant;          uint32_t iQuant = pMB->quant;
252          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
253    
         if (reduced_resolution) {  
                 pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5);  
                 pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4);  
                 pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4);  
         }else{  
254                  pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);                  pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
255                  pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);                  pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
256                  pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);                  pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
         }  
257    
258          memset(block, 0, 6 * 64 * sizeof(int16_t));     /* clear */          memset(block, 0, 6 * 64 * sizeof(int16_t));     /* clear */
259    
# Line 363  Line 323 
323          }          }
324    
325          start_timer();          start_timer();
   
         if (reduced_resolution)  
         {  
                 next_block*=2;  
                 copy_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);  
                 copy_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);  
                 copy_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);  
                 copy_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);  
                 copy_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);  
                 copy_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);  
         }else{  
326                  transfer_16to8copy(pY_Cur, &data[0 * 64], stride);                  transfer_16to8copy(pY_Cur, &data[0 * 64], stride);
327                  transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);                  transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);
328                  transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);                  transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);
329                  transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride);                  transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride);
330                  transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);                  transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);
331                  transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);                  transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);
         }  
332          stop_transfer_timer();          stop_transfer_timer();
333  }  }
334    
# Line 391  Line 339 
339                                  uint8_t * pY_Cur,                                  uint8_t * pY_Cur,
340                                  uint8_t * pU_Cur,                                  uint8_t * pU_Cur,
341                                  uint8_t * pV_Cur,                                  uint8_t * pV_Cur,
                                 int reduced_resolution,  
342                                  const MACROBLOCK * pMB)                                  const MACROBLOCK * pMB)
343  {  {
344          DECLARE_ALIGNED_MATRIX(data, 1, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(data, 1, 64, int16_t, CACHE_LINE);
345    
346          int stride = dec->edged_width;          int stride = dec->edged_width;
347          int next_block = stride * (reduced_resolution ? 16 : 8);          int next_block = stride * 8;
348          int i;          int i;
349          const uint32_t iQuant = pMB->quant;          const uint32_t iQuant = pMB->quant;
350          const int direction = dec->alternate_vertical_scan ? 2 : 0;          const int direction = dec->alternate_vertical_scan ? 2 : 0;
# Line 416  Line 363 
363                  ? (get_inter_block_function_t)get_inter_block_h263                  ? (get_inter_block_function_t)get_inter_block_h263
364                  : (get_inter_block_function_t)get_inter_block_mpeg;                  : (get_inter_block_function_t)get_inter_block_mpeg;
365    
         const add_residual_function_t add_residual = (reduced_resolution)  
                 ? (add_residual_function_t)add_upsampled_8x8_16to8  
                 : (add_residual_function_t)transfer_16to8add;  
   
366          uint8_t *dst[6];          uint8_t *dst[6];
367          int strides[6];          int strides[6];
368    
# Line 429  Line 372 
372                  stride *= 2;                  stride *= 2;
373          }          }
374    
         reduced_resolution = !!reduced_resolution;  
375          dst[0] = pY_Cur;          dst[0] = pY_Cur;
376          dst[2] = pY_Cur + next_block;          dst[2] = pY_Cur + next_block;
377          dst[1] = dst[0] + (8<<reduced_resolution);          dst[1] = dst[0] + 8;
378          dst[3] = dst[2] + (8<<reduced_resolution);          dst[3] = dst[2] + 8;
379          dst[4] = pU_Cur;          dst[4] = pU_Cur;
380          dst[5] = pV_Cur;          dst[5] = pV_Cur;
381          strides[0] = strides[1] = strides[2] = strides[3] = stride;          strides[0] = strides[1] = strides[2] = strides[3] = stride;
# Line 459  Line 401 
401    
402                          /* Add this residual to the predicted block */                          /* Add this residual to the predicted block */
403                          start_timer();                          start_timer();
404                          add_residual(dst[i], &data[0], strides[i]);                          transfer_16to8add(dst[i], &data[0], strides[i]);
405                          stop_transfer_timer();                          stop_transfer_timer();
406                  }                  }
407          }          }
408  }  }
409    
410  static void  static void __inline
411  validate_vector(VECTOR * mv, unsigned int x_pos, unsigned int y_pos, const DECODER * dec)  validate_vector(VECTOR * mv, unsigned int x_pos, unsigned int y_pos, const DECODER * dec)
412  {  {
413          /* clip a vector to valid range          /* clip a vector to valid range
414             prevents crashes if bitstream is broken             prevents crashes if bitstream is broken
415          */          */
416          int i;          int shift = 5 + dec->quarterpel;
417            int xborder_high = (int)(dec->mb_width - x_pos) << shift;
418          for (i = 0; i < 4; i++) {          int xborder_low = (-(int)x_pos-1) << shift;
419            int yborder_high = (int)(dec->mb_height - y_pos) << shift;
420                  int border = (int)(dec->mb_width - x_pos) << (5 + dec->quarterpel);          int yborder_low = (-(int)y_pos-1) << shift;
421                  if (mv[i].x > border) {  
422                          DPRINTF(XVID_DEBUG_MV, "mv.x > max -- %d > %d, MB %d, %d", mv[i].x, border, x_pos, y_pos);  #define CHECK_MV(mv) \
423                          mv[i].x = border;          do { \
424                  } else {          if ((mv).x > xborder_high) { \
425                          border = (-(int)x_pos-1) << (5 + dec->quarterpel);                  DPRINTF(XVID_DEBUG_MV, "mv.x > max -- %d > %d, MB %d, %d", (mv).x, xborder_high, x_pos, y_pos); \
426                          if (mv[i].x < border) {                  (mv).x = xborder_high; \
427                                  DPRINTF(XVID_DEBUG_MV, "mv.x < min -- %d < %d, MB %d, %d", mv[i].x, border, x_pos, y_pos);          } else if ((mv).x < xborder_low) { \
428                                  mv[i].x = border;                  DPRINTF(XVID_DEBUG_MV, "mv.x < min -- %d < %d, MB %d, %d", (mv).x, xborder_low, x_pos, y_pos); \
429                          }                  (mv).x = xborder_low; \
430                  }          } \
431            if ((mv).y > yborder_high) { \
432                  border = (int)(dec->mb_height - y_pos) << (5 + dec->quarterpel);                  DPRINTF(XVID_DEBUG_MV, "mv.y > max -- %d > %d, MB %d, %d", (mv).y, yborder_high, x_pos, y_pos); \
433                  if (mv[i].y >  border) {                  (mv).y = yborder_high; \
434                          DPRINTF(XVID_DEBUG_MV, "mv.y > max -- %d > %d, MB %d, %d", mv[i].y, border, x_pos, y_pos);          } else if ((mv).y < yborder_low) { \
435                          mv[i].y = border;                  DPRINTF(XVID_DEBUG_MV, "mv.y < min -- %d < %d, MB %d, %d", (mv).y, yborder_low, x_pos, y_pos); \
436                  } else {                  (mv).y = yborder_low; \
437                          border = (-(int)y_pos-1) << (5 + dec->quarterpel);          } \
438                          if (mv[i].y < border) {          } while (0)
439                                  DPRINTF(XVID_DEBUG_MV, "mv.y < min -- %d < %d, MB %d, %d", mv[i].y, border, x_pos, y_pos);  
440                                  mv[i].y = border;          CHECK_MV(mv[0]);
441                          }          CHECK_MV(mv[1]);
442                  }          CHECK_MV(mv[2]);
443          }          CHECK_MV(mv[3]);
444  }  }
445    
446  /* decode an inter macroblock */  /* decode an inter macroblock */
# Line 510  Line 452 
452                                  const uint32_t cbp,                                  const uint32_t cbp,
453                                  Bitstream * bs,                                  Bitstream * bs,
454                                  const uint32_t rounding,                                  const uint32_t rounding,
                                 const int reduced_resolution,  
455                                  const int ref)                                  const int ref)
456  {  {
457          uint32_t stride = dec->edged_width;          uint32_t stride = dec->edged_width;
# Line 522  Line 463 
463          int uv_dx, uv_dy;          int uv_dx, uv_dy;
464          VECTOR mv[4];   /* local copy of mvs */          VECTOR mv[4];   /* local copy of mvs */
465    
         if (reduced_resolution) {  
                 pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5);  
                 pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4);  
                 pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4);  
                 for (i = 0; i < 4; i++) {  
                         mv[i].x = RRV_MV_SCALEUP(pMB->mvs[i].x);  
                         mv[i].y = RRV_MV_SCALEUP(pMB->mvs[i].y);  
                 }  
         } else {  
466                  pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);                  pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
467                  pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);                  pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
468                  pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);                  pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
469                  for (i = 0; i < 4; i++)                  for (i = 0; i < 4; i++)
470                          mv[i] = pMB->mvs[i];                          mv[i] = pMB->mvs[i];
         }  
471    
472          validate_vector(mv, x_pos, y_pos, dec);          validate_vector(mv, x_pos, y_pos, dec);
473    
# Line 553  Line 484 
484                  uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];                  uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
485                  uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];                  uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
486    
487                  if (reduced_resolution)                  if (dec->quarterpel)
                         interpolate32x32_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,  
                                                                         mv[0].x, mv[0].y, stride, rounding);  
                 else if (dec->quarterpel)  
488                          interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->qtmp.y, dec->qtmp.y + 64,                          interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->qtmp.y, dec->qtmp.y + 64,
489                                                                          dec->qtmp.y + 128, 16*x_pos, 16*y_pos,                                                                          dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
490                                                                                          mv[0].x, mv[0].y, stride, rounding);                                                                                          mv[0].x, mv[0].y, stride, rounding);
# Line 577  Line 505 
505                  uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf];                  uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf];
506                  uv_dy = (uv_dy >> 3) + roundtab_76[uv_dy & 0xf];                  uv_dy = (uv_dy >> 3) + roundtab_76[uv_dy & 0xf];
507    
508                  if (reduced_resolution) {                  if (dec->quarterpel) {
                         interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,  
                                                                 mv[0].x, mv[0].y, stride, rounding);  
                         interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos + 16, 32*y_pos,  
                                                                 mv[1].x, mv[1].y, stride, rounding);  
                         interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos, 32*y_pos + 16,  
                                                                 mv[2].x, mv[2].y, stride, rounding);  
                         interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos + 16, 32*y_pos + 16,  
                                                                 mv[3].x, mv[3].y, stride, rounding);  
                         interpolate16x16_switch(dec->cur.u, dec->refn[0].u , 16 * x_pos, 16 * y_pos,  
                                                                 uv_dx, uv_dy, stride2, rounding);  
                         interpolate16x16_switch(dec->cur.v, dec->refn[0].v , 16 * x_pos, 16 * y_pos,  
                                                                 uv_dx, uv_dy, stride2, rounding);  
   
                 } else if (dec->quarterpel) {  
509                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,                          interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
510                                                                          dec->qtmp.y + 128, 16*x_pos, 16*y_pos,                                                                          dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
511                                                                          mv[0].x, mv[0].y, stride, rounding);                                                                          mv[0].x, mv[0].y, stride, rounding);
# Line 617  Line 531 
531          }          }
532    
533          /* chroma */          /* chroma */
         if (reduced_resolution) {  
                 interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos,  
                                                                 uv_dx, uv_dy, stride2, rounding);  
                 interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos,  
                                                                 uv_dx, uv_dy, stride2, rounding);  
         } else {  
534                  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,
535                                                                  uv_dx, uv_dy, stride2, rounding);                                                                  uv_dx, uv_dy, stride2, rounding);
536                  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,
537                                                                  uv_dx, uv_dy, stride2, rounding);                                                                  uv_dx, uv_dy, stride2, rounding);
         }  
538    
539          stop_comp_timer();          stop_comp_timer();
540    
541          if (cbp)          if (cbp)
542                  decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur,                  decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, pMB);
                                                         reduced_resolution, pMB);  
543  }  }
544    
545  static void  static void
# Line 680  Line 586 
586          stop_transfer_timer();          stop_transfer_timer();
587    
588          if (cbp)          if (cbp)
589                  decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, 0, pMB);                  decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, pMB);
590    
591  }  }
592    
# Line 688  Line 594 
594  static void  static void
595  decoder_iframe(DECODER * dec,  decoder_iframe(DECODER * dec,
596                                  Bitstream * bs,                                  Bitstream * bs,
                                 int reduced_resolution,  
597                                  int quant,                                  int quant,
598                                  int intra_dc_threshold)                                  int intra_dc_threshold)
599  {  {
600          uint32_t bound;          uint32_t bound;
601          uint32_t x, y;          uint32_t x, y;
602          uint32_t mb_width = dec->mb_width;          const uint32_t mb_width = dec->mb_width;
603          uint32_t mb_height = dec->mb_height;          const uint32_t mb_height = dec->mb_height;
   
         if (reduced_resolution) {  
                 mb_width = (dec->width + 31) / 32;  
                 mb_height = (dec->height + 31) / 32;  
         }  
604    
605          bound = 0;          bound = 0;
606    
# Line 756  Line 656 
656                          }                          }
657    
658                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
659                                                          intra_dc_threshold, bound, reduced_resolution);                                                          intra_dc_threshold, bound);
660    
661                  }                  }
662                  if(dec->out_frm)                  if(dec->out_frm)
# Line 814  Line 714 
714  decoder_pframe(DECODER * dec,  decoder_pframe(DECODER * dec,
715                                  Bitstream * bs,                                  Bitstream * bs,
716                                  int rounding,                                  int rounding,
                                 int reduced_resolution,  
717                                  int quant,                                  int quant,
718                                  int fcode,                                  int fcode,
719                                  int intra_dc_threshold,                                  int intra_dc_threshold,
# Line 823  Line 722 
722          uint32_t x, y;          uint32_t x, y;
723          uint32_t bound;          uint32_t bound;
724          int cp_mb, st_mb;          int cp_mb, st_mb;
725          uint32_t mb_width = dec->mb_width;          const uint32_t mb_width = dec->mb_width;
726          uint32_t mb_height = dec->mb_height;          const uint32_t mb_height = dec->mb_height;
   
         if (reduced_resolution) {  
                 mb_width = (dec->width + 31) / 32;  
                 mb_height = (dec->height + 31) / 32;  
         }  
727    
728          if (!dec->is_edged[0]) {          if (!dec->is_edged[0]) {
729                  start_timer();                  start_timer();
# Line 948  Line 842 
842                                          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;
843                                          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;
844                                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,                                          decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant,
845                                                                          intra_dc_threshold, bound, reduced_resolution);                                                                          intra_dc_threshold, bound);
846                                          continue;                                          continue;
847                                  }                                  }
848    
849                                  decoder_mbinter(dec, mb, x, y, cbp, bs,                                  decoder_mbinter(dec, mb, x, y, cbp, bs, rounding, 0);
                                                                 rounding, reduced_resolution, 0);  
850    
851                          } else if (gmc_warp) {  /* a not coded S(GMC)-VOP macroblock */                          } else if (gmc_warp) {  /* a not coded S(GMC)-VOP macroblock */
852                                  mb->mode = MODE_NOT_CODED_GMC;                                  mb->mode = MODE_NOT_CODED_GMC;
# Line 973  Line 866 
866                                  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;
867    
868                                  decoder_mbinter(dec, mb, x, y, 0, bs,                                  decoder_mbinter(dec, mb, x, y, 0, bs,
869                                                                  rounding, reduced_resolution, 0);                                                                  rounding, 0);
870    
871                                  if(dec->out_frm && cp_mb > 0) {                                  if(dec->out_frm && cp_mb > 0) {
872                                          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);
# Line 1160  Line 1053 
1053          stop_comp_timer();          stop_comp_timer();
1054    
1055          if (cbp)          if (cbp)
1056                  decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, 0, pMB);                  decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, pMB);
1057  }  }
1058    
1059  /* for decode B-frame dbquant */  /* for decode B-frame dbquant */
# Line 1230  Line 1123 
1123                          MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x];                          MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x];
1124                          MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x];                          MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x];
1125                          const int fcode_max = (fcode_forward>fcode_backward) ? fcode_forward : fcode_backward;                          const int fcode_max = (fcode_forward>fcode_backward) ? fcode_forward : fcode_backward;
1126                          uint32_t intra_dc_threshold; /* fake variable */                          int32_t intra_dc_threshold; /* fake variable */
1127    
1128                          if (check_resync_marker(bs, fcode_max  - 1)) {                          if (check_resync_marker(bs, fcode_max  - 1)) {
1129                                  int bound = read_video_packet_header(bs, dec, fcode_max - 1, &quant,                                  int bound = read_video_packet_header(bs, dec, fcode_max - 1, &quant,
# Line 1255  Line 1148 
1148                          if (last_mb->mode == MODE_NOT_CODED) {                          if (last_mb->mode == MODE_NOT_CODED) {
1149                                  mb->cbp = 0;                                  mb->cbp = 0;
1150                                  mb->mode = MODE_FORWARD;                                  mb->mode = MODE_FORWARD;
1151                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 1);                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 1);
1152                                  continue;                                  continue;
1153                          }                          }
1154    
# Line 1338  Line 1231 
1231                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_backward, dec->p_bmv, dec, x, y);                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_backward, dec->p_bmv, dec, x, y);
1232                                  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];
1233    
1234                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 0);                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0);
1235                                  break;                                  break;
1236    
1237                          case MODE_FORWARD:                          case MODE_FORWARD:
1238                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv, dec, x, y);                                  get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv, dec, x, y);
1239                                  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];
1240    
1241                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 1);                                  decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 1);
1242                                  break;                                  break;
1243    
1244                          default:                          default:
# Line 1402  Line 1295 
1295    
1296          Bitstream bs;          Bitstream bs;
1297          uint32_t rounding;          uint32_t rounding;
         uint32_t reduced_resolution;  
1298          uint32_t quant = 2;          uint32_t quant = 2;
1299          uint32_t fcode_forward;          uint32_t fcode_forward;
1300          uint32_t fcode_backward;          uint32_t fcode_backward;
# Line 1457  Line 1349 
1349    
1350  repeat:  repeat:
1351    
1352          coding_type = BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,          coding_type = BitstreamReadHeaders(&bs, dec, &rounding,
1353                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp);                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp);
1354    
1355          DPRINTF(XVID_DEBUG_HEADER, "coding_type=%i,  packed=%i,  time=%lli,  time_pp=%i,  time_bp=%i\n",          DPRINTF(XVID_DEBUG_HEADER, "coding_type=%i,  packed=%i,  time=%"
1356    #if defined(_MSC_VER)
1357        "I64"
1358    #else
1359        "ll"
1360    #endif
1361        "i,  time_pp=%i,  time_bp=%i\n",
1362                                                          coding_type,    dec->packed_mode, dec->time, dec->time_pp, dec->time_bp);                                                          coding_type,    dec->packed_mode, dec->time, dec->time_pp, dec->time_bp);
1363    
1364          if (coding_type == -1) { /* nothing */          if (coding_type == -1) { /* nothing */
# Line 1508  Line 1406 
1406          } else if (coding_type != B_VOP) {          } else if (coding_type != B_VOP) {
1407                  switch(coding_type) {                  switch(coding_type) {
1408                  case I_VOP :                  case I_VOP :
1409                          decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);                          decoder_iframe(dec, &bs, quant, intra_dc_threshold);
1410                          break;                          break;
1411                  case P_VOP :                  case P_VOP :
1412                          decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,                          decoder_pframe(dec, &bs, rounding, quant,
1413                                                  fcode_forward, intra_dc_threshold, NULL);                                                  fcode_forward, intra_dc_threshold, NULL);
1414                          break;                          break;
1415                  case S_VOP :                  case S_VOP :
1416                          decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,                          decoder_pframe(dec, &bs, rounding, quant,
1417                                                  fcode_forward, intra_dc_threshold, &gmc_warp);                                                  fcode_forward, intra_dc_threshold, &gmc_warp);
1418                          break;                          break;
1419                  case N_VOP :                  case N_VOP :
# Line 1526  Line 1424 
1424                          break;                          break;
1425                  }                  }
1426    
                 if (reduced_resolution) {  
                         image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,  
                                 (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width,  
                                 16, 0);  
                 }  
   
1427                  /* 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 */
1428                  if (!(dec->low_delay_default && dec->packed_mode)) {                  if (!(dec->low_delay_default && dec->packed_mode)) {
1429                          if (dec->low_delay) {                          if (dec->low_delay) {
# Line 1549  Line 1441 
1441                  image_swap(&dec->cur, &dec->refn[0]);                  image_swap(&dec->cur, &dec->refn[0]);
1442                  dec->is_edged[0] = 0;                  dec->is_edged[0] = 0;
1443                  SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs);                  SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs);
                 dec->last_reduced_resolution = reduced_resolution;  
1444                  dec->last_coding_type = coding_type;                  dec->last_coding_type = coding_type;
1445    
1446                  dec->frames++;                  dec->frames++;
# Line 1594  Line 1485 
1485    
1486  done :  done :
1487    
1488          /* low_delay_default mode: if we've gotten here without outputting anything,    /* if we reach here without outputing anything _and_
1489             then output the recently decoded frame, or print an error message  */       the calling application has specified low_delay_default,
1490         we *must* output something.
1491         this always occurs on the first call to decode() call
1492         when bframes are present in the bitstream. it may also
1493         occur if no vops  were seen in the bitstream
1494    
1495         if packed_mode is enabled, then we output the recently
1496         decoded frame (the very first ivop). otherwise we have
1497         nothing to display, and therefore output a black screen.
1498      */
1499          if (dec->low_delay_default && output == 0) {          if (dec->low_delay_default && output == 0) {
1500                  if (dec->packed_mode && seen_something) {                  if (dec->packed_mode && seen_something) {
                         /* output the recently decoded frame */  
1501                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant);                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant);
1502                  } else {                  } else {
1503                          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);
                         image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,  
                                 "warning: nothing to output");  
                         image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,  
                                 "bframe decoder lag");  
   
1504                          decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP, quant);                          decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP, quant);
1505                          if (stats) stats->type = XVID_TYPE_NOTHING;                          if (stats) stats->type = XVID_TYPE_NOTHING;
1506                  }                  }

Legend:
Removed from v.1.66  
changed lines
  Added in v.1.71

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