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.

skin_token.c, playback.c, add get_temp_mp3entry()

add function get_temp_mp3entry() to return a valid mp3entry from scratch_mem
UNBUFFERED_ID3
or if playback hasn't been started used statically allocated mp3entry
NEXTTRACK_ID3

Change-Id: I3909fb585e0f5ad590f917ce827e991440f1fe75

authored by

William Wilgus and committed by
William Wilgus
b07d7d6a d323d968

+50 -18
+24 -18
apps/gui/skin_engine/skin_tokens.c
··· 542 542 } 543 543 #endif 544 544 545 - static struct mp3entry* get_mp3entry_from_offset(int offset, struct mp3entry *bufid3, char **filename) 545 + static struct mp3entry* get_mp3entry_from_offset(int offset, 546 + struct mp3entry **freeid3, char **filename) 546 547 { 547 548 struct mp3entry* pid3 = NULL; 548 549 struct wps_state *state = get_wps_state(); 549 550 struct cuesheet *cue = state->id3 ? state->id3->cuesheet : NULL; 550 551 const char *fname = NULL; 552 + 551 553 if (cue && cue->curr_track_idx + offset < cue->track_count) 552 554 pid3 = state->id3; 553 555 else if (offset == 0) ··· 556 558 pid3 = state->nid3; 557 559 else 558 560 { 559 - memset(bufid3, 0, sizeof(*bufid3)); 560 - /*static char filename_buf[MAX_PATH + 1];removed g#5926 */ 561 + /* we had to get a temp id3 entry, fill freeid3 to free later */ 562 + struct mp3entry *bufid3 = get_temp_mp3entry(NULL); 563 + *freeid3 = bufid3; 561 564 fname = playlist_peek(offset, bufid3->path, sizeof(bufid3->path)); 562 565 *filename = (char*)fname; 563 566 ··· 581 584 return pid3; 582 585 } 583 586 584 - /* Don't inline this; it was broken out of get_token_value to reduce stack usage. 585 - * Tokens which use current id3 go here */ 586 - static const char * NOINLINE try_id3_token(struct wps_token *token, int offset, 587 + /* Tokens which use current id3 go here */ 588 + static const char *try_id3_token(struct wps_token *token, int offset, 587 589 char *buf, int buf_size, 588 590 int limit, int *intval) 589 591 { 590 592 const char *out_text = NULL; 591 593 char *filename = NULL; 592 - int numeric_ret = -1; 593 - const char *numeric_buf = buf; 594 - 595 - #if ID3V2_BUF_SIZE <= 900 596 - struct mp3entry tempid3, *id3; 597 - #else 598 - static struct mp3entry tempid3, *id3; 599 - #endif 594 + struct mp3entry *id3, *freeid3 = NULL; 600 595 601 - id3 = get_mp3entry_from_offset(token->next? 1: offset, &tempid3, &filename); 596 + /* if freeid3 is filled on return we need to free the id3 when finished */ 597 + id3 = get_mp3entry_from_offset(token->next? 1: offset, &freeid3, &filename); 602 598 603 599 if (token->type == SKIN_TOKEN_REPLAYGAIN) 604 600 { 601 + int numeric_ret = -1; 602 + const char *numeric_buf = buf; 605 603 int globtype = global_settings.replaygain_settings.type; 606 604 int val; 607 605 ··· 642 640 { 643 641 *intval = numeric_ret; 644 642 } 645 - return numeric_buf; 643 + out_text = numeric_buf; 644 + goto free_id3_outtext; 646 645 } 647 646 648 647 struct wps_state *state = get_wps_state(); ··· 651 650 out_text = get_cuesheetid3_token(token, id3, 652 651 token->next?1:offset, buf, buf_size); 653 652 if (out_text) 654 - return out_text; 653 + goto free_id3_outtext; 655 654 } 656 655 657 656 out_text = get_id3_token(token, id3, filename, buf, buf_size, limit, intval); 657 + 658 658 if (out_text) 659 - return out_text; 659 + goto free_id3_outtext; 660 660 661 + if (freeid3) 662 + get_temp_mp3entry(freeid3); 661 663 #if CONFIG_TUNER 662 664 return get_radio_token(token, offset, buf, buf_size, limit, intval); 663 665 #else 664 666 return NULL; 665 667 #endif 668 + free_id3_outtext: 669 + if (freeid3) 670 + get_temp_mp3entry(freeid3); 671 + return out_text; 666 672 } 667 673 668 674 /* Don't inline this; it was broken out of get_token_value to reduce stack
+24
apps/playback.c
··· 428 428 } 429 429 } 430 430 431 + struct mp3entry* get_temp_mp3entry(struct mp3entry *free) 432 + { 433 + /* free should be NULL on first call pass back the returned mp3entry to unlock */ 434 + enum audio_id3_types id3_num = UNBUFFERED_ID3; 435 + /* playback hasn't started return NEXTTRACK_ID3 (statically allocated) */ 436 + if (!audio_scratch_memory) 437 + id3_num = NEXTTRACK_ID3; 438 + 439 + if (free) 440 + { 441 + /* scratch_mem_init() has to aquire the lock 442 + * to change id3_num via audio_scratch_memory.. */ 443 + if (free == id3_get(id3_num)) 444 + id3_mutex_unlock(); 445 + 446 + return NULL; 447 + } 448 + id3_mutex_lock(); 449 + 450 + struct mp3entry *temp_id3 = id3_get(id3_num); 451 + wipe_mp3entry(temp_id3); 452 + return temp_id3; 453 + } 454 + 431 455 /* Copy an mp3entry into one of the mp3 entries */ 432 456 static void id3_write(enum audio_id3_types id3_num, 433 457 const struct mp3entry *id3_src)
+2
apps/playback.h
··· 93 93 94 94 unsigned int playback_status(void); 95 95 96 + struct mp3entry* get_temp_mp3entry(struct mp3entry *free); 97 + 96 98 #endif /* _PLAYBACK_H */