moonlight-stream / moonlight-android

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

Choppy video on Android 12 (Pixel 4a 5g) Edit: And other devices #1108

Open famus484 opened 1 year ago

famus484 commented 1 year ago

Describe the bug

Even though moonlight renders at 60 fps, the video feed is very choppy. It happens with all frame pacing options, with "Prefer smoothest video" not yielding good results. The results are somewhat better on Balanced (the new one) than the rest, but it still is choppy and there and the rendering framerate often drops a bit below incoming (maybe it is by design?).

On Android 11 with same phone, Balanced with FPS limit yelds a very fluid video.

It happens with both stock Android 12 and custom roms such as LineageOS 19.1 or GrapheneOS.

Affected games All the games I tried, including emulators and halo infinite. Probably happens independently?

Moonlight settings (please complete the following information) The problem occurs whether I select HEVC or AVC, and whether I use stretch the screen or not. As in the description, Frame pacing option has an impact, but not the intended one, as Lowest latency (12) ~ Balanced with FPSlimit (12) ~ Smoothest video (12) < Balanced (12) ~Balanced (11) <<<<<< Balanced with FPS limit (11)~Balanced with FPS limit (ShieldTV, Firestick)~Default settings on Qt

Device details (please complete the following information)

Additional context As Moonlight is a very important use case of my phone, and as the choppy video breaks my immersion, I will probably be returning on Android 11 for the time being, and I don't have another pixel to test android 12. I can reinstall Android 12 relatively quickly to help test anything. If that problem is solvable, I would probably return on 12 as it's better practice for security.

cgutman commented 1 year ago

Interesting. I am using Android 12 on my Pixel 6 Pro and have not seen any degradation in video smoothness. Since Android 12 has been out almost a year without reports like this, I suspect it must be something more specific to your individual device or configuration.

Do you see additional network latency or network latency variance on Android 12 vs Android 11 when using the performance overlay?

famus484 commented 1 year ago

Oh actually I had the issue since the day Android 12 on came out, with the cycle "Upgrade to 12-> immediately notice bug -> factory reset -> still bug -> Downgrade to 11" happening multiple times since last year. I didn't report it earlier because I was just confortable staying on 11 anyways.

I don't think it is likely to be my phone configuration, as factory reset did not help. I even installed a rom without google, went straight to Moonlight and nothing else installed and still had it. But yes, it must be my specific phone model.

I don't remember seeing anything unusual in the stats (I should have taken screenshots before reverting to android 11 lol). But is it a likely cause? If network was the problem, shouldn't "smoothest video" still put out a smooth stream, just giving me more latency?

I must say, it could very well be a problem with Android 12 implementation on my phone. I had other issues, one being the battery degrading very quicker than on Android 11.

As far as I was experimenting, it's as if Balanced should have been working fine, but often rendering framerate dipped 0.5FPS below incoming, corresponding to "choppy spikes". Actually, that's also the behavior of Balanced on Android 11, I just tested (while BwFPSl works good on 11). Is that dip typical?

famus484 commented 1 year ago

So I'd suspect that the "Balanced" dip is a problem specifically for my device whatever OS, and that if it's solvable here in 11 then all I would have to do once in Android 12 is select Balanced?

For the rest of the modes, thinking about it, it's as if they don't behave discernly differently (I guess I should measure on a bigger sample) whether I select lowest, BwFPSl or smoothest in Android 12, while they do quite a lot in Android 11.

cgutman commented 1 year ago

If network was the problem, shouldn't "smoothest video" still put out a smooth stream, just giving me more latency?

No, we can only display the frames we receive as we receive them. If we're having periods of time where no video traffic is making it through, there's nothing we can do to cover that up.

As far as I was experimenting, it's as if Balanced should have been working fine, but often rendering framerate dipped 0.5FPS below incoming, corresponding to "choppy spikes". Actually, that's also the behavior of Balanced on Android 11, I just tested (while BwFPSl works good on 11). Is that dip typical?

Potentially. If frames are coming in at inconsistent rates due to network jitter, we have to drop them or latency will accumulate. Dropped frames are not unusual at all since a given frame only has a 16 ms delivery window to hit before it gets superseded by the next one. Anything as simple as a bit of WiFi congestion/interference, network/CPU usage by other apps, and plenty more can cause that tiny window to be missed and a frame to be dropped.

Out of curiosity, have you tried the Android 13 beta to see if the problem persists there?

For the rest of the modes, thinking about it, it's as if they don't behave discernly differently (I guess I should measure on a bigger sample) whether I select lowest, BwFPSl or smoothest in Android 12, while they do quite a lot in Android 11.

That is interesting and may imply that whatever is causing the stuttering issue is too large to be smoothed over by even the greatest buffering of frames that we can do.

famus484 commented 1 year ago

No, we can only display the frames we receive as we receive them. If we're having periods of time where no video traffic is making it through, there's nothing we can do to cover that up.

Oh, I see! When I re-upgrade I will check, but from what I remember there was no particular big latency. In all modes (except balanced), it felt as snappy as always, about sub-frame latency at 60fps.

That is interesting and may imply that whatever is causing the stuttering issue is too large to be smoothed over by even the greatest buffering of frames that we can do.

It is definitely possible. Although it doesn't feel more choppy then "lowest latency" on Android 11 (which is expected to be choppy). And here, "smoothest" definitely buffers the video sufficiently for smoothness, which I could tell by the clear huge latency and butter smoothnest of the stream. My memory may be wrong, but I don't remember my phone even trying to buffer on 12 with the same smoothest setting (no bigger latency and still as choppy).

