[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.17, Thu Oct 16 12:16:00 2003 UTC revision 1.49.2.26, Wed Dec 17 17:07:38 2003 UTC
# Line 41  Line 41 
41  #include "bitstream/mbcoding.h"  #include "bitstream/mbcoding.h"
42    
43  #include "quant/quant.h"  #include "quant/quant.h"
44    #include "quant/quant_matrix.h"
45  #include "dct/idct.h"  #include "dct/idct.h"
46  #include "dct/fdct.h"  #include "dct/fdct.h"
47  #include "utils/mem_transfer.h"  #include "utils/mem_transfer.h"
# Line 57  Line 58 
58    
59  #include "image/image.h"  #include "image/image.h"
60  #include "image/colorspace.h"  #include "image/colorspace.h"
61    #include "image/postprocessing.h"
62  #include "utils/mem_align.h"  #include "utils/mem_align.h"
63    
64  static int  static int
# Line 175  Line 177 
177          if (dec == NULL) {          if (dec == NULL) {
178                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
179          }          }
180    
181          memset(dec, 0, sizeof(DECODER));          memset(dec, 0, sizeof(DECODER));
182    
183            dec->mpeg_quant_matrices = xvid_malloc(sizeof(uint16_t) * 64 * 8, CACHE_LINE);
184            if (dec->mpeg_quant_matrices == NULL) {
185                    xvid_free(dec);
186                    return XVID_ERR_MEMORY;
187            }
188    
189          create->handle = dec;          create->handle = dec;
190    
191          dec->width = create->width;          dec->width = create->width;
# Line 196  Line 205 
205          dec->last_mbs = NULL;          dec->last_mbs = NULL;
206    
207          init_timer();          init_timer();
208            init_postproc();
209            init_mpeg_matrix(dec->mpeg_quant_matrices);
210    
211          /* For B-frame support (used to save reference frame's time */          /* For B-frame support (used to save reference frame's time */
212          dec->frames = 0;          dec->frames = 0;
# Line 226  Line 237 
237          image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);          image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
238          image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);          image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);
239          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);          image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
240            xvid_free(dec->mpeg_quant_matrices);
241          xvid_free(dec);          xvid_free(dec);
242    
243          write_timer();          write_timer();
# Line 321  Line 333 
333    
334                  start_timer();                  start_timer();
335                  if (dec->quant_type == 0) {                  if (dec->quant_type == 0) {
336                          dequant_h263_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler);                          dequant_h263_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler, dec->mpeg_quant_matrices);
337                  } else {                  } else {
338                          dequant_mpeg_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler);                          dequant_mpeg_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler, dec->mpeg_quant_matrices);
339                  }                  }
340                  stop_iquant_timer();                  stop_iquant_timer();
341    
# Line 373  Line 385 
385          DECLARE_ALIGNED_MATRIX(block, 1, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(block, 1, 64, int16_t, CACHE_LINE);
386          DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);
387    
388          int stride = dec->edged_width, next_block = stride * (reduced_resolution ? 16 : 8);          int stride = dec->edged_width;
389            int next_block = stride * (reduced_resolution ? 16 : 8);
390          const int stride2 = stride/2;          const int stride2 = stride/2;
391          int i;          int i;
392          const uint32_t iQuant = pMB->quant;          const uint32_t iQuant = pMB->quant;
# Line 391  Line 404 
404                          stop_coding_timer();                          stop_coding_timer();
405    
406                          start_timer();                          start_timer();
407                          dequant(&data[i * 64], block, iQuant);                          dequant(&data[i * 64], block, iQuant, dec->mpeg_quant_matrices);
408                          stop_iquant_timer();                          stop_iquant_timer();
409    
410                          start_timer();                          start_timer();
# Line 450  Line 463 
463  {  {
464          uint32_t stride = dec->edged_width;          uint32_t stride = dec->edged_width;
465          uint32_t stride2 = stride / 2;          uint32_t stride2 = stride / 2;
         uint32_t next_block = stride * (reduced_resolution ? 16 : 8);  
466          uint32_t i;          uint32_t i;
467    
468          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
# Line 963  Line 975 
975  {  {
976          uint32_t stride = dec->edged_width;          uint32_t stride = dec->edged_width;
977          uint32_t stride2 = stride / 2;          uint32_t stride2 = stride / 2;
         uint32_t next_block = stride * 8;  
978          int uv_dx, uv_dy;          int uv_dx, uv_dy;
979          int b_uv_dx, b_uv_dy;          int b_uv_dx, b_uv_dy;
980          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
# Line 1165  Line 1176 
1176          const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp;          const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp;
1177          int i;          int i;
1178    
 #ifdef BFRAMES_DEC_DEBUG  
         FILE *fp;  
         static char first=0;  
 #define BFRAME_DEBUG  
         if (!first && fp) { \  
                 fprintf(fp,"Y=%3d   X=%3d   MB=%2d   CBP=%02X\n",y,x,mb->mode,mb->cbp); \  
         }  
 #endif  
   
1179          start_timer();          start_timer();
1180          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,          image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height,
1181                                          dec->width, dec->height);                                          dec->width, dec->height);
# Line 1181  Line 1183 
1183                                          dec->width, dec->height);                                          dec->width, dec->height);
1184          stop_edges_timer();          stop_edges_timer();
1185    
 #ifdef BFRAMES_DEC_DEBUG  
         if (!first){  
                 fp=fopen("C:\\XVIDDBG.TXT","w");  
         }  
 #endif  
   
