summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/pcmbuf.c50
1 files changed, 32 insertions, 18 deletions
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c
index e2b1d7f87b..91b9f1329b 100644
--- a/apps/pcmbuf.c
+++ b/apps/pcmbuf.c
@@ -104,6 +104,8 @@ static size_t pcmbuf_mix_sample IDATA_ATTR;
104static bool low_latency_mode = false; 104static bool low_latency_mode = false;
105static bool pcmbuf_flush; 105static bool pcmbuf_flush;
106 106
107static int codec_thread_priority = 0;
108
107extern struct thread_entry *codec_thread_p; 109extern struct thread_entry *codec_thread_p;
108 110
109/* Helpful macros for use in conditionals this assumes some of the above 111/* Helpful macros for use in conditionals this assumes some of the above
@@ -235,30 +237,37 @@ static inline void pcmbuf_add_chunk(void)
235 audiobuffer_fillpos = 0; 237 audiobuffer_fillpos = 0;
236} 238}
237 239
238static void pcmbuf_under_watermark(void)
239{
240#ifdef HAVE_PRIORITY_SCHEDULING 240#ifdef HAVE_PRIORITY_SCHEDULING
241 static int old_priority = 0; 241static void boost_codec_thread(bool boost)
242 242{
243 if (LOW_DATA(2) && pcm_is_playing()) 243 if (boost)
244 { 244 {
245 if (!old_priority) 245 if (codec_thread_priority == 0)
246 { 246 codec_thread_priority = thread_set_priority(
247 /* Buffer is critically low so override UI priority. */ 247 codec_thread_p, PRIORITY_REALTIME);
248 old_priority = thread_set_priority(codec_thread_p,
249 PRIORITY_REALTIME);
250 }
251 } 248 }
252 else if (old_priority) 249 else if (codec_thread_priority != 0)
253 { 250 {
254 /* Set back the original priority. */ 251 thread_set_priority(codec_thread_p, codec_thread_priority);
255 thread_set_priority(codec_thread_p, old_priority); 252 codec_thread_priority = 0;
256 old_priority = 0;
257 } 253 }
258#endif 254}
255#endif /* HAVE_PRIORITY_SCHEDULING */
259 256
260 /* Fill audio buffer by boosting cpu */ 257static void pcmbuf_under_watermark(void)
261 trigger_cpu_boost(); 258{
259 /* Only codec thread initiates boost - voice boosts the cpu when playing
260 a clip */
261 if (thread_get_current() == codec_thread_p)
262 {
263#ifdef HAVE_PRIORITY_SCHEDULING
264 /* If buffer is critically low, override UI priority, else
265 set back to the original priority. */
266 boost_codec_thread(LOW_DATA(2) && pcm_is_playing());
267#endif
268 /* Fill audio buffer by boosting cpu */
269 trigger_cpu_boost();
270 }
262 271
263 /* Disable crossfade if < .5s of audio */ 272 /* Disable crossfade if < .5s of audio */
264 if (LOW_DATA(2)) 273 if (LOW_DATA(2))
@@ -364,6 +373,11 @@ void pcmbuf_play_stop(void)
364 crossfade_init = false; 373 crossfade_init = false;
365 crossfade_active = false; 374 crossfade_active = false;
366 pcmbuf_flush = false; 375 pcmbuf_flush = false;
376
377#ifdef HAVE_PRIORITY_SCHEDULING
378 /* Can unboost the codec thread here no matter who's calling */
379 boost_codec_thread(false);
380#endif
367} 381}
368 382
369int pcmbuf_used_descs(void) { 383int pcmbuf_used_descs(void) {