1

I have an application which records audio via microphone and directly encodes the raw PCM-data to MP3 via LAME (configured for most performance), before sending that stream via HTTP.

On my Galaxy S5, it's working flawlessly while screen is ON, but seconds after turning the screen OFF, the process get's struggling due to lack of CPU.

I'm using all known required options to prevent the device from sleeping and theoretically it's working as the CPU does not sleep, but just scaling the CPU too low:

  1. service is running in foreground-state
  2. I have a WIFI_MODE_FULL_HIGH_PERF-lock
  3. and a PARTIAL_WAKE_LOCK to prevent the CPU from sleeping
  4. priority of all affected threads is set to android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);

The application is theoretically working very well and used on hundred of thousand devices meanwhile.

But if the user is using the MP3-encoder + screen off, there is a chance that the CPU doesn't deliver enough power anymore to encode + stream the data smooth.

The CPU-governor of my S5 is "interactive" - if I set it to "performance", the problem is gone.

Anybody an idea how to prevent Android from sleeping, without using root to change the governor all the time the app is in use?

Martin L.
  • 3,006
  • 6
  • 36
  • 60
  • Have you tried periodically calling `PowerManager.userActivity(SystemClock.uptimeMillis(), true)` once the screen has been turned off? That may work to fake user interaction and keep the CPU from being ramped down. It may turn the screen on, it's not clear what the behavior is in this specific case. – Larry Schiefer Sep 04 '14 at 13:07
  • Very good hint Larry, but sadly that seems to have no affect here. I just ran a test and called that frequently while sending the audio-data, but the CPU is still scaling down after a few seconds after I manually turned the screen off. Too bad :/ – Martin L. Sep 04 '14 at 14:31
  • The Spotify app suffers from this problem when I have a DragonFly connected via an OTG cable. I wonder whether it is a Samsung specific issue or something built into Android. – Dan Def May 22 '17 at 17:42

0 Answers0