From f4f4111536951feed392a6869575ed80ffe87c4d Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Tue, 27 Jul 2004 14:10:48 +0000 Subject: [PATCH] Added possibility to select the priority of the ID3 tags git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4962 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugin.c | 113 +++++++++++++++----------------- apps/plugin.h | 117 +++++++++++++++------------------- apps/plugins/vbrfix.c | 2 +- apps/talk.c | 2 +- firmware/export/id3.h | 2 +- firmware/export/mpeg.h | 1 + firmware/id3.c | 22 ++++--- firmware/mpeg.c | 15 +++-- uisimulator/common/mpegplay.c | 2 +- 9 files changed, 129 insertions(+), 147 deletions(-) diff --git a/apps/plugin.c b/apps/plugin.c index 413caf87a1..e5a496c567 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -88,19 +88,25 @@ static const struct plugin_api rockbox_api = { lcd_puts, lcd_puts_scroll, lcd_stop_scroll, + lcd_set_contrast, #ifdef HAVE_LCD_CHARCELLS lcd_define_pattern, lcd_get_locked_pattern, lcd_unlock_pattern, lcd_putc, + lcd_put_cursor, + lcd_remove_cursor, + lcd_icon, #else lcd_putsxy, + lcd_puts_style, lcd_bitmap, lcd_drawline, lcd_clearline, lcd_drawpixel, lcd_clearpixel, lcd_setfont, + font_get, lcd_clearrect, lcd_fillrect, lcd_drawrect, @@ -109,14 +115,21 @@ static const struct plugin_api rockbox_api = { lcd_update, lcd_update_rect, scrollbar, + checkbox, + &lcd_framebuffer[0][0], + lcd_blit, #ifndef SIMULATOR lcd_roll, #endif #endif + backlight_on, + backlight_off, /* button */ button_get, button_get_w_tmo, + button_status, + button_clear_queue, /* file */ (open_func)PREFIX(open), @@ -131,6 +144,7 @@ static const struct plugin_api rockbox_api = { PREFIX(filesize), fprintf, read_line, + settings_parseline, /* dir */ PREFIX(opendir), @@ -139,14 +153,21 @@ static const struct plugin_api rockbox_api = { /* kernel */ PREFIX(sleep), + yield, usb_screen, ¤t_tick, + default_event_handler, + create_thread, + remove_thread, /* strings and memory */ snprintf, strcpy, + strncpy, strlen, strrchr, + strcmp, + strcasecmp, memset, memcpy, #ifndef SIMULATOR @@ -154,32 +175,6 @@ static const struct plugin_api rockbox_api = { #endif /* sound */ -#ifndef SIMULATOR -#ifdef HAVE_MAS3587F - mas_codec_readreg, -#endif -#endif - - /* misc */ - srand, - rand, - splash, - (qsort_func)qsort, - kbd_input, - mpeg_current_track, - atoi, - get_time, - plugin_get_buffer, - - /* new stuff at the end, sort into place next time the API gets incompatible */ - -#ifndef HAVE_LCD_CHARCELLS - &lcd_framebuffer[0][0], - lcd_blit, -#endif - yield, - - plugin_get_mp3_buffer, mpeg_sound_set, #ifndef SIMULATOR mp3_play_data, @@ -187,23 +182,12 @@ static const struct plugin_api rockbox_api = { mp3_play_stop, mp3_is_playing, bitswap, +#ifdef HAVE_MAS3587F + mas_codec_readreg, #endif - &global_settings, - backlight_set_timeout, -#ifndef SIMULATOR - ata_sleep, #endif -#ifdef HAVE_LCD_BITMAP - checkbox, -#endif -#ifndef SIMULATOR - plugin_register_timer, - plugin_unregister_timer, -#endif - plugin_tsr, - create_thread, - remove_thread, - lcd_set_contrast, + + /* playback control */ mpeg_play, mpeg_stop, mpeg_pause, @@ -215,8 +199,31 @@ static const struct plugin_api rockbox_api = { playlist_amount, mpeg_status, mpeg_has_changed_track, -#ifdef HAVE_LCD_BITMAP - font_get, + + /* misc */ + srand, + rand, + splash, + (qsort_func)qsort, + kbd_input, + mpeg_current_track, + atoi, + get_time, + plugin_get_buffer, + plugin_get_mp3_buffer, +#ifndef SIMULATOR + plugin_register_timer, + plugin_unregister_timer, +#endif + plugin_tsr, + + /* new stuff at the end, sort into place next time the API gets incompatible */ + + + &global_settings, + backlight_set_timeout, +#ifndef SIMULATOR + ata_sleep, #endif #if defined(DEBUG) || defined(SIMULATOR) debugf, @@ -238,26 +245,6 @@ static const struct plugin_api rockbox_api = { set_time, reset_poweroff_timer, - backlight_on, - backlight_off, - -#ifdef HAVE_LCD_CHARCELLS - lcd_icon, -#endif -#ifdef HAVE_LCD_BITMAP - lcd_puts_style, -#endif -#ifdef HAVE_LCD_CHARCELLS - lcd_put_cursor, - lcd_remove_cursor, -#endif - settings_parseline, - strcmp, - button_status, - button_clear_queue, - strncpy, - strcasecmp, - default_event_handler }; int plugin_load(char* plugin, void* parameter) diff --git a/apps/plugin.h b/apps/plugin.h index 74700879b4..51607a53e6 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -60,12 +60,12 @@ #endif /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 24 +#define PLUGIN_API_VERSION 25 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any new function which are "waiting" at the end of the function table) */ -#define PLUGIN_MIN_API_VERSION 19 +#define PLUGIN_MIN_API_VERSION 25 /* plugin return codes */ enum plugin_status { @@ -114,13 +114,18 @@ struct plugin_api { void (*lcd_puts)(int x, int y, unsigned char *string); void (*lcd_puts_scroll)(int x, int y, unsigned char* string); void (*lcd_stop_scroll)(void); + void (*lcd_set_contrast)(int x); #ifdef HAVE_LCD_CHARCELLS void (*lcd_define_pattern)(int which,char *pattern); unsigned char (*lcd_get_locked_pattern)(void); void (*lcd_unlock_pattern)(unsigned char pat); void (*lcd_putc)(int x, int y, unsigned short ch); + void (*lcd_put_cursor)(int x, int y, char cursor_char); + void (*lcd_remove_cursor)(void); + void (*lcd_icon)(int icon, bool enable); #else void (*lcd_putsxy)(int x, int y, const unsigned char *string); + void (*lcd_puts_style)(int x, int y, unsigned char *str, int style); void (*lcd_bitmap)(const unsigned char *src, int x, int y, int nx, int ny, bool clear); void (*lcd_drawline)(int x1, int y1, int x2, int y2); @@ -128,6 +133,7 @@ struct plugin_api { void (*lcd_drawpixel)(int x, int y); void (*lcd_clearpixel)(int x, int y); void (*lcd_setfont)(int font); + struct font* (*font_get)(int font); void (*lcd_clearrect)(int x, int y, int nx, int ny); void (*lcd_fillrect)(int x, int y, int nx, int ny); void (*lcd_drawrect)(int x, int y, int nx, int ny); @@ -137,14 +143,21 @@ struct plugin_api { void (*lcd_update_rect)(int x, int y, int width, int height); void (*scrollbar)(int x, int y, int width, int height, int items, int min_shown, int max_shown, int orientation); + void (*checkbox)(int x, int y, int width, int height, bool checked); + unsigned char* lcd_framebuffer; + void (*lcd_blit) (unsigned char* p_data, int x, int y, int width, int height, int stride); #ifndef SIMULATOR void (*lcd_roll)(int pixels); #endif #endif + void (*backlight_on)(void); + void (*backlight_off)(void); /* button */ int (*button_get)(bool block); int (*button_get_w_tmo)(int ticks); + int (*button_status)(void); + void (*button_clear_queue)(void); /* file */ int (*open)(const char* pathname, int flags); @@ -159,6 +172,7 @@ struct plugin_api { int (*filesize)(int fd); int (*fprintf)(int fd, const char *fmt, ...); int (*read_line)(int fd, char* buffer, int buffer_size); + bool (*settings_parseline)(char* line, char** name, char** value); /* dir */ DIR* (*opendir)(const char* name); @@ -167,14 +181,21 @@ struct plugin_api { /* kernel */ void (*sleep)(int ticks); + void (*yield)(void); void (*usb_screen)(void); long* current_tick; + int (*default_event_handler)(int event); + int (*create_thread)(void* function, void* stack, int stack_size, char *name); + void (*remove_thread)(int threadnum); /* strings and memory */ int (*snprintf)(char *buf, size_t size, const char *fmt, ...); char* (*strcpy)(char *dst, const char *src); + char *(*strncpy)(char *dst, const char *src, size_t length); size_t (*strlen)(const char *str); char * (*strrchr)(const char *s, int c); + int (*strcmp)(const char *, const char *); + int (*strcasecmp)(const char *, const char *); void* (*memset)(void *dst, int c, size_t length); void* (*memcpy)(void *out, const void *in, size_t n); #ifndef SIMULATOR @@ -182,32 +203,6 @@ struct plugin_api { #endif /* sound */ -#ifndef SIMULATOR -#ifdef HAVE_MAS3587F - int (*mas_codec_readreg)(int reg); -#endif -#endif - - /* misc */ - void (*srand)(unsigned int seed); - int (*rand)(void); - void (*splash)(int ticks, bool center, char *fmt, ...); - void (*qsort)(void *base, size_t nmemb, size_t size, - int(*compar)(const void *, const void *)); - int (*kbd_input)(char* buffer, int buflen); - struct mp3entry* (*mpeg_current_track)(void); - int (*atoi)(const char *str); - struct tm* (*get_time)(void); - void* (*plugin_get_buffer)(int* buffer_size); - - /* new stuff, sort in next time the API gets broken! */ -#ifndef HAVE_LCD_CHARCELLS - unsigned char* lcd_framebuffer; - void (*lcd_blit) (unsigned char* p_data, int x, int y, int width, int height, int stride); -#endif - void (*yield)(void); - - void* (*plugin_get_mp3_buffer)(int* buffer_size); void (*mpeg_sound_set)(int setting, int value); #ifndef SIMULATOR void (*mp3_play_data)(unsigned char* start, int size, void (*get_more)(unsigned char** start, int* size)); @@ -215,23 +210,10 @@ struct plugin_api { void (*mp3_play_stop)(void); bool (*mp3_is_playing)(void); void (*bitswap)(unsigned char *data, int length); +#ifdef HAVE_MAS3587F + int (*mas_codec_readreg)(int reg); #endif - struct user_settings* global_settings; - void (*backlight_set_timeout)(int index); -#ifndef SIMULATOR - int (*ata_sleep)(void); #endif -#ifdef HAVE_LCD_BITMAP - void (*checkbox)(int x, int y, int width, int height, bool checked); -#endif -#ifndef SIMULATOR - int (*plugin_register_timer)(int cycles, int prio, void (*timer_callback)(void)); - void (*plugin_unregister_timer)(void); -#endif - void (*plugin_tsr)(void (*exit_callback)(void)); - int (*create_thread)(void* function, void* stack, int stack_size, char *name); - void (*remove_thread)(int threadnum); - void (*lcd_set_contrast)(int x); /* playback control */ void (*mpeg_play)(int offset); @@ -246,14 +228,37 @@ struct plugin_api { int (*mpeg_status)(void); bool (*mpeg_has_changed_track)(void); -#ifdef HAVE_LCD_BITMAP - struct font* (*font_get)(int font); + /* misc */ + void (*srand)(unsigned int seed); + int (*rand)(void); + void (*splash)(int ticks, bool center, char *fmt, ...); + void (*qsort)(void *base, size_t nmemb, size_t size, + int(*compar)(const void *, const void *)); + int (*kbd_input)(char* buffer, int buflen); + struct mp3entry* (*mpeg_current_track)(void); + int (*atoi)(const char *str); + struct tm* (*get_time)(void); + void* (*plugin_get_buffer)(int* buffer_size); + void* (*plugin_get_mp3_buffer)(int* buffer_size); +#ifndef SIMULATOR + int (*plugin_register_timer)(int cycles, int prio, void (*timer_callback)(void)); + void (*plugin_unregister_timer)(void); #endif + void (*plugin_tsr)(void (*exit_callback)(void)); + + /* new stuff, sort in next time the API gets broken! */ + + struct user_settings* global_settings; + void (*backlight_set_timeout)(int index); +#ifndef SIMULATOR + int (*ata_sleep)(void); +#endif + #if defined(DEBUG) || defined(SIMULATOR) void (*debugf)(char *fmt, ...); #endif - bool (*mp3info)(struct mp3entry *entry, char *filename) ; + bool (*mp3info)(struct mp3entry *entry, char *filename, bool v1first); int (*count_mp3_frames)(int fd, int startpos, int filesize, void (*progressfunc)(int)); int (*create_xing_header)(int fd, int startpos, int filesize, @@ -274,26 +279,6 @@ struct plugin_api { int (*set_time)(struct tm *tm); void (*reset_poweroff_timer)(void); - void (*backlight_on)(void); - void (*backlight_off)(void); - -#ifdef HAVE_LCD_CHARCELLS - void (*lcd_icon)(int icon, bool enable); -#endif -#ifdef HAVE_LCD_BITMAP - void (*lcd_puts_style)(int x, int y, unsigned char *str, int style); -#endif -#ifdef HAVE_LCD_CHARCELLS - void (*lcd_put_cursor)(int x, int y, char cursor_char); - void (*lcd_remove_cursor)(void); -#endif - bool (*settings_parseline)(char* line, char** name, char** value); - int (*strcmp)(const char *, const char *); - int (*button_status)(void); - void (*button_clear_queue)(void); - char *(*strncpy)(char *dst, const char *src, size_t length); - int (*strcasecmp)(const char *, const char *); - int (*default_event_handler)(int event); }; /* defined by the plugin loader (plugin.c) */ diff --git a/apps/plugins/vbrfix.c b/apps/plugins/vbrfix.c index 1beca2669d..0077340ec9 100644 --- a/apps/plugins/vbrfix.c +++ b/apps/plugins/vbrfix.c @@ -145,7 +145,7 @@ static bool vbr_fix(char *selected_file) xingupdate(0); - rc = rb->mp3info(&entry, selected_file); + rc = rb->mp3info(&entry, selected_file, false); if(rc < 0) { fileerror(rc); return true; diff --git a/apps/talk.c b/apps/talk.c index 462ab85dd1..51e8ae7f01 100644 --- a/apps/talk.c +++ b/apps/talk.c @@ -390,7 +390,7 @@ int talk_file(char* filename, bool enqueue) if (p_thumbnail == NULL || size_for_thumbnail <= 0) return -1; - if(mp3info(&info, filename)) /* use this to find real start */ + if(mp3info(&info, filename, false)) /* use this to find real start */ { return 0; /* failed to open, or invalid */ } diff --git a/firmware/export/id3.h b/firmware/export/id3.h index 6e53e4c66c..10f8002db6 100644 --- a/firmware/export/id3.h +++ b/firmware/export/id3.h @@ -74,7 +74,7 @@ enum { ID3_VER_2_4 }; -bool mp3info(struct mp3entry *entry, char *filename); +bool mp3info(struct mp3entry *entry, char *filename, bool v1first); char* id3_get_genre(struct mp3entry* id3); #endif diff --git a/firmware/export/mpeg.h b/firmware/export/mpeg.h index 252e509c94..51932c5090 100644 --- a/firmware/export/mpeg.h +++ b/firmware/export/mpeg.h @@ -96,6 +96,7 @@ void mpeg_error_clear(void); /* in order to keep the recording here, I have to expose this */ void rec_tick(void); void playback_tick(void); /* FixMe: get rid of this, use mp3_get_playtime() */ +void mpeg_id3_options(bool _v1first); #define MPEG_STATUS_PLAY 1 #define MPEG_STATUS_PAUSE 2 diff --git a/firmware/id3.c b/firmware/id3.c index 70add41b6b..03c37c027e 100644 --- a/firmware/id3.c +++ b/firmware/id3.c @@ -798,13 +798,12 @@ static int getsonglength(int fd, struct mp3entry *entry) * Checks all relevant information (such as ID3v1 tag, ID3v2 tag, length etc) * about an MP3 file and updates it's entry accordingly. * - * Arguments: entry - the entry to check and update with the new information - * - * Returns: void */ -bool mp3info(struct mp3entry *entry, char *filename) +bool mp3info(struct mp3entry *entry, char *filename, bool v1first) { int fd; + int v1found = false; + fd = open(filename, O_RDONLY); if(-1 == fd) return true; @@ -819,7 +818,10 @@ bool mp3info(struct mp3entry *entry, char *filename) entry->tracknum = 0; entry->genre = 0xff; - if (entry->id3v2len) + if(v1first) + v1found = setid3v1title(fd, entry); + + if (!v1found && entry->id3v2len) setid3v2title(fd, entry); entry->length = getsonglength(fd, entry); @@ -827,10 +829,10 @@ bool mp3info(struct mp3entry *entry, char *filename) the true size of the MP3 stream */ entry->filesize -= entry->first_frame_offset; - /* only seek to end of file if no id3v2 tags were found */ - if (!entry->id3v2len) { - if(!entry->title) - setid3v1title(fd, entry); + /* only seek to end of file if no id3v2 tags were found, + and we already haven't looked for a v1 tag */ + if (!v1first && !entry->id3v2len) { + setid3v1title(fd, entry); } close(fd); @@ -860,7 +862,7 @@ int main(int argc, char **argv) for(i=1; iid3), filename)) + if(mp3info(&(t->id3), filename, v1first)) { DEBUGF("Bad mp3\n"); return -1; @@ -1985,6 +1987,11 @@ static void mpeg_thread(void) static struct mp3entry taginfo; #endif /* #ifdef SIMULATOR */ +void mpeg_id3_options(bool _v1first) +{ + v1first = _v1first; +} + struct mp3entry* mpeg_current_track() { #ifdef SIMULATOR @@ -2443,7 +2450,7 @@ void mpeg_play(int offset) trackname = playlist_peek( steps ); if (!trackname) break; - if(mp3info(&taginfo, trackname)) { + if(mp3info(&taginfo, trackname, v1first)) { /* bad mp3, move on */ if(++steps > playlist_amount()) break; @@ -2518,7 +2525,7 @@ void mpeg_next(void) file = playlist_peek(steps); if(!file) break; - if(mp3info(&taginfo, file)) { + if(mp3info(&taginfo, file, v1first)) { if(++steps > playlist_amount()) break; continue; @@ -2546,7 +2553,7 @@ void mpeg_prev(void) file = playlist_peek(steps); if(!file) break; - if(mp3info(&taginfo, file)) { + if(mp3info(&taginfo, file, v1first)) { steps--; continue; } diff --git a/uisimulator/common/mpegplay.c b/uisimulator/common/mpegplay.c index c7e2552b35..fa1333b3b5 100644 --- a/uisimulator/common/mpegplay.c +++ b/uisimulator/common/mpegplay.c @@ -133,7 +133,7 @@ void real_mpeg_play(char* fname) static struct dither d0, d1; int key=0; - mp3info(&mp3, fname); + mp3info(&mp3, fname, false); /* FIXME: honor the v1first setting */ init_sound(&sound);