summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/playback.c50
1 files changed, 24 insertions, 26 deletions
diff --git a/apps/playback.c b/apps/playback.c
index db04f3a784..98b73b4639 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -68,7 +68,7 @@ static volatile bool paused;
68#define CODEC_WAV "/.rockbox/codecs/codecwav.rock"; 68#define CODEC_WAV "/.rockbox/codecs/codecwav.rock";
69 69
70#define AUDIO_WATERMARK 0x70000 70#define AUDIO_WATERMARK 0x70000
71#define AUDIO_FILE_CHUNK (1024*512) 71#define AUDIO_FILE_CHUNK (1024*32)
72 72
73#define AUDIO_PLAY 1 73#define AUDIO_PLAY 1
74#define AUDIO_STOP 2 74#define AUDIO_STOP 2
@@ -107,9 +107,6 @@ static const char codec_thread_name[] = "codec";
107/* Is file buffer currently being refilled? */ 107/* Is file buffer currently being refilled? */
108static volatile bool filling; 108static volatile bool filling;
109 109
110/* Interrupts buffer filling. */
111static volatile bool interrupt;
112
113/* Ring buffer where tracks and codecs are loaded. */ 110/* Ring buffer where tracks and codecs are loaded. */
114char *codecbuf; 111char *codecbuf;
115 112
@@ -423,7 +420,7 @@ void audio_fill_file_buffer(void)
423 /* Give codecs some processing time. */ 420 /* Give codecs some processing time. */
424 yield_codecs(); 421 yield_codecs();
425 422
426 if (interrupt) { 423 if (!queue_empty(&audio_queue)) {
427 logf("Filling interrupted"); 424 logf("Filling interrupted");
428 close(current_fd); 425 close(current_fd);
429 current_fd = -1; 426 current_fd = -1;
@@ -543,7 +540,7 @@ bool loadcodec(const char *trackname, bool start_play)
543 i = 0; 540 i = 0;
544 while (i < size) { 541 while (i < size) {
545 yield_codecs(); 542 yield_codecs();
546 if (interrupt) { 543 if (!queue_empty(&audio_queue)) {
547 logf("Buffering interrupted"); 544 logf("Buffering interrupted");
548 close(fd); 545 close(fd);
549 return false; 546 return false;
@@ -610,10 +607,12 @@ bool audio_load_track(int offset, bool start_play, int peek_offset)
610 } 607 }
611 tracks[track_widx].filebuf = &codecbuf[buf_widx]; 608 tracks[track_widx].filebuf = &codecbuf[buf_widx];
612 609
613 logf("%s", trackname); 610 //logf("%s", trackname);
614 logf("Buffering track:%d/%d", track_widx, track_ridx); 611 logf("Buffering track:%d/%d", track_widx, track_ridx);
615 612
616 if (interrupt) { 613 if (!queue_empty(&audio_queue)) {
614 logf("Interrupted!");
615 ci.stop_codec = true;
617 close(fd); 616 close(fd);
618 return false; 617 return false;
619 } 618 }
@@ -637,10 +636,12 @@ bool audio_load_track(int offset, bool start_play, int peek_offset)
637 } else { 636 } else {
638 lseek(fd, 0, SEEK_SET); 637 lseek(fd, 0, SEEK_SET);
639 } 638 }
639 /*
640 logf("T:%s", tracks[track_widx].id3.title); 640 logf("T:%s", tracks[track_widx].id3.title);
641 logf("L:%d", tracks[track_widx].id3.length); 641 logf("L:%d", tracks[track_widx].id3.length);
642 logf("O:%d", tracks[track_widx].id3.first_frame_offset); 642 logf("O:%d", tracks[track_widx].id3.first_frame_offset);
643 logf("F:%d", tracks[track_widx].id3.frequency); 643 logf("F:%d", tracks[track_widx].id3.frequency);
644 */
644 tracks[track_widx].taginfo_ready = true; 645 tracks[track_widx].taginfo_ready = true;
645 break ; 646 break ;
646 647
@@ -715,12 +716,13 @@ bool audio_load_track(int offset, bool start_play, int peek_offset)
715 break; 716 break;
716 } 717 }
717 718
719 track_changed = true;
718 track_count++; 720 track_count++;
719 i = tracks[track_widx].filepos; 721 i = tracks[track_widx].filepos;
720 while (i < size) { 722 while (i < size) {
721 /* Give codecs some processing time to prevent glitches. */ 723 /* Give codecs some processing time to prevent glitches. */
722 yield_codecs(); 724 yield_codecs();
723 if (interrupt) { 725 if (!queue_empty(&audio_queue)) {
724 logf("Buffering interrupted"); 726 logf("Buffering interrupted");
725 close(fd); 727 close(fd);
726 return false; 728 return false;
@@ -734,6 +736,7 @@ bool audio_load_track(int offset, bool start_play, int peek_offset)
734 copy_n = MIN((int)fill_bytesleft, copy_n); 736 copy_n = MIN((int)fill_bytesleft, copy_n);
735 rc = read(fd, &codecbuf[buf_widx], copy_n); 737 rc = read(fd, &codecbuf[buf_widx], copy_n);
736 if (rc < 0) { 738 if (rc < 0) {
739 logf("File error!");
737 close(fd); 740 close(fd);
738 return false; 741 return false;
739 } 742 }
@@ -782,10 +785,9 @@ void audio_insert_tracks(int offset, bool start_playing)
782 785
783void audio_play_start(int offset) 786void audio_play_start(int offset)
784{ 787{
785 memset(&tracks, 0, sizeof(struct track_info)); 788 memset(&tracks, 0, sizeof(struct track_info) * MAX_TRACK);
786 sound_set(SOUND_VOLUME, global_settings.volume); 789 sound_set(SOUND_VOLUME, global_settings.volume);
787 track_count = 0; 790 track_count = 0;
788 track_changed = true;
789 track_widx = 0; 791 track_widx = 0;
790 track_ridx = 0; 792 track_ridx = 0;
791 buf_ridx = 0; 793 buf_ridx = 0;
@@ -808,12 +810,13 @@ void audio_check_buffer(void)
808 810
809 /* Fill buffer as full as possible for cross-fader. */ 811 /* Fill buffer as full as possible for cross-fader. */
810#ifndef SIMULATOR 812#ifndef SIMULATOR
811 if (cur_ti->id3.length - cur_ti->id3.elapsed < 20000) 813 if (cur_ti->id3.length - cur_ti->id3.elapsed < 20000 && playing)
812 pcm_set_boost_mode(true); 814 pcm_set_boost_mode(true);
813#endif 815#endif
814 816
815 /* Start buffer filling as necessary. */ 817 /* Start buffer filling as necessary. */
816 if (codecbufused > AUDIO_WATERMARK || interrupt || !playing) 818 if (codecbufused > AUDIO_WATERMARK || !queue_empty(&audio_queue)
819 || !playing || ci.stop_codec || ci.reload_codec)
817 return ; 820 return ;
818 821
819 filling = true; 822 filling = true;
@@ -915,7 +918,7 @@ void audio_change_track(void)
915 918
916bool codec_request_next_track_callback(void) 919bool codec_request_next_track_callback(void)
917{ 920{
918 if (ci.stop_codec || !playing) 921 if (ci.stop_codec || !playing || !queue_empty(&audio_queue))
919 return false; 922 return false;
920 923
921 logf("Request new track"); 924 logf("Request new track");
@@ -989,21 +992,20 @@ void audio_thread(void)
989 yield(); 992 yield();
990 audio_check_buffer(); 993 audio_check_buffer();
991 994
992 queue_wait_w_tmo(&audio_queue, &ev, 0); 995 queue_wait_w_tmo(&audio_queue, &ev, 10);
993 switch (ev.id) { 996 switch (ev.id) {
994 case AUDIO_PLAY: 997 case AUDIO_PLAY:
995 interrupt = false;
996 ci.stop_codec = true; 998 ci.stop_codec = true;
997 ci.reload_codec = false; 999 ci.reload_codec = false;
998 ci.seek_time = 0; 1000 ci.seek_time = 0;
999#ifndef SIMULATOR 1001#ifndef SIMULATOR
1000 pcm_play_stop(); 1002 pcm_play_stop();
1001#endif 1003#endif
1002 paused = false;
1003 audio_play_start((int)ev.data); 1004 audio_play_start((int)ev.data);
1004 break ; 1005 break ;
1005 1006
1006 case AUDIO_STOP: 1007 case AUDIO_STOP:
1008 paused = false;
1007#ifndef SIMULATOR 1009#ifndef SIMULATOR
1008 pcm_play_stop(); 1010 pcm_play_stop();
1009 pcm_play_pause(true); 1011 pcm_play_pause(true);
@@ -1092,12 +1094,11 @@ void codec_thread(void)
1092 1094
1093 if (playing && !ci.stop_codec && !ci.reload_codec) { 1095 if (playing && !ci.stop_codec && !ci.reload_codec) {
1094 audio_change_track(); 1096 audio_change_track();
1095 } else if (ci.reload_codec) { 1097 continue ;
1096 interrupt = true; 1098 } else if (ci.stop_codec) {
1097 } else { 1099 //playing = false;
1098 playing = false;
1099 } 1100 }
1100 queue_post(&audio_queue, AUDIO_CODEC_DONE, (void *)status); 1101 //queue_post(&audio_queue, AUDIO_CODEC_DONE, (void *)status);
1101 } 1102 }
1102 } 1103 }
1103} 1104}
@@ -1146,7 +1147,6 @@ void audio_play(int offset)
1146{ 1147{
1147 logf("audio_play"); 1148 logf("audio_play");
1148 ci.stop_codec = true; 1149 ci.stop_codec = true;
1149 playing = false;
1150#ifndef SIMULATOR 1150#ifndef SIMULATOR
1151 pcm_play_pause(true); 1151 pcm_play_pause(true);
1152#endif 1152#endif
@@ -1157,6 +1157,7 @@ void audio_stop(void)
1157{ 1157{
1158 logf("audio_stop"); 1158 logf("audio_stop");
1159 playing = false; 1159 playing = false;
1160 paused = false;
1160 ci.stop_codec = true; 1161 ci.stop_codec = true;
1161 if (current_fd) { 1162 if (current_fd) {
1162 close(current_fd); 1163 close(current_fd);
@@ -1196,7 +1197,6 @@ void audio_next(void)
1196 1197
1197 /* Detect if disk is spinning.. */ 1198 /* Detect if disk is spinning.. */
1198 if (filling) { 1199 if (filling) {
1199 interrupt = true;
1200 ci.stop_codec = true; 1200 ci.stop_codec = true;
1201 playlist_next(1); 1201 playlist_next(1);
1202 queue_post(&audio_queue, AUDIO_PLAY, 0); 1202 queue_post(&audio_queue, AUDIO_PLAY, 0);
@@ -1217,7 +1217,6 @@ void audio_prev(void)
1217#endif 1217#endif
1218 1218
1219 if (filling) { 1219 if (filling) {
1220 interrupt = true;
1221 ci.stop_codec = true; 1220 ci.stop_codec = true;
1222 playlist_next(-1); 1221 playlist_next(-1);
1223 queue_post(&audio_queue, AUDIO_PLAY, 0); 1222 queue_post(&audio_queue, AUDIO_PLAY, 0);
@@ -1398,7 +1397,6 @@ void audio_init(void)
1398 //codecbuflen = 2*512*1024; 1397 //codecbuflen = 2*512*1024;
1399 codecbufused = 0; 1398 codecbufused = 0;
1400 filling = false; 1399 filling = false;
1401 interrupt = false;
1402 codecbuf = &audiobuf[MALLOC_BUFSIZE]; 1400 codecbuf = &audiobuf[MALLOC_BUFSIZE];
1403 playing = false; 1401 playing = false;
1404 paused = false; 1402 paused = false;