1186          for (y = 0; y < dec->mb_height; y++) {          for (y = 0; y < dec->mb_height; y++) {
1187                  /* Initialize Pred Motion Vector */                  /* Initialize Pred Motion Vector */
1188                  dec->p_fmv = dec->p_bmv = zeromv;                  dec->p_fmv = dec->p_bmv = zeromv;
1189                  for (x = 0; x < dec->mb_width; x++) {                  for (x = 0; x < dec->mb_width; x++) {
1190                          MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x];                          MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x];
1191                          MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x];                          MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x];
1192                            const int fcode_max = (fcode_forward>fcode_backward) ? fcode_forward : fcode_backward;
1193                            uint32_t intra_dc_threshold; /* fake variable */
1194    
1195                            if (check_resync_marker(bs, fcode_max  - 1)) {
1196                                    int bound = read_video_packet_header(bs, dec, fcode_max - 1, &quant,
1197                                                                                                             &fcode_forward, &fcode_backward, &intra_dc_threshold);
1198                                    x = bound % dec->mb_width;
1199                                    y = bound / dec->mb_width;
1200                                    /* reset predicted macroblocks */
1201                                    dec->p_fmv = dec->p_bmv = zeromv;
1202                            }
1203    
1204                          mv =                          mv =
1205                          mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] =                          mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] =
# Line 1305  Line 1312 
1312                          }                          }
1313                  } /* End of for */                  } /* End of for */
1314          }          }
   
 #ifdef BFRAMES_DEC_DEBUG  
         if (!first){  
                 first=1;  
                 if (fp)  
                         fclose(fp);  
         }  
 #endif  
1315  }  }
1316    
1317  /* perform post processing if necessary, and output the image */  /* perform post processing if necessary, and output the image */
1318  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,
1319                                          xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type)                                          xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type)
1320  {  {
1321            if (frame->general & (XVID_DEBLOCKY|XVID_DEBLOCKUV) && mbs != NULL)     /* post process */
1322            {
1323                    /* note: image is stored to tmp */
1324                    image_copy(&dec->tmp, img, dec->edged_width, dec->height);
1325                    image_postproc(&dec->tmp, dec->edged_width,
1326                                               mbs, dec->mb_width, dec->mb_height, dec->mb_width,
1327                                               frame->general, dec->frames);
1328                    img = &dec->tmp;
1329            }
1330    
1331          image_output(img, dec->width, dec->height,          image_output(img, dec->width, dec->height,
1332                                   dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride,                                   dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride,
1333                                   frame->output.csp, dec->interlacing);                                   frame->output.csp, dec->interlacing);
# Line 1453  Line 1462 
1462                          /* XXX: not_coded vops are not used for forward prediction */                          /* XXX: not_coded vops are not used for forward prediction */
1463                          /* we should not swap(last_mbs,mbs) */                          /* we should not swap(last_mbs,mbs) */
1464                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);
1465                            SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs); /* it will be swapped back */
1466                          break;                          break;
1467                  }                  }
1468    
# Line 1494  Line 1504 
1504                          /* attemping to decode a bvop without atleast 2 reference frames */                          /* attemping to decode a bvop without atleast 2 reference frames */
1505                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
1506                                                  "broken b-frame, mising ref frames");                                                  "broken b-frame, mising ref frames");
1507                            stats->type = XVID_TYPE_NOTHING;
1508                  } else if (dec->time_pp <= dec->time_bp) {                  } else if (dec->time_pp <= dec->time_bp) {
1509                          /* this occurs when dx50_bvop_compatibility==0 sequences are                          /* this occurs when dx50_bvop_compatibility==0 sequences are
1510                          decoded in vfw. */                          decoded in vfw. */
1511                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16,
1512                                                  "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);
1513                            stats->type = XVID_TYPE_NOTHING;
1514                  } else {                  } else {
1515                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);
1516                            decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);
1517                  }                  }
1518    
                 decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);  
1519                  output = 1;                  output = 1;
1520                  dec->frames++;                  dec->frames++;
1521          }          }

Legend:
Removed from v.1.49.2.17  
changed lines
  Added in v.1.49.2.26

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