moonlight-stream / moonlight-android

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

Sound cuts out #988

Closed maddogspeighty closed 2 years ago

maddogspeighty commented 2 years ago

I've had an issue since yesterday when I last had a go, I've replicated the problem on the shield tv and android phone, I connect to an aws vm, it was working fine over a week ago.

When starting a game the sound is either not there or if it is it will eventually cut out and go silent.

I can sometimes get it back by coming out of moonlight and then resuming and the sound may come back, if it does it is then out of sync.

I can also start a game and have sound, if I come out of moonlight and then go back and resume the sound has normally gone.

I can't think of what I can try, I've tried reinstalling geforce experience, reinstalling moonlight.

I've tested with parsec and the sound doesn't cut out and go silent.

It's either moonlight or my aws vm.

cgutman commented 2 years ago

What version of GeForce Experience is on your AWS VM?

Do you have a PC that you can use to test streaming from your AWS VM? It will be much easier to get logs from Moonlight on PC. If so, please try the latest portable development build from here: https://ci.appveyor.com/project/cgutman/moonlight-qt/builds/39582824/job/sswiuj0wtam00r0s/artifacts

maddogspeighty commented 2 years ago

I've tested the windows version again and it's fine, I've gone back to 9.9.2 build and it's working fine, no sound Drop outs.

cgutman commented 2 years ago

Can you answer the rest of the questions though? Downgrading is not an option on some platforms, so if there’s a Moonlight bug, I need to get the information required to fix it.

What version of Geforce Experience are you running?

Did you just test the official v3.1.3 PC release or the actual version I linked in the previous post?

maddogspeighty commented 2 years ago

I dont have my vm on at the moment but it is the geforce version this script installs.

https://github.com/acceleration3/cloudgamestream

As far as I'm aware I cant update as it is the version that works with Tesla T4's.

I'm using the 3.1.3 build and its working fine, tested at home and at my workplace, I can test with the portable build if you like, I don't think it will show anything as the issues only really persisted on the android version.

Let me know if you need anything else.

cgutman commented 2 years ago

The reason I asked specifically about testing that specific development build of Moonlight PC is because Moonlight PC v3.1.3 lacks the significant audio handling changes that recent iOS and Android versions (and that development build) have. It's nearly a complete rewrite of how GameStream audio data is handled to enable Moonlight to recover dropped audio packets.

When I release Moonlight PC v3.1.4, it will contain those audio changes. If they are introducing regressions for some users, I need to know to make sure I'm not breaking existing users with the update and to fix users that are currently affected on iOS and Android.

maddogspeighty commented 2 years ago

I can test the build above then, what are you wanting from me once I've tested it.

cgutman commented 2 years ago

If you could upload the Moonlight.log files after streaming and let me know if the audio sounded okay or not, that would be fantastic. Moonlight's logs will be in the same folder as Moonlight.exe.

maddogspeighty commented 2 years ago

Will do that now and then post the logs, hopefully it will help.

maddogspeighty commented 2 years ago

To confirm geforce version is 3.13.0.85.

Here are my logs.

Audio didnt drop or not start at all, only thing I noticed which I also notice on the android version is when resuming a game that has already been started is the audio seems to be slightly out of sync, for example, when in a menu for a game and it audio clicks when you move up and down, on the first boot of a game its in sync, when closing and then resuming the audio click happens slightly after pressing up or down.

Moonlight-1623858562.log Moonlight-1623859242.log

maddogspeighty commented 2 years ago

Did you manage to have a look.

cgutman commented 2 years ago

I did. I need to confirm GFE 3.13 sends FEC packets and I'm going to PoC a version without packet loss recovery to see if that can help stop the audio from getting behind. I am also going to try to reproduce the issue manually by inducing the same failures in your logs.

maddogspeighty commented 2 years ago

Thanks for letting me know, hope you manage to work it out.

cgutman commented 2 years ago

I think I have a fix. Give this APK a try on your Android devices: https://drive.google.com/file/d/1BrpcBLv5C5M0aAYSdBeOURQqu0vmqZdK/view?usp=sharing

It should hopefully solve the both the audio cutouts and the delay.

maddogspeighty commented 2 years ago

I've tested it and unfortunately I can't get any sound with that version.

cgutman commented 2 years ago

Indeed, there was a bug handling surround sound modes on old GFE versions in that APK.

Try this one: https://drive.google.com/file/d/1UmO-dLk-QvwmYoVa96m8u6XwS5Ux1f7H/view?usp=sharing

maddogspeighty commented 2 years ago

We definitely have progress so thanks, I no longer loose sound but there is still an audio delay after resuming a game, no delay when first starting a game.

cgutman commented 2 years ago

Does the delay happen both with stereo and surround sound audio modes in Moonlight?

Can you see if this APK improves/fixes the delay? I want to see if I'm on the right track. https://drive.google.com/file/d/1Rjje_-npq1E-1LTvEcqzG9U2ZcoDqBAL/view?usp=sharing

maddogspeighty commented 2 years ago

I will check tomorrow and report back, cheers.

maddogspeighty commented 2 years ago

Tested and it doesn't seem to make a difference whether I have stereo or surround sound enabled, the audio delay is still the same.

cgutman commented 2 years ago

OK, interesting. Does the audio delay go away completely with v9.9.2?

Can you collect some new Moonlight logs from this latest development build on your PC client? https://ci.appveyor.com/project/cgutman/moonlight-qt/builds/39693254/job/2t30cqe4mgifmgkr/artifacts

maddogspeighty commented 2 years ago

No, the audio delay was still there on 9.9.2 after resuming a game.

I've tested the build above and the delay seemed to be better, still seemed to be slightly behind though, here's my log.

Moonlight-1624349604.log

maddogspeighty commented 2 years ago

Did my latest log help at all.

cgutman commented 2 years ago

Yes, I understand what's going on but it's going to be rather complex to fix. Fortunately, I'm glad to know it's not a regression, so it won't block shipping the other fix.

What you're experiencing is a result of bufferbloat. Some router (likely on the Internet) between your client and host is buffering a bunch of packets then bursting them out all at once, rather than delivering them at a steady constant rate like they should.

This is the cause of those Video decode unit queue overflow warnings in your logs too. The bursts of data are so big that it results in more than 15 (!) frames being queued all at once. That's over 250 ms worth of frames being thrown at the client all at one time. Since the display is still refreshing at 60 FPS (16.67 ms), we obviously can't display all 15 frames in 16 ms, so we have to drop most of them.

The same thing is happening to your audio data. While those audio packets accumulate in the buffers of the router waiting to be sent out, the time that they should have been played on the client comes and goes. When the burst of audio data finally comes, we end up with ~250 ms of data to play in a ~5 ms period. This huge batch fills up buffers all throughout the stack including the socket's receive buffer, audio packet queue, and the playback buffer of the audio device itself. Since the audio playback device consumes exactly 5 ms worth of audio data every 5 ms, there's nowhere for that extra accumulated audio data from the packet burst to drain and the accumulated latency in the buffers and queues remains.

The fix is to implement code to immediately drop audio packets that are too late to play. However, this is much easier said than done. Host and client clocks can drift over time and network routes changes can cause persistent reduction or increases of latency while streaming, so what "late" means can change by the second. This logic has to be written and tested extremely carefully so as to not break previously working setups.

maddogspeighty commented 2 years ago

I know on the first load of a game the audio is in sync, if I don't come out of it and then resume do you think the audio should stay in sync, I haven't had chance to test for a long period to see if that's the case.

DragarX commented 2 years ago

Any progress on this? I still have audio cut out issues on Chromecast using moonlight 9.10.1

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.