diff options
Diffstat (limited to 'apps/playback.c')
-rw-r--r-- | apps/playback.c | 99 |
1 files changed, 50 insertions, 49 deletions
diff --git a/apps/playback.c b/apps/playback.c index 421783e0f7..4fd27ce72e 100644 --- a/apps/playback.c +++ b/apps/playback.c | |||
@@ -249,7 +249,7 @@ static size_t buffer_margin = 0; /* Buffer margin aka anti-skip buffer (A/C-) * | |||
249 | 249 | ||
250 | /* Multiple threads */ | 250 | /* Multiple threads */ |
251 | /* Set the watermark to trigger buffer fill (A/C) FIXME */ | 251 | /* Set the watermark to trigger buffer fill (A/C) FIXME */ |
252 | static void set_filebuf_watermark(int seconds, size_t max); | 252 | static void set_filebuf_watermark(const int seconds, const size_t max); |
253 | 253 | ||
254 | /* Audio thread */ | 254 | /* Audio thread */ |
255 | static struct event_queue audio_queue NOCACHEBSS_ATTR; | 255 | static struct event_queue audio_queue NOCACHEBSS_ATTR; |
@@ -277,7 +277,7 @@ static struct event_queue pcmbuf_queue NOCACHEBSS_ATTR; | |||
277 | /* Function to be called by pcm buffer callbacks. | 277 | /* Function to be called by pcm buffer callbacks. |
278 | * Permissible Context(s): Audio interrupt | 278 | * Permissible Context(s): Audio interrupt |
279 | */ | 279 | */ |
280 | static void pcmbuf_callback_queue_post(long id, intptr_t data) | 280 | static void pcmbuf_callback_queue_post(const long id, intptr_t data) |
281 | { | 281 | { |
282 | /* No lock since we're already in audio interrupt context */ | 282 | /* No lock since we're already in audio interrupt context */ |
283 | queue_post(&pcmbuf_queue, id, data); | 283 | queue_post(&pcmbuf_queue, id, data); |
@@ -313,7 +313,7 @@ static void pcmbuf_queue_clear(void) | |||
313 | 313 | ||
314 | /* --- Helper functions --- */ | 314 | /* --- Helper functions --- */ |
315 | 315 | ||
316 | static struct mp3entry *bufgetid3(int handle_id) | 316 | static struct mp3entry *bufgetid3(const int handle_id) |
317 | { | 317 | { |
318 | if (handle_id < 0) | 318 | if (handle_id < 0) |
319 | return NULL; | 319 | return NULL; |
@@ -384,7 +384,7 @@ void audio_hard_stop(void) | |||
384 | #endif | 384 | #endif |
385 | } | 385 | } |
386 | 386 | ||
387 | bool audio_restore_playback(int type) | 387 | bool audio_restore_playback(const int type) |
388 | { | 388 | { |
389 | switch (type) | 389 | switch (type) |
390 | { | 390 | { |
@@ -401,7 +401,7 @@ bool audio_restore_playback(int type) | |||
401 | } | 401 | } |
402 | } | 402 | } |
403 | 403 | ||
404 | unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size) | 404 | unsigned char *audio_get_buffer(const bool talk_buf, size_t *buffer_size) |
405 | { | 405 | { |
406 | unsigned char *buf, *end; | 406 | unsigned char *buf, *end; |
407 | 407 | ||
@@ -621,7 +621,7 @@ bool audio_has_changed_track(void) | |||
621 | return false; | 621 | return false; |
622 | } | 622 | } |
623 | 623 | ||
624 | void audio_play(long offset) | 624 | void audio_play(const long offset) |
625 | { | 625 | { |
626 | logf("audio_play"); | 626 | logf("audio_play"); |
627 | 627 | ||
@@ -710,7 +710,7 @@ void audio_pre_ff_rewind(void) | |||
710 | queue_post(&audio_queue, Q_AUDIO_PRE_FF_REWIND, 0); | 710 | queue_post(&audio_queue, Q_AUDIO_PRE_FF_REWIND, 0); |
711 | } | 711 | } |
712 | 712 | ||
713 | void audio_ff_rewind(long newpos) | 713 | void audio_ff_rewind(const long newpos) |
714 | { | 714 | { |
715 | LOGFQUEUE("audio > audio Q_AUDIO_FF_REWIND"); | 715 | LOGFQUEUE("audio > audio Q_AUDIO_FF_REWIND"); |
716 | queue_post(&audio_queue, Q_AUDIO_FF_REWIND, newpos); | 716 | queue_post(&audio_queue, Q_AUDIO_FF_REWIND, newpos); |
@@ -753,7 +753,7 @@ int audio_get_file_pos(void) | |||
753 | } | 753 | } |
754 | 754 | ||
755 | #ifndef HAVE_FLASH_STORAGE | 755 | #ifndef HAVE_FLASH_STORAGE |
756 | void audio_set_buffer_margin(int setting) | 756 | void audio_set_buffer_margin(const int setting) |
757 | { | 757 | { |
758 | static const int lookup[] = {5, 15, 30, 60, 120, 180, 300, 600}; | 758 | static const int lookup[] = {5, 15, 30, 60, 120, 180, 300, 600}; |
759 | buffer_margin = lookup[setting]; | 759 | buffer_margin = lookup[setting]; |
@@ -762,8 +762,8 @@ void audio_set_buffer_margin(int setting) | |||
762 | } | 762 | } |
763 | #endif | 763 | #endif |
764 | 764 | ||
765 | /* Take nescessary steps to enable or disable the crossfade setting */ | 765 | /* Take necessary steps to enable or disable the crossfade setting */ |
766 | void audio_set_crossfade(int enable) | 766 | void audio_set_crossfade(const int enable) |
767 | { | 767 | { |
768 | size_t offset; | 768 | size_t offset; |
769 | bool was_playing; | 769 | bool was_playing; |
@@ -805,7 +805,7 @@ void audio_set_crossfade(int enable) | |||
805 | 805 | ||
806 | /* --- Routines called from multiple threads --- */ | 806 | /* --- Routines called from multiple threads --- */ |
807 | 807 | ||
808 | static void set_filebuf_watermark(int seconds, size_t max) | 808 | static void set_filebuf_watermark(const int seconds, const size_t max) |
809 | { | 809 | { |
810 | size_t bytes; | 810 | size_t bytes; |
811 | 811 | ||
@@ -817,7 +817,7 @@ static void set_filebuf_watermark(int seconds, size_t max) | |||
817 | buf_set_watermark(bytes); | 817 | buf_set_watermark(bytes); |
818 | } | 818 | } |
819 | 819 | ||
820 | const char * get_codec_filename(int cod_spec) | 820 | const char *get_codec_filename(const int cod_spec) |
821 | { | 821 | { |
822 | const char *fname; | 822 | const char *fname; |
823 | 823 | ||
@@ -849,13 +849,14 @@ const char * get_codec_filename(int cod_spec) | |||
849 | 849 | ||
850 | /* --- Codec thread --- */ | 850 | /* --- Codec thread --- */ |
851 | static bool codec_pcmbuf_insert_callback( | 851 | static bool codec_pcmbuf_insert_callback( |
852 | const void *ch1, const void *ch2, int count) | 852 | const void *ch1, const void *ch2, const int count) |
853 | { | 853 | { |
854 | const char *src[2] = { ch1, ch2 }; | 854 | const char *src[2] = { ch1, ch2 }; |
855 | 855 | ||
856 | while (count > 0) | 856 | int remaining = count; |
857 | while (remaining > 0) | ||
857 | { | 858 | { |
858 | int out_count = dsp_output_count(ci.dsp, count); | 859 | int out_count = dsp_output_count(ci.dsp, remaining); |
859 | int inp_count; | 860 | int inp_count; |
860 | char *dest; | 861 | char *dest; |
861 | 862 | ||
@@ -879,8 +880,8 @@ static bool codec_pcmbuf_insert_callback( | |||
879 | return true; | 880 | return true; |
880 | 881 | ||
881 | /* Input size has grown, no error, just don't write more than length */ | 882 | /* Input size has grown, no error, just don't write more than length */ |
882 | if (inp_count > count) | 883 | if (inp_count > remaining) |
883 | inp_count = count; | 884 | inp_count = remaining; |
884 | 885 | ||
885 | out_count = dsp_process(ci.dsp, dest, src, inp_count); | 886 | out_count = dsp_process(ci.dsp, dest, src, inp_count); |
886 | 887 | ||
@@ -889,7 +890,7 @@ static bool codec_pcmbuf_insert_callback( | |||
889 | 890 | ||
890 | pcmbuf_write_complete(out_count); | 891 | pcmbuf_write_complete(out_count); |
891 | 892 | ||
892 | count -= inp_count; | 893 | remaining -= inp_count; |
893 | } | 894 | } |
894 | 895 | ||
895 | return true; | 896 | return true; |
@@ -905,8 +906,8 @@ static void* codec_get_memory_callback(size_t *size) | |||
905 | "elapsed" value of the previous (to the codec, but current to the | 906 | "elapsed" value of the previous (to the codec, but current to the |
906 | user/PCM/WPS) track, so that the progressbar reaches the end. | 907 | user/PCM/WPS) track, so that the progressbar reaches the end. |
907 | During that transition, the WPS will display prevtrack_id3. */ | 908 | During that transition, the WPS will display prevtrack_id3. */ |
908 | static void codec_pcmbuf_position_callback(size_t size) ICODE_ATTR; | 909 | static void codec_pcmbuf_position_callback(const size_t size) ICODE_ATTR; |
909 | static void codec_pcmbuf_position_callback(size_t size) | 910 | static void codec_pcmbuf_position_callback(const size_t size) |
910 | { | 911 | { |
911 | /* This is called from an ISR, so be quick */ | 912 | /* This is called from an ISR, so be quick */ |
912 | unsigned int time = size * 1000 / 4 / NATIVE_FREQUENCY + | 913 | unsigned int time = size * 1000 / 4 / NATIVE_FREQUENCY + |
@@ -921,7 +922,7 @@ static void codec_pcmbuf_position_callback(size_t size) | |||
921 | prevtrack_id3.elapsed = time; | 922 | prevtrack_id3.elapsed = time; |
922 | } | 923 | } |
923 | 924 | ||
924 | static void codec_set_elapsed_callback(unsigned int value) | 925 | static void codec_set_elapsed_callback(const unsigned int value) |
925 | { | 926 | { |
926 | unsigned int latency; | 927 | unsigned int latency; |
927 | if (ci.seek_time) | 928 | if (ci.seek_time) |
@@ -941,7 +942,7 @@ static void codec_set_elapsed_callback(unsigned int value) | |||
941 | } | 942 | } |
942 | } | 943 | } |
943 | 944 | ||
944 | static void codec_set_offset_callback(size_t value) | 945 | static void codec_set_offset_callback(const size_t value) |
945 | { | 946 | { |
946 | unsigned int latency; | 947 | unsigned int latency; |
947 | 948 | ||
@@ -955,14 +956,14 @@ static void codec_set_offset_callback(size_t value) | |||
955 | curtrack_id3.offset = value - latency; | 956 | curtrack_id3.offset = value - latency; |
956 | } | 957 | } |
957 | 958 | ||
958 | static void codec_advance_buffer_counters(size_t amount) | 959 | static void codec_advance_buffer_counters(const size_t amount) |
959 | { | 960 | { |
960 | bufadvance(CUR_TI->audio_hid, amount); | 961 | bufadvance(CUR_TI->audio_hid, amount); |
961 | ci.curpos += amount; | 962 | ci.curpos += amount; |
962 | } | 963 | } |
963 | 964 | ||
964 | /* copy up-to size bytes into ptr and return the actual size copied */ | 965 | /* copy up-to size bytes into ptr and return the actual size copied */ |
965 | static size_t codec_filebuf_callback(void *ptr, size_t size) | 966 | static size_t codec_filebuf_callback(void *ptr, const size_t size) |
966 | { | 967 | { |
967 | ssize_t copy_n; | 968 | ssize_t copy_n; |
968 | 969 | ||
@@ -982,7 +983,7 @@ static size_t codec_filebuf_callback(void *ptr, size_t size) | |||
982 | return copy_n; | 983 | return copy_n; |
983 | } /* codec_filebuf_callback */ | 984 | } /* codec_filebuf_callback */ |
984 | 985 | ||
985 | static void* codec_request_buffer_callback(size_t *realsize, size_t reqsize) | 986 | static void* codec_request_buffer_callback(size_t *realsize, const size_t reqsize) |
986 | { | 987 | { |
987 | size_t copy_n = reqsize; | 988 | size_t copy_n = reqsize; |
988 | ssize_t ret; | 989 | ssize_t ret; |
@@ -1021,7 +1022,7 @@ static int get_codec_base_type(int type) | |||
1021 | return type; | 1022 | return type; |
1022 | } | 1023 | } |
1023 | 1024 | ||
1024 | static void codec_advance_buffer_callback(size_t amount) | 1025 | static void codec_advance_buffer_callback(const size_t amount) |
1025 | { | 1026 | { |
1026 | codec_advance_buffer_counters(amount); | 1027 | codec_advance_buffer_counters(amount); |
1027 | codec_set_offset_callback(ci.curpos); | 1028 | codec_set_offset_callback(ci.curpos); |
@@ -1088,7 +1089,7 @@ static int codec_get_file_pos(void) | |||
1088 | return pos; | 1089 | return pos; |
1089 | } | 1090 | } |
1090 | 1091 | ||
1091 | static off_t codec_mp3_get_filepos_callback(int newtime) | 1092 | static off_t codec_mp3_get_filepos_callback(const int newtime) |
1092 | { | 1093 | { |
1093 | off_t newpos; | 1094 | off_t newpos; |
1094 | 1095 | ||
@@ -1114,7 +1115,7 @@ static void codec_seek_complete_callback(void) | |||
1114 | ci.seek_time = 0; | 1115 | ci.seek_time = 0; |
1115 | } | 1116 | } |
1116 | 1117 | ||
1117 | static bool codec_seek_buffer_callback(size_t newpos) | 1118 | static bool codec_seek_buffer_callback(const size_t newpos) |
1118 | { | 1119 | { |
1119 | logf("codec_seek_buffer_callback"); | 1120 | logf("codec_seek_buffer_callback"); |
1120 | 1121 | ||
@@ -1128,7 +1129,7 @@ static bool codec_seek_buffer_callback(size_t newpos) | |||
1128 | } | 1129 | } |
1129 | } | 1130 | } |
1130 | 1131 | ||
1131 | static void codec_configure_callback(int setting, intptr_t value) | 1132 | static void codec_configure_callback(const int setting, const intptr_t value) |
1132 | { | 1133 | { |
1133 | switch (setting) { | 1134 | switch (setting) { |
1134 | case CODEC_SET_FILEBUF_WATERMARK: | 1135 | case CODEC_SET_FILEBUF_WATERMARK: |
@@ -1178,7 +1179,7 @@ static inline void codec_crossfade_track_change(void) | |||
1178 | codec_track_changed(); | 1179 | codec_track_changed(); |
1179 | } | 1180 | } |
1180 | 1181 | ||
1181 | static void codec_track_skip_done(bool was_manual) | 1182 | static void codec_track_skip_done(const bool was_manual) |
1182 | { | 1183 | { |
1183 | /* Manual track change (always crossfade or flush audio). */ | 1184 | /* Manual track change (always crossfade or flush audio). */ |
1184 | if (was_manual) | 1185 | if (was_manual) |
@@ -1485,7 +1486,7 @@ static void audio_update_trackinfo(void) | |||
1485 | ci.taginfo_ready = &CUR_TI->taginfo_ready; | 1486 | ci.taginfo_ready = &CUR_TI->taginfo_ready; |
1486 | } | 1487 | } |
1487 | 1488 | ||
1488 | static void buffering_audio_callback(enum callback_event ev, int value) | 1489 | static void buffering_audio_callback(const enum callback_event ev, const int value) |
1489 | { | 1490 | { |
1490 | (void)value; | 1491 | (void)value; |
1491 | logf("buffering_audio_callback"); | 1492 | logf("buffering_audio_callback"); |
@@ -1549,7 +1550,7 @@ static bool audio_release_tracks(void) | |||
1549 | return true; | 1550 | return true; |
1550 | } | 1551 | } |
1551 | 1552 | ||
1552 | static bool audio_loadcodec(bool start_play) | 1553 | static bool audio_loadcodec(const bool start_play) |
1553 | { | 1554 | { |
1554 | int prev_track; | 1555 | int prev_track; |
1555 | char codec_path[MAX_PATH]; /* Full path to codec */ | 1556 | char codec_path[MAX_PATH]; /* Full path to codec */ |
@@ -1667,7 +1668,7 @@ static void audio_set_elapsed(struct mp3entry* id3) | |||
1667 | 1668 | ||
1668 | /* Load one track by making the appropriate bufopen calls. Return true if | 1669 | /* Load one track by making the appropriate bufopen calls. Return true if |
1669 | everything required was loaded correctly, false if not. */ | 1670 | everything required was loaded correctly, false if not. */ |
1670 | static bool audio_load_track(int offset, bool start_play) | 1671 | static bool audio_load_track(const int offset, const bool start_play) |
1671 | { | 1672 | { |
1672 | const char *trackname; | 1673 | const char *trackname; |
1673 | char msgbuf[80]; | 1674 | char msgbuf[80]; |
@@ -1714,8 +1715,9 @@ static bool audio_load_track(int offset, bool start_play) | |||
1714 | 1715 | ||
1715 | tracks[track_widx].filesize = filesize(fd); | 1716 | tracks[track_widx].filesize = filesize(fd); |
1716 | 1717 | ||
1717 | if ((unsigned)offset > tracks[track_widx].filesize) | 1718 | int adjusted_offset = offset; |
1718 | offset = 0; | 1719 | if ((unsigned)adjusted_offset > tracks[track_widx].filesize) |
1720 | adjusted_offset = 0; | ||
1719 | 1721 | ||
1720 | /* Set default values */ | 1722 | /* Set default values */ |
1721 | if (start_play) | 1723 | if (start_play) |
@@ -1827,17 +1829,17 @@ static bool audio_load_track(int offset, bool start_play) | |||
1827 | case AFMT_MPA_L1: | 1829 | case AFMT_MPA_L1: |
1828 | case AFMT_MPA_L2: | 1830 | case AFMT_MPA_L2: |
1829 | case AFMT_MPA_L3: | 1831 | case AFMT_MPA_L3: |
1830 | if (offset > 0) { | 1832 | if (adjusted_offset > 0) { |
1831 | file_offset = offset; | 1833 | file_offset = adjusted_offset; |
1832 | track_id3->offset = offset; | 1834 | track_id3->offset = adjusted_offset; |
1833 | audio_set_elapsed(track_id3); | 1835 | audio_set_elapsed(track_id3); |
1834 | } | 1836 | } |
1835 | break; | 1837 | break; |
1836 | 1838 | ||
1837 | case AFMT_WAVPACK: | 1839 | case AFMT_WAVPACK: |
1838 | if (offset > 0) { | 1840 | if (offset > 0) { |
1839 | file_offset = offset; | 1841 | file_offset = adjusted_offset; |
1840 | track_id3->offset = offset; | 1842 | track_id3->offset = adjusted_offset; |
1841 | track_id3->elapsed = track_id3->length / 2; | 1843 | track_id3->elapsed = track_id3->length / 2; |
1842 | } | 1844 | } |
1843 | break; | 1845 | break; |
@@ -1850,8 +1852,8 @@ static bool audio_load_track(int offset, bool start_play) | |||
1850 | case AFMT_AAC: | 1852 | case AFMT_AAC: |
1851 | case AFMT_MPC: | 1853 | case AFMT_MPC: |
1852 | case AFMT_APE: | 1854 | case AFMT_APE: |
1853 | if (offset > 0) | 1855 | if (adjusted_offset > 0) |
1854 | track_id3->offset = offset; | 1856 | track_id3->offset = adjusted_offset; |
1855 | break; | 1857 | break; |
1856 | 1858 | ||
1857 | case AFMT_NSF: | 1859 | case AFMT_NSF: |
@@ -1890,7 +1892,7 @@ static bool audio_load_track(int offset, bool start_play) | |||
1890 | return true; | 1892 | return true; |
1891 | } | 1893 | } |
1892 | 1894 | ||
1893 | static void audio_fill_file_buffer(bool start_play, size_t offset) | 1895 | static void audio_fill_file_buffer(const bool start_play, const size_t offset) |
1894 | { | 1896 | { |
1895 | struct queue_event ev; | 1897 | struct queue_event ev; |
1896 | bool had_next_track = audio_next_track() != NULL; | 1898 | bool had_next_track = audio_next_track() != NULL; |
@@ -1914,10 +1916,8 @@ static void audio_fill_file_buffer(bool start_play, size_t offset) | |||
1914 | /* Save the current resume position once. */ | 1916 | /* Save the current resume position once. */ |
1915 | playlist_update_resume_info(audio_current_track()); | 1917 | playlist_update_resume_info(audio_current_track()); |
1916 | 1918 | ||
1919 | continue_buffering = audio_load_track(offset, start_play); | ||
1917 | do { | 1920 | do { |
1918 | continue_buffering = audio_load_track(offset, start_play); | ||
1919 | start_play = false; | ||
1920 | offset = 0; | ||
1921 | sleep(1); | 1921 | sleep(1); |
1922 | if (queue_peek(&audio_queue, &ev)) { | 1922 | if (queue_peek(&audio_queue, &ev)) { |
1923 | if (ev.id != Q_AUDIO_FILL_BUFFER) | 1923 | if (ev.id != Q_AUDIO_FILL_BUFFER) |
@@ -1929,6 +1929,7 @@ static void audio_fill_file_buffer(bool start_play, size_t offset) | |||
1929 | } | 1929 | } |
1930 | break; | 1930 | break; |
1931 | } | 1931 | } |
1932 | continue_buffering = audio_load_track(0, false); | ||
1932 | } while (continue_buffering); | 1933 | } while (continue_buffering); |
1933 | 1934 | ||
1934 | if (!had_next_track && audio_next_track()) | 1935 | if (!had_next_track && audio_next_track()) |
@@ -2193,7 +2194,7 @@ static void audio_stop_playback(void) | |||
2193 | memset(&curtrack_id3, 0, sizeof(struct mp3entry)); | 2194 | memset(&curtrack_id3, 0, sizeof(struct mp3entry)); |
2194 | } | 2195 | } |
2195 | 2196 | ||
2196 | static void audio_play_start(size_t offset) | 2197 | static void audio_play_start(const size_t offset) |
2197 | { | 2198 | { |
2198 | int i; | 2199 | int i; |
2199 | 2200 | ||
@@ -2286,7 +2287,7 @@ static void audio_new_playlist(void) | |||
2286 | } | 2287 | } |
2287 | 2288 | ||
2288 | /* Called on manual track skip */ | 2289 | /* Called on manual track skip */ |
2289 | static void audio_initiate_track_change(long direction) | 2290 | static void audio_initiate_track_change(const long direction) |
2290 | { | 2291 | { |
2291 | logf("audio_initiate_track_change(%ld)", direction); | 2292 | logf("audio_initiate_track_change(%ld)", direction); |
2292 | 2293 | ||
@@ -2298,7 +2299,7 @@ static void audio_initiate_track_change(long direction) | |||
2298 | } | 2299 | } |
2299 | 2300 | ||
2300 | /* Called on manual dir skip */ | 2301 | /* Called on manual dir skip */ |
2301 | static void audio_initiate_dir_change(long direction) | 2302 | static void audio_initiate_dir_change(const long direction) |
2302 | { | 2303 | { |
2303 | playlist_end = false; | 2304 | playlist_end = false; |
2304 | dir_skip = true; | 2305 | dir_skip = true; |