Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.
My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c index ebc31fb..586c143 100644 static void commit_chunk(bool flush_next_time) /* Set priority of the codec thread */ #ifdef HAVE_PRIORITY_SCHEDULING -static void boost_codec_thread(bool boost) +static void boost_codec_thread(void) { + + static const int prios[11] = { + PRIORITY_PLAYBACK_MAX, + PRIORITY_PLAYBACK_MAX+1, + PRIORITY_PLAYBACK_MAX+2, + PRIORITY_PLAYBACK_MAX+3, + PRIORITY_PLAYBACK_MAX+4, + PRIORITY_PLAYBACK_MAX+5, + PRIORITY_PLAYBACK_MAX+7, + /* raised priority above 70% shouldn't be needed */ + PRIORITY_PLAYBACK, + PRIORITY_PLAYBACK, + PRIORITY_PLAYBACK, + PRIORITY_PLAYBACK, + }; + int fill_state = pcmbuf_unplayed_bytes * 100 / pcmbuf_size; /* in % */ + int new_prio = prios[fill_state/10]; + /* Keep voice and codec threads at the same priority or else voice * will starve if the codec thread's priority is boosted. */ - if (boost) - { - int priority = (PRIORITY_PLAYBACK - PRIORITY_PLAYBACK_MAX)*pcmbuf_unplayed_bytes - / (2*NATIVE_FREQUENCY) + PRIORITY_PLAYBACK_MAX; - - if (priority != codec_thread_priority) - { - codec_thread_priority = priority; - thread_set_priority(codec_thread_id, priority); - voice_thread_set_priority(priority); - } - } - else if (codec_thread_priority != PRIORITY_PLAYBACK) - { - thread_set_priority(codec_thread_id, PRIORITY_PLAYBACK); - voice_thread_set_priority(PRIORITY_PLAYBACK); - codec_thread_priority = PRIORITY_PLAYBACK; - } + thread_set_priority(codec_thread_id, new_prio); + voice_thread_set_priority(new_prio); + codec_thread_priority = new_prio; } #else #define boost_codec_thread(boost) do{}while(0) static bool prepare_insert(size_t length) if (thread_get_current() == codec_thread_id) #endif /* SIMULATOR */ { - if (pcmbuf_unplayed_bytes <= pcmbuf_watermark) - { - /* Fill PCM buffer by boosting cpu */ + /* boost cpu if necessary */ + if (pcmbuf_unplayed_bytes < pcmbuf_watermark) trigger_cpu_boost(); - /* If buffer is critically low, override UI priority, else - set back to the original priority. */ - boost_codec_thread(LOW_DATA(2)); - } - else - { - boost_codec_thread(false); - } + boost_codec_thread(); } #ifdef HAVE_CROSSFADE void pcmbuf_play_stop(void) DISPLAY_DESC("play_stop"); /* Can unboost the codec thread here no matter who's calling */ - boost_codec_thread(false); + boost_codec_thread(); } void pcmbuf_pause(bool pause) |