diff options
author | William Wilgus <wilgus.william@gmail.com> | 2024-12-25 12:17:37 -0500 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2024-12-26 00:58:51 -0500 |
commit | b07d7d6af0c823eea31829d48e68841973d6c7b6 (patch) | |
tree | f0527cb2ae03973b155488a3efa7ecee2bb82d4c | |
parent | d323d968d8be89733a27ae2fe6e1729227286d24 (diff) | |
download | rockbox-b07d7d6af0.tar.gz rockbox-b07d7d6af0.zip |
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
-rw-r--r-- | apps/gui/skin_engine/skin_tokens.c | 42 | ||||
-rw-r--r-- | apps/playback.c | 24 | ||||
-rw-r--r-- | apps/playback.h | 2 |
3 files changed, 50 insertions, 18 deletions
diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c index 2351f638c8..21ad8e8b89 100644 --- a/apps/gui/skin_engine/skin_tokens.c +++ b/apps/gui/skin_engine/skin_tokens.c @@ -542,12 +542,14 @@ const char *get_radio_token(struct wps_token *token, int preset_offset, } #endif -static struct mp3entry* get_mp3entry_from_offset(int offset, struct mp3entry *bufid3, char **filename) +static struct mp3entry* get_mp3entry_from_offset(int offset, + struct mp3entry **freeid3, char **filename) { struct mp3entry* pid3 = NULL; struct wps_state *state = get_wps_state(); struct cuesheet *cue = state->id3 ? state->id3->cuesheet : NULL; const char *fname = NULL; + if (cue && cue->curr_track_idx + offset < cue->track_count) pid3 = state->id3; else if (offset == 0) @@ -556,8 +558,9 @@ static struct mp3entry* get_mp3entry_from_offset(int offset, struct mp3entry *bu pid3 = state->nid3; else { - memset(bufid3, 0, sizeof(*bufid3)); - /*static char filename_buf[MAX_PATH + 1];removed g#5926 */ + /* we had to get a temp id3 entry, fill freeid3 to free later */ + struct mp3entry *bufid3 = get_temp_mp3entry(NULL); + *freeid3 = bufid3; fname = playlist_peek(offset, bufid3->path, sizeof(bufid3->path)); *filename = (char*)fname; @@ -581,27 +584,22 @@ static struct mp3entry* get_mp3entry_from_offset(int offset, struct mp3entry *bu return pid3; } -/* Don't inline this; it was broken out of get_token_value to reduce stack usage. - * Tokens which use current id3 go here */ -static const char * NOINLINE try_id3_token(struct wps_token *token, int offset, +/* Tokens which use current id3 go here */ +static const char *try_id3_token(struct wps_token *token, int offset, char *buf, int buf_size, int limit, int *intval) { const char *out_text = NULL; char *filename = NULL; - int numeric_ret = -1; - const char *numeric_buf = buf; - -#if ID3V2_BUF_SIZE <= 900 - struct mp3entry tempid3, *id3; -#else - static struct mp3entry tempid3, *id3; -#endif + struct mp3entry *id3, *freeid3 = NULL; - id3 = get_mp3entry_from_offset(token->next? 1: offset, &tempid3, &filename); + /* if freeid3 is filled on return we need to free the id3 when finished */ + id3 = get_mp3entry_from_offset(token->next? 1: offset, &freeid3, &filename); if (token->type == SKIN_TOKEN_REPLAYGAIN) { + int numeric_ret = -1; + const char *numeric_buf = buf; int globtype = global_settings.replaygain_settings.type; int val; @@ -642,7 +640,8 @@ static const char * NOINLINE try_id3_token(struct wps_token *token, int offset, { *intval = numeric_ret; } - return numeric_buf; + out_text = numeric_buf; + goto free_id3_outtext; } struct wps_state *state = get_wps_state(); @@ -651,18 +650,25 @@ static const char * NOINLINE try_id3_token(struct wps_token *token, int offset, out_text = get_cuesheetid3_token(token, id3, token->next?1:offset, buf, buf_size); if (out_text) - return out_text; + goto free_id3_outtext; } out_text = get_id3_token(token, id3, filename, buf, buf_size, limit, intval); + if (out_text) - return out_text; + goto free_id3_outtext; + if (freeid3) + get_temp_mp3entry(freeid3); #if CONFIG_TUNER return get_radio_token(token, offset, buf, buf_size, limit, intval); #else return NULL; #endif +free_id3_outtext: + if (freeid3) + get_temp_mp3entry(freeid3); + return out_text; } /* Don't inline this; it was broken out of get_token_value to reduce stack diff --git a/apps/playback.c b/apps/playback.c index 3f535ebd9f..0c0de0db0b 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -428,6 +428,30 @@ static inline struct mp3entry * id3_get(enum audio_id3_types id3_num) } } +struct mp3entry* get_temp_mp3entry(struct mp3entry *free) +{ + /* free should be NULL on first call pass back the returned mp3entry to unlock */ + enum audio_id3_types id3_num = UNBUFFERED_ID3; + /* playback hasn't started return NEXTTRACK_ID3 (statically allocated) */ + if (!audio_scratch_memory) + id3_num = NEXTTRACK_ID3; + + if (free) + { + /* scratch_mem_init() has to aquire the lock + * to change id3_num via audio_scratch_memory.. */ + if (free == id3_get(id3_num)) + id3_mutex_unlock(); + + return NULL; + } + id3_mutex_lock(); + + struct mp3entry *temp_id3 = id3_get(id3_num); + wipe_mp3entry(temp_id3); + return temp_id3; +} + /* Copy an mp3entry into one of the mp3 entries */ static void id3_write(enum audio_id3_types id3_num, const struct mp3entry *id3_src) diff --git a/apps/playback.h b/apps/playback.h index 782f69fa38..e388055f9b 100644 --- a/apps/playback.h +++ b/apps/playback.h @@ -93,4 +93,6 @@ size_t audio_get_filebuflen(void); unsigned int playback_status(void); +struct mp3entry* get_temp_mp3entry(struct mp3entry *free); + #endif /* _PLAYBACK_H */ |