aboutsummaryrefslogtreecommitdiffstats
path: root/src/inputPlugins
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2006-10-03 00:58:20 +0000
committerWarren Dukes <warren.dukes@gmail.com>2006-10-03 00:58:20 +0000
commit648f48ce3b0685260f4c578b5eccd0d1b7471046 (patch)
treedf1115a0676e3374ffaec87120c878c80688fec9 /src/inputPlugins
parent4d6db2eb375e52415866274d1e15addc324e4aeb (diff)
downloadmpd-648f48ce3b0685260f4c578b5eccd0d1b7471046.tar.gz
mpd-648f48ce3b0685260f4c578b5eccd0d1b7471046.tar.xz
mpd-648f48ce3b0685260f4c578b5eccd0d1b7471046.zip
handle invalid xing tags better.
git-svn-id: https://svn.musicpd.org/mpd/trunk@4866 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/inputPlugins/mp3_plugin.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c
index f0744f22c..5275dcf9b 100644
--- a/src/inputPlugins/mp3_plugin.c
+++ b/src/inputPlugins/mp3_plugin.c
@@ -648,6 +648,29 @@ static int decodeFirstFrame(mp3DecodeData * data, DecoderControl * dc,
ptr = data->stream.anc_ptr;
bitlen = data->stream.anc_bitlen;
+ /*
+ * Attempt to calulcate the length of the song from filesize
+ */
+ size_t offset = data->inStream->offset;
+ mad_timer_t duration = data->frame.header.duration;
+ float frameTime = ((float)mad_timer_count(duration, MAD_UNITS_MILLISECONDS)) / 1000;
+
+ if (data->stream.this_frame != NULL)
+ offset -= data->stream.bufend - data->stream.this_frame;
+ else
+ offset -= data->stream.bufend - data->stream.buffer;
+
+ if (data->inStream->size >= offset) {
+ data->totalTime = ((data->inStream->size - offset) * 8.0) / (data->frame).header.bitrate;
+ data->maxFrames = data->totalTime / frameTime + FRAMES_CUSHION;
+ } else {
+ data->maxFrames = FRAMES_CUSHION;
+ data->totalTime = 0;
+ }
+
+ /*
+ * if an xing tag exists, use that!
+ */
if (parse_xing(&xing, &ptr, &bitlen)) {
data->foundXing = 1;
data->muteFrame = MUTEFRAME_SKIP;
@@ -657,31 +680,16 @@ static int decodeFirstFrame(mp3DecodeData * data, DecoderControl * dc,
data->dropSamplesAtEnd = lame.encoderPadding;
}
- if (xing.flags & XING_FRAMES) {
+ if ((xing.flags & XING_FRAMES) && xing.frames) {
mad_timer_t duration = data->frame.header.duration;
mad_timer_multiply(&duration, xing.frames);
data->totalTime = ((float)mad_timer_count(duration, MAD_UNITS_MILLISECONDS)) / 1000;
data->maxFrames = xing.frames;
}
- } else {
- size_t offset = data->inStream->offset;
- mad_timer_t duration = data->frame.header.duration;
- float frameTime = ((float)mad_timer_count(duration, MAD_UNITS_MILLISECONDS)) / 1000;
-
- if (data->stream.this_frame != NULL)
- offset -= data->stream.bufend - data->stream.this_frame;
- else
- offset -= data->stream.bufend - data->stream.buffer;
-
- if (data->inStream->size >= offset) {
- data->totalTime = ((data->inStream->size - offset) * 8.0) / (data->frame).header.bitrate;
- data->maxFrames = data->totalTime / frameTime + FRAMES_CUSHION;
- } else {
- data->maxFrames = FRAMES_CUSHION;
- data->totalTime = 0;
- }
}
+ if (!data->maxFrames) return -1;
+
data->frameOffset = xmalloc(sizeof(long) * data->maxFrames);
data->times = xmalloc(sizeof(mad_timer_t) * data->maxFrames);