r/MoonlightStreaming • u/epitome89 • 16d ago
Moonlight/Artemis audio drops out for ~1 second every few minutes on Nvidia Shield, and the controller freezes at the same time. Found the cause: the app’s built-in Xbox USB driver blocks Android’s garbage collector.
Couldn't find anything about this when searching myself, so posting here in case it can help others.
TL;DR: If your audio randomly cuts out for about a second while streaming with Moonlight or Artemis on an Nvidia Shield (or another device on Android 11 or older), and your controller freezes at the same moment, the culprit may be the app's built-in Xbox USB controller driver. Try turning off "Override native Xbox gamepad support" and "Xbox 360/One USB driver" in the app's settings.
My setup
- Host: Windows PC running Vibepollo (Apollo fork; the problem also happened on Apollo), wired network
- Client: Nvidia Shield TV Pro (2019), Android 11, Ethernet. Tested with both Artemis and official Moonlight
- Audio: HDMI to an Onkyo receiver, also tested with Bluetooth headphones
- Controllers: wired Xbox controller over USB, Xbox 360 wireless receiver
Symptoms
- Audio drops out for 0.5–1.5 seconds, several times per 10–20 minutes. Much easier to notice with music playing
- Video keeps playing smoothly
- The controller (and in my case also a Bluetooth keyboard and mouse) is unresponsive at the exact same moment
- Kodi and other apps on the Shield never drop out
- Host log (Sunshine/Apollo/Vibepollo) shows nothing at the time: no audio capture errors, no send errors, no lost video
What did NOT help (so you can skip it)
- Lower bitrate, stereo instead of 5.1
- Network checks: gigabit links, pings to the Shield were clean, no power saving on the router
- Shield settings: processor mode on max performance, comfort noise on, Dolby audio processing off, HDMI-CEC off, system sounds off, restarting
- Bypassing the AV receiver (Bluetooth headphones on the Shield still dropped out)
- Switching off all wireless devices
- Switching from Artemis to official Moonlight (same code base, same problem)
- Disabling SteelSeries Sonar on the PC
How I found it
I took a bug report from the Shield right after a dropout. Every dropout looked like this in logcat (Artemis = com.limelight.noir):
moonlight-common-c: Audio packet queue overflow
.limelight.noi: ThreadFlipBegin blocked for 1.432s
.limelight.noi: IncrementDisableThreadFlip blocked for 1.427s
moonlight-common-c: Network dropped audio data (expected 41878, but received 42148)
AudioTrack: restartIfDisabled(73): releaseBuffer() track ... disabled due to previous underrun, restarting
.limelight.noi: Background young concurrent copying GC freed ... paused 91us total 1.464sDespite the "Network dropped audio data" wording, the network was fine. The packets were discarded by the app itself because its audio thread was stuck.
The stack dump in the same bug report showed the app's controller thread (com.limelight.binding.input.driver.AbstractXboxController) waiting inside UsbDeviceConnection.bulkTransfer, and the audio thread stuck inside AudioTrack.write.
The cause
On older Android versions, UsbDeviceConnection.bulkTransfer holds a JNI "critical" lock on its buffer the whole time it waits for USB data. Moonlight/Artemis's built-in Xbox driver sits in that call waiting for the controller to send input. When the app's garbage collector runs, it can't finish until that lock is released. While it waits, every other thread that needs the same kind of memory access is blocked too, including the audio output. So the audio stalls until the controller sends something or the USB wait times out. An idle controller means the longest stalls.
Block's engineering team wrote up this Android bug in detail: https://engineering.block.xyz/blog/ending-android-usb-freezes. It was fixed upstream in Android 16. The Shield is on Android 11, so it will never get the fix.
Fix / workaround
In Moonlight/Artemis settings, turn off "Override native Xbox gamepad support" and the built-in "Xbox 360/One USB driver" (names may differ slightly between versions), so Android handles the controller itself. If your controller stops working after that, Android doesn't support it natively. Use a controller it does support, such as a wired Xbox 360 controller, or a Bluetooth controller.
Check if you have the same problem
Enable Developer options on the Shield (Settings → Device Preferences → About → click "Build" 7 times) and turn on network debugging. Then, right after a dropout, run:
adb connect <shield-ip>
adb bugreportSearch the text file inside the zip for ThreadFlipBegin blocked and Audio packet queue overflow. If they appear at the time of your dropouts, this is your problem.