1
0
Fork 0
forked from len0rd/rockbox

Accept FS#8053 by Bertrik Sikken: playback.c and mpeg.c simplification by removal of last_track argument in track_(un)buffer callback.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15384 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Nicolas Pennequin 2007-10-31 13:43:50 +00:00
parent b41b1b3141
commit 7f79564abc
5 changed files with 25 additions and 88 deletions

View file

@ -252,9 +252,9 @@ static bool skipped_during_pause = false; /* Do we need to clear the PCM buffer
/* When the playing track has changed from the user's perspective */ /* When the playing track has changed from the user's perspective */
void (*track_changed_callback)(struct mp3entry *id3) = NULL; void (*track_changed_callback)(struct mp3entry *id3) = NULL;
/* When a track has been buffered */ /* When a track has been buffered */
void (*track_buffer_callback)(struct mp3entry *id3, bool last_track) = NULL; void (*track_buffer_callback)(struct mp3entry *id3) = NULL;
/* When a track's buffer has been overwritten or cleared */ /* When a track's buffer has been overwritten or cleared */
void (*track_unbuffer_callback)(struct mp3entry *id3, bool last_track) = NULL; void (*track_unbuffer_callback)(struct mp3entry *id3) = NULL;
static size_t buffer_margin = 0; /* Buffer margin aka anti-skip buffer (A/C-) */ static size_t buffer_margin = 0; /* Buffer margin aka anti-skip buffer (A/C-) */
@ -2129,7 +2129,6 @@ static void audio_update_trackinfo(void)
static void audio_clear_track_entries(bool clear_unbuffered) static void audio_clear_track_entries(bool clear_unbuffered)
{ {
int cur_idx = track_widx; int cur_idx = track_widx;
int last_idx = -1;
logf("Clearing tracks:%d/%d, %d", track_ridx, track_widx, clear_unbuffered); logf("Clearing tracks:%d/%d, %d", track_ridx, track_widx, clear_unbuffered);
@ -2146,30 +2145,16 @@ static void audio_clear_track_entries(bool clear_unbuffered)
* otherwise clear the track if that option is selected */ * otherwise clear the track if that option is selected */
if (tracks[cur_idx].event_sent) if (tracks[cur_idx].event_sent)
{ {
if (last_idx >= 0) /* If there is an unbuffer callback, call it, otherwise,
{ * just clear the track */
/* If there is an unbuffer callback, call it, otherwise, if (track_unbuffer_callback && tracks[cur_idx].id3_hid > 0)
* just clear the track */ track_unbuffer_callback(bufgetid3(tracks[cur_idx].id3_hid));
if (track_unbuffer_callback && tracks[last_idx].id3_hid > 0)
track_unbuffer_callback(bufgetid3(tracks[last_idx].id3_hid), false);
clear_track_info(&tracks[last_idx]); clear_track_info(&tracks[cur_idx]);
}
last_idx = cur_idx;
} }
else if (clear_unbuffered) else if (clear_unbuffered)
clear_track_info(&tracks[cur_idx]); clear_track_info(&tracks[cur_idx]);
} }
/* We clear the previous instance of a buffered track throughout
* the above loop to facilitate 'last' detection. Clear/notify
* the last track here */
if (last_idx >= 0)
{
if (track_unbuffer_callback && tracks[last_idx].id3_hid > 0)
track_unbuffer_callback(bufgetid3(tracks[last_idx].id3_hid), true);
clear_track_info(&tracks[last_idx]);
}
} }
static bool audio_release_tracks(void) static bool audio_release_tracks(void)
@ -2527,7 +2512,6 @@ static bool audio_load_track(int offset, bool start_play)
static void audio_generate_postbuffer_events(void) static void audio_generate_postbuffer_events(void)
{ {
int cur_idx; int cur_idx;
int last_idx = -1;
logf("Postbuffer:%d/%d",track_ridx,track_widx); logf("Postbuffer:%d/%d",track_ridx,track_widx);
@ -2538,27 +2522,16 @@ static void audio_generate_postbuffer_events(void)
while (1) { while (1) {
if (!tracks[cur_idx].event_sent) if (!tracks[cur_idx].event_sent)
{ {
if (last_idx >= 0 && !tracks[last_idx].event_sent) /* Mark the event 'sent' even if we don't really send one */
{ tracks[cur_idx].event_sent = true;
/* Mark the event 'sent' even if we don't really send one */ if (track_buffer_callback && tracks[cur_idx].id3_hid > 0)
tracks[last_idx].event_sent = true; track_buffer_callback(bufgetid3(tracks[cur_idx].id3_hid));
if (track_buffer_callback && tracks[last_idx].id3_hid > 0)
track_buffer_callback(bufgetid3(tracks[last_idx].id3_hid), false);
}
last_idx = cur_idx;
} }
if (cur_idx == track_widx) if (cur_idx == track_widx)
break; break;
cur_idx++; cur_idx++;
cur_idx &= MAX_TRACK_MASK; cur_idx &= MAX_TRACK_MASK;
} }
if (last_idx >= 0 && !tracks[last_idx].event_sent)
{
tracks[last_idx].event_sent = true;
if (track_buffer_callback && tracks[last_idx].id3_hid > 0)
track_buffer_callback(bufgetid3(tracks[last_idx].id3_hid), true);
}
} }
} }
@ -2767,14 +2740,12 @@ skip_done:
return Q_CODEC_REQUEST_COMPLETE; return Q_CODEC_REQUEST_COMPLETE;
} }
void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3, void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3))
bool last_track))
{ {
track_buffer_callback = handler; track_buffer_callback = handler;
} }
void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3, void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3))
bool last_track))
{ {
track_unbuffer_callback = handler; track_unbuffer_callback = handler;
} }

View file

@ -42,10 +42,8 @@
/* Functions */ /* Functions */
const char * get_codec_filename(int cod_spec); const char * get_codec_filename(int cod_spec);
void audio_set_track_changed_event(void (*handler)(struct mp3entry *id3)); void audio_set_track_changed_event(void (*handler)(struct mp3entry *id3));
void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3, void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3));
bool last_track)); void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3));
void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3,
bool last_track));
void voice_wait(void); void voice_wait(void);
#if CONFIG_CODEC == SWCODEC /* This #ifdef is better here than gui/gwps.c */ #if CONFIG_CODEC == SWCODEC /* This #ifdef is better here than gui/gwps.c */

View file

@ -633,10 +633,9 @@ static int compare(const void *p1, const void *p2)
return strncasecmp(e1->name, e2->name, MAX_PATH); return strncasecmp(e1->name, e2->name, MAX_PATH);
} }
static void tagtree_buffer_event(struct mp3entry *id3, bool last_track) static void tagtree_buffer_event(struct mp3entry *id3)
{ {
(void)id3; (void)id3;
(void)last_track;
/* Do not gather data unless proper setting has been enabled. */ /* Do not gather data unless proper setting has been enabled. */
if (!global_settings.runtimedb) if (!global_settings.runtimedb)
@ -663,9 +662,8 @@ static void tagtree_buffer_event(struct mp3entry *id3, bool last_track)
tagcache_search_finish(&tcs); tagcache_search_finish(&tcs);
} }
static void tagtree_unbuffer_event(struct mp3entry *id3, bool last_track) static void tagtree_unbuffer_event(struct mp3entry *id3)
{ {
(void)last_track;
long playcount; long playcount;
long playtime; long playtime;
long lastplayed; long lastplayed;

View file

@ -57,10 +57,8 @@ void rec_tick(void);
void playback_tick(void); /* FixMe: get rid of this, use mp3_get_playtime() */ void playback_tick(void); /* FixMe: get rid of this, use mp3_get_playtime() */
void audio_set_track_changed_event(void (*handler)(struct mp3entry *id3)); void audio_set_track_changed_event(void (*handler)(struct mp3entry *id3));
void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3, void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3));
bool last_track)); void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3));
void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3,
bool last_track));
void audio_set_cuesheet_callback(bool (*handler)(const char *filename)); void audio_set_cuesheet_callback(bool (*handler)(const char *filename));
#endif #endif

