1
0
Fork 0
forked from len0rd/rockbox

Get rid of useless playlist probing and fix up some data types.

Playback checked the files' presence before attempting to buffer
the track. Just get rid of that and save an extra open/close call.
It will find out if the path is bad when the metadata fails.

Fix some size_t/off_t conflation. No need to update plugin version
because no plugin actually uses bufopen().

Change-Id: I3db112449dc0b2eeb91c546f308880ac82494fc7
This commit is contained in:
Michael Sevakis 2017-12-17 16:12:10 -05:00
parent d14e3f45a8
commit dfff938dff
4 changed files with 66 additions and 81 deletions

View file

@ -93,7 +93,7 @@ struct memory_handle {
size_t data; /* Start index of the handle's data buffer */ size_t data; /* Start index of the handle's data buffer */
size_t ridx; /* Read pointer, relative to the main buffer */ size_t ridx; /* Read pointer, relative to the main buffer */
size_t widx; /* Write pointer, relative to the main buffer */ size_t widx; /* Write pointer, relative to the main buffer */
ssize_t filesize; /* File total length */ off_t filesize; /* File total length (possibly trimmed at tail) */
off_t start; /* Offset at which we started reading the file */ off_t start; /* Offset at which we started reading the file */
off_t pos; /* Read position in file */ off_t pos; /* Read position in file */
off_t volatile end; /* Offset at which we stopped reading the file */ off_t volatile end; /* Offset at which we stopped reading the file */
@ -917,7 +917,7 @@ management functions for all the actual handle management work.
return value: <0 if the file cannot be opened, or one file already return value: <0 if the file cannot be opened, or one file already
queued to be opened, otherwise the handle for the file in the buffer queued to be opened, otherwise the handle for the file in the buffer
*/ */
int bufopen(const char *file, size_t offset, enum data_type type, int bufopen(const char *file, off_t offset, enum data_type type,
void *user_data) void *user_data)
{ {
int handle_id = ERR_BUFFER_FULL; int handle_id = ERR_BUFFER_FULL;
@ -1508,8 +1508,28 @@ These functions are exported, to allow interaction with the buffer.
They take care of the content of the structs, and rely on the linked list They take care of the content of the structs, and rely on the linked list
management functions for all the actual handle management work. management functions for all the actual handle management work.
*/ */
bool buf_is_handle(int handle_id)
{
return find_handle(handle_id) != NULL;
}
ssize_t buf_handle_offset(int handle_id) int buf_handle_data_type(int handle_id)
{
const struct memory_handle *h = find_handle(handle_id);
if (!h)
return ERR_HANDLE_NOT_FOUND;
return h->type;
}
off_t buf_filesize(int handle_id)
{
const struct memory_handle *h = find_handle(handle_id);
if (!h)
return ERR_HANDLE_NOT_FOUND;
return h->filesize;
}
off_t buf_handle_offset(int handle_id)
{ {
const struct memory_handle *h = find_handle(handle_id); const struct memory_handle *h = find_handle(handle_id);
if (!h) if (!h)
@ -1517,22 +1537,7 @@ ssize_t buf_handle_offset(int handle_id)
return h->start; return h->start;
} }
void buf_set_base_handle(int handle_id) off_t buf_handle_remaining(int handle_id)
{
mutex_lock(&llist_mutex);
base_handle_id = handle_id;
mutex_unlock(&llist_mutex);
}
enum data_type buf_handle_data_type(int handle_id)
{
const struct memory_handle *h = find_handle(handle_id);
if (!h)
return TYPE_UNKNOWN;
return h->type;
}
ssize_t buf_handle_remaining(int handle_id)
{ {
const struct memory_handle *h = find_handle(handle_id); const struct memory_handle *h = find_handle(handle_id);
if (!h) if (!h)
@ -1540,11 +1545,6 @@ ssize_t buf_handle_remaining(int handle_id)
return h->filesize - h->end; return h->filesize - h->end;
} }
bool buf_is_handle(int handle_id)
{
return find_handle(handle_id) != NULL;
}
bool buf_pin_handle(int handle_id, bool pin) bool buf_pin_handle(int handle_id, bool pin)
{ {
struct memory_handle *h = find_handle(handle_id); struct memory_handle *h = find_handle(handle_id);
@ -1576,6 +1576,14 @@ size_t buf_length(void)
return buffer_len; return buffer_len;
} }
/* Set the handle from which useful data is counted */
void buf_set_base_handle(int handle_id)
{
mutex_lock(&llist_mutex);
base_handle_id = handle_id;
mutex_unlock(&llist_mutex);
}
/* Return the amount of buffer space used */ /* Return the amount of buffer space used */
size_t buf_used(void) size_t buf_used(void)
{ {

View file

@ -75,7 +75,7 @@ bool buffering_reset(char *buf, size_t buflen);
* NOTE: Tail operations are only legal when the end of the file is buffered. * NOTE: Tail operations are only legal when the end of the file is buffered.
****************************************************************************/ ****************************************************************************/
int bufopen(const char *file, size_t offset, enum data_type type, int bufopen(const char *file, off_t offset, enum data_type type,
void *user_data); void *user_data);
int bufalloc(const void *src, size_t size, enum data_type type); int bufalloc(const void *src, size_t size, enum data_type type);
bool bufclose(int handle_id); bool bufclose(int handle_id);
@ -101,17 +101,19 @@ ssize_t bufcuttail(int handle_id, size_t size);
* buf_back_off_storage: tell buffering thread to take it easy * buf_back_off_storage: tell buffering thread to take it easy
****************************************************************************/ ****************************************************************************/
enum data_type buf_handle_data_type(int handle_id);
ssize_t buf_handle_remaining(int handle_id);
bool buf_is_handle(int handle_id); bool buf_is_handle(int handle_id);
ssize_t buf_handle_offset(int handle_id); int buf_handle_data_type(int handle_id);
void buf_set_base_handle(int handle_id); off_t buf_filesize(int handle_id);
size_t buf_length(void); off_t buf_handle_offset(int handle_id);
size_t buf_used(void); off_t buf_handle_remaining(int handle_id);
bool buf_pin_handle(int handle_id, bool pin); bool buf_pin_handle(int handle_id, bool pin);
bool buf_signal_handle(int handle_id, bool signal); bool buf_signal_handle(int handle_id, bool signal);
size_t buf_length(void);
size_t buf_used(void);
/* Settings */ /* Settings */
void buf_set_base_handle(int handle_id);
void buf_set_watermark(size_t bytes); void buf_set_watermark(size_t bytes);
size_t buf_get_watermark(void); size_t buf_get_watermark(void);

View file

@ -227,11 +227,6 @@ struct track_info
#endif #endif
int audio_hid; /* Main audio data handle ID */ int audio_hid; /* Main audio data handle ID */
}; }; }; };
off_t filesize; /* File total length on disk
TODO: This should be stored
in the handle or the
id3 and would use less
ram */
}; };
/* On-buffer info format; includes links */ /* On-buffer info format; includes links */
@ -459,8 +454,6 @@ static void track_info_wipe(struct track_info *infop)
FOR_EACH_TRACK_INFO_HANDLE(i) FOR_EACH_TRACK_INFO_HANDLE(i)
infop->handle[i] = ERR_HANDLE_NOT_FOUND; infop->handle[i] = ERR_HANDLE_NOT_FOUND;
infop->filesize = 0;
} }
/** --- Track list --- **/ /** --- Track list --- **/
@ -1065,7 +1058,7 @@ static void audio_update_filebuf_watermark(int seconds)
track that fits, in which case we should avoid constant buffer track that fits, in which case we should avoid constant buffer
low events */ low events */
if (track_list_count() > 1) if (track_list_count() > 1)
bytes = info.filesize + 1; bytes = buf_filesize(info.audio_hid) + 1;
} }
} }
else else
@ -1613,7 +1606,7 @@ static bool audio_start_codec(bool auto_skip)
id3_write(CODEC_ID3, cur_id3); id3_write(CODEC_ID3, cur_id3);
ci.audio_hid = info.audio_hid; ci.audio_hid = info.audio_hid;
ci.filesize = info.filesize; ci.filesize = buf_filesize(info.audio_hid);
buf_set_base_handle(info.audio_hid); buf_set_base_handle(info.audio_hid);
/* All required data is now available for the codec */ /* All required data is now available for the codec */
@ -1870,33 +1863,12 @@ static int audio_load_track(void)
playlist_peek_offset); playlist_peek_offset);
/* Get track name from current playlist read position */ /* Get track name from current playlist read position */
int fd = -1; char path_buf[MAX_PATH + 1];
char name_buf[MAX_PATH + 1]; const char *path = playlist_peek(playlist_peek_offset,
const char *trackname; path_buf,
sizeof (path_buf));
while (1) if (!path)
{
trackname = playlist_peek(playlist_peek_offset, name_buf,
sizeof (name_buf));
if (!trackname)
break;
/* Test for broken playlists by probing for the files */
fd = open(trackname, O_RDONLY);
if (fd >= 0)
break;
logf("Open failed");
/* Skip invalid entry from playlist */
playlist_skip_entry(NULL, playlist_peek_offset);
/* Sync the playlist if it isn't finished */
if (playlist_peek(playlist_peek_offset, NULL, 0))
playlist_next(0);
}
if (!trackname)
{ {
/* No track - exhausted the playlist entries */ /* No track - exhausted the playlist entries */
logf("End-of-playlist"); logf("End-of-playlist");
@ -1920,7 +1892,7 @@ static int audio_load_track(void)
/* Successfully opened the file - get track metadata */ /* Successfully opened the file - get track metadata */
if (filling == STATE_FULL || if (filling == STATE_FULL ||
(info.id3_hid = bufopen(trackname, 0, TYPE_ID3, NULL)) < 0) (info.id3_hid = bufopen(path, 0, TYPE_ID3, NULL)) < 0)
{ {
/* Buffer or track list is full */ /* Buffer or track list is full */
struct mp3entry *ub_id3; struct mp3entry *ub_id3;
@ -1929,9 +1901,15 @@ static int audio_load_track(void)
/* Load the metadata for the first unbuffered track */ /* Load the metadata for the first unbuffered track */
ub_id3 = id3_get(UNBUFFERED_ID3); ub_id3 = id3_get(UNBUFFERED_ID3);
id3_mutex_lock();
get_metadata(ub_id3, fd, trackname); int fd = open(path, O_RDONLY);
id3_mutex_unlock(); if (fd >= 0)
{
id3_mutex_lock();
get_metadata(ub_id3, fd, path);
id3_mutex_unlock();
close(fd);
}
if (filling != STATE_FULL) if (filling != STATE_FULL)
{ {
@ -1944,8 +1922,6 @@ static int audio_load_track(void)
} }
else else
{ {
info.filesize = filesize(fd);
if (!track_list_commit_info(&info)) if (!track_list_commit_info(&info))
{ {
track_list_free_info(&info); track_list_free_info(&info);
@ -1957,7 +1933,6 @@ static int audio_load_track(void)
track_list.in_progress_hid = info.self_hid; track_list.in_progress_hid = info.self_hid;
} }
close(fd);
return LOAD_TRACK_OK; return LOAD_TRACK_OK;
} }
@ -2050,23 +2025,23 @@ static int audio_finish_load_track(struct track_info *infop)
#endif /* HAVE_CODEC_BUFFERING */ #endif /* HAVE_CODEC_BUFFERING */
/** Finally, load the audio **/ /** Finally, load the audio **/
size_t file_offset = 0; off_t file_offset = 0;
if (track_id3->elapsed > track_id3->length) if (track_id3->elapsed > track_id3->length)
track_id3->elapsed = 0; track_id3->elapsed = 0;
if ((off_t)track_id3->offset >= infop->filesize) if ((off_t)track_id3->offset >= buf_filesize(infop->audio_hid))
track_id3->offset = 0; track_id3->offset = 0;
logf("%s: set offset for %s to %lu\n", __func__, logf("%s: set offset for %s to %lu\n", __func__,
track_id3->title, (unsigned long)track_id3->offset); track_id3->title, track_id3->offset);
/* Adjust for resume rewind so we know what to buffer - starting the codec /* Adjust for resume rewind so we know what to buffer - starting the codec
calls it again, so we don't save it (and they shouldn't accumulate) */ calls it again, so we don't save it (and they shouldn't accumulate) */
unsigned long elapsed, offset; unsigned long elapsed, offset;
resume_rewind_adjust_progress(track_id3, &elapsed, &offset); resume_rewind_adjust_progress(track_id3, &elapsed, &offset);
logf("%s: Set resume for %s to %lu %lX", __func__, logf("%s: Set resume for %s to %lu %lu", __func__,
track_id3->title, elapsed, offset); track_id3->title, elapsed, offset);
enum data_type audiotype = rbcodec_format_is_atomic(track_id3->codectype) ? enum data_type audiotype = rbcodec_format_is_atomic(track_id3->codectype) ?
@ -3049,7 +3024,7 @@ static void audio_on_ff_rewind(long time)
/* Set the codec API to the correct metadata and track info */ /* Set the codec API to the correct metadata and track info */
ci.audio_hid = cur_info.audio_hid; ci.audio_hid = cur_info.audio_hid;
ci.filesize = cur_info.filesize; ci.filesize = buf_filesize(cur_info.audio_hid);
buf_set_base_handle(cur_info.audio_hid); buf_set_base_handle(cur_info.audio_hid);
} }
@ -3343,9 +3318,9 @@ static void buffer_event_finished_callback(unsigned short id, void *ev_data)
{ {
(void)id; (void)id;
int hid = *(const int *)ev_data; int hid = *(const int *)ev_data;
const enum data_type htype = buf_handle_data_type(hid); int htype = buf_handle_data_type(hid);
logf("handle %d finished buffering (type:%u)", hid, (unsigned)htype); logf("handle %d finished buffering (type:%d)", hid, htype);
/* Limit queue traffic */ /* Limit queue traffic */
switch (htype) switch (htype)

View file

@ -925,7 +925,7 @@ struct plugin_api {
#if (CONFIG_CODEC == SWCODEC) #if (CONFIG_CODEC == SWCODEC)
/* buffering API */ /* buffering API */
int (*bufopen)(const char *file, size_t offset, enum data_type type, int (*bufopen)(const char *file, off_t offset, enum data_type type,
void *user_data); void *user_data);
int (*bufalloc)(const void *src, size_t size, enum data_type type); int (*bufalloc)(const void *src, size_t size, enum data_type type);
bool (*bufclose)(int handle_id); bool (*bufclose)(int handle_id);