diff --git a/apps/main.c b/apps/main.c index 596d76223d..9d5aa77bcf 100644 --- a/apps/main.c +++ b/apps/main.c @@ -144,15 +144,32 @@ void init_tagcache(void) { #ifdef HAVE_LCD_BITMAP int font_w, font_h; - - /* Print "Scanning disk..." to the display. */ - lcd_getstringsize("A", &font_w, &font_h); - lcd_putsxy((LCD_WIDTH/2) - ((strlen(str(LANG_TAGCACHE_INIT))*font_w)/2), - LCD_HEIGHT-font_h*3, str(LANG_TAGCACHE_INIT)); - lcd_update(); #endif tagcache_init(); + + while (!tagcache_is_initialized()) + { +#ifdef HAVE_LCD_BITMAP + char buf[64]; + int ret; + + ret = tagcache_get_commit_step(); + if (ret > 0) + { + snprintf(buf, sizeof buf, "%s [%d/%d]", + str(LANG_TAGCACHE_INIT), ret, TAG_COUNT); + + /* Print "Scanning disk..." to the display. */ + lcd_getstringsize("A", &font_w, &font_h); + lcd_putsxy((LCD_WIDTH/2) - ((strlen(buf)*font_w)/2), + LCD_HEIGHT-font_h*3, buf); + lcd_update(); + } +#endif + sleep(HZ/4); + } + tagtree_init(); #ifdef HAVE_LCD_BITMAP @@ -377,9 +394,9 @@ void init(void) init_dircache(); - init_tagcache(); gui_sync_wps_init(); settings_apply(); + init_tagcache(); status_init(); playlist_init(); diff --git a/apps/tagcache.c b/apps/tagcache.c index b6b12b7035..b91e065ab8 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -59,6 +59,12 @@ static const int unique_tags[] = { tag_artist, tag_album, tag_genre, tag_compose /* Numeric tags (we can use these tags with conditional clauses). */ static const int numeric_tags[] = { tag_year, tag_tracknumber, tag_length, tag_bitrate }; +/* When thread initialization and memory allocation has been made. */ +static bool tagcache_init_done = false; + +/* Progress indicator while committing the cache. */ +static int init_step; + /* Queue commands. */ #define Q_STOP_SCAN 0 #define Q_START_SCAN 1 @@ -1780,8 +1786,10 @@ static bool commit(void) logf("commit %d entries...", header.entry_count); /* Now create the index files. */ + init_step = 0; for (i = 0; i < TAG_COUNT; i++) { + init_step++; if (tagcache_is_numeric_tag(i)) { build_numeric_index(i, &header, tmpfd); @@ -1791,11 +1799,13 @@ static bool commit(void) { logf("tagcache failed init"); remove_files(); + init_step = 0; return false; } } close(tmpfd); + init_step = 0; /* Update the master index headers. */ masterfd = open(TAGCACHE_FILE_MASTER, O_RDWR); @@ -2221,6 +2231,20 @@ static void tagcache_thread(void) struct event ev; bool check_done = false; + /* If the previous cache build/update was interrupted, commit + * the changes first. */ + cpu_boost(true); + allocate_tempbuf(); + commit(); + free_tempbuf(); + cpu_boost(false); + +#ifdef HAVE_TC_RAMCACHE + /* Allocate space for the tagcache if found on disk. */ + allocate_tagcache(); +#endif + tagcache_init_done = true; + while (1) { queue_wait_w_tmo(&tagcache_queue, &ev, HZ); @@ -2316,22 +2340,20 @@ bool tagcache_is_ramcache(void) void tagcache_init(void) { - /* If the previous cache build/update was interrupted, commit - * the changes first. */ - cpu_boost(true); - allocate_tempbuf(); - commit(); - free_tempbuf(); - cpu_boost(false); - -#ifdef HAVE_TC_RAMCACHE - /* Allocate space for the tagcache if found on disk. */ - allocate_tagcache(); -#endif - + tagcache_init_done = false; + init_step = 0; queue_init(&tagcache_queue); create_thread(tagcache_thread, tagcache_stack, sizeof(tagcache_stack), tagcache_thread_name); } +bool tagcache_is_initialized(void) +{ + return tagcache_init_done; +} + +int tagcache_get_commit_step(void) +{ + return init_step; +} diff --git a/apps/tagcache.h b/apps/tagcache.h index 2def028b7c..468c48c45d 100644 --- a/apps/tagcache.h +++ b/apps/tagcache.h @@ -100,6 +100,8 @@ bool tagcache_is_ramcache(void); bool tagcache_fill_tags(struct mp3entry *id3, const char *filename); #endif void tagcache_init(void); +bool tagcache_is_initialized(void); +int tagcache_get_commit_step(void); void tagcache_start_scan(void); void tagcache_stop_scan(void); bool tagcache_force_update(void);