moonlight-stream / moonlight-android

GameStream client for Android
GNU General Public License v3.0
4.15k stars 665 forks source link

Audio latency when using Android TV clients on some TVs #1161

Open safijari opened 1 year ago

safijari commented 1 year ago

Describe the bug So first off I don't know if this is a moonlight bug, but I'm also not sure where else to post this. There is an AV sync problem that appears to be different when using the same client device (I've tried on Chromecast, FireTV, and Nvidia Shield) on various displays. Specifically, the output audio is delayed when playing from the TV. At first I thought this was an issue with a new TV that I had bought but that doesn't seem to be the case. Lemme try to describe what happens as best as I can:

Say I'm using a CCWGTV (4K) and running moonlight on it. If I connect it to my monitor, I notice little to no issues with audio latency. If I connect it to my old TV (some old Samsung LCD TV) I notice a slight audio latency. If I connect it to my LG C1 or Hisense U7H, I notice what sounds like 100ms ish audio latency (i.e the audio is lagging behind the video). On both these TVs, if I connect my Steam Deck instead I see no noticeable latency when using moonlight (which in my mind at least rules out the TV). The latency issue exists in all 3 Android TVs I've tried, with it being slightly less on the Nvidia Shield.

The funny thing is that if I plug in USB headphones directly to the Android TV device, there's no noticeable latency in the audio, so whatever is happening is happening in some HDMI related audio processing. Note that game mode is on on all TVs, and I've tried my best to disable 5.1 audio and any audio processing in all the TVs as well as Android TV devices.

Steps to reproduce Plug a chromecast or firetv into an LG C1 or Hisense U7H TV and stream your computer to it using moonlight.

Affected games The issue does not appear to be game specific.

Other Moonlight clients No, when using moonlight on my Steam Deck and connecting it to the same TVs, there's no audio latency. It appears to be Android TV specific.

Moonlight settings (please complete the following information) The problem exists with default settings as well.

Device details (please complete the following information)

Server PC details (please complete the following information)

allenwp commented 1 year ago

I’m not sure this would be helpful, but I made a tool for measuring HDMI audio latency of devices like TVs, soundbars, etc. If you want to rule out audio processing delay that happens with HDMI inputs on your Android TV, you could try measuring its audio latency and compare to other devices that don’t experience this issue.

https://avlatency.com/tools/av-latency-com-toolkit/

Emmanuel-Tsapekis commented 1 year ago

I have precisely the same problem. I have described the issue in this Reddit post I found that a great way to measure the latency is in the audio settings of the game "Hi-Fi Rush" and this YouTube video It's definitely the android tv moonlight application. I didn't try on mobile android, but I guess that should be my next try!

EDIT: I just tried on my android phone and would you guess it - no latency! I'm not sure if the android tv app is different from the mobile android app. That could still be to blame if not the OS

Emmanuel-Tsapekis commented 1 year ago

I'm a programmer btw. I haven't worked on Android or even worked open source before, but maybe I should take a look to see if I can't fix it myself. If anyone has advice on where to start looking, that would be great!

Emmanuel-Tsapekis commented 1 year ago

Taking a look, it would seem that it's an android tv OS problem. Maybe it's just my version (android 10) though - I have no way of checking whether it's fixed in android versions 11+

inox9 commented 3 weeks ago

Unfortunately it's still not fixed in Android TV 11 - on xiaomi stick 4k audio is behind video for around 500 ms at least. Are there any plans on fixing this?