summaryrefslogtreecommitdiff
path: root/apps/playback.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/playback.c')
-rw-r--r--apps/playback.c101
1 files changed, 49 insertions, 52 deletions
diff --git a/apps/playback.c b/apps/playback.c
index de58e8b40d..880c9acf7e 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 */
252static void set_filebuf_watermark(const int seconds, const size_t max); 252static void set_filebuf_watermark(int seconds, size_t max);
253 253
254/* Audio thread */ 254/* Audio thread */
255static struct event_queue audio_queue NOCACHEBSS_ATTR; 255static 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 */
280static void pcmbuf_callback_queue_post(const long id, intptr_t data) 280static void pcmbuf_callback_queue_post(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
316static struct mp3entry *bufgetid3(const int handle_id) 316static struct mp3entry *bufgetid3(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
387bool audio_restore_playback(const int type) 387bool audio_restore_playback(int type)
388{ 388{
389 switch (type) 389 switch (type)
390 { 390 {
@@ -401,7 +401,7 @@ bool audio_restore_playback(const int type)
401 } 401 }
402} 402}
403 403
404unsigned char *audio_get_buffer(const bool talk_buf, size_t *buffer_size) 404unsigned char *audio_get_buffer(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
624void audio_play(const long offset) 624void audio_play(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
713void audio_ff_rewind(const long newpos) 713void audio_ff_rewind(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
756void audio_set_buffer_margin(const int setting) 756void audio_set_buffer_margin(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];
@@ -763,7 +763,7 @@ void audio_set_buffer_margin(const int setting)
763#endif 763#endif
764 764
765/* Take necessary steps to enable or disable the crossfade setting */ 765/* Take necessary steps to enable or disable the crossfade setting */
766void audio_set_crossfade(const int enable) 766void audio_set_crossfade(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(const int enable)
805 805
806/* --- Routines called from multiple threads --- */ 806/* --- Routines called from multiple threads --- */
807 807
808static void set_filebuf_watermark(const int seconds, const size_t max) 808static void set_filebuf_watermark(int seconds, size_t max)
809{ 809{
810 size_t bytes; 810 size_t bytes;
811 811
@@ -817,7 +817,7 @@ static void set_filebuf_watermark(const int seconds, const size_t max)
817 buf_set_watermark(bytes); 817 buf_set_watermark(bytes);
818} 818}
819 819
820const char *get_codec_filename(const int cod_spec) 820const char *get_codec_filename(int cod_spec)
821{ 821{
822 const char *fname; 822 const char *fname;
823 823
@@ -838,11 +838,10 @@ const char *get_codec_filename(const int cod_spec)
838 afmt, fname ? fname : "<unknown>"); 838 afmt, fname ? fname : "<unknown>");
839#else /* !HAVE_RECORDING */ 839#else /* !HAVE_RECORDING */
840 /* Always decoder */ 840 /* Always decoder */
841 int afmt = cod_spec; 841 if ((unsigned)cod_spec >= AFMT_NUM_CODECS)
842 if ((unsigned)afmt >= AFMT_NUM_CODECS) 842 cod_spec = AFMT_UNKNOWN;
843 afmt = AFMT_UNKNOWN; 843 fname = audio_formats[cod_spec].codec_root_fn;
844 fname = audio_formats[afmt].codec_root_fn; 844 logf("Codec: %d - %s", cod_spec, fname ? fname : "<unknown>");
845 logf("Codec: %d - %s", afmt, fname ? fname : "<unknown>");
846#endif /* HAVE_RECORDING */ 845#endif /* HAVE_RECORDING */
847 846
848 return fname; 847 return fname;
@@ -850,14 +849,13 @@ const char *get_codec_filename(const int cod_spec)
850 849
851/* --- Codec thread --- */ 850/* --- Codec thread --- */
852static bool codec_pcmbuf_insert_callback( 851static bool codec_pcmbuf_insert_callback(
853 const void *ch1, const void *ch2, const int count) 852 const void *ch1, const void *ch2, int count)
854{ 853{
855 const char *src[2] = { ch1, ch2 }; 854 const char *src[2] = { ch1, ch2 };
856 855
857 int remaining = count; 856 while (count > 0)
858 while (remaining > 0)
859 { 857 {
860 int out_count = dsp_output_count(ci.dsp, remaining); 858 int out_count = dsp_output_count(ci.dsp, count);
861 int inp_count; 859 int inp_count;
862 char *dest; 860 char *dest;
863 861
@@ -881,8 +879,8 @@ static bool codec_pcmbuf_insert_callback(
881 return true; 879 return true;
882 880
883 /* Input size has grown, no error, just don't write more than length */ 881 /* Input size has grown, no error, just don't write more than length */
884 if (inp_count > remaining) 882 if (inp_count > count)
885 inp_count = remaining; 883 inp_count = count;
886 884
887 out_count = dsp_process(ci.dsp, dest, src, inp_count); 885 out_count = dsp_process(ci.dsp, dest, src, inp_count);
888 886
@@ -891,7 +889,7 @@ static bool codec_pcmbuf_insert_callback(
891 889
892 pcmbuf_write_complete(out_count); 890 pcmbuf_write_complete(out_count);
893 891
894 remaining -= inp_count; 892 count -= inp_count;
895 } 893 }
896 894
897 return true; 895 return true;
@@ -907,8 +905,8 @@ static void* codec_get_memory_callback(size_t *size)
907 "elapsed" value of the previous (to the codec, but current to the 905 "elapsed" value of the previous (to the codec, but current to the
908 user/PCM/WPS) track, so that the progressbar reaches the end. 906 user/PCM/WPS) track, so that the progressbar reaches the end.
909 During that transition, the WPS will display prevtrack_id3. */ 907 During that transition, the WPS will display prevtrack_id3. */
910static void codec_pcmbuf_position_callback(const size_t size) ICODE_ATTR; 908static void codec_pcmbuf_position_callback(size_t size) ICODE_ATTR;
911static void codec_pcmbuf_position_callback(const size_t size) 909static void codec_pcmbuf_position_callback(size_t size)
912{ 910{
913 /* This is called from an ISR, so be quick */ 911 /* This is called from an ISR, so be quick */
914 unsigned int time = size * 1000 / 4 / NATIVE_FREQUENCY + 912 unsigned int time = size * 1000 / 4 / NATIVE_FREQUENCY +
@@ -923,7 +921,7 @@ static void codec_pcmbuf_position_callback(const size_t size)
923 prevtrack_id3.elapsed = time; 921 prevtrack_id3.elapsed = time;
924} 922}
925 923
926static void codec_set_elapsed_callback(const unsigned int value) 924static void codec_set_elapsed_callback(unsigned int value)
927{ 925{
928 unsigned int latency; 926 unsigned int latency;
929 if (ci.seek_time) 927 if (ci.seek_time)
@@ -943,7 +941,7 @@ static void codec_set_elapsed_callback(const unsigned int value)
943 } 941 }
944} 942}
945 943
946static void codec_set_offset_callback(const size_t value) 944static void codec_set_offset_callback(size_t value)
947{ 945{
948 unsigned int latency; 946 unsigned int latency;
949 947
@@ -957,14 +955,14 @@ static void codec_set_offset_callback(const size_t value)
957 curtrack_id3.offset = value - latency; 955 curtrack_id3.offset = value - latency;
958} 956}
959 957
960static void codec_advance_buffer_counters(const size_t amount) 958static void codec_advance_buffer_counters(size_t amount)
961{ 959{
962 bufadvance(CUR_TI->audio_hid, amount); 960 bufadvance(CUR_TI->audio_hid, amount);
963 ci.curpos += amount; 961 ci.curpos += amount;
964} 962}
965 963
966/* copy up-to size bytes into ptr and return the actual size copied */ 964/* copy up-to size bytes into ptr and return the actual size copied */
967static size_t codec_filebuf_callback(void *ptr, const size_t size) 965static size_t codec_filebuf_callback(void *ptr, size_t size)
968{ 966{
969 ssize_t copy_n; 967 ssize_t copy_n;
970 968
@@ -984,7 +982,7 @@ static size_t codec_filebuf_callback(void *ptr, const size_t size)
984 return copy_n; 982 return copy_n;
985} /* codec_filebuf_callback */ 983} /* codec_filebuf_callback */
986 984
987static void* codec_request_buffer_callback(size_t *realsize, const size_t reqsize) 985static void* codec_request_buffer_callback(size_t *realsize, size_t reqsize)
988{ 986{
989 size_t copy_n = reqsize; 987 size_t copy_n = reqsize;
990 ssize_t ret; 988 ssize_t ret;
@@ -1023,7 +1021,7 @@ static int get_codec_base_type(int type)
1023 return type; 1021 return type;
1024} 1022}
1025 1023
1026static void codec_advance_buffer_callback(const size_t amount) 1024static void codec_advance_buffer_callback(size_t amount)
1027{ 1025{
1028 codec_advance_buffer_counters(amount); 1026 codec_advance_buffer_counters(amount);
1029 codec_set_offset_callback(ci.curpos); 1027 codec_set_offset_callback(ci.curpos);
@@ -1090,7 +1088,7 @@ static int codec_get_file_pos(void)
1090 return pos; 1088 return pos;
1091} 1089}
1092 1090
1093static off_t codec_mp3_get_filepos_callback(const int newtime) 1091static off_t codec_mp3_get_filepos_callback(int newtime)
1094{ 1092{
1095 off_t newpos; 1093 off_t newpos;
1096 1094
@@ -1116,7 +1114,7 @@ static void codec_seek_complete_callback(void)
1116 ci.seek_time = 0; 1114 ci.seek_time = 0;
1117} 1115}
1118 1116
1119static bool codec_seek_buffer_callback(const size_t newpos) 1117static bool codec_seek_buffer_callback(size_t newpos)
1120{ 1118{
1121 logf("codec_seek_buffer_callback"); 1119 logf("codec_seek_buffer_callback");
1122 1120
@@ -1130,7 +1128,7 @@ static bool codec_seek_buffer_callback(const size_t newpos)
1130 } 1128 }
1131} 1129}
1132 1130
1133static void codec_configure_callback(const int setting, const intptr_t value) 1131static void codec_configure_callback(int setting, intptr_t value)
1134{ 1132{
1135 switch (setting) { 1133 switch (setting) {
1136 case CODEC_SET_FILEBUF_WATERMARK: 1134 case CODEC_SET_FILEBUF_WATERMARK:
@@ -1180,7 +1178,7 @@ static inline void codec_crossfade_track_change(void)
1180 codec_track_changed(); 1178 codec_track_changed();
1181} 1179}
1182 1180
1183static void codec_track_skip_done(const bool was_manual) 1181static void codec_track_skip_done(bool was_manual)
1184{ 1182{
1185 /* Manual track change (always crossfade or flush audio). */ 1183 /* Manual track change (always crossfade or flush audio). */
1186 if (was_manual) 1184 if (was_manual)
@@ -1487,7 +1485,7 @@ static void audio_update_trackinfo(void)
1487 ci.taginfo_ready = &CUR_TI->taginfo_ready; 1485 ci.taginfo_ready = &CUR_TI->taginfo_ready;
1488} 1486}
1489 1487
1490static void buffering_audio_callback(const enum callback_event ev, const int value) 1488static void buffering_audio_callback(enum callback_event ev, int value)
1491{ 1489{
1492 (void)value; 1490 (void)value;
1493 logf("buffering_audio_callback"); 1491 logf("buffering_audio_callback");
@@ -1551,7 +1549,7 @@ static bool audio_release_tracks(void)
1551 return true; 1549 return true;
1552} 1550}
1553 1551
1554static bool audio_loadcodec(const bool start_play) 1552static bool audio_loadcodec(bool start_play)
1555{ 1553{
1556 int prev_track; 1554 int prev_track;
1557 char codec_path[MAX_PATH]; /* Full path to codec */ 1555 char codec_path[MAX_PATH]; /* Full path to codec */
@@ -1669,7 +1667,7 @@ static void audio_set_elapsed(struct mp3entry* id3)
1669 1667
1670/* Load one track by making the appropriate bufopen calls. Return true if 1668/* Load one track by making the appropriate bufopen calls. Return true if
1671 everything required was loaded correctly, false if not. */ 1669 everything required was loaded correctly, false if not. */
1672static bool audio_load_track(const int offset, const bool start_play) 1670static bool audio_load_track(int offset, bool start_play)
1673{ 1671{
1674 const char *trackname; 1672 const char *trackname;
1675 char msgbuf[80]; 1673 char msgbuf[80];
@@ -1716,9 +1714,8 @@ static bool audio_load_track(const int offset, const bool start_play)
1716 1714
1717 tracks[track_widx].filesize = filesize(fd); 1715 tracks[track_widx].filesize = filesize(fd);
1718 1716
1719 int adjusted_offset = offset; 1717 if ((unsigned)offset > tracks[track_widx].filesize)
1720 if ((unsigned)adjusted_offset > tracks[track_widx].filesize) 1718 offset = 0;
1721 adjusted_offset = 0;
1722 1719
1723 /* Set default values */ 1720 /* Set default values */
1724 if (start_play) 1721 if (start_play)
@@ -1830,17 +1827,17 @@ static bool audio_load_track(const int offset, const bool start_play)
1830 case AFMT_MPA_L1: 1827 case AFMT_MPA_L1:
1831 case AFMT_MPA_L2: 1828 case AFMT_MPA_L2:
1832 case AFMT_MPA_L3: 1829 case AFMT_MPA_L3:
1833 if (adjusted_offset > 0) { 1830 if (offset > 0) {
1834 file_offset = adjusted_offset; 1831 file_offset = offset;
1835 track_id3->offset = adjusted_offset; 1832 track_id3->offset = offset;
1836 audio_set_elapsed(track_id3); 1833 audio_set_elapsed(track_id3);
1837 } 1834 }
1838 break; 1835 break;
1839 1836
1840 case AFMT_WAVPACK: 1837 case AFMT_WAVPACK:
1841 if (offset > 0) { 1838 if (offset > 0) {
1842 file_offset = adjusted_offset; 1839 file_offset = offset;
1843 track_id3->offset = adjusted_offset; 1840 track_id3->offset = offset;
1844 track_id3->elapsed = track_id3->length / 2; 1841 track_id3->elapsed = track_id3->length / 2;
1845 } 1842 }
1846 break; 1843 break;
@@ -1853,8 +1850,8 @@ static bool audio_load_track(const int offset, const bool start_play)
1853 case AFMT_AAC: 1850 case AFMT_AAC:
1854 case AFMT_MPC: 1851 case AFMT_MPC:
1855 case AFMT_APE: 1852 case AFMT_APE:
1856 if (adjusted_offset > 0) 1853 if (offset > 0)
1857 track_id3->offset = adjusted_offset; 1854 track_id3->offset = offset;
1858 break; 1855 break;
1859 1856
1860 case AFMT_NSF: 1857 case AFMT_NSF:
@@ -1893,7 +1890,7 @@ static bool audio_load_track(const int offset, const bool start_play)
1893 return true; 1890 return true;
1894} 1891}
1895 1892
1896static void audio_fill_file_buffer(const bool start_play, const size_t offset) 1893static void audio_fill_file_buffer(bool start_play, size_t offset)
1897{ 1894{
1898 struct queue_event ev; 1895 struct queue_event ev;
1899 bool had_next_track = audio_next_track() != NULL; 1896 bool had_next_track = audio_next_track() != NULL;
@@ -2195,7 +2192,7 @@ static void audio_stop_playback(void)
2195 memset(&curtrack_id3, 0, sizeof(struct mp3entry)); 2192 memset(&curtrack_id3, 0, sizeof(struct mp3entry));
2196} 2193}
2197 2194
2198static void audio_play_start(const size_t offset) 2195static void audio_play_start(size_t offset)
2199{ 2196{
2200 int i; 2197 int i;
2201 2198
@@ -2288,7 +2285,7 @@ static void audio_new_playlist(void)
2288} 2285}
2289 2286
2290/* Called on manual track skip */ 2287/* Called on manual track skip */
2291static void audio_initiate_track_change(const long direction) 2288static void audio_initiate_track_change(long direction)
2292{ 2289{
2293 logf("audio_initiate_track_change(%ld)", direction); 2290 logf("audio_initiate_track_change(%ld)", direction);
2294 2291
@@ -2300,7 +2297,7 @@ static void audio_initiate_track_change(const long direction)
2300} 2297}
2301 2298
2302/* Called on manual dir skip */ 2299/* Called on manual dir skip */
2303static void audio_initiate_dir_change(const long direction) 2300static void audio_initiate_dir_change(long direction)
2304{ 2301{
2305 playlist_end = false; 2302 playlist_end = false;
2306 dir_skip = true; 2303 dir_skip = true;