# Buffer starvation with FMOD 2 on Huawei Android Phones when screen is locked

**URL:** https://qa.fmod.com/t/buffer-starvation-with-fmod-2-on-huawei-android-phones-when-screen-is-locked/16513
**Category:** FMOD Engine
**Tags:** android
**Created:** [December 3, 2020, 5:16pm UTC](https://qa.fmod.com/t/buffer-starvation-with-fmod-2-on-huawei-android-phones-when-screen-is-locked/16513 "2020-12-03T17:16:54Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![alexandre.dubois.mtl](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alexandre.dubois.mtl/32/1739_2.png) [@alexandre.dubois.mtl](https://qa.fmod.com/u/alexandre.dubois.mtl)
#### Post date: [December 3, 2020, 5:16pm UTC](https://qa.fmod.com/t/buffer-starvation-with-fmod-2-on-huawei-android-phones-when-screen-is-locked/16513/1 "2020-12-03T17:16:54Z")

</div>

Hello,

I have found a bug that seems only reproducible on certain Huawei Android phones where a Buffer starvation occurs when the screen is locked.

Here is an example of the bug happening in the `play_sound` sample app taken from FMOD Engine 2.01.06, with the loop enabled on `drumloop.wav`: [https://www.youtube.com/watch?v=hmHOc09Buig](https://www.youtube.com/watch?v=hmHOc09Buig)

When the sound stops, I see these warnings in the logs:

2020-12-03 11:31:56.914 7424-7552/org.fmod.example W/fmod: OutputRingBuffer::read : Buffer starvation detected, requested 1920 bytes, 896 / 32768 bytes available.  
2020-12-03 11:31:56.914 7424-7552/org.fmod.example W/fmod: OutputRingBuffer::read : Increasing block count to 5.  
2020-12-03 11:31:56.915 7424-7545/org.fmod.example W/fmod: OutputAAudio::mixerThread : Increasing buffer size to 2160 due to detected xruns.  
2020-12-03 11:31:56.916 7424-7552/org.fmod.example W/fmod: OutputRingBuffer::read : Buffer starvation detected, requested 1920 bytes, 896 / 32768 bytes available.  
2020-12-03 11:31:56.916 7424-7552/org.fmod.example W/fmod: OutputRingBuffer::read : Increasing block count to 6.  
2020-12-03 11:31:56.916 7424-7552/org.fmod.example W/fmod: OutputRingBuffer::read : Buffer starvation detected, requested 1920 bytes, 0 / 32768 bytes available.  
2020-12-03 11:31:56.916 7424-7552/org.fmod.example W/fmod: OutputRingBuffer::read : Increasing block count to 7.  
2020-12-03 11:31:56.916 7424-7552/org.fmod.example W/fmod: OutputRingBuffer::read : Buffer starvation detected, requested 1920 bytes, 0 / 32768 bytes available.  
2020-12-03 11:31:56.916 7424-7552/org.fmod.example W/fmod: OutputRingBuffer::read : Increasing block count to 8.  
2020-12-03 11:31:56.916 7424-7552/org.fmod.example W/fmod: OutputRingBuffer::read : Buffer starvation detected, requested 1920 bytes, 0 / 32768 bytes available.  
2020-12-03 11:31:56.916 7424-7552/org.fmod.example I/chatty: uid=10137(org.fmod.example) identical 17 lines  
2020-12-03 11:31:56.916 7424-7552/org.fmod.example W/fmod: OutputRingBuffer::read : Buffer starvation detected, requested 1920 bytes, 0 / 32768 bytes available.  
2020-12-03 11:31:56.916 7424-7552/org.fmod.example W/fmod: OutputRingBuffer::read : Buffer starvation detected, requested 1920 bytes, 0 / 32768 bytes available.  
2020-12-03 11:31:56.916 7424-7552/org.fmod.example W/fmod: OutputRingBuffer::read : Buffer starvation detected, requested 1920 bytes, 0 / 32768 bytes available.  
2020-12-03 11:31:56.916 7424-7552/org.fmod.example W/fmod: OutputRingBuffer::read : Buffer starvation detected, requested 1920 bytes, 0 / 32768 bytes available.  
2020-12-03 11:31:56.916 7424-7552/org.fmod.example W/fmod: OutputRingBuffer::read : Buffer starvation detected, requested 1920 bytes, 256 / 32768 bytes available.

I have also tested the exact same scenario with FMOD 1.10.20, and the bug does not happen.

I was able to reproduce this on the Huawei Mate 30, P30 Pro & P30 Lite, all running Android 10.

Thanks!

---

<div class="post-metadata">

### Author: ![tristanjl](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/tristanjl/32/261_2.png) [@tristanjl](https://qa.fmod.com/u/tristanjl)
#### Post date: [December 4, 2020, 1:00am UTC](https://qa.fmod.com/t/buffer-starvation-with-fmod-2-on-huawei-android-phones-when-screen-is-locked/16513/2 "2020-12-04T01:00:18Z")

</div>

Hi alexandre,

The example apps do not suspend or resume the mixer when the application loses focus. At this point, as FMOD works as a low latency audio solution and the OS can throttle the app, stuttering can occur.

You can hook up [mixerSuspend](https://www.fmod.com/resources/documentation-api?version=2.1&page=core-api-system.html#system_mixersuspend) and [mixerResume](https://www.fmod.com/resources/documentation-api?version=2.1&page=core-api-system.html#system_mixerresume) to the application callbacks to better interact with the OS.

---

<div class="post-metadata">

### Author: ![alexandre.dubois.mtl](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alexandre.dubois.mtl/32/1739_2.png) [@alexandre.dubois.mtl](https://qa.fmod.com/u/alexandre.dubois.mtl)
#### Post date: [December 4, 2020, 4:45pm UTC](https://qa.fmod.com/t/buffer-starvation-with-fmod-2-on-huawei-android-phones-when-screen-is-locked/16513/3 "2020-12-04T16:45:59Z")

</div>

Hi Tristanjl,

Thanks for responding to me!

For my particular use case, I want the sound to keep playing, even when that app is in background. And it isn’t just stuttering, it’s as if there is a something that just blocks the sound files from getting streamed to FMOD 2. One thing I should mention is that this only happens when the phone is not charging.

When running the same test on other devices, I can keep the sound playing for hours without interruption. Also, when testing with FMOD 1 on these Huawei devices, I can also play sounds for hours without interruption.

It’s the combination of these Huawei devices and FMOD 2 that causes this problem, which makes me feel like there is a bug in FMOD 2 that should be fixed.

Thanks!

Alex

---

<div class="post-metadata">

### Author: ![tristanjl](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/tristanjl/32/261_2.png) [@tristanjl](https://qa.fmod.com/u/tristanjl)
#### Post date: [January 15, 2021, 12:38am UTC](https://qa.fmod.com/t/buffer-starvation-with-fmod-2-on-huawei-android-phones-when-screen-is-locked/16513/4 "2021-01-15T00:38:52Z")

</div>

The old behaviour might still be possible using OpenSL (as our thread usage has change for AAudio - the OS now controls the thread priority of our audio thread). If you call [https://fmod.com/resources/documentation-api?version=2.0&page=core-api-system.html#system\_setoutput](https://fmod.com/resources/documentation-api?version=2.0&page=core-api-system.html#system_setoutput) choosing FMOD\_OUTPUTTYPE\_OPENSL, you might get the old behaviour.

---

<div class="post-metadata">

### Author: ![alexandre.dubois.mtl](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/alexandre.dubois.mtl/32/1739_2.png) [@alexandre.dubois.mtl](https://qa.fmod.com/u/alexandre.dubois.mtl)
#### Post date: [January 20, 2021, 8:06pm UTC](https://qa.fmod.com/t/buffer-starvation-with-fmod-2-on-huawei-android-phones-when-screen-is-locked/16513/5 "2021-01-20T20:06:33Z")

</div>

Hi tristanjl,

Thank you for your suggestion, this works perfectly!

Alex
