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.

PictureFlow: Don't require restart before rebuilding cache

You were asked to restart the plugin, before
PictureFlow would rebuild the cache after
selecting the menu option for it. This patch
eliminates the need for leaving the plugin, and
PictureFlow will rebuild its cache immediately.

Change-Id: I47ec78339fdc91efd42cd7850829256417682eae

authored by

Christian Soffke and committed by
Solomon Peachy
dff29110 87344d18

+201 -139
+4 -4
apps/lang/english.lang
··· 14828 14828 </phrase> 14829 14829 <phrase> 14830 14830 id: LANG_CACHE_REBUILT_NEXT_RESTART 14831 - desc: in the pictureflow splash messages 14831 + desc: deprecated 14832 14832 user: core 14833 14833 <source> 14834 - *: "Cache will be rebuilt on next restart" 14834 + *: "" 14835 14835 </source> 14836 14836 <dest> 14837 - *: "Cache will be rebuilt on next restart" 14837 + *: "" 14838 14838 </dest> 14839 14839 <voice> 14840 - *: "Cache will be rebuilt on next restart" 14840 + *: "" 14841 14841 </voice> 14842 14842 </phrase> 14843 14843 <phrase>
+197 -135
apps/plugins/pictureflow/pictureflow.c
··· 566 566 void reset_track_list(void); 567 567 568 568 static bool thread_is_running; 569 - static bool wants_to_quit = false; 569 + static bool wants_to_quit; 570 570 571 571 /* 572 572 Prevent picture loading thread from allocating ··· 574 574 performing buffer-shifting operations. 575 575 */ 576 576 static struct mutex buf_ctx_mutex; 577 - static bool buf_ctx_locked = false; 577 + static bool buf_ctx_locked; 578 578 579 579 static int cover_animation_keyframe; 580 580 static int extra_fade; ··· 3169 3169 3170 3170 3171 3171 static void skip_animation_to_idle_state(void); 3172 + static void return_to_idle_state(void) 3173 + { 3174 + if (pf_state == pf_show_tracks) 3175 + free_borrowed_tracks(); 3176 + if (pf_state == pf_show_tracks || 3177 + pf_state == pf_cover_in || 3178 + pf_state == pf_cover_out) 3179 + skip_animation_to_idle_state(); 3180 + else if (pf_state == pf_scrolling) 3181 + set_current_slide(target); 3182 + 3183 + pf_state = pf_idle; 3184 + } 3185 + 3186 + 3187 + static void set_initial_slide(const char* selected_file) 3188 + { 3189 + if (selected_file) 3190 + set_current_slide(retrieve_id3(&id3, selected_file) ? 3191 + id3_get_index(&id3) : 3192 + pf_cfg.last_album); 3193 + else 3194 + set_current_slide(rb->audio_status() ? 3195 + id3_get_index(rb->audio_current_track()) : 3196 + pf_cfg.last_album); 3197 + 3198 + } 3199 + 3200 + static void reselect(unsigned int hash_album, unsigned int hash_artist) 3201 + { 3202 + int i, album_idx, artist_idx; 3203 + for (i = 0; i < pf_idx.album_ct; i++ ) 3204 + { 3205 + album_idx = pf_idx.album_index[i].name_idx; 3206 + artist_idx = pf_idx.album_index[i].artist_idx; 3207 + 3208 + if(hash_album == mfnv(pf_idx.album_names + album_idx) && 3209 + hash_artist == mfnv(pf_idx.artist_names + artist_idx)) 3210 + { 3211 + set_current_slide(i); 3212 + pf_cfg.last_album = i; 3213 + return; 3214 + } 3215 + } 3216 + set_initial_slide(NULL); 3217 + } 3218 + 3172 3219 static bool sort_albums(int new_sorting, bool from_settings) 3173 3220 { 3174 - int i, album_idx, artist_idx; 3175 - char* current_album_name = NULL; 3176 - char* current_album_artist = NULL; 3221 + unsigned int hash_album, hash_artist; 3177 3222 static const char* sort_options[] = { 3178 3223 ID2P(LANG_ARTIST_PLUS_NAME), 3179 3224 ID2P(LANG_ARTIST_PLUS_YEAR), ··· 3196 3241 return false; 3197 3242 } 3198 3243 3199 - /* set idle state */ 3200 - if (pf_state == pf_show_tracks) 3201 - free_borrowed_tracks(); 3202 - if (pf_state == pf_show_tracks || 3203 - pf_state == pf_cover_in || 3204 - pf_state == pf_cover_out) 3205 - skip_animation_to_idle_state(); 3206 - else if (pf_state == pf_scrolling) 3207 - set_current_slide(target); 3208 - pf_state = pf_idle; 3244 + return_to_idle_state(); 3209 3245 3210 3246 pf_cfg.sort_albums_by = new_sorting; 3211 3247 if (!from_settings) ··· 3225 3261 #endif 3226 3262 } 3227 3263 3228 - current_album_artist = get_album_artist(center_index); 3229 - current_album_name = get_album_name(center_index); 3264 + hash_album = mfnv(get_album_name(center_index)); 3265 + hash_artist = mfnv(get_album_artist(center_index)); 3230 3266 3231 3267 end_pf_thread(); /* stop loading of covers */ 3232 3268 ··· 3240 3276 is_initial_slide = true; 3241 3277 create_pf_thread(); 3242 3278 3243 - /* Go to previously selected slide */ 3244 - for (i = 0; i < pf_idx.album_ct; i++ ) 3245 - { 3246 - album_idx = pf_idx.album_index[i].name_idx; 3247 - artist_idx = pf_idx.album_index[i].artist_idx; 3279 + reselect(hash_album, hash_artist); 3248 3280 3249 - if(!rb->strcmp(pf_idx.album_names + album_idx, current_album_name) && 3250 - !rb->strcmp(pf_idx.artist_names + artist_idx, current_album_artist)) 3251 - { 3252 - set_current_slide(i); 3253 - pf_cfg.last_album = i; 3254 - } 3255 - } 3256 3281 return true; 3257 3282 } 3258 3283 ··· 3630 3655 rb->remove(EMPTY_SLIDE); 3631 3656 configfile_save(CONFIG_FILE, config, 3632 3657 CONFIG_NUM_ITEMS, CONFIG_VERSION); 3633 - rb->splash(HZ, ID2P(LANG_CACHE_REBUILT_NEXT_RESTART)); 3634 - break; 3658 + return -3; /* re-init */ 3635 3659 case 11: 3636 3660 pf_cfg.update_albumart = true; 3637 3661 pf_cfg.cache_version = CACHE_REBUILD; 3638 3662 rb->remove(EMPTY_SLIDE); 3639 3663 configfile_save(CONFIG_FILE, config, 3640 3664 CONFIG_NUM_ITEMS, CONFIG_VERSION); 3641 - rb->splash(HZ, ID2P(LANG_CACHE_REBUILT_NEXT_RESTART)); 3642 - break; 3665 + return -3; /* re-init */ 3643 3666 case 12: 3644 3667 rb->set_option(rb->str(LANG_WPS_INTEGRATION), 3645 3668 &pf_cfg.auto_wps, RB_INT, wps_options, 3, NULL); ··· 3727 3750 #endif 3728 3751 case PF_MENU_SETTINGS: 3729 3752 result = settings_menu(); 3730 - if ( result != 0 ) return result; 3753 + if (result != 0) 3754 + return result; 3731 3755 break; 3732 3756 case PF_MENU_QUIT: 3733 3757 return -1; ··· 4390 4414 } 4391 4415 } 4392 4416 4393 - 4394 - static void set_initial_slide(const char* selected_file) 4395 - { 4396 - if (selected_file) 4397 - set_current_slide(retrieve_id3(&id3, selected_file) ? 4398 - id3_get_index(&id3) : 4399 - pf_cfg.last_album); 4400 - else 4401 - set_current_slide(rb->audio_status() ? 4402 - id3_get_index(rb->audio_current_track()) : 4403 - pf_cfg.last_album); 4404 - 4405 - } 4406 - 4407 4417 /** 4408 4418 Display an error message and wait for input. 4409 4419 */ ··· 4415 4425 rb->sleep(2 * HZ); 4416 4426 } 4417 4427 4418 - /** 4419 - Main function that also contain the main plasma 4420 - algorithm. 4421 - */ 4422 - static int pictureflow_main(const char* selected_file) 4428 + static bool init(void) 4423 4429 { 4424 4430 int ret = SUCCESS; 4431 + void * buf; 4432 + size_t buf_size; 4425 4433 4426 - rb->lcd_setfont(FONT_UI); 4434 + #ifdef HAVE_ADJUSTABLE_CPU_FREQ 4435 + rb->cpu_boost(true); /* revert in cleanup */ 4436 + #endif 4427 4437 4428 - if ( ! rb->dir_exists( CACHE_PREFIX ) ) { 4429 - if ( rb->mkdir( CACHE_PREFIX ) < 0 ) { 4430 - error_wait("Could not create directory " CACHE_PREFIX); 4431 - return PLUGIN_OK; 4432 - } 4433 - } 4438 + wants_to_quit = false; 4434 4439 4440 + /* must appear before config load */ 4435 4441 rb->memset(&aa_cache, 0, sizeof(struct albumart_t)); 4436 - config_set_defaults(&pf_cfg); 4437 4442 4443 + config_set_defaults(&pf_cfg); /* must appear before configfile_save */ 4438 4444 configfile_load(CONFIG_FILE, config, CONFIG_NUM_ITEMS, CONFIG_VERSION); 4439 4445 4440 4446 #ifdef HAVE_BACKLIGHT 4441 4447 if(pf_cfg.backlight_mode == 0) 4442 - backlight_ignore_timeout(); 4448 + backlight_ignore_timeout(); /* restore in cleanup */ 4443 4449 #endif 4444 4450 4451 + #if PF_PLAYBACK_CAPABLE 4452 + buf = rb->plugin_get_buffer(&buf_size); 4453 + #else 4454 + buf = rb->plugin_get_audio_buffer(&buf_size); 4455 + #ifndef SIMULATOR 4456 + if ((uintptr_t)buf < (uintptr_t)plugin_start_addr) 4457 + { 4458 + uint32_t tmp_size = (uintptr_t)plugin_start_addr - (uintptr_t)buf; 4459 + buf_size = MIN(buf_size, tmp_size); 4460 + } 4461 + #endif 4462 + #endif 4463 + 4464 + #ifdef USEGSLIB 4465 + long grey_buf_used; 4466 + if (!grey_init(buf, buf_size, GREY_BUFFERED|GREY_ON_COP, 4467 + LCD_WIDTH, LCD_HEIGHT, &grey_buf_used)) 4468 + { 4469 + error_wait("Greylib init failed!"); 4470 + return false; 4471 + } 4472 + grey_setfont(FONT_UI); 4473 + buf_size -= grey_buf_used; 4474 + buf = (void*)(grey_buf_used + (char*)buf); 4475 + #endif 4476 + 4477 + /* store buffer pointers and sizes */ 4478 + pf_idx.buf = buf; 4479 + pf_idx.buf_sz = buf_size; 4480 + 4481 + rb->lcd_setfont(FONT_UI); 4482 + 4483 + if (!rb->dir_exists(CACHE_PREFIX)) 4484 + { 4485 + if (rb->mkdir( CACHE_PREFIX ) < 0) 4486 + { 4487 + error_wait("Could not create directory " CACHE_PREFIX); 4488 + return false; 4489 + } 4490 + } 4491 + 4445 4492 rb->mutex_init(&buf_ctx_mutex); 4446 4493 4447 4494 init_scroll_lines(); 4448 4495 init_reflect_table(); 4449 4496 4450 4497 /*Scan will trigger when no file is found or the option was activated*/ 4451 - if ((pf_cfg.cache_version != CACHE_VERSION)||(load_album_index() < 0)){ 4498 + if ((pf_cfg.cache_version != CACHE_VERSION)|| (load_album_index() < 0)) 4499 + { 4452 4500 ret = create_album_index(); 4453 4501 4454 - if (ret == 0){ 4502 + if (ret == 0) 4503 + { 4455 4504 pf_cfg.cache_version = CACHE_REBUILD; 4456 - if (save_album_index() < 0) { 4505 + if (save_album_index() < 0) 4457 4506 rb->splash(HZ, "Could not write index"); 4458 - }; 4459 4507 } 4460 4508 } 4461 4509 4462 - if (ret == ERROR_BUFFER_FULL) { 4510 + if (ret == ERROR_BUFFER_FULL) 4511 + { 4463 4512 error_wait("Not enough memory for album names"); 4464 - return PLUGIN_OK; 4465 - } else if (ret == ERROR_NO_ALBUMS) { 4513 + return false; 4514 + } 4515 + else if (ret == ERROR_NO_ALBUMS) 4516 + { 4466 4517 error_wait("No albums found. Please enable database"); 4467 - return PLUGIN_OK; 4468 - } else if (ret == ERROR_USER_ABORT) 4469 - return PLUGIN_OK; 4518 + return false; 4519 + } 4520 + else if (ret == ERROR_USER_ABORT) 4521 + return false; 4470 4522 4471 4523 number_of_slides = pf_idx.album_ct; 4472 4524 ··· 4474 4526 if (aa_bufsz < DISPLAY_WIDTH * DISPLAY_HEIGHT * sizeof(pix_t)) 4475 4527 { 4476 4528 error_wait("Not enough memory for album art cache"); 4477 - return PLUGIN_OK; 4529 + return false; 4478 4530 } 4479 4531 4480 4532 ALIGN_BUFFER(pf_idx.buf, pf_idx.buf_sz, sizeof(long)); ··· 4484 4536 pf_idx.buf += aa_bufsz; 4485 4537 pf_idx.buf_sz -= aa_bufsz; 4486 4538 4487 - if (!create_empty_slide(pf_cfg.cache_version != CACHE_VERSION)) { 4539 + rb->buflib_init(&buf_ctx, (void *)pf_idx.buf, pf_idx.buf_sz); 4540 + initialize_slide_cache(); 4541 + is_initial_slide = true; 4542 + 4543 + if (!create_empty_slide(pf_cfg.cache_version != CACHE_VERSION)) 4544 + { 4488 4545 config_save(CACHE_REBUILD, false); 4489 4546 error_wait("Could not load the empty slide"); 4490 - return PLUGIN_OK; 4547 + return false; 4491 4548 } 4492 4549 4493 - if ((pf_cfg.cache_version != CACHE_VERSION) && !create_albumart_cache()) { 4550 + if ((pf_cfg.cache_version != CACHE_VERSION) && !create_albumart_cache()) 4551 + { 4494 4552 config_save(CACHE_REBUILD, false); 4495 4553 error_wait("Could not create album art cache"); 4496 - } else if(aa_cache.inspected < pf_idx.album_ct) { 4497 - rb->splash(HZ * 2, "Updating album art cache in background"); 4498 4554 } 4555 + else if(aa_cache.inspected < pf_idx.album_ct) 4556 + rb->splash(HZ * 2, "Updating album art cache in background"); 4499 4557 4500 4558 if (pf_cfg.cache_version != CACHE_VERSION) 4501 - { 4502 4559 config_save(CACHE_VERSION, pf_cfg.update_albumart); 4503 - } 4504 - 4505 - rb->buflib_init(&buf_ctx, (void *)pf_idx.buf, pf_idx.buf_sz); 4506 4560 4507 4561 if ((empty_slide_hid = read_pfraw(EMPTY_SLIDE, 0)) < 0) 4508 4562 { 4509 4563 error_wait("Unable to load empty slide image"); 4510 - return PLUGIN_OK; 4564 + return false; 4511 4565 } 4512 4566 4513 - if (!create_pf_thread()) { 4567 + if (!create_pf_thread()) 4568 + { 4514 4569 error_wait("Cannot create thread!"); 4515 - return PLUGIN_OK; 4570 + return false; 4516 4571 } 4517 - 4518 - initialize_slide_cache(); 4519 4572 4520 4573 buffer = LCD_BUF; 4521 4574 ··· 4533 4586 4534 4587 recalc_offsets(); 4535 4588 reset_slides(); 4536 - set_initial_slide(selected_file); 4589 + 4590 + #ifdef USEGSLIB 4591 + grey_show(true); 4592 + grey_set_drawmode(DRMODE_FG); 4593 + #endif 4594 + rb->lcd_set_drawmode(DRMODE_FG); 4537 4595 4596 + return true; 4597 + } 4598 + 4599 + static bool reinit(void) 4600 + { 4601 + return_to_idle_state(); 4602 + 4603 + unsigned int hash_album = mfnv(get_album_name(center_index)); 4604 + unsigned int hash_artist = mfnv(get_album_artist(center_index)); 4605 + 4606 + cleanup(); 4607 + if (init()) 4608 + { 4609 + reselect(hash_album, hash_artist); 4610 + return true; 4611 + } 4612 + return false; 4613 + } 4614 + 4615 + /** 4616 + Main function that also contain the main plasma 4617 + algorithm. 4618 + */ 4619 + static int pictureflow_main(void) 4620 + { 4621 + int ret; 4538 4622 char fpstxt[10]; 4539 4623 int button; 4540 - 4541 4624 int frames = 0; 4542 4625 long last_update = *rb->current_tick; 4543 4626 long current_update; 4544 4627 long update_interval = 100; 4545 4628 int fps = 0; 4546 4629 int fpstxt_y; 4547 - 4548 4630 bool instant_update; 4549 - #ifdef USEGSLIB 4550 - grey_show(true); 4551 - grey_set_drawmode(DRMODE_FG); 4552 - #endif 4553 - rb->lcd_set_drawmode(DRMODE_FG); 4631 + 4554 4632 while (true) { 4555 4633 current_update = *rb->current_tick; 4556 4634 frames++; ··· 4668 4746 ret = main_menu(); 4669 4747 FOR_NB_SCREENS(i) 4670 4748 rb->viewportmanager_theme_undo(i, false); 4671 - if ( ret == -2 ) return PLUGIN_GOTO_WPS; 4672 - if ( ret == -1 ) return PLUGIN_OK; 4673 - if ( ret != 0 ) return ret; 4749 + 4750 + if (ret == -3) 4751 + { 4752 + if (!reinit()) 4753 + return PLUGIN_OK; 4754 + } 4755 + else if (ret == -2) 4756 + return PLUGIN_GOTO_WPS; 4757 + else if (ret == -1) 4758 + return PLUGIN_OK; 4759 + else if (ret != 0 ) 4760 + return ret; 4761 + else 4762 + { 4674 4763 #ifdef USEGSLIB 4675 - grey_show(true); 4764 + grey_show(true); 4676 4765 #endif 4677 - mylcd_set_drawmode(DRMODE_FG); 4766 + mylcd_set_drawmode(DRMODE_FG); 4767 + } 4678 4768 break; 4679 4769 4680 4770 case PF_NEXT: ··· 4822 4912 4823 4913 int ret; 4824 4914 const char *file = parameter; 4825 - 4826 - void * buf; 4827 - size_t buf_size; 4828 4915 bool file_id3 = (parameter && (((char *) parameter)[0] == '/')); 4829 4916 4830 4917 if (!check_database()) ··· 4832 4919 error_wait("Please enable database"); 4833 4920 return PLUGIN_OK; 4834 4921 } 4835 - 4836 4922 atexit(cleanup); 4837 4923 4838 - #ifdef HAVE_ADJUSTABLE_CPU_FREQ 4839 - rb->cpu_boost(true); 4840 - #endif 4841 - #if PF_PLAYBACK_CAPABLE 4842 - buf = rb->plugin_get_buffer(&buf_size); 4843 - #else 4844 - buf = rb->plugin_get_audio_buffer(&buf_size); 4845 - #ifndef SIMULATOR 4846 - if ((uintptr_t)buf < (uintptr_t)plugin_start_addr) 4924 + if (init()) 4847 4925 { 4848 - uint32_t tmp_size = (uintptr_t)plugin_start_addr - (uintptr_t)buf; 4849 - buf_size = MIN(buf_size, tmp_size); 4926 + set_initial_slide(file_id3 ? file : NULL); 4927 + ret = pictureflow_main(); 4850 4928 } 4851 - #endif 4852 - #endif 4929 + else 4930 + ret = PLUGIN_OK; 4853 4931 4854 - #ifdef USEGSLIB 4855 - long grey_buf_used; 4856 - if (!grey_init(buf, buf_size, GREY_BUFFERED|GREY_ON_COP, 4857 - LCD_WIDTH, LCD_HEIGHT, &grey_buf_used)) 4932 + if ( ret == PLUGIN_OK || ret == PLUGIN_GOTO_WPS) 4858 4933 { 4859 - error_wait("Greylib init failed!"); 4860 - return PLUGIN_OK; 4861 - } 4862 - grey_setfont(FONT_UI); 4863 - buf_size -= grey_buf_used; 4864 - buf = (void*)(grey_buf_used + (char*)buf); 4865 - #endif 4866 - 4867 - /* store buffer pointers and sizes */ 4868 - pf_idx.buf = buf; 4869 - pf_idx.buf_sz = buf_size; 4870 - 4871 - ret = file_id3 ? pictureflow_main(file) : pictureflow_main(NULL); 4872 - if ( ret == PLUGIN_OK || ret == PLUGIN_GOTO_WPS) { 4873 4934 if (pf_state == pf_scrolling) 4874 4935 pf_cfg.last_album = target; 4875 4936 else 4876 4937 pf_cfg.last_album = center_index; 4938 + 4877 4939 if (configfile_save(CONFIG_FILE, config, CONFIG_NUM_ITEMS, 4878 4940 CONFIG_VERSION)) 4879 4941 {