diff options
-rw-r--r-- | apps/wps-display.c | 21 | ||||
-rw-r--r-- | firmware/id3.c | 42 | ||||
-rw-r--r-- | firmware/id3.h | 9 |
3 files changed, 60 insertions, 12 deletions
diff --git a/apps/wps-display.c b/apps/wps-display.c index 19e505c52f..5ac2aa1f2b 100644 --- a/apps/wps-display.c +++ b/apps/wps-display.c | |||
@@ -295,6 +295,27 @@ static char* get_tag(struct mp3entry* id3, | |||
295 | else | 295 | else |
296 | return NULL; | 296 | return NULL; |
297 | break; | 297 | break; |
298 | |||
299 | case 'v': /* id3 version */ | ||
300 | switch (id3->id3version) { | ||
301 | case ID3_VER_1_0: | ||
302 | return "1"; | ||
303 | |||
304 | case ID3_VER_1_1: | ||
305 | return "1.1"; | ||
306 | |||
307 | case ID3_VER_2_2: | ||
308 | return "2.2"; | ||
309 | |||
310 | case ID3_VER_2_3: | ||
311 | return "2.3"; | ||
312 | |||
313 | case ID3_VER_2_4: | ||
314 | return "2.4"; | ||
315 | |||
316 | default: | ||
317 | return NULL; | ||
318 | } | ||
298 | } | 319 | } |
299 | break; | 320 | break; |
300 | 321 | ||
diff --git a/firmware/id3.c b/firmware/id3.c index 4b72e4ca4d..2dd03c19eb 100644 --- a/firmware/id3.c +++ b/firmware/id3.c | |||
@@ -168,6 +168,8 @@ static bool setid3v1title(int fd, struct mp3entry *entry) | |||
168 | if (strncmp(buffer, "TAG", 3)) | 168 | if (strncmp(buffer, "TAG", 3)) |
169 | return false; | 169 | return false; |
170 | 170 | ||
171 | entry->id3version = ID3_VER_1_0; | ||
172 | |||
171 | for (i=0; i < (int)sizeof offsets; i++) { | 173 | for (i=0; i < (int)sizeof offsets; i++) { |
172 | char* ptr = buffer + offsets[i]; | 174 | char* ptr = buffer + offsets[i]; |
173 | 175 | ||
@@ -179,17 +181,17 @@ static bool setid3v1title(int fd, struct mp3entry *entry) | |||
179 | 181 | ||
180 | switch(i) { | 182 | switch(i) { |
181 | case 0: | 183 | case 0: |
182 | strcpy(entry->id3v1buf[2], ptr); | 184 | strncpy(entry->id3v1buf[2], ptr, 30); |
183 | entry->title = entry->id3v1buf[2]; | 185 | entry->title = entry->id3v1buf[2]; |
184 | break; | 186 | break; |
185 | 187 | ||
186 | case 1: | 188 | case 1: |
187 | strcpy(entry->id3v1buf[0], ptr); | 189 | strncpy(entry->id3v1buf[0], ptr, 30); |
188 | entry->artist = entry->id3v1buf[0]; | 190 | entry->artist = entry->id3v1buf[0]; |
189 | break; | 191 | break; |
190 | 192 | ||
191 | case 2: | 193 | case 2: |
192 | strcpy(entry->id3v1buf[1], ptr); | 194 | strncpy(entry->id3v1buf[1], ptr, 30); |
193 | entry->album = entry->id3v1buf[1]; | 195 | entry->album = entry->id3v1buf[1]; |
194 | break; | 196 | break; |
195 | 197 | ||
@@ -201,8 +203,10 @@ static bool setid3v1title(int fd, struct mp3entry *entry) | |||
201 | case 4: | 203 | case 4: |
202 | /* id3v1.1 uses last two bytes of comment field for track | 204 | /* id3v1.1 uses last two bytes of comment field for track |
203 | number: first must be 0 and second is track num */ | 205 | number: first must be 0 and second is track num */ |
204 | if (*ptr == 0) | 206 | if (!ptr[0] && ptr[1]) { |
205 | entry->tracknum = ptr[1]; | 207 | entry->tracknum = ptr[1]; |
208 | entry->id3version = ID3_VER_1_1; | ||
209 | } | ||
206 | break; | 210 | break; |
207 | 211 | ||
208 | case 5: | 212 | case 5: |
@@ -230,7 +234,7 @@ static void setid3v2title(int fd, struct mp3entry *entry) | |||
230 | int size; | 234 | int size; |
231 | int bufferpos = 0, totframelen, framelen; | 235 | int bufferpos = 0, totframelen, framelen; |
232 | char header[10]; | 236 | char header[10]; |
233 | unsigned short int version; | 237 | unsigned char version; |
234 | char *buffer = entry->id3v2buf; | 238 | char *buffer = entry->id3v2buf; |
235 | char *tracknum = NULL; | 239 | char *tracknum = NULL; |
236 | int bytesread = 0; | 240 | int bytesread = 0; |
@@ -245,16 +249,30 @@ static void setid3v2title(int fd, struct mp3entry *entry) | |||
245 | if(10 != read(fd, header, 10)) | 249 | if(10 != read(fd, header, 10)) |
246 | return; | 250 | return; |
247 | 251 | ||
248 | version = (unsigned short int)header[3]; | ||
249 | |||
250 | /* Get the total ID3 tag size */ | 252 | /* Get the total ID3 tag size */ |
251 | size = entry->id3v2len - 10; | 253 | size = entry->id3v2len - 10; |
252 | 254 | ||
253 | /* Set minimum frame size according to ID3v2 version */ | 255 | version = header[3]; |
254 | if(version > 2) | 256 | switch ( version ) { |
255 | minframesize = 12; | 257 | case 2: |
256 | else | 258 | entry->id3version = ID3_VER_2_2; |
257 | minframesize = 8; | 259 | minframesize = 8; |
260 | break; | ||
261 | |||
262 | case 3: | ||
263 | entry->id3version = ID3_VER_2_3; | ||
264 | minframesize = 12; | ||
265 | break; | ||
266 | |||
267 | case 4: | ||
268 | entry->id3version = ID3_VER_2_4; | ||
269 | minframesize = 12; | ||
270 | break; | ||
271 | |||
272 | default: | ||
273 | /* unsupported id3 version */ | ||
274 | return; | ||
275 | } | ||
258 | 276 | ||
259 | /* | 277 | /* |
260 | * We must have at least minframesize bytes left for the | 278 | * We must have at least minframesize bytes left for the |
diff --git a/firmware/id3.h b/firmware/id3.h index 11d9eee19e..55ce002c2e 100644 --- a/firmware/id3.h +++ b/firmware/id3.h | |||
@@ -30,6 +30,7 @@ struct mp3entry { | |||
30 | int version; | 30 | int version; |
31 | int layer; | 31 | int layer; |
32 | int year; | 32 | int year; |
33 | unsigned char id3version; | ||
33 | unsigned char genre; | 34 | unsigned char genre; |
34 | unsigned int bitrate; | 35 | unsigned int bitrate; |
35 | unsigned int frequency; | 36 | unsigned int frequency; |
@@ -62,6 +63,14 @@ struct mp3entry { | |||
62 | #define VBR_BYTES_FLAG 0x02 | 63 | #define VBR_BYTES_FLAG 0x02 |
63 | #define VBR_TOC_FLAG 0x04 | 64 | #define VBR_TOC_FLAG 0x04 |
64 | 65 | ||
66 | enum { | ||
67 | ID3_VER_1_0 = 1, | ||
68 | ID3_VER_1_1, | ||
69 | ID3_VER_2_2, | ||
70 | ID3_VER_2_3, | ||
71 | ID3_VER_2_4 | ||
72 | }; | ||
73 | |||
65 | bool mp3info(struct mp3entry *entry, char *filename); | 74 | bool mp3info(struct mp3entry *entry, char *filename); |
66 | 75 | ||
67 | #endif | 76 | #endif |