mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-20 18:42:41 -05:00
playlist: Simplify get_track_filename()
Have get_track_filename() read track seek offset & insert type itself to avoid duplicating code. Most callers are not interested in that information, and only use it to call get_track_filename(). Change-Id: I46d50fda10e515f74e27eebdded8e281bbf4456f
This commit is contained in:
parent
9ba51e3552
commit
3b1e95d480
1 changed files with 21 additions and 54 deletions
|
|
@ -1100,8 +1100,8 @@ static int get_next_dir(char *dir, int direction)
|
||||||
/*
|
/*
|
||||||
* gets pathname for track at seek index
|
* gets pathname for track at seek index
|
||||||
*/
|
*/
|
||||||
static int get_track_filename(struct playlist_info* playlist, int index, int seek,
|
static int get_track_filename(struct playlist_info* playlist, int index,
|
||||||
bool control_file, char *buf, int buf_length)
|
char *buf, int buf_length)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int max = -1;
|
int max = -1;
|
||||||
|
|
@ -1109,8 +1109,10 @@ static int get_track_filename(struct playlist_info* playlist, int index, int see
|
||||||
char dir_buf[MAX_PATH+1];
|
char dir_buf[MAX_PATH+1];
|
||||||
bool utf8 = playlist->utf8;
|
bool utf8 = playlist->utf8;
|
||||||
|
|
||||||
if (buf_length > MAX_PATH+1)
|
playlist_write_lock(playlist);
|
||||||
buf_length = MAX_PATH+1;
|
|
||||||
|
bool control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK;
|
||||||
|
unsigned long seek = playlist->indices[index] & PLAYLIST_SEEK_MASK;
|
||||||
|
|
||||||
#ifdef HAVE_DIRCACHE
|
#ifdef HAVE_DIRCACHE
|
||||||
if (playlist->dcfrefs_handle)
|
if (playlist->dcfrefs_handle)
|
||||||
|
|
@ -1126,8 +1128,6 @@ static int get_track_filename(struct playlist_info* playlist, int index, int see
|
||||||
|
|
||||||
if (max < 0)
|
if (max < 0)
|
||||||
{
|
{
|
||||||
playlist_write_lock(playlist);
|
|
||||||
|
|
||||||
if (control_file)
|
if (control_file)
|
||||||
{
|
{
|
||||||
fd = playlist->control_fd;
|
fd = playlist->control_fd;
|
||||||
|
|
@ -1140,7 +1140,7 @@ static int get_track_filename(struct playlist_info* playlist, int index, int see
|
||||||
|
|
||||||
if(-1 != fd)
|
if(-1 != fd)
|
||||||
{
|
{
|
||||||
if (lseek(fd, seek, SEEK_SET) != seek)
|
if (lseek(fd, seek, SEEK_SET) != (off_t)seek)
|
||||||
max = -1;
|
max = -1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -1163,10 +1163,10 @@ static int get_track_filename(struct playlist_info* playlist, int index, int see
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
playlist_write_unlock(playlist);
|
|
||||||
|
|
||||||
if (max < 0)
|
if (max < 0)
|
||||||
{
|
{
|
||||||
|
playlist_write_unlock(playlist);
|
||||||
|
|
||||||
if (usb_detect() == USB_INSERTED)
|
if (usb_detect() == USB_INSERTED)
|
||||||
; /* ignore error on usb plug */
|
; /* ignore error on usb plug */
|
||||||
else if (control_file)
|
else if (control_file)
|
||||||
|
|
@ -1179,10 +1179,12 @@ static int get_track_filename(struct playlist_info* playlist, int index, int see
|
||||||
}
|
}
|
||||||
|
|
||||||
strmemccpy(dir_buf, playlist->filename, playlist->dirlen);
|
strmemccpy(dir_buf, playlist->filename, playlist->dirlen);
|
||||||
|
playlist_write_unlock(playlist);
|
||||||
|
|
||||||
return format_track_path(buf, tmp_buf, buf_length, dir_buf);
|
if (format_track_path(buf, tmp_buf, buf_length, dir_buf) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
(void)index;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -1811,8 +1813,6 @@ static void dc_thread_playlist(void)
|
||||||
struct playlist_info *playlist = ¤t_playlist;
|
struct playlist_info *playlist = ¤t_playlist;
|
||||||
struct dircache_fileref *dcfrefs;
|
struct dircache_fileref *dcfrefs;
|
||||||
int index;
|
int index;
|
||||||
int seek;
|
|
||||||
bool control_file;
|
|
||||||
|
|
||||||
/* Thread starts out stopped */
|
/* Thread starts out stopped */
|
||||||
long sleep_time = TIMEOUT_BLOCK;
|
long sleep_time = TIMEOUT_BLOCK;
|
||||||
|
|
@ -1890,12 +1890,8 @@ static void dc_thread_playlist(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK;
|
|
||||||
seek = playlist->indices[index] & PLAYLIST_SEEK_MASK;
|
|
||||||
|
|
||||||
/* Load the filename from playlist file. */
|
/* Load the filename from playlist file. */
|
||||||
if (get_track_filename(playlist, index, seek,
|
if (get_track_filename(playlist, index, tmp, sizeof(tmp)))
|
||||||
control_file, tmp, sizeof(tmp)) < 0)
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Obtain the dircache file entry cookie. */
|
/* Obtain the dircache file entry cookie. */
|
||||||
|
|
@ -2416,31 +2412,24 @@ int playlist_get_seed(const struct playlist_info* playlist)
|
||||||
int playlist_get_track_info(struct playlist_info* playlist, int index,
|
int playlist_get_track_info(struct playlist_info* playlist, int index,
|
||||||
struct playlist_track_info* info)
|
struct playlist_track_info* info)
|
||||||
{
|
{
|
||||||
int seek;
|
|
||||||
bool control_file;
|
|
||||||
|
|
||||||
if (!playlist)
|
if (!playlist)
|
||||||
playlist = ¤t_playlist;
|
playlist = ¤t_playlist;
|
||||||
|
|
||||||
if (index < 0 || index >= playlist->amount)
|
if (index < 0 || index >= playlist->amount)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK;
|
if (get_track_filename(playlist, index,
|
||||||
seek = playlist->indices[index] & PLAYLIST_SEEK_MASK;
|
info->filename, sizeof(info->filename)))
|
||||||
|
|
||||||
if (get_track_filename(playlist, index, seek, control_file,
|
|
||||||
info->filename, sizeof(info->filename)) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
info->attr = 0;
|
info->attr = 0;
|
||||||
|
|
||||||
if (control_file)
|
if (playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK)
|
||||||
{
|
{
|
||||||
if (playlist->indices[index] & PLAYLIST_QUEUE_MASK)
|
if (playlist->indices[index] & PLAYLIST_QUEUE_MASK)
|
||||||
info->attr |= PLAYLIST_ATTR_QUEUED;
|
info->attr |= PLAYLIST_ATTR_QUEUED;
|
||||||
else
|
else
|
||||||
info->attr |= PLAYLIST_ATTR_INSERTED;
|
info->attr |= PLAYLIST_ATTR_INSERTED;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playlist->indices[index] & PLAYLIST_SKIPPED)
|
if (playlist->indices[index] & PLAYLIST_SKIPPED)
|
||||||
|
|
@ -2720,8 +2709,6 @@ void playlist_set_modified(struct playlist_info *playlist, bool modified)
|
||||||
int playlist_move(struct playlist_info* playlist, int index, int new_index)
|
int playlist_move(struct playlist_info* playlist, int index, int new_index)
|
||||||
{
|
{
|
||||||
int result = -1;
|
int result = -1;
|
||||||
int seek;
|
|
||||||
bool control_file;
|
|
||||||
bool queue;
|
bool queue;
|
||||||
bool current = false;
|
bool current = false;
|
||||||
int r;
|
int r;
|
||||||
|
|
@ -2778,15 +2765,10 @@ int playlist_move(struct playlist_info* playlist, int index, int new_index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK;
|
|
||||||
queue = playlist->indices[index] & PLAYLIST_QUEUE_MASK;
|
queue = playlist->indices[index] & PLAYLIST_QUEUE_MASK;
|
||||||
seek = playlist->indices[index] & PLAYLIST_SEEK_MASK;
|
|
||||||
|
|
||||||
if (get_track_filename(playlist, index, seek,
|
if (get_track_filename(playlist, index, filename, sizeof(filename)))
|
||||||
control_file, filename, sizeof(filename)) < 0)
|
|
||||||
{
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
|
||||||
|
|
||||||
/* We want to insert the track at the position that was specified by
|
/* We want to insert the track at the position that was specified by
|
||||||
new_index. This may be different then new_index because of the
|
new_index. This may be different then new_index because of the
|
||||||
|
|
@ -2987,10 +2969,8 @@ bool playlist_next_dir(int direction)
|
||||||
const char* playlist_peek(int steps, char* buf, size_t buf_size)
|
const char* playlist_peek(int steps, char* buf, size_t buf_size)
|
||||||
{
|
{
|
||||||
struct playlist_info* playlist = ¤t_playlist;
|
struct playlist_info* playlist = ¤t_playlist;
|
||||||
int seek;
|
|
||||||
char *temp_ptr;
|
char *temp_ptr;
|
||||||
int index;
|
int index;
|
||||||
bool control_file;
|
|
||||||
|
|
||||||
index = get_next_index(playlist, steps, -1);
|
index = get_next_index(playlist, steps, -1);
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
|
|
@ -3000,11 +2980,7 @@ const char* playlist_peek(int steps, char* buf, size_t buf_size)
|
||||||
if (!buf || !buf_size)
|
if (!buf || !buf_size)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK;
|
if (get_track_filename(playlist, index, buf, buf_size))
|
||||||
seek = playlist->indices[index] & PLAYLIST_SEEK_MASK;
|
|
||||||
|
|
||||||
if (get_track_filename(playlist, index, seek,
|
|
||||||
control_file, buf, buf_size) < 0)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
temp_ptr = buf;
|
temp_ptr = buf;
|
||||||
|
|
@ -3620,10 +3596,6 @@ int playlist_save(struct playlist_info* playlist, char *filename,
|
||||||
index = playlist->first_index;
|
index = playlist->first_index;
|
||||||
for (i=0; i<playlist->amount; i++)
|
for (i=0; i<playlist->amount; i++)
|
||||||
{
|
{
|
||||||
bool control_file;
|
|
||||||
bool queue;
|
|
||||||
int seek;
|
|
||||||
|
|
||||||
/* user abort */
|
/* user abort */
|
||||||
if (action_userabort(TIMEOUT_NOBLOCK))
|
if (action_userabort(TIMEOUT_NOBLOCK))
|
||||||
{
|
{
|
||||||
|
|
@ -3631,15 +3603,10 @@ int playlist_save(struct playlist_info* playlist, char *filename,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK;
|
|
||||||
queue = playlist->indices[index] & PLAYLIST_QUEUE_MASK;
|
|
||||||
seek = playlist->indices[index] & PLAYLIST_SEEK_MASK;
|
|
||||||
|
|
||||||
/* Don't save queued files */
|
/* Don't save queued files */
|
||||||
if (!queue)
|
if (!(playlist->indices[index] & PLAYLIST_QUEUE_MASK))
|
||||||
{
|
{
|
||||||
if (get_track_filename(playlist, index, seek,
|
if (get_track_filename(playlist, index, tmp_buf, sizeof(tmp_buf)))
|
||||||
control_file, tmp_buf, MAX_PATH+1) < 0)
|
|
||||||
{
|
{
|
||||||
result = -1;
|
result = -1;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue