Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

plugins: properties: optimize slightly

- We only have to update stats->dirname when entering
a new directory, or when id3cb needs to be called
- Reduce frequency for calling get_action and LCD update
- Replace dir_stats->len and hardcoded MAX_PATH with
sizeof
- Don't show paths in Properties during scanning
- Don't show error when user cancels

Change-Id: I4afbeba561e69188e8039fa8d91eb1e91318bdab

+33 -30
+33 -30
apps/plugins/properties.c
··· 27 27 28 28 struct dir_stats { 29 29 char dirname[MAX_PATH]; 30 - int len; 31 30 unsigned int dir_count; 32 31 unsigned int file_count; 33 32 unsigned int audio_file_count; 34 33 unsigned long long byte_count; 34 + bool canceled; 35 35 }; 36 36 37 37 enum props_types { ··· 147 147 static bool _dir_properties(struct dir_stats *stats, bool (*id3_cb)(const char*)) 148 148 { 149 149 bool result = true; 150 - static long last_tick = 0; 150 + static unsigned long last_lcd_update, last_get_action; 151 151 struct dirent* entry; 152 152 int dirlen = rb->strlen(stats->dirname); 153 153 DIR* dir = rb->opendir(stats->dirname); ··· 161 161 while(result && (0 != (entry = rb->readdir(dir)))) 162 162 { 163 163 struct dirinfo info = rb->dir_get_info(dir, entry); 164 - 165 - rb->snprintf(stats->dirname + dirlen, stats->len - dirlen, "/%s", 166 - entry->d_name); /* append name to current directory */ 167 - 168 164 if (info.attribute & ATTR_DIRECTORY) 169 165 { 170 166 if (!rb->strcmp((char *)entry->d_name, ".") || 171 167 !rb->strcmp((char *)entry->d_name, "..")) 172 168 continue; /* skip these */ 173 169 170 + rb->snprintf(stats->dirname + dirlen, sizeof(stats->dirname) - dirlen, 171 + "/%s", entry->d_name); /* append name to current directory */ 172 + 174 173 if (!id3_cb) 175 174 { 176 175 stats->dir_count++; /* new directory */ 177 - if (*rb->current_tick - last_tick > (HZ/8)) 176 + if (*rb->current_tick - last_lcd_update > (HZ/2)) 178 177 { 179 178 unsigned int log; 180 - last_tick = *(rb->current_tick); 179 + last_lcd_update = *(rb->current_tick); 181 180 rb->lcd_clear_display(); 182 - rb->lcd_puts(0, 0, "SCANNING..."); 183 - rb->lcd_puts(0, 1, stats->dirname); 184 - rb->lcd_putsf(0, 2, "Directories: %d", stats->dir_count); 185 - rb->lcd_putsf(0, 3, "Files: %d (Audio: %d)", 181 + rb->lcd_putsf(0, 0, "Directories: %d", stats->dir_count); 182 + rb->lcd_putsf(0, 1, "Files: %d (Audio: %d)", 186 183 stats->file_count, stats->audio_file_count); 187 184 log = human_size_log(stats->byte_count); 188 - rb->lcd_putsf(0, 4, "Size: %lu %s", 185 + rb->lcd_putsf(0, 2, "Size: %lu %s", 189 186 (unsigned long)(stats->byte_count >> (10*log)), 190 187 rb->str(units[log])); 191 188 rb->lcd_update(); ··· 205 202 { 206 203 rb->splash_progress(mul_id3_count, stats->audio_file_count, "%s (%s)", 207 204 rb->str(LANG_WAIT), rb->str(LANG_OFF_ABORT)); 205 + rb->snprintf(stats->dirname + dirlen, sizeof(stats->dirname) - dirlen, 206 + "/%s", entry->d_name); /* append name to current directory */ 208 207 id3_cb(stats->dirname); /* allow metadata to be collected */ 209 208 } 210 209 211 - if(ACTION_STD_CANCEL == rb->get_action(CONTEXT_STD,TIMEOUT_NOBLOCK)) 212 - result = false; 210 + if (TIME_AFTER(*(rb->current_tick), last_get_action + HZ/8)) 211 + { 212 + if(ACTION_STD_CANCEL == rb->get_action(CONTEXT_STD,TIMEOUT_NOBLOCK)) 213 + { 214 + stats->canceled = true; 215 + result = false; 216 + } 217 + last_get_action = *(rb->current_tick); 218 + } 213 219 rb->yield(); 214 220 } 215 221 rb->closedir(dir); ··· 230 236 unsigned int log; 231 237 bool success; 232 238 233 - rb->strlcpy(stats->dirname, selected_file, MAX_PATH); 239 + rb->strlcpy(stats->dirname, selected_file, sizeof(stats->dirname)); 234 240 if (id3_cb) 235 241 rb->splash_progress_set_delay(HZ / 2); /* hide progress bar for 0.5s */ 236 242 ··· 248 254 249 255 if (!id3_cb) 250 256 { 251 - rb->strlcpy(str_dirname, selected_file, MAX_PATH); 257 + rb->strlcpy(str_dirname, selected_file, sizeof(str_dirname)); 252 258 rb->snprintf(str_dircount, sizeof str_dircount, "%d", stats->dir_count); 253 259 rb->snprintf(str_filecount, sizeof str_filecount, "%d", stats->file_count); 254 260 rb->snprintf(str_audio_filecount, sizeof str_filecount, "%d", ··· 475 481 enum plugin_status plugin_start(const void* parameter) 476 482 { 477 483 int ret; 478 - static struct dir_stats stats = 479 - { 480 - .len = MAX_PATH, 481 - .dir_count = 0, 482 - .file_count = 0, 483 - .audio_file_count = 0, 484 - .byte_count = 0, 485 - }; 484 + static struct dir_stats stats; 486 485 487 486 const char *file = parameter; 488 487 if(!parameter) ··· 498 497 int dirlen = (file_name - file); 499 498 500 499 rb->strlcpy(str_dirname, file, dirlen + 1); 501 - rb->snprintf(str_filename, sizeof str_filename, "%s", file+dirlen); 500 + rb->snprintf(str_filename, sizeof str_filename, "%s", file + dirlen); 502 501 503 502 if(!determine_file_or_dir()) 504 503 { ··· 514 513 if(!(props_type == PROPS_DIR ? 515 514 dir_properties(file, &stats, NULL) : file_properties(file))) 516 515 { 517 - /* something went wrong (to do: tell user what it was (nesting,...) */ 518 - rb->splash(0, ID2P(LANG_PROPERTIES_FAIL)); 519 - rb->action_userabort(TIMEOUT_BLOCK); 516 + if (!stats.canceled) 517 + { 518 + /* something went wrong (to do: tell user what it was (nesting,...) */ 519 + rb->splash(0, ID2P(LANG_PROPERTIES_FAIL)); 520 + rb->action_userabort(TIMEOUT_BLOCK); 521 + } 520 522 return PLUGIN_OK; 521 523 } 522 524 } ··· 534 536 ret = rb->browse_id3(&id3, 0, 0, NULL, mul_id3_count); /* database tracks */ 535 537 else if ((ret = browse_file_or_dir(&stats)) < 0) 536 538 ret = assemble_track_info(file, &stats) ? /* playlist or folder tracks */ 537 - rb->browse_id3(&id3, 0, 0, NULL, mul_id3_count) : -1; 539 + rb->browse_id3(&id3, 0, 0, NULL, mul_id3_count) : 540 + (stats.canceled ? 0 : -1); 538 541 539 542 FOR_NB_SCREENS(i) 540 543 rb->viewportmanager_theme_undo(i, false);