summaryrefslogtreecommitdiff
path: root/lib/rbcodec/metadata/mp3.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/metadata/mp3.c')
-rw-r--r--lib/rbcodec/metadata/mp3.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/rbcodec/metadata/mp3.c b/lib/rbcodec/metadata/mp3.c
index 661fea8e51..2096e70898 100644
--- a/lib/rbcodec/metadata/mp3.c
+++ b/lib/rbcodec/metadata/mp3.c
@@ -71,7 +71,9 @@ static int getsonglength(int fd, struct mp3entry *entry)
71 if(bytecount < 0) 71 if(bytecount < 0)
72 return -1; 72 return -1;
73 73
74 bytecount += entry->id3v2len; 74 /* Subtract the meta information from the file size to get
75 the true size of the MP3 stream */
76 entry->filesize -= entry->id3v1len + entry->id3v2len;
75 77
76 /* Validate byte count, in case the file has been edited without 78 /* Validate byte count, in case the file has been edited without
77 * updating the header. 79 * updating the header.
@@ -99,6 +101,9 @@ static int getsonglength(int fd, struct mp3entry *entry)
99 } 101 }
100 } 102 }
101 103
104 entry->filesize -= bytecount;
105 bytecount += entry->id3v2len;
106
102 entry->bitrate = info.bitrate; 107 entry->bitrate = info.bitrate;
103 entry->frequency = info.frequency; 108 entry->frequency = info.frequency;
104 entry->layer = info.layer; 109 entry->layer = info.layer;
@@ -127,7 +132,7 @@ static int getsonglength(int fd, struct mp3entry *entry)
127 if (info.bitrate < 8) 132 if (info.bitrate < 8)
128 filetime = 0; 133 filetime = 0;
129 else 134 else
130 filetime = (entry->filesize - bytecount) / (info.bitrate / 8); 135 filetime = entry->filesize / (info.bitrate >> 3);
131 /* bitrate is in kbps so this delivers milliseconds. Doing bitrate / 8 136 /* bitrate is in kbps so this delivers milliseconds. Doing bitrate / 8
132 * instead of filesize * 8 is exact, because mpeg audio bitrates are 137 * instead of filesize * 8 is exact, because mpeg audio bitrates are
133 * always multiples of 8, and it avoids overflows. */ 138 * always multiples of 8, and it avoids overflows. */
@@ -163,6 +168,7 @@ bool get_mp3_metadata(int fd, struct mp3entry *entry)
163{ 168{
164 entry->title = NULL; 169 entry->title = NULL;
165 entry->filesize = filesize(fd); 170 entry->filesize = filesize(fd);
171 entry->id3v1len = getid3v1len(fd);
166 entry->id3v2len = getid3v2len(fd); 172 entry->id3v2len = getid3v2len(fd);
167 entry->tracknum = 0; 173 entry->tracknum = 0;
168 entry->discnum = 0; 174 entry->discnum = 0;
@@ -174,10 +180,6 @@ bool get_mp3_metadata(int fd, struct mp3entry *entry)
174 return false; 180 return false;
175 entry->length = len; 181 entry->length = len;
176 182
177 /* Subtract the meta information from the file size to get
178 the true size of the MP3 stream */
179 entry->filesize -= entry->first_frame_offset;
180
181 /* only seek to end of file if no id3v2 tags were found */ 183 /* only seek to end of file if no id3v2 tags were found */
182 if (!entry->id3v2len) { 184 if (!entry->id3v2len) {
183 setid3v1title(fd, entry); 185 setid3v1title(fd, entry);