summaryrefslogtreecommitdiff
path: root/apps/pcmbuf.c
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2006-09-16 16:18:11 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2006-09-16 16:18:11 +0000
commita85044bf9eaa0a7206c1978d3cfd57ab2d7fae2f (patch)
treea30695ed540bf32365d577f46398f712c7a494c4 /apps/pcmbuf.c
parentbaf5494341cdd6cdb9590e21d429920b9bc4a2c6 (diff)
downloadrockbox-a85044bf9eaa0a7206c1978d3cfd57ab2d7fae2f.tar.gz
rockbox-a85044bf9eaa0a7206c1978d3cfd57ab2d7fae2f.zip
New scheduler, with priorities for swcodec platforms. Frequent task
switching should be more efficient and tasks are stored in linked lists to eliminate unnecessary task switching to improve performance. Audio should no longer skip on swcodec targets caused by too CPU hungry UI thread or background threads. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10958 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/pcmbuf.c')
-rw-r--r--apps/pcmbuf.c42
1 files changed, 35 insertions, 7 deletions
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c
index b18d411db6..f8fd2af82a 100644
--- a/apps/pcmbuf.c
+++ b/apps/pcmbuf.c
@@ -35,9 +35,10 @@
35#include "settings.h" 35#include "settings.h"
36#include "audio.h" 36#include "audio.h"
37#include "dsp.h" 37#include "dsp.h"
38#include "thread.h"
38 39
39/* 1.5s low mark */ 40/* Keep watermark high for iPods at least (2s) */
40#define PCMBUF_WATERMARK (NATIVE_FREQUENCY * 6) 41#define PCMBUF_WATERMARK (NATIVE_FREQUENCY * 8)
41 42
42/* Structure we can use to queue pcm chunks in memory to be played 43/* Structure we can use to queue pcm chunks in memory to be played
43 * by the driver code. */ 44 * by the driver code. */
@@ -94,6 +95,8 @@ static size_t pcmbuf_mix_sample IDATA_ATTR;
94static bool low_latency_mode = false; 95static bool low_latency_mode = false;
95static bool pcmbuf_flush; 96static bool pcmbuf_flush;
96 97
98extern struct thread_entry *codec_thread_p;
99
97/* Helpful macros for use in conditionals this assumes some of the above 100/* Helpful macros for use in conditionals this assumes some of the above
98 * static variable names */ 101 * static variable names */
99#define NEED_FLUSH(position) \ 102#define NEED_FLUSH(position) \
@@ -109,14 +112,37 @@ static bool pcmbuf_flush_fillpos(void);
109void pcmbuf_boost(bool state) 112void pcmbuf_boost(bool state)
110{ 113{
111 static bool boost_state = false; 114 static bool boost_state = false;
112 115#ifdef HAVE_PRIORITY_SCHEDULING
116 static bool priority_modified = false;
117#endif
118
113 if (crossfade_init || crossfade_active) 119 if (crossfade_init || crossfade_active)
114 return; 120 return;
115 121
116 if (state != boost_state) { 122 if (state != boost_state)
123 {
117 cpu_boost(state); 124 cpu_boost(state);
118 boost_state = state; 125 boost_state = state;
119 } 126 }
127
128#ifdef HAVE_PRIORITY_SCHEDULING
129 if (state && LOW_DATA(2) && pcm_is_playing())
130 {
131 if (!priority_modified)
132 {
133 /* Buffer is critically low so override UI priority. */
134 priority_modified = true;
135 thread_set_priority(codec_thread_p, PRIORITY_REALTIME);
136 }
137 }
138 else if (priority_modified)
139 {
140 /* Set back the original priority. */
141 thread_set_priority(codec_thread_p, PRIORITY_PLAYBACK);
142 priority_modified = false;
143 }
144
145#endif
120} 146}
121#endif 147#endif
122 148
@@ -244,7 +270,9 @@ static void pcmbuf_under_watermark(void)
244 pcmbuf_boost(true); 270 pcmbuf_boost(true);
245 /* Disable crossfade if < .5s of audio */ 271 /* Disable crossfade if < .5s of audio */
246 if (LOW_DATA(2)) 272 if (LOW_DATA(2))
273 {
247 crossfade_active = false; 274 crossfade_active = false;
275 }
248} 276}
249 277
250void pcmbuf_set_event_handler(void (*event_handler)(void)) 278void pcmbuf_set_event_handler(void (*event_handler)(void))
@@ -270,8 +298,8 @@ bool pcmbuf_is_lowdata(void)
270 crossfade_init || crossfade_active) 298 crossfade_init || crossfade_active)
271 return false; 299 return false;
272 300
273 /* 0.5 seconds of buffer is low data */ 301 /* 1 seconds of buffer is low data */
274 return LOW_DATA(2); 302 return LOW_DATA(4);
275} 303}
276 304
277/* Amount of bytes left in the buffer. */ 305/* Amount of bytes left in the buffer. */
@@ -443,7 +471,7 @@ static bool pcmbuf_flush_fillpos(void)
443 pcmbuf_play_start(); 471 pcmbuf_play_start();
444 } 472 }
445 /* Let approximately one chunk of data playback */ 473 /* Let approximately one chunk of data playback */
446 sleep(PCMBUF_TARGET_CHUNK/(NATIVE_FREQUENCY * 4) / 5); 474 sleep(HZ*PCMBUF_TARGET_CHUNK/(NATIVE_FREQUENCY*4));
447 } 475 }
448 pcmbuf_add_chunk(); 476 pcmbuf_add_chunk();
449 return true; 477 return true;