[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.68, Sun Dec 5 13:56:13 2004 UTC revision 1.71, Mon May 23 09:29:43 2005 UTC
# Line 73  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 87  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 171  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 1155  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 1384  Line 1352 
1352          coding_type = BitstreamReadHeaders(&bs, dec, &rounding,          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 1511  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.68  
changed lines
  Added in v.1.71

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