summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Pennequin <nicolas.pennequin@free.fr>2007-10-31 13:43:50 +0000
committerNicolas Pennequin <nicolas.pennequin@free.fr>2007-10-31 13:43:50 +0000
commit7f79564abc7b0a7afce8c4519c69684d86d57829 (patch)
tree9ca5f4576f2f76c8306398816622ce86304ef733
parentb41b1b3141e87491826749c0e074b18ea5d25d77 (diff)
downloadrockbox-7f79564abc7b0a7afce8c4519c69684d86d57829.tar.gz
rockbox-7f79564abc7b0a7afce8c4519c69684d86d57829.zip
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
-rw-r--r--apps/playback.c55
-rw-r--r--apps/playback.h6
-rw-r--r--apps/tagtree.c6
-rw-r--r--firmware/export/mpeg.h6
-rw-r--r--firmware/mpeg.c40
5 files changed, 25 insertions, 88 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}
diff --git a/apps/playback.h b/apps/playback.h
index 9088af9b6e..b005e63b3c 100644
--- a/apps/playback.h
+++ b/apps/playback.h
@@ -42,10 +42,8 @@
42/* Functions */ 42/* Functions */
43const char * get_codec_filename(int cod_spec); 43const char * get_codec_filename(int cod_spec);
44void audio_set_track_changed_event(void (*handler)(struct mp3entry *id3)); 44void audio_set_track_changed_event(void (*handler)(struct mp3entry *id3));
45void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3, 45void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3));
46 bool last_track)); 46void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3));
47void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3,
48 bool last_track));
49void voice_wait(void); 47void voice_wait(void);
50 48
51#if CONFIG_CODEC == SWCODEC /* This #ifdef is better here than gui/gwps.c */ 49#if CONFIG_CODEC == SWCODEC /* This #ifdef is better here than gui/gwps.c */
diff --git a/apps/tagtree.c b/apps/tagtree.c
index c0d9f0f425..60bdfb2c0e 100644
--- a/apps/tagtree.c
+++ b/apps/tagtree.c
@@ -633,10 +633,9 @@ static int compare(const void *p1, const void *p2)
633 return strncasecmp(e1->name, e2->name, MAX_PATH); 633 return strncasecmp(e1->name, e2->name, MAX_PATH);
634} 634}
635 635
636static void tagtree_buffer_event(struct mp3entry *id3, bool last_track) 636static void tagtree_buffer_event(struct mp3entry *id3)
637{ 637{
638 (void)id3; 638 (void)id3;
639 (void)last_track;
640 639
641 /* Do not gather data unless proper setting has been enabled. */ 640 /* Do not gather data unless proper setting has been enabled. */
642 if (!global_settings.runtimedb) 641 if (!global_settings.runtimedb)
@@ -663,9 +662,8 @@ static void tagtree_buffer_event(struct mp3entry *id3, bool last_track)
663 tagcache_search_finish(&tcs); 662 tagcache_search_finish(&tcs);
664} 663}
665 664
666static void tagtree_unbuffer_event(struct mp3entry *id3, bool last_track) 665static void tagtree_unbuffer_event(struct mp3entry *id3)
667{ 666{
668 (void)last_track;
669 long playcount; 667 long playcount;
670 long playtime; 668 long playtime;
671 long lastplayed; 669 long lastplayed;
diff --git a/firmware/export/mpeg.h b/firmware/export/mpeg.h
index 9de8c499af..3e36c44ac5 100644
--- a/firmware/export/mpeg.h
+++ b/firmware/export/mpeg.h
@@ -57,10 +57,8 @@ void rec_tick(void);
57void playback_tick(void); /* FixMe: get rid of this, use mp3_get_playtime() */ 57void playback_tick(void); /* FixMe: get rid of this, use mp3_get_playtime() */
58 58
59void audio_set_track_changed_event(void (*handler)(struct mp3entry *id3)); 59void audio_set_track_changed_event(void (*handler)(struct mp3entry *id3));
60void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3, 60void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3));
61 bool last_track)); 61void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3));
62void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3,
63 bool last_track));
64void audio_set_cuesheet_callback(bool (*handler)(const char *filename)); 62void audio_set_cuesheet_callback(bool (*handler)(const char *filename));
65 63
66#endif 64#endif
diff --git a/firmware/mpeg.c b/firmware/mpeg.c
index a4632aae38..c09ef38376 100644
--- a/firmware/mpeg.c
+++ b/firmware/mpeg.c
@@ -118,8 +118,8 @@ static int track_write_idx = 0;
118 118
119/* Callback function to call when current track has really changed. */ 119/* Callback function to call when current track has really changed. */
120void (*track_changed_callback)(struct mp3entry *id3) = NULL; 120void (*track_changed_callback)(struct mp3entry *id3) = NULL;
121void (*track_buffer_callback)(struct mp3entry *id3, bool last_track); 121void (*track_buffer_callback)(struct mp3entry *id3);
122void (*track_unbuffer_callback)(struct mp3entry *id3, bool last_track); 122void (*track_unbuffer_callback)(struct mp3entry *id3);
123 123
124/* Cuesheet callback */ 124/* Cuesheet callback */
125static bool (*cuesheet_callback)(const char *filename) = NULL; 125static bool (*cuesheet_callback)(const char *filename) = NULL;
@@ -475,14 +475,12 @@ unsigned long mpeg_get_last_header(void)
475#endif /* !SIMULATOR */ 475#endif /* !SIMULATOR */
476} 476}
477 477
478void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3, 478void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3))
479 bool last_track))
480{ 479{
481 track_buffer_callback = handler; 480 track_buffer_callback = handler;
482} 481}
483 482
484void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3, 483void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3))
485 bool last_track))
486{ 484{
487 track_unbuffer_callback = handler; 485 track_unbuffer_callback = handler;
488} 486}
@@ -502,29 +500,16 @@ void audio_set_cuesheet_callback(bool (*handler)(const char *filename))
502static void generate_unbuffer_events(void) 500static void generate_unbuffer_events(void)
503{ 501{
504 int i; 502 int i;
505 int event_count = 0;
506 int numentries = MAX_TRACK_ENTRIES - num_tracks_in_memory(); 503 int numentries = MAX_TRACK_ENTRIES - num_tracks_in_memory();
507 int cur_idx = track_write_idx; 504 int cur_idx = track_write_idx;
508
509 for (i = 0; i < numentries; i++)
510 {
511 if (trackdata[cur_idx].event_sent)
512 event_count++;
513
514 cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK;
515 }
516
517 cur_idx = track_write_idx;
518 505
519 for (i = 0; i < numentries; i++) 506 for (i = 0; i < numentries; i++)
520 { 507 {
521 /* Send an event to notify that track has finished. */ 508 /* Send an event to notify that track has finished. */
522 if (trackdata[cur_idx].event_sent) 509 if (trackdata[cur_idx].event_sent)
523 { 510 {
524 event_count--;
525 if (track_unbuffer_callback) 511 if (track_unbuffer_callback)
526 track_unbuffer_callback(&trackdata[cur_idx].id3, 512 track_unbuffer_callback(&trackdata[cur_idx].id3);
527 event_count == 0);
528 trackdata[cur_idx].event_sent = false; 513 trackdata[cur_idx].event_sent = false;
529 } 514 }
530 cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK; 515 cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK;
@@ -535,28 +520,15 @@ static void generate_unbuffer_events(void)
535static void generate_postbuffer_events(void) 520static void generate_postbuffer_events(void)
536{ 521{
537 int i; 522 int i;
538 int event_count = 0;
539 int numentries = num_tracks_in_memory(); 523 int numentries = num_tracks_in_memory();
540 int cur_idx = track_read_idx; 524 int cur_idx = track_read_idx;
541 525
542 for (i = 0; i < numentries; i++) 526 for (i = 0; i < numentries; i++)
543 { 527 {
544 if (!trackdata[cur_idx].event_sent) 528 if (!trackdata[cur_idx].event_sent)
545 event_count++;
546
547 cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK;
548 }
549
550 cur_idx = track_read_idx;
551
552 for (i = 0; i < numentries; i++)
553 {
554 if (!trackdata[cur_idx].event_sent)
555 { 529 {
556 event_count--;
557 if (track_buffer_callback) 530 if (track_buffer_callback)
558 track_buffer_callback(&trackdata[cur_idx].id3, 531 track_buffer_callback(&trackdata[cur_idx].id3);
559 event_count == 0);
560 trackdata[cur_idx].event_sent = true; 532 trackdata[cur_idx].event_sent = true;
561 } 533 }
562 cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK; 534 cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK;