Fix FS#11175. playlist_peek() wasn't thread safe (due to a static filename buffer), so frequent calls from the main thread would cause the audio thread to buffer the wrong track.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27773 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Magnus Holmgren 2010-08-11 19:01:50 +00:00
parent de44ae7efc
commit 113764d9c0
5 changed files with 19 additions and 13 deletions

View file

@ -218,7 +218,7 @@ void draw_playlist_viewer_list(struct gui_wps *gwps, struct playlistviewer *view
int x, length, alignment = SKIN_TOKEN_ALIGN_LEFT; int x, length, alignment = SKIN_TOKEN_ALIGN_LEFT;
struct mp3entry *pid3; struct mp3entry *pid3;
char buf[MAX_PATH*2], tempbuf[MAX_PATH]; char buf[MAX_PATH*2], tempbuf[MAX_PATH], filename_buf[MAX_PATH + 1];
const char *filename; const char *filename;
#if CONFIG_TUNER #if CONFIG_TUNER
if (current_screen() == GO_TO_FM) if (current_screen() == GO_TO_FM)
@ -249,7 +249,8 @@ void draw_playlist_viewer_list(struct gui_wps *gwps, struct playlistviewer *view
else else
#endif #endif
{ {
filename = playlist_peek(i-cur_pos); filename = playlist_peek(i-cur_pos, filename_buf,
sizeof(filename_buf));
if (i == cur_pos) if (i == cur_pos)
{ {
pid3 = state->id3; pid3 = state->id3;

View file

@ -1113,6 +1113,7 @@ static bool audio_loadcodec(bool start_play)
actually loaded by the buffering thread. */ actually loaded by the buffering thread. */
static bool audio_load_track(size_t offset, bool start_play) static bool audio_load_track(size_t offset, bool start_play)
{ {
char name_buf[MAX_PATH + 1];
const char *trackname; const char *trackname;
int fd = -1; int fd = -1;
@ -1140,7 +1141,8 @@ static bool audio_load_track(size_t offset, bool start_play)
logf("Buffering track: r%d/w%d", track_ridx, track_widx); logf("Buffering track: r%d/w%d", track_ridx, track_widx);
/* Get track name from current playlist read position. */ /* Get track name from current playlist read position. */
while ((trackname = playlist_peek(last_peek_offset)) != NULL) while ((trackname = playlist_peek(last_peek_offset, name_buf,
sizeof(name_buf))) != NULL)
{ {
/* Handle broken playlists. */ /* Handle broken playlists. */
fd = open(trackname, O_RDONLY); fd = open(trackname, O_RDONLY);

View file

@ -144,7 +144,6 @@ struct directory_search_context {
}; };
static struct playlist_info current_playlist; static struct playlist_info current_playlist;
static char now_playing[MAX_PATH+1];
static void empty_playlist(struct playlist_info* playlist, bool resume); static void empty_playlist(struct playlist_info* playlist, bool resume);
static void new_playlist(struct playlist_info* playlist, const char *dir, static void new_playlist(struct playlist_info* playlist, const char *dir,
@ -2456,7 +2455,7 @@ bool playlist_check(int steps)
/* get trackname of track that is "steps" away from current playing track. /* get trackname of track that is "steps" away from current playing track.
NULL is used to identify end of playlist */ NULL is used to identify end of playlist */
const char* playlist_peek(int steps) const char* playlist_peek(int steps, char* buf, size_t buf_size)
{ {
struct playlist_info* playlist = &current_playlist; struct playlist_info* playlist = &current_playlist;
int seek; int seek;
@ -2471,11 +2470,11 @@ const char* playlist_peek(int steps)
control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK; control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK;
seek = playlist->indices[index] & PLAYLIST_SEEK_MASK; seek = playlist->indices[index] & PLAYLIST_SEEK_MASK;
if (get_filename(playlist, index, seek, control_file, now_playing, if (get_filename(playlist, index, seek, control_file, buf,
MAX_PATH+1) < 0) buf_size) < 0)
return NULL; return NULL;
temp_ptr = now_playing; temp_ptr = buf;
if (!playlist->in_ram || control_file) if (!playlist->in_ram || control_file)
{ {
@ -2494,7 +2493,7 @@ const char* playlist_peek(int steps)
/* Even though this is an invalid file, we still need to pass a /* Even though this is an invalid file, we still need to pass a
file name to the caller because NULL is used to indicate end file name to the caller because NULL is used to indicate end
of playlist */ of playlist */
return now_playing; return buf;
} }
} }

View file

@ -127,7 +127,7 @@ int playlist_add(const char *filename);
int playlist_shuffle(int random_seed, int start_index); int playlist_shuffle(int random_seed, int start_index);
void playlist_start(int start_index, int offset); void playlist_start(int start_index, int offset);
bool playlist_check(int steps); bool playlist_check(int steps);
const char *playlist_peek(int steps); const char *playlist_peek(int steps, char* buf, size_t buf_size);
int playlist_next(int steps); int playlist_next(int steps);
bool playlist_next_dir(int direction); bool playlist_next_dir(int direction);
int playlist_get_resume_info(int *resume_index); int playlist_get_resume_info(int *resume_index);

View file

@ -1075,6 +1075,7 @@ bool bookmark_play(char *resume_file, int index, int offset, int seed,
lastdir[0]='\0'; lastdir[0]='\0';
if (playlist_create(resume_file, NULL) != -1) if (playlist_create(resume_file, NULL) != -1)
{ {
char filename_buf[MAX_PATH + 1];
const char* peek_filename; const char* peek_filename;
resume_directory(resume_file); resume_directory(resume_file);
if (global_settings.playlist_shuffle) if (global_settings.playlist_shuffle)
@ -1082,13 +1083,15 @@ bool bookmark_play(char *resume_file, int index, int offset, int seed,
/* Check if the file is at the same spot in the directory, /* Check if the file is at the same spot in the directory,
else search for it */ else search for it */
peek_filename = playlist_peek(index); peek_filename = playlist_peek(index, filename_buf,
sizeof(filename_buf));
if (peek_filename == NULL) if (peek_filename == NULL)
{ {
/* playlist has shrunk, search from the top */ /* playlist has shrunk, search from the top */
index = 0; index = 0;
peek_filename = playlist_peek(index); peek_filename = playlist_peek(index, filename_buf,
sizeof(filename_buf));
if (peek_filename == NULL) if (peek_filename == NULL)
return false; return false;
} }
@ -1097,7 +1100,8 @@ bool bookmark_play(char *resume_file, int index, int offset, int seed,
{ {
for ( i=0; i < playlist_amount(); i++ ) for ( i=0; i < playlist_amount(); i++ )
{ {
peek_filename = playlist_peek(i); peek_filename = playlist_peek(i, filename_buf,
sizeof(filename_buf));
if (peek_filename == NULL) if (peek_filename == NULL)
return false; return false;