summaryrefslogtreecommitdiff
path: root/apps/playback.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/playback.c')
-rw-r--r--apps/playback.c43
1 files changed, 30 insertions, 13 deletions
diff --git a/apps/playback.c b/apps/playback.c
index c5b6fbc6a5..875a157ba4 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -162,7 +162,7 @@ static int new_track;
162/* Callback function to call when current track has really changed. */ 162/* Callback function to call when current track has really changed. */
163void (*track_changed_callback)(struct track_info *ti); 163void (*track_changed_callback)(struct track_info *ti);
164void (*track_buffer_callback)(struct mp3entry *id3, bool last_track); 164void (*track_buffer_callback)(struct mp3entry *id3, bool last_track);
165void (*track_unbuffer_callback)(struct mp3entry *id3, bool disk_spinning); 165void (*track_unbuffer_callback)(struct mp3entry *id3, bool last_track);
166 166
167/* Configuration */ 167/* Configuration */
168static int conf_bufferlimit; 168static int conf_bufferlimit;
@@ -598,7 +598,7 @@ void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3,
598} 598}
599 599
600void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3, 600void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3,
601 bool disk_spinning)) 601 bool last_track))
602{ 602{
603 track_unbuffer_callback = handler; 603 track_unbuffer_callback = handler;
604} 604}
@@ -990,17 +990,37 @@ void audio_play_start(int offset)
990 990
991void audio_clear_track_entries(void) 991void audio_clear_track_entries(void)
992{ 992{
993 int cur_idx; 993 int cur_idx, event_count;
994 int i; 994 int i;
995 995
996 cur_idx = track_widx; 996 cur_idx = track_widx;
997 event_count = 0;
997 for (i = 0; i < MAX_TRACK - track_count; i++) { 998 for (i = 0; i < MAX_TRACK - track_count; i++) {
998 if (++cur_idx >= MAX_TRACK) 999 if (++cur_idx >= MAX_TRACK)
999 cur_idx = 0; 1000 cur_idx = 0;
1000 1001
1001 /* Send event to notify that track has finished. */ 1002 if (tracks[cur_idx].event_sent)
1002 if (track_unbuffer_callback && tracks[cur_idx].event_sent) 1003 event_count++;
1003 track_unbuffer_callback(&tracks[cur_idx].id3, filling); 1004
1005 if (!track_unbuffer_callback)
1006 memset(&tracks[cur_idx], 0, sizeof(struct track_info));
1007 }
1008
1009 if (!track_unbuffer_callback)
1010 return ;
1011
1012 cur_idx = track_widx;
1013 for (i = 0; i < MAX_TRACK - track_count; i++) {
1014 if (++cur_idx >= MAX_TRACK)
1015 cur_idx = 0;
1016
1017 /* Send an event to notify that track has finished. */
1018 if (tracks[cur_idx].event_sent) {
1019 tracks[cur_idx].event_sent = true;
1020 event_count--;
1021 track_unbuffer_callback(&tracks[cur_idx].id3, event_count == 0);
1022 }
1023
1004 memset(&tracks[cur_idx], 0, sizeof(struct track_info)); 1024 memset(&tracks[cur_idx], 0, sizeof(struct track_info));
1005 } 1025 }
1006} 1026}
@@ -1163,7 +1183,6 @@ static void audio_stop_playback(void)
1163 pcm_play_stop(); 1183 pcm_play_stop();
1164 pcm_play_pause(true); 1184 pcm_play_pause(true);
1165 track_count = 0; 1185 track_count = 0;
1166 filling = true;
1167 audio_clear_track_entries(); 1186 audio_clear_track_entries();
1168 filling = false; 1187 filling = false;
1169} 1188}
@@ -1695,17 +1714,17 @@ void mpeg_id3_options(bool _v1first)
1695 v1first = _v1first; 1714 v1first = _v1first;
1696} 1715}
1697 1716
1698/* 1717
1699void test_buffer_event(struct mp3entry *id3, bool last_track) 1718void test_buffer_event(struct mp3entry *id3, bool last_track)
1700{ 1719{
1701 logf("be:%d%s", last_track, id3->title); 1720 logf("be:%d%s", last_track, id3->title);
1702} 1721}
1703 1722
1704void test_unbuffer_event(struct mp3entry *id3, bool disk_spinning) 1723void test_unbuffer_event(struct mp3entry *id3, bool last_track)
1705{ 1724{
1706 logf("ube:%d%s", disk_spinning, id3->title); 1725 logf("ube:%d%s", last_track, id3->title);
1707} 1726}
1708*/ 1727
1709 1728
1710void audio_init(void) 1729void audio_init(void)
1711{ 1730{
@@ -1729,10 +1748,8 @@ void audio_init(void)
1729 logf("fbuf:%0x", codecbuflen); 1748 logf("fbuf:%0x", codecbuflen);
1730 logf("mbuf:%0x", MALLOC_BUFSIZE); 1749 logf("mbuf:%0x", MALLOC_BUFSIZE);
1731 1750
1732 /*
1733 audio_set_track_buffer_event(test_buffer_event); 1751 audio_set_track_buffer_event(test_buffer_event);
1734 audio_set_track_unbuffer_event(test_unbuffer_event); 1752 audio_set_track_unbuffer_event(test_unbuffer_event);
1735 */
1736 1753
1737 /* Initialize codec api. */ 1754 /* Initialize codec api. */
1738 ci.read_filebuf = codec_filebuf_callback; 1755 ci.read_filebuf = codec_filebuf_callback;