1
0
Fork 0
forked from len0rd/rockbox

Ensure that codecs are cleared from the buffer if they will not be needed by the track about to play and some minor changes for correctness with no functional difference

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9605 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Brandon Low 2006-04-11 12:29:46 +00:00
parent d2848f3d72
commit 3b76544fa9

View file

@ -648,12 +648,8 @@ static void buffer_wind_forward(void)
buf_ridx -= filebuflen; buf_ridx -= filebuflen;
} }
static void buffer_wind_backward(bool need_codec) static void buffer_wind_backward(size_t rewind)
{ {
/* Rewind the buffer to the beginning of the new track */
size_t rewind = ci.curpos + prev_ti->codecsize + cur_ti->filesize;
if (need_codec)
rewind += cur_ti->codecsize;
/* Check and handle buffer wrapping */ /* Check and handle buffer wrapping */
if (rewind > buf_ridx) if (rewind > buf_ridx)
buf_ridx += filebuflen; buf_ridx += filebuflen;
@ -731,8 +727,7 @@ static void audio_check_new_track(long direction)
{ {
/* This is how much 'back' data must remain uncleared for us /* This is how much 'back' data must remain uncleared for us
* to safely backup to the beginning of the previous track */ * to safely backup to the beginning of the previous track */
size_t req_size = size_t req_size = ci.curpos + prev_ti->codecsize + cur_ti->filesize;
ci.curpos + prev_ti->codecsize + tracks[track_ridx].filesize;
/* This is the amount of 'back' data available on the buffer */ /* This is the amount of 'back' data available on the buffer */
size_t buf_back = buf_ridx; size_t buf_back = buf_ridx;
if (buf_back < buf_widx) if (buf_back < buf_widx)
@ -759,12 +754,12 @@ static void audio_check_new_track(long direction)
else else
{ {
cur_ti->has_codec = true; cur_ti->has_codec = true;
buffer_wind_backward(true); buffer_wind_backward(req_size);
} }
} }
} }
else else
buffer_wind_backward(false); buffer_wind_backward(req_size);
} }
} }
mutex_unlock(&mutex_interthread); mutex_unlock(&mutex_interthread);
@ -1117,11 +1112,13 @@ static void audio_read_file(void)
static void codec_discard_codec_callback(void) static void codec_discard_codec_callback(void)
{ {
tracks[track_ridx].has_codec = false; if (tracks[track_ridx].has_codec) {
filebufused -= tracks[track_ridx].codecsize; tracks[track_ridx].has_codec = false;
buf_ridx += tracks[track_ridx].codecsize; filebufused -= tracks[track_ridx].codecsize;
if (buf_ridx >= filebuflen) buf_ridx += tracks[track_ridx].codecsize;
buf_ridx -= filebuflen; if (buf_ridx >= filebuflen)
buf_ridx -= filebuflen;
}
} }
static bool loadcodec(bool start_play) static bool loadcodec(bool start_play)
@ -1747,19 +1744,20 @@ bool codec_request_next_track_callback(void)
} }
/* Check if the next codec is the same file. */ /* Check if the next codec is the same file. */
if (get_codec_base_type(prev_ti->id3.codectype) != if (get_codec_base_type(prev_ti->id3.codectype) ==
get_codec_base_type(cur_ti->id3.codectype)) get_codec_base_type(cur_ti->id3.codectype))
{
logf("New track loaded");
ci.reload_codec = false;
codec_discard_codec_callback();
return true;
}
else
{ {
logf("New codec:%d/%d", cur_ti->id3.codectype, prev_ti->id3.codectype); logf("New codec:%d/%d", cur_ti->id3.codectype, prev_ti->id3.codectype);
ci.reload_codec = true; ci.reload_codec = true;
return false; return false;
} }
else
{
logf("New track loaded");
ci.reload_codec = false;
return true;
}
} }
/* Invalidates all but currently playing track. */ /* Invalidates all but currently playing track. */
@ -1979,7 +1977,7 @@ void codec_thread(void)
case Q_CODEC_LOAD: case Q_CODEC_LOAD:
logf("Codec start"); logf("Codec start");
if (!cur_ti->has_codec) { if (!tracks[track_ridx].has_codec) {
logf("Codec slot is empty!"); logf("Codec slot is empty!");
/* Wait for the pcm buffer to go empty */ /* Wait for the pcm buffer to go empty */
while (pcm_is_playing()) while (pcm_is_playing())
@ -1991,12 +1989,13 @@ void codec_thread(void)
} }
ci.stop_codec = false; ci.stop_codec = false;
wrap = (size_t)&filebuf[filebuflen] - (size_t)cur_ti->codecbuf; wrap = (size_t)&filebuf[filebuflen] -
(size_t)tracks[track_ridx].codecbuf;
audio_codec_loaded = true; audio_codec_loaded = true;
mutex_lock(&mutex_codecthread); mutex_lock(&mutex_codecthread);
current_codec = CODEC_IDX_AUDIO; current_codec = CODEC_IDX_AUDIO;
status = codec_load_ram(cur_ti->codecbuf, cur_ti->codecsize, status = codec_load_ram(tracks[track_ridx].codecbuf,
&filebuf[0], wrap, &ci); tracks[track_ridx].codecsize, &filebuf[0], wrap, &ci);
mutex_unlock(&mutex_codecthread); mutex_unlock(&mutex_codecthread);
break ; break ;