Mercurial > audlegacy-plugins
comparison src/madplug/decoder.c @ 674:fadf4c18a1cf trunk
[svn] madplug bug fix:
- no longer crashes on extra long TCON tag.
- now scan_file() calculates track length properly.
| author | yaz |
|---|---|
| date | Mon, 19 Feb 2007 18:08:27 -0800 |
| parents | 8ed0af226d0e |
| children | 1733b12ef974 |
comparison
equal
deleted
inserted
replaced
| 673:8ed0af226d0e | 674:fadf4c18a1cf |
|---|---|
| 184 mad_frame_init(&frame); | 184 mad_frame_init(&frame); |
| 185 xing_init(&info->xing); | 185 xing_init(&info->xing); |
| 186 | 186 |
| 187 info->bitrate = 0; | 187 info->bitrate = 0; |
| 188 info->pos = mad_timer_zero; | 188 info->pos = mad_timer_zero; |
| 189 info->duration.seconds = 0; // should be cleared before loop, if we use it as break condition. | |
| 189 | 190 |
| 190 #ifdef DEBUG | 191 #ifdef DEBUG |
| 191 g_message("f: scan_file"); | 192 g_message("f: scan_file"); |
| 192 #endif /* DEBUG */ | 193 #endif /* DEBUG */ |
| 193 | 194 |
| 208 if (len <= 0) | 209 if (len <= 0) |
| 209 break; | 210 break; |
| 210 | 211 |
| 211 mad_stream_buffer(&stream, buffer, len + remainder); | 212 mad_stream_buffer(&stream, buffer, len + remainder); |
| 212 | 213 |
| 213 while (info->duration.seconds == 0) { | 214 while (!fast || (fast && info->frames < N_AVERAGE_FRAMES)) { |
| 214 if (mad_header_decode(&header, &stream) == -1) { | 215 if (mad_header_decode(&header, &stream) == -1) { |
| 215 if (stream.error == MAD_ERROR_BUFLEN) { | 216 if (stream.error == MAD_ERROR_BUFLEN) { |
| 216 break; | 217 break; |
| 217 } | 218 } |
| 218 if (!MAD_RECOVERABLE(stream.error)) { | 219 if (!MAD_RECOVERABLE(stream.error)) { |
| 244 g_message("len = %d", len); | 245 g_message("len = %d", len); |
| 245 #endif /* DEBUG */ | 246 #endif /* DEBUG */ |
| 246 continue; | 247 continue; |
| 247 } | 248 } |
| 248 info->frames++; | 249 info->frames++; |
| 250 | |
| 249 #ifdef DEBUG | 251 #ifdef DEBUG |
| 250 #ifdef DEBUG_INTENSIVELY | 252 #ifdef DEBUG_INTENSIVELY |
| 251 g_message("duration = %lu", | 253 g_message("duration = %lu", |
| 252 mad_timer_count(header.duration, | 254 mad_timer_count(header.duration, |
| 253 MAD_UNITS_MILLISECONDS)); | 255 MAD_UNITS_MILLISECONDS)); |
| 264 info->mpeg_layer = header.layer; | 266 info->mpeg_layer = header.layer; |
| 265 info->mode = header.mode; | 267 info->mode = header.mode; |
| 266 | 268 |
| 267 if (audmad_config.use_xing) { | 269 if (audmad_config.use_xing) { |
| 268 frame.header = header; | 270 frame.header = header; |
| 269 if (mad_frame_decode(&frame, &stream) == -1) | 271 if (mad_frame_decode(&frame, &stream) == -1) { |
| 270 break; | 272 #ifdef DEBUG |
| 273 printf("xing frame decode failed\n"); | |
| 274 #endif | |
| 275 goto no_xing; | |
| 276 } | |
| 271 if (xing_parse | 277 if (xing_parse |
| 272 (&info->xing, stream.anc_ptr, | 278 (&info->xing, stream.anc_ptr, |
| 273 stream.anc_bitlen) == 0) { | 279 stream.anc_bitlen) == 0) { |
| 274 #ifdef DEBUG | 280 #ifdef DEBUG |
| 275 g_message("found xing header"); | 281 g_message("found xing header"); |
| 301 if (info->freq != header.samplerate) | 307 if (info->freq != header.samplerate) |
| 302 g_warning("samplerate varies!!"); | 308 g_warning("samplerate varies!!"); |
| 303 if (info->channels != MAD_NCHANNELS(&header)) | 309 if (info->channels != MAD_NCHANNELS(&header)) |
| 304 g_warning("number of channels varies!!"); | 310 g_warning("number of channels varies!!"); |
| 305 } | 311 } |
| 306 | 312 no_xing: |
| 307 if (fast && info->frames >= N_AVERAGE_FRAMES) { | 313 if (fast && info->frames >= N_AVERAGE_FRAMES) { |
| 308 float frame_size = ((double) data_used) / N_AVERAGE_FRAMES; | 314 float frame_size = ((double) data_used) / N_AVERAGE_FRAMES; |
| 309 info->frames = (info->size - tagsize) / frame_size; | 315 info->frames = (info->size - tagsize) / frame_size; |
| 310 info->duration.seconds /= N_AVERAGE_FRAMES; | 316 info->duration.seconds /= N_AVERAGE_FRAMES; |
| 311 info->duration.fraction /= N_AVERAGE_FRAMES; | 317 info->duration.fraction /= N_AVERAGE_FRAMES; |
