summaryrefslogtreecommitdiff
path: root/apps/playback.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/playback.c')
-rw-r--r--apps/playback.c55
1 files changed, 13 insertions, 42 deletions
diff --git a/apps/playback.c b/apps/playback.c
index 793832322b..5cd8e6def3 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -252,9 +252,9 @@ static bool skipped_during_pause = false; /* Do we need to clear the PCM buffer
252/* When the playing track has changed from the user's perspective */ 252/* When the playing track has changed from the user's perspective */
253void (*track_changed_callback)(struct mp3entry *id3) = NULL; 253void (*track_changed_callback)(struct mp3entry *id3) = NULL;
254/* When a track has been buffered */ 254/* When a track has been buffered */
255void (*track_buffer_callback)(struct mp3entry *id3, bool last_track) = NULL; 255void (*track_buffer_callback)(struct mp3entry *id3) = NULL;
256/* When a track's buffer has been overwritten or cleared */ 256/* When a track's buffer has been overwritten or cleared */
257void (*track_unbuffer_callback)(struct mp3entry *id3, bool last_track) = NULL; 257void (*track_unbuffer_callback)(struct mp3entry *id3) = NULL;
258 258
259static size_t buffer_margin = 0; /* Buffer margin aka anti-skip buffer (A/C-) */ 259static size_t buffer_margin = 0; /* Buffer margin aka anti-skip buffer (A/C-) */
260 260
@@ -2129,7 +2129,6 @@ static void audio_update_trackinfo(void)
2129static void audio_clear_track_entries(bool clear_unbuffered) 2129static void audio_clear_track_entries(bool clear_unbuffered)
2130{ 2130{
2131 int cur_idx = track_widx; 2131 int cur_idx = track_widx;
2132 int last_idx = -1;
2133 2132
2134 logf("Clearing tracks:%d/%d, %d", track_ridx, track_widx, clear_unbuffered); 2133 logf("Clearing tracks:%d/%d, %d", track_ridx, track_widx, clear_unbuffered);
2135 2134
@@ -2146,30 +2145,16 @@ static void audio_clear_track_entries(bool clear_unbuffered)
2146 * otherwise clear the track if that option is selected */ 2145 * otherwise clear the track if that option is selected */
2147 if (tracks[cur_idx].event_sent) 2146 if (tracks[cur_idx].event_sent)
2148 { 2147 {
2149 if (last_idx >= 0) 2148 /* If there is an unbuffer callback, call it, otherwise,
2150 { 2149 * just clear the track */
2151 /* If there is an unbuffer callback, call it, otherwise, 2150 if (track_unbuffer_callback && tracks[cur_idx].id3_hid > 0)
2152 * just clear the track */ 2151 track_unbuffer_callback(bufgetid3(tracks[cur_idx].id3_hid));
2153 if (track_unbuffer_callback && tracks[last_idx].id3_hid > 0)
2154 track_unbuffer_callback(bufgetid3(tracks[last_idx].id3_hid), false);
2155 2152
2156 clear_track_info(&tracks[last_idx]); 2153 clear_track_info(&tracks[cur_idx]);
2157 }
2158 last_idx = cur_idx;
2159 } 2154 }
2160 else if (clear_unbuffered) 2155 else if (clear_unbuffered)
2161 clear_track_info(&tracks[cur_idx]); 2156 clear_track_info(&tracks[cur_idx]);
2162 } 2157 }
2163
2164 /* We clear the previous instance of a buffered track throughout
2165 * the above loop to facilitate 'last' detection. Clear/notify
2166 * the last track here */
2167 if (last_idx >= 0)
2168 {
2169 if (track_unbuffer_callback && tracks[last_idx].id3_hid > 0)
2170 track_unbuffer_callback(bufgetid3(tracks[last_idx].id3_hid), true);
2171 clear_track_info(&tracks[last_idx]);
2172 }
2173} 2158}
2174 2159
2175static bool audio_release_tracks(void) 2160static bool audio_release_tracks(void)
@@ -2527,7 +2512,6 @@ static bool audio_load_track(int offset, bool start_play)
2527static void audio_generate_postbuffer_events(void) 2512static void audio_generate_postbuffer_events(void)
2528{ 2513{
2529 int cur_idx; 2514 int cur_idx;
2530 int last_idx = -1;
2531 2515
2532 logf("Postbuffer:%d/%d",track_ridx,track_widx); 2516 logf("Postbuffer:%d/%d",track_ridx,track_widx);
2533 2517
@@ -2538,27 +2522,16 @@ static void audio_generate_postbuffer_events(void)
2538 while (1) { 2522 while (1) {
2539 if (!tracks[cur_idx].event_sent) 2523 if (!tracks[cur_idx].event_sent)
2540 { 2524 {
2541 if (last_idx >= 0 && !tracks[last_idx].event_sent) 2525 /* Mark the event 'sent' even if we don't really send one */
2542 { 2526 tracks[cur_idx].event_sent = true;
2543 /* Mark the event 'sent' even if we don't really send one */ 2527 if (track_buffer_callback && tracks[cur_idx].id3_hid > 0)
2544 tracks[last_idx].event_sent = true; 2528 track_buffer_callback(bufgetid3(tracks[cur_idx].id3_hid));
2545 if (track_buffer_callback && tracks[last_idx].id3_hid > 0)
2546 track_buffer_callback(bufgetid3(tracks[last_idx].id3_hid), false);
2547 }
2548 last_idx = cur_idx;
2549 } 2529 }
2550 if (cur_idx == track_widx) 2530 if (cur_idx == track_widx)
2551 break; 2531 break;
2552 cur_idx++; 2532 cur_idx++;
2553 cur_idx &= MAX_TRACK_MASK; 2533 cur_idx &= MAX_TRACK_MASK;
2554 } 2534 }
2555
2556 if (last_idx >= 0 && !tracks[last_idx].event_sent)
2557 {
2558 tracks[last_idx].event_sent = true;
2559 if (track_buffer_callback && tracks[last_idx].id3_hid > 0)
2560 track_buffer_callback(bufgetid3(tracks[last_idx].id3_hid), true);
2561 }
2562 } 2535 }
2563} 2536}
2564 2537
@@ -2767,14 +2740,12 @@ skip_done:
2767 return Q_CODEC_REQUEST_COMPLETE; 2740 return Q_CODEC_REQUEST_COMPLETE;
2768} 2741}
2769 2742
2770void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3, 2743void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3))
2771 bool last_track))
2772{ 2744{
2773 track_buffer_callback = handler; 2745 track_buffer_callback = handler;
2774} 2746}
2775 2747
2776void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3, 2748void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3))
2777 bool last_track))
2778{ 2749{
2779 track_unbuffer_callback = handler; 2750 track_unbuffer_callback = handler;
2780} 2751}