Potentially. If frames are coming in at inconsistent rates due to network jitter, we have to drop them or latency will accumulate. Dropped frames are not unusual at all since a given frame only has a 16 ms delivery window to hit before it gets superseded by the next one. Anything as simple as a bit of WiFi congestion/interference, network/CPU usage by other apps, and plenty more can cause that tiny window to be missed and a frame to be dropped.

What I meant was, is "balanced" mode expected to drop more frames/have a lower FPS than all the other modes (including balanced with fps limit and lowest)? In my case, even on Android 12 (certainly in 11), balanced was the only one not yielding the exact same framerate as incoming (ex: often incoming 59.94 while rendering 59.42 in Balanced).

I was thinking about trying 13 beta to see, I guess tomorrow will be a good day to test it. As no Android 12 update has solved it up until now, I doubt Google would fix whatever they did that broke my thing though, and expect them to break more of my things.

Thank you for your help and advice

famus484 commented 1 year ago

All right, I went and installed Android 13 beta, the problem still persists. I took screenshots in both Android 11 and 13 (I could post them here if you prefer), all modes, to compare, and here is what I found:

-The problem is most definitely not Network (as I thought, since it would have been made clear to me, or I'd feel the latency). In Android 13, Network latency was 2-4 ms with variance 2-4ms about all the time (makes sense, as I'm just besides the router, host ethernet). I have decent reliable smooth streams in much, much less good network conditions (on 11 ofc).

-In fact, the problem with Android 12-13 can't be identified from performance overlay. In every mode, all the stats on 11 look as they do on 13 (and probably 12).

-The stats also look very similar (statistically identical) between the modes Lowest latency, BalancedwFPSL and Smoothest video. 1920x1080, incoming same as rendering varying around 60FPS, 0% frames dropped and between 9 to 12 decoding time.

-The only difference with those modes and Balanced is that in that last mode, the rendering framerate is often lower than incoming by about 0.5-1FPS . Other than that, same stats (including 0.00% dropped frames, I don't think I dropped a single frame during the whole test). As earlier, that applies to all Android versions.

Those numbers seem to confirm my hypothesis, that there could be two separate problems. The first one is that in Android 13 (and 12 yesterday), "Balanced with FPS limit" and "smoothest video" behave exactly like "prefer lowest latency", while in Android 11 there is clear and easily distinguishable differences between all 3 modes. I think the missing statistic "Rendering time", which is present in Qt version, would tell that story (I suppose Android doesn't expose it to apps?).

The second one is that "Balanced" mode, accross all Android versions, struggles to keep up with incoming, correlating with choppier stream. I remember a few months ago I had the same problem before on other devices (including my ShieldTV), which you had solved by including "Balanced with FPS limit".

Solving anyone of these problems is definitely sufficient for me, as it would leave me with an enjoyable option in Android 12-13. Although I do it more because it could be an relatively important problem if others experience it. The more I hop between roms, the more I prefer Android 11 (which I'll go back to soon unless you have more tests for me).

famus484 commented 1 year ago

Alright, so I went and collected logcats (adb logcat -c -> open moonlight and change frame pacing, stream a game for a bit, leave the app, adb logcat -d ) for each of the modes, on Android 13. Hope they can help, I sent them to you personally. I'll go back to Android 11 for now, as I need the rest of my phone. I can do the logcat thing there also if it helps.

Cheers!

Delayer2208 commented 1 year ago

I have this issue aswell on a Nokia G20 I tested it on 2 devices 1 with android 11 and the other with android 12 unfortunately their is no way to downgrade back to android 11 on a nokia Hope this gets resolved

Delayer2208 commented 1 year ago

Also the persistent notifications to upgrade android 11 to android 12 on a Nokia are annoying

famus484 commented 1 year ago

I have recently aquired a samsung galaxy tab s6 lite, and it confirms my hypothesis. On Android 10, all modes worked as they should. When upgraded to Android 12, BwFPSl and smoothest video produced a choppy feed. Here though, Balanced worked very well.

I would suspect all Android 12 devices have an inferior experience in BwFPSL 60FPS (also smoothest video). A way to see it is take move the camera around horizontally continously in a smooth shooter/adventure game. The smoothness->sudden choopyness->smoothnest should be clear.

For any device for which "Balanced" works well, such as the Galaxy Tab S6 lite, it's not that much of an issue. But for the other devices, upgrading to Android 12 means a less immersive Moonlight experience. That means that the Shield itself (which didn't work well with "Balanced" if memory serves right) will be a problem when Nvidia releases Android 12/13

Delayer2208 commented 1 year ago

Can confirm issue is still present even after multiple google security updates

hunterzero99 commented 1 year ago

I am not 100% certain this is the same issue, but I recently launched Moonlight on my Chromecast with Google TV (ccwGTV) that has been updated to Android TV 12. This release enabled a Variable Frame Rate feature, that changes the framerate to match a video feed. With Moonlight the framerate is always being changed to 24 or 23.97 fps (I'm not sure which, my HDMI receiver lists both as 24). If I turn off the refresh rate switching option in the system menu, it renders properly at 60 fps and the choppiness goes away.

Here's an article on the feature. I believe the API documentation of what needs to be implemented to properly set the frame rate now is here.

If this is unrelated let me know and I'll open a new bug report or feature request for this.

Delayer2208 commented 1 year ago

Can confirm issue is fixed On my nokia G20 android 12 frame pacing is set n balanced with mantaining fps and Hevc is disabled issue is still present when Hevc is enabled I did not try all the frame pacing options only Balance with fps everything is functioning as it should thx