summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Low <lostlogic@rockbox.org>2006-01-21 22:42:44 +0000
committerBrandon Low <lostlogic@rockbox.org>2006-01-21 22:42:44 +0000
commita3868d35d3621e700abfd51de61ac6f83908a472 (patch)
treea90cc5fb4c285864a182cdb7b1f328ce7324a0a7
parent3458be2d9da84c159c3957316839271ea01193ba (diff)
downloadrockbox-a3868d35d3621e700abfd51de61ac6f83908a472.tar.gz
rockbox-a3868d35d3621e700abfd51de61ac6f83908a472.zip
Continue to update playback status after decoding is complete (the progress bar makes it to 100%!)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8407 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/pcmbuf.c39
-rw-r--r--apps/pcmbuf.h3
-rw-r--r--apps/playback.c19
3 files changed, 41 insertions, 20 deletions
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c
index 2d75185f62..d1835fb197 100644
--- a/apps/pcmbuf.c
+++ b/apps/pcmbuf.c
@@ -83,12 +83,14 @@ struct pcmbufdesc
83 void (*callback)(void); 83 void (*callback)(void);
84} pcmbuffers[NUM_PCM_BUFFERS] IDATA_ATTR; 84} pcmbuffers[NUM_PCM_BUFFERS] IDATA_ATTR;
85 85
86volatile int pcmbuf_read_index; 86static int pcmbuf_read_index;
87volatile int pcmbuf_write_index; 87static int pcmbuf_write_index;
88int pcmbuf_unplayed_bytes IDATA_ATTR; 88static int pcmbuf_unplayed_bytes IDATA_ATTR;
89int pcmbuf_mix_used_bytes; 89static int pcmbuf_mix_used_bytes;
90int pcmbuf_watermark; 90static int pcmbuf_watermark;
91void (*pcmbuf_watermark_event)(int bytes_left); 91static void pcmbuf_under_watermark(int bytes_left);
92static int pcmbuf_num_used_buffers(void);
93static void (*position_callback)(int size);
92static int last_chunksize; 94static int last_chunksize;
93static long mixpos = 0; 95static long mixpos = 0;
94 96
@@ -116,7 +118,7 @@ void pcmbuf_set_boost_mode(bool state)
116} 118}
117#endif 119#endif
118 120
119int pcmbuf_num_used_buffers(void) 121static int pcmbuf_num_used_buffers(void)
120{ 122{
121 return (pcmbuf_write_index - pcmbuf_read_index) & NUM_PCM_BUFFERS_MASK; 123 return (pcmbuf_write_index - pcmbuf_read_index) & NUM_PCM_BUFFERS_MASK;
122} 124}
@@ -125,6 +127,10 @@ static void pcmbuf_callback(unsigned char** start, long* size) ICODE_ATTR;
125static void pcmbuf_callback(unsigned char** start, long* size) 127static void pcmbuf_callback(unsigned char** start, long* size)
126{ 128{
127 struct pcmbufdesc *desc = &pcmbuffers[pcmbuf_read_index]; 129 struct pcmbufdesc *desc = &pcmbuffers[pcmbuf_read_index];
130
131 if (position_callback) {
132 position_callback(last_chunksize);
133 }
128 134
129 pcmbuf_unplayed_bytes -= last_chunksize; 135 pcmbuf_unplayed_bytes -= last_chunksize;
130 audiobuffer_free += last_chunksize; 136 audiobuffer_free += last_chunksize;
@@ -159,19 +165,20 @@ static void pcmbuf_callback(unsigned char** start, long* size)
159 } 165 }
160 166
161 last_chunksize = *size; 167 last_chunksize = *size;
168
162 if(pcmbuf_unplayed_bytes <= pcmbuf_watermark) 169 if(pcmbuf_unplayed_bytes <= pcmbuf_watermark)
163 { 170 {
164 if(pcmbuf_watermark_event) 171 pcmbuf_under_watermark(pcmbuf_unplayed_bytes);
165 {
166 pcmbuf_watermark_event(pcmbuf_unplayed_bytes);
167 }
168 } 172 }
169} 173}
170 174
171void pcmbuf_set_watermark(int numbytes, void (*callback)(int bytes_left)) 175void pcmbuf_set_position_callback(void (*callback)(int size)) {
176 position_callback = callback;
177}
178
179static void pcmbuf_set_watermark_bytes(int numbytes)
172{ 180{
173 pcmbuf_watermark = numbytes; 181 pcmbuf_watermark = numbytes;
174 pcmbuf_watermark_event = callback;
175} 182}
176 183
177bool pcmbuf_add_chunk(void *addr, int size, void (*callback)(void)) 184bool pcmbuf_add_chunk(void *addr, int size, void (*callback)(void))
@@ -192,7 +199,7 @@ bool pcmbuf_add_chunk(void *addr, int size, void (*callback)(void))
192 return false; 199 return false;
193} 200}
194 201
195void pcmbuf_watermark_callback(int bytes_left) 202static void pcmbuf_under_watermark(int bytes_left)
196{ 203{
197 /* Fill audio buffer by boosting cpu */ 204 /* Fill audio buffer by boosting cpu */
198 pcmbuf_boost(true); 205 pcmbuf_boost(true);
@@ -802,9 +809,9 @@ void pcmbuf_crossfade_enable(bool on_off)
802 crossfade_enabled = on_off; 809 crossfade_enabled = on_off;
803 810
804 if (crossfade_enabled) { 811 if (crossfade_enabled) {
805 pcmbuf_set_watermark(pcmbuf_size - (CHUNK_SIZE*6), pcmbuf_watermark_callback); 812 pcmbuf_set_watermark_bytes(pcmbuf_size - (CHUNK_SIZE*6));
806 } else { 813 } else {
807 pcmbuf_set_watermark(PCMBUF_WATERMARK, pcmbuf_watermark_callback); 814 pcmbuf_set_watermark_bytes(PCMBUF_WATERMARK);
808 } 815 }
809} 816}
810 817
diff --git a/apps/pcmbuf.h b/apps/pcmbuf.h
index 9031db60b1..7e7ecf1d75 100644
--- a/apps/pcmbuf.h
+++ b/apps/pcmbuf.h
@@ -30,8 +30,6 @@ bool pcmbuf_is_crossfade_active(void);
30 30
31/* These functions are for playing chained buffers of PCM data */ 31/* These functions are for playing chained buffers of PCM data */
32bool pcmbuf_add_chunk(void *addr, int size, void (*callback)(void)); 32bool pcmbuf_add_chunk(void *addr, int size, void (*callback)(void));
33int pcmbuf_num_used_buffers(void);
34void pcmbuf_set_watermark(int numbytes, void (*callback)(int bytes_left));
35 33
36#ifdef HAVE_ADJUSTABLE_CPU_FREQ 34#ifdef HAVE_ADJUSTABLE_CPU_FREQ
37void pcmbuf_boost(bool state); 35void pcmbuf_boost(bool state);
@@ -45,6 +43,7 @@ void pcmbuf_flush_audio(void);
45void pcmbuf_play_start(void); 43void pcmbuf_play_start(void);
46bool pcmbuf_crossfade_init(void); 44bool pcmbuf_crossfade_init(void);
47void pcmbuf_add_event(void (*event_handler)(void)); 45void pcmbuf_add_event(void (*event_handler)(void));
46void pcmbuf_set_position_callback(void (*callback)(int size));
48unsigned int pcmbuf_get_latency(void); 47unsigned int pcmbuf_get_latency(void);
49bool pcmbuf_insert_buffer(char *buf, long length); 48bool pcmbuf_insert_buffer(char *buf, long length);
50void pcmbuf_flush_buffer(long length); 49void pcmbuf_flush_buffer(long length);
diff --git a/apps/playback.c b/apps/playback.c
index 3da4b6fbdb..48b993474b 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -179,6 +179,7 @@ static struct track_info tracks[MAX_TRACK];
179 179
180/* Pointer to track info structure about current song playing. */ 180/* Pointer to track info structure about current song playing. */
181static struct track_info *cur_ti; 181static struct track_info *cur_ti;
182static struct track_info *prev_ti;
182 183
183/* Have we reached end of the current playlist. */ 184/* Have we reached end of the current playlist. */
184static bool playlist_end = false; 185static bool playlist_end = false;
@@ -395,6 +396,17 @@ void* get_codec_memory_callback(long *size)
395 return &audiobuf[0]; 396 return &audiobuf[0];
396} 397}
397 398
399static void pcmbuf_position_callback(int size) ICODE_ATTR;
400static void pcmbuf_position_callback(int size) {
401 unsigned int time = size * 1000 / 4 / 44100 + prev_ti->id3.elapsed;
402 if (time >= prev_ti->id3.length) {
403 pcmbuf_set_position_callback(NULL);
404 prev_ti->id3.elapsed = cur_ti->id3.length;
405 } else {
406 prev_ti->id3.elapsed = time;
407 }
408}
409
398void codec_set_elapsed_callback(unsigned int value) 410void codec_set_elapsed_callback(unsigned int value)
399{ 411{
400 unsigned int latency; 412 unsigned int latency;
@@ -1640,8 +1652,8 @@ static void audio_change_track(void)
1640 1652
1641bool codec_request_next_track_callback(void) 1653bool codec_request_next_track_callback(void)
1642{ 1654{
1643 struct track_info *prev_ti = cur_ti; 1655 prev_ti = cur_ti;
1644 1656
1645 if (current_codec == CODEC_IDX_VOICE) { 1657 if (current_codec == CODEC_IDX_VOICE) {
1646 voice_remaining = 0; 1658 voice_remaining = 0;
1647 /* Terminate the codec if there are messages waiting on the queue or 1659 /* Terminate the codec if there are messages waiting on the queue or
@@ -1649,6 +1661,8 @@ bool codec_request_next_track_callback(void)
1649 return !ci_voice.stop_codec && queue_empty(&voice_codec_queue); 1661 return !ci_voice.stop_codec && queue_empty(&voice_codec_queue);
1650 } 1662 }
1651 1663
1664 pcmbuf_set_position_callback(pcmbuf_position_callback);
1665
1652 if (ci.stop_codec || !playing) 1666 if (ci.stop_codec || !playing)
1653 return false; 1667 return false;
1654 1668
@@ -1878,6 +1892,7 @@ void audio_thread(void)
1878 if (track_changed_callback) 1892 if (track_changed_callback)
1879 track_changed_callback(&cur_ti->id3); 1893 track_changed_callback(&cur_ti->id3);
1880 playlist_update_resume_info(audio_current_track()); 1894 playlist_update_resume_info(audio_current_track());
1895 pcmbuf_set_position_callback(NULL);
1881 break ; 1896 break ;
1882 1897
1883 case AUDIO_CODEC_DONE: 1898 case AUDIO_CODEC_DONE: