diff options
author | Miika Pekkarinen <miipekk@ihme.org> | 2008-03-16 13:55:16 +0000 |
---|---|---|
committer | Miika Pekkarinen <miipekk@ihme.org> | 2008-03-16 13:55:16 +0000 |
commit | 19c6e66c1353993659ee007a6c1792a6b0b7ba13 (patch) | |
tree | 1dd7f88282b2e543fb5b22458fcb2f3bf1c7eb80 /apps | |
parent | 478ba0afa11061a620e44cd9cc60debd955b1b33 (diff) | |
download | rockbox-19c6e66c1353993659ee007a6c1792a6b0b7ba13.tar.gz rockbox-19c6e66c1353993659ee007a6c1792a6b0b7ba13.zip |
Implement the playback event handling as a system-wide multi-purpose event system. Unified mpeg.c and playback.c audio event handling. Converted ata_idle_notify to use the new event handling system also.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16682 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/lang/english.lang | 16 | ||||
-rw-r--r-- | apps/main.c | 2 | ||||
-rw-r--r-- | apps/playback.c | 58 | ||||
-rw-r--r-- | apps/playback.h | 14 | ||||
-rw-r--r-- | apps/scrobbler.c | 17 | ||||
-rw-r--r-- | apps/settings.c | 20 | ||||
-rw-r--r-- | apps/tagtree.c | 11 |
7 files changed, 21 insertions, 117 deletions
diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 3911223d2d..e5df04a460 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang | |||
@@ -8191,29 +8191,27 @@ | |||
8191 | </phrase> | 8191 | </phrase> |
8192 | <phrase> | 8192 | <phrase> |
8193 | id: LANG_SETTINGS_SAVE_FAILED | 8193 | id: LANG_SETTINGS_SAVE_FAILED |
8194 | desc: displayed if save settings has failed | 8194 | desc: DEPRECATED |
8195 | user: | 8195 | user: |
8196 | <source> | 8196 | <source> |
8197 | *: "Save Failed" | 8197 | *: "" |
8198 | </source> | 8198 | </source> |
8199 | <dest> | 8199 | <dest> |
8200 | *: "Save Failed" | 8200 | *: "" |
8201 | </dest> | 8201 | </dest> |
8202 | <voice> | 8202 | <voice> |
8203 | *: "Save Failed" | 8203 | *: "" |
8204 | </voice> | 8204 | </voice> |
8205 | </phrase> | 8205 | </phrase> |
8206 | <phrase> | 8206 | <phrase> |
8207 | id: LANG_SETTINGS_PARTITION | 8207 | id: LANG_SETTINGS_PARTITION |
8208 | desc: if save settings has failed | 8208 | desc: DEPRECATED |
8209 | user: | 8209 | user: |
8210 | <source> | 8210 | <source> |
8211 | *: "No partition?" | 8211 | *: "" |
8212 | player: "Partition?" | ||
8213 | </source> | 8212 | </source> |
8214 | <dest> | 8213 | <dest> |
8215 | *: "No partition?" | 8214 | *: "" |
8216 | player: "Partition?" | ||
8217 | </dest> | 8215 | </dest> |
8218 | <voice> | 8216 | <voice> |
8219 | *: "" | 8217 | *: "" |
diff --git a/apps/main.c b/apps/main.c index 598597520f..5dd92e5e02 100644 --- a/apps/main.c +++ b/apps/main.c | |||
@@ -19,7 +19,6 @@ | |||
19 | #include "config.h" | 19 | #include "config.h" |
20 | 20 | ||
21 | #include "ata.h" | 21 | #include "ata.h" |
22 | #include "ata_idle_notify.h" | ||
23 | #include "disk.h" | 22 | #include "disk.h" |
24 | #include "fat.h" | 23 | #include "fat.h" |
25 | #include "lcd.h" | 24 | #include "lcd.h" |
@@ -428,7 +427,6 @@ static void init(void) | |||
428 | } | 427 | } |
429 | #endif | 428 | #endif |
430 | 429 | ||
431 | ata_idle_notify_init(); | ||
432 | rc = ata_init(); | 430 | rc = ata_init(); |
433 | if(rc) | 431 | if(rc) |
434 | { | 432 | { |
diff --git a/apps/playback.c b/apps/playback.c index b36f68f135..ee1787e612 100644 --- a/apps/playback.c +++ b/apps/playback.c | |||
@@ -245,13 +245,6 @@ static bool skipped_during_pause = false; /* Do we need to clear the PCM buffer | |||
245 | */ | 245 | */ |
246 | static bool codec_requested_stop = false; | 246 | static bool codec_requested_stop = false; |
247 | 247 | ||
248 | struct playback_event { | ||
249 | enum PLAYBACK_EVENT_TYPE type; | ||
250 | void (*callback)(void *data); | ||
251 | }; | ||
252 | |||
253 | struct playback_event events[PLAYBACK_MAX_EVENTS]; | ||
254 | |||
255 | static size_t buffer_margin = 0; /* Buffer margin aka anti-skip buffer (A/C-) */ | 248 | static size_t buffer_margin = 0; /* Buffer margin aka anti-skip buffer (A/C-) */ |
256 | 249 | ||
257 | /* Multiple threads */ | 250 | /* Multiple threads */ |
@@ -1447,51 +1440,6 @@ static void codec_thread(void) | |||
1447 | 1440 | ||
1448 | /* --- Audio thread --- */ | 1441 | /* --- Audio thread --- */ |
1449 | 1442 | ||
1450 | void playback_add_event(enum PLAYBACK_EVENT_TYPE type, void (*handler)) | ||
1451 | { | ||
1452 | int i; | ||
1453 | |||
1454 | /* Try to find a free slot. */ | ||
1455 | for (i = 0; i < PLAYBACK_MAX_EVENTS; i++) | ||
1456 | { | ||
1457 | if (events[i].callback == NULL) | ||
1458 | { | ||
1459 | events[i].type = type; | ||
1460 | events[i].callback = handler; | ||
1461 | return; | ||
1462 | } | ||
1463 | } | ||
1464 | |||
1465 | panicf("playback event line full"); | ||
1466 | } | ||
1467 | |||
1468 | void playback_remove_event(enum PLAYBACK_EVENT_TYPE type, void (*handler)) | ||
1469 | { | ||
1470 | int i; | ||
1471 | |||
1472 | for (i = 0; i < PLAYBACK_MAX_EVENTS; i++) | ||
1473 | { | ||
1474 | if (events[i].type == type && events[i].callback == handler) | ||
1475 | { | ||
1476 | events[i].callback = NULL; | ||
1477 | return; | ||
1478 | } | ||
1479 | } | ||
1480 | |||
1481 | panicf("playback event not found"); | ||
1482 | } | ||
1483 | |||
1484 | static void send_event(enum PLAYBACK_EVENT_TYPE type, void *data) | ||
1485 | { | ||
1486 | int i; | ||
1487 | |||
1488 | for (i = 0; i < PLAYBACK_MAX_EVENTS; i++) | ||
1489 | { | ||
1490 | if (events[i].type == type && events[i].callback != NULL) | ||
1491 | events[i].callback(data); | ||
1492 | } | ||
1493 | } | ||
1494 | |||
1495 | static bool audio_have_tracks(void) | 1443 | static bool audio_have_tracks(void) |
1496 | { | 1444 | { |
1497 | return (audio_track_count() != 0); | 1445 | return (audio_track_count() != 0); |
@@ -1783,7 +1731,7 @@ static bool audio_load_track(int offset, bool start_play) | |||
1783 | { | 1731 | { |
1784 | if (get_metadata(&id3, fd, trackname)) | 1732 | if (get_metadata(&id3, fd, trackname)) |
1785 | { | 1733 | { |
1786 | send_event(PLAYBACK_EVENT_TRACK_BUFFER, &id3); | 1734 | send_event(PLAYBACK_EVENT_TRACK_BUFFER, false, &id3); |
1787 | 1735 | ||
1788 | tracks[track_widx].id3_hid = | 1736 | tracks[track_widx].id3_hid = |
1789 | bufalloc(&id3, sizeof(struct mp3entry), TYPE_ID3); | 1737 | bufalloc(&id3, sizeof(struct mp3entry), TYPE_ID3); |
@@ -2020,7 +1968,7 @@ static int audio_check_new_track(void) | |||
2020 | bool end_of_playlist; /* Temporary flag, not the same as playlist_end */ | 1968 | bool end_of_playlist; /* Temporary flag, not the same as playlist_end */ |
2021 | 1969 | ||
2022 | /* Now it's good time to send track unbuffer events. */ | 1970 | /* Now it's good time to send track unbuffer events. */ |
2023 | send_event(PLAYBACK_EVENT_TRACK_FINISH, &curtrack_id3); | 1971 | send_event(PLAYBACK_EVENT_TRACK_FINISH, false, &curtrack_id3); |
2024 | 1972 | ||
2025 | if (dir_skip) | 1973 | if (dir_skip) |
2026 | { | 1974 | { |
@@ -2391,7 +2339,7 @@ static void audio_finalise_track_change(void) | |||
2391 | bufgetid3(prev_ti->id3_hid)->elapsed = 0; | 2339 | bufgetid3(prev_ti->id3_hid)->elapsed = 0; |
2392 | } | 2340 | } |
2393 | 2341 | ||
2394 | send_event(PLAYBACK_EVENT_TRACK_CHANGE, &curtrack_id3); | 2342 | send_event(PLAYBACK_EVENT_TRACK_CHANGE, false, &curtrack_id3); |
2395 | 2343 | ||
2396 | track_changed = true; | 2344 | track_changed = true; |
2397 | playlist_update_resume_info(audio_current_track()); | 2345 | playlist_update_resume_info(audio_current_track()); |
diff --git a/apps/playback.h b/apps/playback.h index 14ba35cea4..0b78eb3bcb 100644 --- a/apps/playback.h +++ b/apps/playback.h | |||
@@ -24,6 +24,7 @@ | |||
24 | 24 | ||
25 | #include "id3.h" | 25 | #include "id3.h" |
26 | #include "mp3data.h" | 26 | #include "mp3data.h" |
27 | #include "events.h" | ||
27 | 28 | ||
28 | #define CODEC_IDX_AUDIO 0 | 29 | #define CODEC_IDX_AUDIO 0 |
29 | #define CODEC_IDX_VOICE 1 | 30 | #define CODEC_IDX_VOICE 1 |
@@ -39,13 +40,6 @@ | |||
39 | 40 | ||
40 | #define MAX_TRACK_MASK (MAX_TRACK-1) | 41 | #define MAX_TRACK_MASK (MAX_TRACK-1) |
41 | 42 | ||
42 | #define PLAYBACK_MAX_EVENTS 4 | ||
43 | enum PLAYBACK_EVENT_TYPE { | ||
44 | PLAYBACK_EVENT_TRACK_BUFFER, | ||
45 | PLAYBACK_EVENT_TRACK_FINISH, | ||
46 | PLAYBACK_EVENT_TRACK_CHANGE, | ||
47 | }; | ||
48 | |||
49 | /* Functions */ | 43 | /* Functions */ |
50 | const char * get_codec_filename(int cod_spec); | 44 | const char * get_codec_filename(int cod_spec); |
51 | void voice_wait(void); | 45 | void voice_wait(void); |
@@ -53,13 +47,7 @@ void voice_wait(void); | |||
53 | #if CONFIG_CODEC == SWCODEC /* This #ifdef is better here than gui/gwps.c */ | 47 | #if CONFIG_CODEC == SWCODEC /* This #ifdef is better here than gui/gwps.c */ |
54 | extern void audio_next_dir(void); | 48 | extern void audio_next_dir(void); |
55 | extern void audio_prev_dir(void); | 49 | extern void audio_prev_dir(void); |
56 | void playback_add_event(enum PLAYBACK_EVENT_TYPE type, void (*handler)); | ||
57 | void playback_remove_event(enum PLAYBACK_EVENT_TYPE type, void (*handler)); | ||
58 | #else | 50 | #else |
59 | /* Really, should get rid of these HWCODEC api definitions here. */ | ||
60 | void audio_set_track_changed_event(void (*handler)(struct mp3entry *id3)); | ||
61 | void audio_set_track_buffer_event(void (*handler)(struct mp3entry *id3)); | ||
62 | void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3)); | ||
63 | # define audio_next_dir() | 51 | # define audio_next_dir() |
64 | #define audio_prev_dir() | 52 | #define audio_prev_dir() |
65 | #endif | 53 | #endif |
diff --git a/apps/scrobbler.c b/apps/scrobbler.c index 16869bf18f..2f60e858e1 100644 --- a/apps/scrobbler.c +++ b/apps/scrobbler.c | |||
@@ -183,7 +183,10 @@ static void add_to_cache(unsigned long play_length) | |||
183 | } else { | 183 | } else { |
184 | cache_pos++; | 184 | cache_pos++; |
185 | if (!scrobbler_ata_callback) | 185 | if (!scrobbler_ata_callback) |
186 | scrobbler_ata_callback = register_ata_idle_func(scrobbler_flush_callback); | 186 | { |
187 | register_ata_idle_func(scrobbler_flush_callback); | ||
188 | scrobbler_ata_callback = true; | ||
189 | } | ||
187 | } | 190 | } |
188 | 191 | ||
189 | } | 192 | } |
@@ -224,11 +227,7 @@ int scrobbler_init(void) | |||
224 | 227 | ||
225 | scrobbler_cache = buffer_alloc(SCROBBLER_MAX_CACHE*SCROBBLER_CACHE_LEN); | 228 | scrobbler_cache = buffer_alloc(SCROBBLER_MAX_CACHE*SCROBBLER_CACHE_LEN); |
226 | 229 | ||
227 | #if CONFIG_CODEC == SWCODEC | 230 | add_event(PLAYBACK_EVENT_TRACK_CHANGE, scrobbler_change_event); |
228 | playback_add_event(PLAYBACK_EVENT_TRACK_CHANGE, scrobbler_change_event); | ||
229 | #else | ||
230 | audio_set_track_changed_event(&scrobbler_change_event); | ||
231 | #endif | ||
232 | cache_pos = 0; | 231 | cache_pos = 0; |
233 | pending = false; | 232 | pending = false; |
234 | scrobbler_initialised = true; | 233 | scrobbler_initialised = true; |
@@ -263,11 +262,7 @@ void scrobbler_shutdown(void) | |||
263 | 262 | ||
264 | if (scrobbler_initialised) | 263 | if (scrobbler_initialised) |
265 | { | 264 | { |
266 | #if CONFIG_CODEC == SWCODEC | 265 | remove_event(PLAYBACK_EVENT_TRACK_CHANGE, scrobbler_change_event); |
267 | playback_remove_event(PLAYBACK_EVENT_TRACK_CHANGE, scrobbler_change_event); | ||
268 | #else | ||
269 | audio_set_track_changed_event(NULL); | ||
270 | #endif | ||
271 | scrobbler_initialised = false; | 266 | scrobbler_initialised = false; |
272 | } | 267 | } |
273 | } | 268 | } |
diff --git a/apps/settings.c b/apps/settings.c index 27832b427f..7eec15baf3 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -601,25 +601,7 @@ int settings_save( void ) | |||
601 | target doesnt have rtc ram */ | 601 | target doesnt have rtc ram */ |
602 | write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); | 602 | write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); |
603 | #endif | 603 | #endif |
604 | if(!register_ata_idle_func(flush_config_block_callback)) | 604 | register_ata_idle_func(flush_config_block_callback); |
605 | { | ||
606 | int i; | ||
607 | FOR_NB_SCREENS(i) | ||
608 | { | ||
609 | screens[i].clear_display(); | ||
610 | #ifdef HAVE_LCD_CHARCELLS | ||
611 | screens[i].puts(0, 0, str(LANG_SETTINGS_SAVE_FAILED)); | ||
612 | screens[i].puts(0, 1, str(LANG_SETTINGS_PARTITION)); | ||
613 | #else | ||
614 | screens[i].puts(4, 2, str(LANG_SETTINGS_SAVE_FAILED)); | ||
615 | screens[i].puts(2, 4, str(LANG_SETTINGS_PARTITION)); | ||
616 | screens[i].update(); | ||
617 | #endif | ||
618 | } | ||
619 | cond_talk_ids_fq(LANG_SETTINGS_SAVE_FAILED); | ||
620 | sleep(HZ*2); | ||
621 | return -1; | ||
622 | } | ||
623 | return 0; | 605 | return 0; |
624 | } | 606 | } |
625 | bool settings_save_config(int options) | 607 | bool settings_save_config(int options) |
diff --git a/apps/tagtree.c b/apps/tagtree.c index c5e3ebff1e..4572204ae5 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c | |||
@@ -924,14 +924,9 @@ void tagtree_init(void) | |||
924 | root_menu = 0; | 924 | root_menu = 0; |
925 | 925 | ||
926 | uniqbuf = buffer_alloc(UNIQBUF_SIZE); | 926 | uniqbuf = buffer_alloc(UNIQBUF_SIZE); |
927 | #if CONFIG_CODEC == SWCODEC | 927 | |
928 | playback_add_event(PLAYBACK_EVENT_TRACK_BUFFER, tagtree_buffer_event); | 928 | add_event(PLAYBACK_EVENT_TRACK_BUFFER, tagtree_buffer_event); |
929 | playback_add_event(PLAYBACK_EVENT_TRACK_FINISH, tagtree_track_finish_event); | 929 | add_event(PLAYBACK_EVENT_TRACK_FINISH, tagtree_track_finish_event); |
930 | #else | ||
931 | audio_set_track_buffer_event(tagtree_buffer_event); | ||
932 | audio_set_track_unbuffer_event(tagtree_track_finish_event); | ||
933 | #endif | ||
934 | |||
935 | } | 930 | } |
936 | 931 | ||
937 | static bool show_search_progress(bool init, int count) | 932 | static bool show_search_progress(bool init, int count) |