Revert recent changes that are broken

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15439 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Brandon Low 2007-11-03 21:48:08 +00:00
parent 19eae2bd9b
commit c2e1cc1e39
3 changed files with 56 additions and 38 deletions

View file

@ -105,7 +105,7 @@
/* assert(sizeof(struct memory_handle)%4==0) */
struct memory_handle {
int id; /* A unique ID for the handle */
unsigned int id; /* A unique ID for the handle */
enum data_type type; /* Type of data buffered with this handle */
char path[MAX_PATH]; /* Path if data originated in a file */
int fd; /* File descriptor to path (-1 if closed) */
@ -146,7 +146,7 @@ static struct memory_handle *first_handle;
static int num_handles; /* number of handles in the list */
static int base_handle_id;
static unsigned int base_handle_id;
static struct mutex llist_mutex;
@ -224,7 +224,7 @@ static struct memory_handle *add_handle(size_t data_size, const bool can_wrap,
const bool alloc_all)
{
/* gives each handle a unique id, unsigned to handle wraps gracefully */
static int cur_handle_id = 0;
static unsigned int cur_handle_id = 1;
size_t shift;
size_t new_widx;
size_t len;
@ -291,7 +291,9 @@ static struct memory_handle *add_handle(size_t data_size, const bool can_wrap,
buf_widx = RINGBUF_ADD(buf_widx, sizeof(struct memory_handle));
new_handle->id = cur_handle_id;
cur_handle_id = (cur_handle_id + 1) & BUF_HANDLE_ID_MASK;
/* Use += 2 instead of ++ to guarantee that the low bit is always high and
* prevent the assignment of a zero id when wrapping. */
cur_handle_id += 2;
new_handle->next = NULL;
num_handles++;
@ -356,9 +358,9 @@ static bool rm_handle(const struct memory_handle *h)
/* Return a pointer to the memory handle of given ID.
NULL if the handle wasn't found */
static struct memory_handle *find_handle(const int handle_id)
static struct memory_handle *find_handle(const unsigned int handle_id)
{
if (handle_id < 0)
if (handle_id <= 0)
return NULL;
mutex_lock(&llist_mutex);
@ -548,7 +550,7 @@ static bool buffer_handle(int handle_id)
logf("buffer_handle(%d)", handle_id);
struct memory_handle *h = find_handle(handle_id);
if (!h)
return false;
return -1;
if (h->filerem == 0) {
/* nothing left to buffer */
@ -768,7 +770,7 @@ void update_data_counters(void)
{
struct memory_handle *m = find_handle(base_handle_id);
if (!m)
base_handle_id = -1;
base_handle_id = 0;
memset(&data_counters, 0, sizeof(data_counters));
@ -1308,7 +1310,7 @@ bool buffering_reset(char *buf, size_t buflen)
cur_handle = NULL;
cached_handle = NULL;
num_handles = 0;
base_handle_id = -1;
base_handle_id = 0;
buffer_callback_count = 0;
memset(buffer_low_callback_funcs, 0, sizeof(buffer_low_callback_funcs));

View file

@ -65,7 +65,6 @@ bool buffering_reset(char *buf, size_t buflen);
* amount of data is ready (unless EOF is reached).
****************************************************************************/
#define BUF_HANDLE_ID_MASK 0x7FFFFFFF
#define BUF_MAX_HANDLES 256
int bufopen(const char *file, size_t offset, enum data_type type);

View file

@ -217,6 +217,7 @@ struct track_info {
size_t filesize; /* File total length */
bool has_codec; /* Codec length in bytes */
bool taginfo_ready; /* Is metadata read */
bool event_sent; /* Was this track's buffered event sent */
@ -365,23 +366,23 @@ static bool clear_track_info(struct track_info *track)
if (!track)
return false;
if (track->codec_hid >= 0) {
if (track->codec_hid > 0) {
if (bufclose(track->codec_hid))
track->codec_hid = -1;
track->codec_hid = 0;
else
return false;
}
if (track->id3_hid >= 0) {
if (track->id3_hid > 0) {
if (bufclose(track->id3_hid))
track->id3_hid = -1;
track->id3_hid = 0;
else
return false;
}
if (track->audio_hid >= 0) {
if (track->audio_hid > 0) {
if (bufclose(track->audio_hid))
track->audio_hid = -1;
track->audio_hid = 0;
else
return false;
}
@ -642,7 +643,7 @@ struct mp3entry* audio_current_track(void)
return &curtrack_id3;
else if (offset == -1 && *prevtrack_id3.path)
return &prevtrack_id3;
else if (tracks[cur_idx].id3_hid >= 0)
else if (tracks[cur_idx].id3_hid > 0)
return bufgetid3(tracks[cur_idx].id3_hid);
memset(&temp_id3, 0, sizeof(struct mp3entry));
@ -681,7 +682,7 @@ struct mp3entry* audio_next_track(void)
next_idx++;
next_idx &= MAX_TRACK_MASK;
if (tracks[next_idx].id3_hid < 0)
if (tracks[next_idx].id3_hid <= 0)
return NULL;
return &nexttrack_id3;
@ -1681,10 +1682,11 @@ static void codec_pcmbuf_track_changed_callback(void)
static void codec_discard_codec_callback(void)
{
if (CUR_TI->codec_hid >= 0)
if (CUR_TI->codec_hid > 0)
{
bufclose(CUR_TI->codec_hid);
CUR_TI->codec_hid = -1;
CUR_TI->codec_hid = 0;
CUR_TI->has_codec = false;
}
}
@ -1849,7 +1851,7 @@ static void codec_thread(void)
case Q_CODEC_LOAD:
LOGFQUEUE("codec < Q_CODEC_LOAD");
if (CUR_TI->codec_hid < 0) {
if (CUR_TI->codec_hid <= 0) {
logf("Codec slot is empty!");
/* Wait for the pcm buffer to go empty */
while (pcm_is_playing())
@ -1961,7 +1963,7 @@ static void codec_thread(void)
}
}
if (CUR_TI->codec_hid >= 0)
if (CUR_TI->codec_hid > 0)
{
LOGFQUEUE("codec > codec Q_CODEC_LOAD");
queue_post(&codec_queue, Q_CODEC_LOAD, 0);
@ -2042,18 +2044,18 @@ long audio_filebufused(void)
static void audio_update_trackinfo(void)
{
if (CUR_TI->id3_hid >= 0)
if (CUR_TI->id3_hid > 0)
copy_mp3entry(&curtrack_id3, bufgetid3(CUR_TI->id3_hid));
CUR_TI->taginfo_ready = (CUR_TI->id3_hid >= 0);
CUR_TI->taginfo_ready = (CUR_TI->id3_hid > 0);
int next_idx = track_ridx + 1;
next_idx &= MAX_TRACK_MASK;
if (tracks[next_idx].id3_hid >= 0)
if (tracks[next_idx].id3_hid > 0)
copy_mp3entry(&nexttrack_id3, bufgetid3(tracks[next_idx].id3_hid));
tracks[next_idx].taginfo_ready = (tracks[next_idx].id3_hid >= 0);
tracks[next_idx].taginfo_ready = (tracks[next_idx].id3_hid > 0);
ci.filesize = CUR_TI->filesize;
curtrack_id3.elapsed = 0;
@ -2094,7 +2096,7 @@ static void audio_clear_track_entries(bool clear_unbuffered)
{
/* If there is an unbuffer callback, call it, otherwise,
* just clear the track */
if (track_unbuffer_callback && tracks[cur_idx].id3_hid >= 0)
if (track_unbuffer_callback && tracks[cur_idx].id3_hid > 0)
track_unbuffer_callback(bufgetid3(tracks[cur_idx].id3_hid));
clear_track_info(&tracks[cur_idx]);
@ -2125,7 +2127,7 @@ static bool audio_loadcodec(bool start_play)
int prev_track;
char codec_path[MAX_PATH]; /* Full path to codec */
if (tracks[track_widx].id3_hid < 0) {
if (tracks[track_widx].id3_hid <= 0) {
return false;
}
@ -2134,7 +2136,7 @@ static bool audio_loadcodec(bool start_play)
if (codec_fn == NULL)
return false;
tracks[track_widx].codec_hid = -1;
tracks[track_widx].codec_hid = false;
if (start_play)
{
@ -2171,11 +2173,26 @@ static bool audio_loadcodec(bool start_play)
codec_get_full_path(codec_path, codec_fn);
/* Found a codec filename */
tracks[track_widx].has_codec = true;
tracks[track_widx].codec_hid = bufopen(codec_path, 0, TYPE_CODEC);
if (tracks[track_widx].codec_hid < 0)
{
if (tracks[track_widx].codec_hid == ERR_FILE_ERROR)
{
logf("Codec file error");
tracks[track_widx].has_codec = false;
}
else
{
logf("Not enough space");
}
return false;
}
logf("Loaded codec");
return true;
}
@ -2298,16 +2315,15 @@ static bool audio_load_track(int offset, bool start_play)
}
/* Get track metadata if we don't already have it. */
if (tracks[track_widx].id3_hid < 0)
if (tracks[track_widx].id3_hid <= 0)
{
if (get_metadata(&id3, fd, trackname))
{
tracks[track_widx].id3_hid =
bufalloc(&id3, sizeof(struct mp3entry), TYPE_ID3);
tracks[track_widx].taginfo_ready =
(tracks[track_widx].id3_hid >= 0);
tracks[track_widx].id3_hid = bufalloc(&id3, sizeof(struct mp3entry),
TYPE_ID3);
tracks[track_widx].taginfo_ready = (tracks[track_widx].id3_hid > 0);
if (tracks[track_widx].id3_hid < 0)
if (tracks[track_widx].id3_hid <= 0)
{
last_peek_offset--;
close(fd);
@ -2360,9 +2376,10 @@ static bool audio_load_track(int offset, bool start_play)
/* Load the codec. */
if (!audio_loadcodec(start_play))
{
if (tracks[track_widx].codec_hid == ERR_BUFFER_FULL)
if (tracks[track_widx].has_codec)
{
/* No space for codec on buffer, not an error */
tracks[track_widx].has_codec = false;
return false;
}
@ -2436,7 +2453,7 @@ static bool audio_load_track(int offset, bool start_play)
tracks[track_widx].audio_hid = bufopen(trackname, file_offset, type);
if (tracks[track_widx].audio_hid < 0)
if (tracks[track_widx].audio_hid <= 0)
return false;
if (start_play)
@ -2466,7 +2483,7 @@ static void audio_generate_postbuffer_events(void)
{
/* Mark the event 'sent' even if we don't really send one */
tracks[cur_idx].event_sent = true;
if (track_buffer_callback && tracks[cur_idx].id3_hid >= 0)
if (track_buffer_callback && tracks[cur_idx].id3_hid > 0)
track_buffer_callback(bufgetid3(tracks[cur_idx].id3_hid));
}
if (cur_idx == track_widx)