comparison src/madplug/decoder.c @ 959:b2fbf53360cf trunk

[svn] bug fix for #897 - make mp3 header parsing continue even if xing header is located first. - if xing header does not provide enough information to calculate average bitrate, scan_file() now calculate it from frames.
author yaz
date Sat, 14 Apr 2007 22:08:50 -0700
parents 3673bbab7372
children 6ba4a4bfd127
comparison
equal deleted inserted replaced
958:30e515b6e651 959:b2fbf53360cf
176 int tagsize = 0; 176 int tagsize = 0;
177 unsigned char buffer[BUFFER_SIZE]; 177 unsigned char buffer[BUFFER_SIZE];
178 struct mad_frame frame; /* to read xing data */ 178 struct mad_frame frame; /* to read xing data */
179 gboolean has_xing = FALSE; 179 gboolean has_xing = FALSE;
180 int bitrate_frames = 0; 180 int bitrate_frames = 0;
181 guint xing_bitrate = 0;
181 182
182 mad_stream_init(&stream); 183 mad_stream_init(&stream);
183 mad_header_init(&header); 184 mad_header_init(&header);
184 mad_frame_init(&frame); 185 mad_frame_init(&frame);
185 xing_init(&info->xing); 186 xing_init(&info->xing);
297 mad_timer_multiply(&info->duration, info->frames); 298 mad_timer_multiply(&info->duration, info->frames);
298 else { 299 else {
299 info->duration.seconds = info->tuple->length / 1000; 300 info->duration.seconds = info->tuple->length / 1000;
300 info->duration.fraction = info->tuple->length % 1000; 301 info->duration.fraction = info->tuple->length % 1000;
301 } 302 }
302 info->bitrate = 303 xing_bitrate =
303 8.0 * info->xing.bytes / 304 8.0 * info->xing.bytes /
304 mad_timer_count(info->duration, 305 mad_timer_count(info->duration,
305 MAD_UNITS_SECONDS); 306 MAD_UNITS_SECONDS);
306 break; 307 #ifdef DEBUG
308 g_message("xing: bitrate = %d", xing_bitrate);
309 #endif
310 continue;
307 } 311 }
308 } 312 }
309 313
310 } 314 }
311 else { 315 else {
361 } 365 }
362 if (stream.error != MAD_ERROR_BUFLEN) 366 if (stream.error != MAD_ERROR_BUFLEN)
363 break; 367 break;
364 } 368 }
365 369
366 if (info->vbr && !has_xing) 370 if (info->vbr && xing_bitrate == 0) {
367 info->bitrate = info->bitrate / bitrate_frames; 371 info->bitrate = info->bitrate / bitrate_frames;
372 #ifdef DEBUG
373 g_message("info->bitrate = %d", info->bitrate);
374 #endif
375 }
368 376
369 mad_frame_finish(&frame); 377 mad_frame_finish(&frame);
370 mad_header_finish(&header); 378 mad_header_finish(&header);
371 mad_stream_finish(&stream); 379 mad_stream_finish(&stream);
372 xing_finish(&info->xing); 380 xing_finish(&info->xing);
373 381
374 #ifdef DEBUG 382 #ifdef DEBUG
383 g_message("scan_file: info->frames = %d", info->frames);
375 g_message("e: scan_file"); 384 g_message("e: scan_file");
376 #endif /* DEBUG */ 385 #endif /* DEBUG */
377 return (info->frames != 0 || info->remote == TRUE); 386 return (info->frames != 0 || info->remote == TRUE);
378 } 387 }
379 388