diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2013-07-12 12:06:38 -0400 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2013-07-13 00:08:51 -0400 |
commit | 023f6b6efd5407dc77c1253789f61baabb6607d6 (patch) | |
tree | 40d43117a7651715a2ce983eedff56b27962881a /apps/mpeg.c | |
parent | ffa8626b0c93f8a65e0e17190917f7f173160842 (diff) | |
download | rockbox-023f6b6efd5407dc77c1253789f61baabb6607d6.tar.gz rockbox-023f6b6efd5407dc77c1253789f61baabb6607d6.zip |
Get rid of some superfluous single-purpose functions in playback.
* Remove explicit tracking of elapsed time of previous track.
* Remove function to obtain auto skip flag.
* Most playback events now carry the extra information instead and
pass 'struct track_event *' for data.
* Tweak scrobbler to use PLAYBACK_EVENT_TRACK_FINISH, which makes
it cleaner and removes the struct mp3entry.
Change-Id: I500d2abb4056a32646496efc3617406e36811ec5
Diffstat (limited to 'apps/mpeg.c')
-rw-r--r-- | apps/mpeg.c | 54 |
1 files changed, 20 insertions, 34 deletions
diff --git a/apps/mpeg.c b/apps/mpeg.c index 5c206c79f1..2783a24085 100644 --- a/apps/mpeg.c +++ b/apps/mpeg.c | |||
@@ -129,8 +129,6 @@ static unsigned int current_track_counter = 0; | |||
129 | 129 | ||
130 | #ifndef SIMULATOR | 130 | #ifndef SIMULATOR |
131 | static void stop_playing(void); | 131 | static void stop_playing(void); |
132 | /* Play time of the previous track */ | ||
133 | static unsigned long prev_track_elapsed; | ||
134 | 132 | ||
135 | static int track_read_idx = 0; | 133 | static int track_read_idx = 0; |
136 | static int track_write_idx = 0; | 134 | static int track_write_idx = 0; |
@@ -362,7 +360,15 @@ static bool audio_dispatch_event(unsigned short event, unsigned long data) | |||
362 | } | 360 | } |
363 | return false; | 361 | return false; |
364 | } | 362 | } |
365 | #endif | 363 | |
364 | static void send_track_event(unsigned int id, struct mp3entry *id3) | ||
365 | { | ||
366 | struct mp3entry *cur_id3 = | ||
367 | &trackdata[track_read_idx & MAX_TRACK_ENTRIES_MASK].id3; | ||
368 | unsigned int flags = id3 == cur_id3 ? TEF_CURRENT : 0; | ||
369 | send_event(id, &(struct track_event){ .flags = flags, .id3 = id3 }); | ||
370 | } | ||
371 | #endif /* SIMULATOR */ | ||
366 | 372 | ||
367 | /***********************************************************************/ | 373 | /***********************************************************************/ |
368 | 374 | ||
@@ -609,7 +615,7 @@ static void generate_unbuffer_events(void) | |||
609 | for (i = 0; i < numentries; i++) | 615 | for (i = 0; i < numentries; i++) |
610 | { | 616 | { |
611 | /* Send an event to notify that track has finished. */ | 617 | /* Send an event to notify that track has finished. */ |
612 | send_event(PLAYBACK_EVENT_TRACK_FINISH, &trackdata[cur_idx].id3); | 618 | send_track_event(PLAYBACK_EVENT_TRACK_FINISH, &trackdata[cur_idx].id3); |
613 | cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK; | 619 | cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK; |
614 | } | 620 | } |
615 | } | 621 | } |
@@ -623,7 +629,7 @@ static void generate_postbuffer_events(void) | |||
623 | 629 | ||
624 | for (i = 0; i < numentries; i++) | 630 | for (i = 0; i < numentries; i++) |
625 | { | 631 | { |
626 | send_event(PLAYBACK_EVENT_TRACK_BUFFER, &trackdata[cur_idx].id3); | 632 | send_track_event(PLAYBACK_EVENT_TRACK_BUFFER, &trackdata[cur_idx].id3); |
627 | cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK; | 633 | cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK; |
628 | } | 634 | } |
629 | } | 635 | } |
@@ -1006,7 +1012,7 @@ static struct trackdata *add_track_to_tag_list(const char *filename) | |||
1006 | send_nid3_event = (track_write_idx == track_read_idx + 1); | 1012 | send_nid3_event = (track_write_idx == track_read_idx + 1); |
1007 | track_write_idx = (track_write_idx+1) & MAX_TRACK_ENTRIES_MASK; | 1013 | track_write_idx = (track_write_idx+1) & MAX_TRACK_ENTRIES_MASK; |
1008 | if (send_nid3_event) | 1014 | if (send_nid3_event) |
1009 | send_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, NULL); | 1015 | send_track_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, &track->id3); |
1010 | debug_tags(); | 1016 | debug_tags(); |
1011 | return track; | 1017 | return track; |
1012 | } | 1018 | } |
@@ -1093,17 +1099,11 @@ static int new_file(int steps) | |||
1093 | 1099 | ||
1094 | static void stop_playing(void) | 1100 | static void stop_playing(void) |
1095 | { | 1101 | { |
1096 | struct trackdata *track; | ||
1097 | |||
1098 | /* Stop the current stream */ | 1102 | /* Stop the current stream */ |
1099 | mp3_play_stop(); | 1103 | mp3_play_stop(); |
1100 | playing = false; | 1104 | playing = false; |
1101 | filling = false; | 1105 | filling = false; |
1102 | 1106 | ||
1103 | track = get_trackdata(0); | ||
1104 | if (track != NULL) | ||
1105 | prev_track_elapsed = track->id3.elapsed; | ||
1106 | |||
1107 | if(mpeg_file >= 0) | 1107 | if(mpeg_file >= 0) |
1108 | close(mpeg_file); | 1108 | close(mpeg_file); |
1109 | mpeg_file = -1; | 1109 | mpeg_file = -1; |
@@ -1112,17 +1112,12 @@ static void stop_playing(void) | |||
1112 | reset_mp3_buffer(); | 1112 | reset_mp3_buffer(); |
1113 | } | 1113 | } |
1114 | 1114 | ||
1115 | static void end_current_track(void) { | 1115 | static void end_current_track(void) |
1116 | struct trackdata *track; | 1116 | { |
1117 | |||
1118 | play_pending = false; | 1117 | play_pending = false; |
1119 | playing = false; | 1118 | playing = false; |
1120 | mp3_play_pause(false); | 1119 | mp3_play_pause(false); |
1121 | 1120 | ||
1122 | track = get_trackdata(0); | ||
1123 | if (track != NULL) | ||
1124 | prev_track_elapsed = track->id3.elapsed; | ||
1125 | |||
1126 | reset_mp3_buffer(); | 1121 | reset_mp3_buffer(); |
1127 | remove_all_tags(); | 1122 | remove_all_tags(); |
1128 | generate_unbuffer_events(); | 1123 | generate_unbuffer_events(); |
@@ -1164,9 +1159,6 @@ static void track_change(void) | |||
1164 | { | 1159 | { |
1165 | DEBUGF("Track change\n"); | 1160 | DEBUGF("Track change\n"); |
1166 | 1161 | ||
1167 | struct trackdata *track = get_trackdata(0); | ||
1168 | prev_track_elapsed = track->id3.elapsed; | ||
1169 | |||
1170 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) | 1162 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
1171 | /* Reset the AVC */ | 1163 | /* Reset the AVC */ |
1172 | sound_set_avc(-1); | 1164 | sound_set_avc(-1); |
@@ -1177,17 +1169,15 @@ static void track_change(void) | |||
1177 | remove_current_tag(); | 1169 | remove_current_tag(); |
1178 | update_playlist(); | 1170 | update_playlist(); |
1179 | if (is_playing) | 1171 | if (is_playing) |
1180 | send_event(PLAYBACK_EVENT_TRACK_CHANGE, audio_current_track()); | 1172 | { |
1173 | send_track_event(PLAYBACK_EVENT_TRACK_CHANGE, | ||
1174 | audio_current_track()); | ||
1175 | } | ||
1181 | } | 1176 | } |
1182 | 1177 | ||
1183 | current_track_counter++; | 1178 | current_track_counter++; |
1184 | } | 1179 | } |
1185 | 1180 | ||
1186 | unsigned long audio_prev_elapsed(void) | ||
1187 | { | ||
1188 | return prev_track_elapsed; | ||
1189 | } | ||
1190 | |||
1191 | #ifdef DEBUG | 1181 | #ifdef DEBUG |
1192 | void hexdump(const unsigned char *buf, int len) | 1182 | void hexdump(const unsigned char *buf, int len) |
1193 | { | 1183 | { |
@@ -1229,7 +1219,8 @@ static void start_playback_if_ready(void) | |||
1229 | if (play_pending_track_change) | 1219 | if (play_pending_track_change) |
1230 | { | 1220 | { |
1231 | play_pending_track_change = false; | 1221 | play_pending_track_change = false; |
1232 | send_event(PLAYBACK_EVENT_TRACK_CHANGE, audio_current_track()); | 1222 | send_track_event(PLAYBACK_EVENT_TRACK_CHANGE, |
1223 | audio_current_track()); | ||
1233 | } | 1224 | } |
1234 | play_pending = false; | 1225 | play_pending = false; |
1235 | } | 1226 | } |
@@ -2828,11 +2819,6 @@ void audio_play(long offset) | |||
2828 | void audio_stop(void) | 2819 | void audio_stop(void) |
2829 | { | 2820 | { |
2830 | #ifndef SIMULATOR | 2821 | #ifndef SIMULATOR |
2831 | if (playing) | ||
2832 | { | ||
2833 | struct trackdata *track = get_trackdata(0); | ||
2834 | prev_track_elapsed = track->id3.elapsed; | ||
2835 | } | ||
2836 | mpeg_stop_done = false; | 2822 | mpeg_stop_done = false; |
2837 | queue_post(&mpeg_queue, MPEG_STOP, 0); | 2823 | queue_post(&mpeg_queue, MPEG_STOP, 0); |
2838 | while(!mpeg_stop_done) | 2824 | while(!mpeg_stop_done) |