View file

@ -118,8 +118,8 @@ static int track_write_idx = 0;
/* Callback function to call when current track has really changed. */ /* Callback function to call when current track has really changed. */
void (*track_changed_callback)(struct mp3entry *id3) = NULL; void (*track_changed_callback)(struct mp3entry *id3) = NULL;
void (*track_buffer_callback)(struct mp3entry *id3, bool last_track); void (*track_buffer_callback)(struct mp3entry *id3);
void (*track_unbuffer_callback)(struct mp3entry *id3, bool last_track); void (*track_unbuffer_callback)(struct mp3entry *id3);
/* Cuesheet callback */ /* Cuesheet callback */
static bool (*cuesheet_callback)(const char *filename) = NULL; static bool (*cuesheet_callback)(const char *filename) = NULL;
@ -475,14 +475,12 @@ unsigned long mpeg_get_last_header(void)
#endif /* !SIMULATOR */ #endif /* !SIMULATOR */
} }
void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3, void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3))
bool last_track))
{ {
track_buffer_callback = handler; track_buffer_callback = handler;
} }
void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3, void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3))
bool last_track))
{ {
track_unbuffer_callback = handler; track_unbuffer_callback = handler;
} }
@ -502,29 +500,16 @@ void audio_set_cuesheet_callback(bool (*handler)(const char *filename))
static void generate_unbuffer_events(void) static void generate_unbuffer_events(void)
{ {
int i; int i;
int event_count = 0;
int numentries = MAX_TRACK_ENTRIES - num_tracks_in_memory(); int numentries = MAX_TRACK_ENTRIES - num_tracks_in_memory();
int cur_idx = track_write_idx; int cur_idx = track_write_idx;
for (i = 0; i < numentries; i++)
{
if (trackdata[cur_idx].event_sent)
event_count++;
cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK;
}
cur_idx = track_write_idx;
for (i = 0; i < numentries; i++) for (i = 0; i < numentries; i++)
{ {
/* Send an event to notify that track has finished. */ /* Send an event to notify that track has finished. */
if (trackdata[cur_idx].event_sent) if (trackdata[cur_idx].event_sent)
{ {
event_count--;
if (track_unbuffer_callback) if (track_unbuffer_callback)
track_unbuffer_callback(&trackdata[cur_idx].id3, track_unbuffer_callback(&trackdata[cur_idx].id3);
event_count == 0);
trackdata[cur_idx].event_sent = false; trackdata[cur_idx].event_sent = false;
} }
cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK; cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK;
@ -535,28 +520,15 @@ static void generate_unbuffer_events(void)
static void generate_postbuffer_events(void) static void generate_postbuffer_events(void)
{ {
int i; int i;
int event_count = 0;
int numentries = num_tracks_in_memory(); int numentries = num_tracks_in_memory();
int cur_idx = track_read_idx; int cur_idx = track_read_idx;
for (i = 0; i < numentries; i++)
{
if (!trackdata[cur_idx].event_sent)
event_count++;
cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK;
}
cur_idx = track_read_idx;
for (i = 0; i < numentries; i++) for (i = 0; i < numentries; i++)
{ {
if (!trackdata[cur_idx].event_sent) if (!trackdata[cur_idx].event_sent)
{ {
event_count--;
if (track_buffer_callback) if (track_buffer_callback)
track_buffer_callback(&trackdata[cur_idx].id3, track_buffer_callback(&trackdata[cur_idx].id3);
event_count == 0);
trackdata[cur_idx].event_sent = true; trackdata[cur_idx].event_sent = true;
} }
cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK; cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK;