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:
parent
b41b1b3141
commit
7f79564abc
5 changed files with 25 additions and 88 deletions
|
@ -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 */
|
||||
void (*track_changed_callback)(struct mp3entry *id3) = NULL;
|
||||
/* 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 */
|
||||
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-) */
|
||||
|
||||
|
@ -2129,7 +2129,6 @@ static void audio_update_trackinfo(void)
|
|||
static void audio_clear_track_entries(bool clear_unbuffered)
|
||||
{
|
||||
int cur_idx = track_widx;
|
||||
int last_idx = -1;
|
||||
|
||||
logf("Clearing tracks:%d/%d, %d", track_ridx, track_widx, clear_unbuffered);
|
||||
|
||||
|
@ -2145,31 +2144,17 @@ static void audio_clear_track_entries(bool clear_unbuffered)
|
|||
/* If the track is buffered, conditionally clear/notify,
|
||||
* otherwise clear the track if that option is selected */
|
||||
if (tracks[cur_idx].event_sent)
|
||||
{
|
||||
if (last_idx >= 0)
|
||||
{
|
||||
/* If there is an unbuffer callback, call it, otherwise,
|
||||
* just clear the track */
|
||||
if (track_unbuffer_callback && tracks[last_idx].id3_hid > 0)
|
||||
track_unbuffer_callback(bufgetid3(tracks[last_idx].id3_hid), false);
|
||||
if (track_unbuffer_callback && tracks[cur_idx].id3_hid > 0)
|
||||
track_unbuffer_callback(bufgetid3(tracks[cur_idx].id3_hid));
|
||||
|
||||
clear_track_info(&tracks[last_idx]);
|
||||
}
|
||||
last_idx = cur_idx;
|
||||
clear_track_info(&tracks[cur_idx]);
|
||||
}
|
||||
else if (clear_unbuffered)
|
||||
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)
|
||||
|
@ -2527,7 +2512,6 @@ static bool audio_load_track(int offset, bool start_play)
|
|||
static void audio_generate_postbuffer_events(void)
|
||||
{
|
||||
int cur_idx;
|
||||
int last_idx = -1;
|
||||
|
||||
logf("Postbuffer:%d/%d",track_ridx,track_widx);
|
||||
|
||||
|
@ -2537,28 +2521,17 @@ static void audio_generate_postbuffer_events(void)
|
|||
|
||||
while (1) {
|
||||
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[last_idx].event_sent = true;
|
||||
if (track_buffer_callback && tracks[last_idx].id3_hid > 0)
|
||||
track_buffer_callback(bufgetid3(tracks[last_idx].id3_hid), false);
|
||||
}
|
||||
last_idx = cur_idx;
|
||||
tracks[cur_idx].event_sent = true;
|
||||
if (track_buffer_callback && tracks[cur_idx].id3_hid > 0)
|
||||
track_buffer_callback(bufgetid3(tracks[cur_idx].id3_hid));
|
||||
}
|
||||
if (cur_idx == track_widx)
|
||||
break;
|
||||
cur_idx++;
|
||||
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;
|
||||
}
|
||||
|
||||
void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3,
|
||||
bool last_track))
|
||||
void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3))
|
||||
{
|
||||
track_buffer_callback = handler;
|
||||
}
|
||||
|
||||
void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3,
|
||||
bool last_track))
|
||||
void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3))
|
||||
{
|
||||
track_unbuffer_callback = handler;
|
||||
}
|
||||
|
|
|
@ -42,10 +42,8 @@
|
|||
/* Functions */
|
||||
const char * get_codec_filename(int cod_spec);
|
||||
void audio_set_track_changed_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,
|
||||
bool last_track));
|
||||
void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3));
|
||||
void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3));
|
||||
void voice_wait(void);
|
||||
|
||||
#if CONFIG_CODEC == SWCODEC /* This #ifdef is better here than gui/gwps.c */
|
||||
|
|
|
@ -633,10 +633,9 @@ static int compare(const void *p1, const void *p2)
|
|||
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)last_track;
|
||||
|
||||
/* Do not gather data unless proper setting has been enabled. */
|
||||
if (!global_settings.runtimedb)
|
||||
|
@ -663,9 +662,8 @@ static void tagtree_buffer_event(struct mp3entry *id3, bool last_track)
|
|||
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 playtime;
|
||||
long lastplayed;
|
||||
|
|
|
@ -57,10 +57,8 @@ void rec_tick(void);
|
|||
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_buffer_event(void (*handler)(struct mp3entry *id3,
|
||||
bool last_track));
|
||||
void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3,
|
||||
bool last_track));
|
||||
void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3));
|
||||
void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3));
|
||||
void audio_set_cuesheet_callback(bool (*handler)(const char *filename));
|
||||
|
||||
#endif
|
||||
|
|
|
@ -118,8 +118,8 @@ static int track_write_idx = 0;
|
|||
|
||||
/* Callback function to call when current track has really changed. */
|
||||
void (*track_changed_callback)(struct mp3entry *id3) = NULL;
|
||||
void (*track_buffer_callback)(struct mp3entry *id3, bool last_track);
|
||||
void (*track_unbuffer_callback)(struct mp3entry *id3, bool last_track);
|
||||
void (*track_buffer_callback)(struct mp3entry *id3);
|
||||
void (*track_unbuffer_callback)(struct mp3entry *id3);
|
||||
|
||||
/* Cuesheet callback */
|
||||
static bool (*cuesheet_callback)(const char *filename) = NULL;
|
||||
|
@ -475,14 +475,12 @@ unsigned long mpeg_get_last_header(void)
|
|||
#endif /* !SIMULATOR */
|
||||
}
|
||||
|
||||
void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3,
|
||||
bool last_track))
|
||||
void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3))
|
||||
{
|
||||
track_buffer_callback = handler;
|
||||
}
|
||||
|
||||
void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3,
|
||||
bool last_track))
|
||||
void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3))
|
||||
{
|
||||
track_unbuffer_callback = handler;
|
||||
}
|
||||
|
@ -502,29 +500,16 @@ void audio_set_cuesheet_callback(bool (*handler)(const char *filename))
|
|||
static void generate_unbuffer_events(void)
|
||||
{
|
||||
int i;
|
||||
int event_count = 0;
|
||||
int numentries = MAX_TRACK_ENTRIES - num_tracks_in_memory();
|
||||
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++)
|
||||
{
|
||||
/* Send an event to notify that track has finished. */
|
||||
if (trackdata[cur_idx].event_sent)
|
||||
{
|
||||
event_count--;
|
||||
if (track_unbuffer_callback)
|
||||
track_unbuffer_callback(&trackdata[cur_idx].id3,
|
||||
event_count == 0);
|
||||
track_unbuffer_callback(&trackdata[cur_idx].id3);
|
||||
trackdata[cur_idx].event_sent = false;
|
||||
}
|
||||
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)
|
||||
{
|
||||
int i;
|
||||
int event_count = 0;
|
||||
int numentries = num_tracks_in_memory();
|
||||
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++)
|
||||
{
|
||||
if (!trackdata[cur_idx].event_sent)
|
||||
{
|
||||
event_count--;
|
||||
if (track_buffer_callback)
|
||||
track_buffer_callback(&trackdata[cur_idx].id3,
|
||||
event_count == 0);
|
||||
track_buffer_callback(&trackdata[cur_idx].id3);
|
||||
trackdata[cur_idx].event_sent = true;
|
||||
}
|
||||
cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue