ALVR icon indicating copy to clipboard operation
ALVR copied to clipboard

App completely freezes

Open FingrMastr opened this issue 7 years ago • 32 comments

This is a detailed report of this problem: timeframe and log of server side and client side of ALVR.

The streaming started successfully and without noticeable stutter. In this particolar test it went well for exactly 9 munites and 53 seconds. Then the Quest app freezed completely showing the last static frame. If I move head, no movement in the headset, but server preview window shows correct tracking.

The freeze for me is occurring with variable timeframe from about 7-8 minutes to 20-25 minutes.

The exact time when it occurred is 11:49:00. Here is an extract of Logcat from Android Studio:

2019-10-18 11:48:53.000 12804-12906/com.polygraphene.alvr I/ALVR Native: Sending timesync. 2019-10-18 11:48:53.006 12804-12906/com.polygraphene.alvr I/ALVR Native: TimeSync: server - client = 83078 us RTT = 5750 us 2019-10-18 11:48:53.102 12804-12920/com.polygraphene.alvr I/VrApi: FPS=72,Prd=82ms,Tear=0,Early=0,Stale=0,VSnc=1,Lat=1,Fov=0,CPU4/GPU=3/3,1958/515MHz,OC=FF,TA=0/E0/0,SP=N/F/N,Mem=1804MHz,Free=1397MB,PSM=0,PLS=0,Temp=29.0C/0.0C,TW=2.21ms,App=7.88ms,GD=0.00ms,CPU&GPU=8.36ms,LCnt=1,GPU%=0.64,CPU%=0.41(W0.53) 2019-10-18 11:48:53.483 12804-12905/com.polygraphene.alvr E/OutputFrameQueue: FrameQueue is full. Discard old frame. 2019-10-18 11:48:54.000 12804-12906/com.polygraphene.alvr I/ALVR Native: Sending timesync. 2019-10-18 11:48:54.003 12804-12906/com.polygraphene.alvr I/ALVR Native: TimeSync: server - client = 83865 us RTT = 3002 us 2019-10-18 11:48:54.102 12804-12920/com.polygraphene.alvr I/VrApi: FPS=72,Prd=84ms,Tear=0,Early=0,Stale=0,VSnc=1,Lat=1,Fov=0,CPU4/GPU=3/3,1958/515MHz,OC=FF,TA=0/E0/0,SP=N/F/N,Mem=1804MHz,Free=1396MB,PSM=0,PLS=0,Temp=29.0C/0.0C,TW=2.19ms,App=7.95ms,GD=0.00ms,CPU&GPU=8.36ms,LCnt=1,GPU%=0.60,CPU%=0.40(W0.48) 2019-10-18 11:48:55.000 12804-12906/com.polygraphene.alvr I/ALVR Native: Sending timesync. 2019-10-18 11:48:55.010 12804-12906/com.polygraphene.alvr I/ALVR Native: TimeSync: server - client = 80121 us RTT = 9809 us 2019-10-18 11:48:55.102 12804-12920/com.polygraphene.alvr I/VrApi: FPS=72,Prd=76ms,Tear=0,Early=0,Stale=0,VSnc=1,Lat=1,Fov=0,CPU4/GPU=3/3,1958/515MHz,OC=FF,TA=0/E0/0,SP=N/F/N,Mem=1804MHz,Free=1396MB,PSM=0,PLS=0,Temp=29.0C/0.0C,TW=2.18ms,App=7.96ms,GD=0.00ms,CPU&GPU=8.39ms,LCnt=1,GPU%=0.61,CPU%=0.39(W0.48) 2019-10-18 11:48:56.000 12804-12906/com.polygraphene.alvr I/ALVR Native: Sending timesync. 2019-10-18 11:48:56.006 12804-12906/com.polygraphene.alvr I/ALVR Native: TimeSync: server - client = 82575 us RTT = 6152 us 2019-10-18 11:48:56.103 12804-12920/com.polygraphene.alvr I/VrApi: FPS=72,Prd=78ms,Tear=0,Early=0,Stale=0,VSnc=1,Lat=1,Fov=0,CPU4/GPU=3/3,1958/515MHz,OC=FF,TA=0/E0/0,SP=N/F/N,Mem=1804MHz,Free=1396MB,PSM=0,PLS=0,Temp=29.0C/0.0C,TW=2.18ms,App=7.83ms,GD=0.00ms,CPU&GPU=8.37ms,LCnt=1,GPU%=0.65,CPU%=0.45(W0.48) 2019-10-18 11:48:57.000 12804-12906/com.polygraphene.alvr I/ALVR Native: Sending timesync. 2019-10-18 11:48:57.006 12804-12906/com.polygraphene.alvr I/ALVR Native: TimeSync: server - client = 81958 us RTT = 6309 us 2019-10-18 11:48:57.103 12804-12920/com.polygraphene.alvr I/VrApi: FPS=72,Prd=80ms,Tear=0,Early=0,Stale=0,VSnc=1,Lat=1,Fov=0,CPU4/GPU=3/3,1958/515MHz,OC=FF,TA=0/E0/0,SP=N/F/N,Mem=1804MHz,Free=1395MB,PSM=0,PLS=0,Temp=30.0C/0.0C,TW=2.19ms,App=8.04ms,GD=0.00ms,CPU&GPU=8.37ms,LCnt=1,GPU%=0.63,CPU%=0.44(W0.50) 2019-10-18 11:48:58.000 12804-12906/com.polygraphene.alvr I/ALVR Native: Sending timesync. 2019-10-18 11:48:58.007 12804-12906/com.polygraphene.alvr I/ALVR Native: TimeSync: server - client = 82355 us RTT = 7010 us 2019-10-18 11:48:58.103 12804-12920/com.polygraphene.alvr I/VrApi: FPS=72,Prd=82ms,Tear=0,Early=0,Stale=0,VSnc=1,Lat=1,Fov=0,CPU4/GPU=3/3,1958/515MHz,OC=FF,TA=0/E0/0,SP=N/F/N,Mem=1804MHz,Free=1401MB,PSM=0,PLS=0,Temp=30.0C/0.0C,TW=2.19ms,App=7.97ms,GD=0.00ms,CPU&GPU=8.33ms,LCnt=1,GPU%=0.63,CPU%=0.40(W0.47) 2019-10-18 11:48:58.717 12804-12905/com.polygraphene.alvr E/OutputFrameQueue: FrameQueue is full. Discard old frame. 2019-10-18 11:48:59.000 12804-12906/com.polygraphene.alvr I/ALVR Native: Sending timesync. 2019-10-18 11:48:59.006 12804-12906/com.polygraphene.alvr I/ALVR Native: TimeSync: server - client = 82945 us RTT = 6469 us 2019-10-18 11:49:00.001 12804-12906/com.polygraphene.alvr I/ALVR Native: Sending timesync. 2019-10-18 11:49:00.011 12804-12906/com.polygraphene.alvr I/ALVR Native: TimeSync: server - client = 80622 us RTT = 9729 us 2019-10-18 11:49:00.311 12804-12906/com.polygraphene.alvr E/ALVR Native: NAL Queue is full. 2019-10-18 11:49:00.325 12804-12906/com.polygraphene.alvr E/ALVR Native: NAL Queue is full. 2019-10-18 11:49:00.335 12804-12906/com.polygraphene.alvr E/ALVR Native: NAL Queue is full. 2019-10-18 11:49:00.353 12804-12906/com.polygraphene.alvr E/ALVR Native: NAL Queue is full.

The log "NAL Queue is full" is then the only log, until I closed the app from Android Studio stop button. Please note that when the freeze occurs, the right menu button is not working anymore. There is no way of doing ABSOLUTELY nothing then. I noticed however, that if I brutally close SteamVR, the app returns in the white connection screen and Quest returns to be responsive.

At this link are the logs form the Server app, with normal and frameindex log enabled, for the very same timeframe:

https://drive.google.com/open?id=1uHwyIC7OzfeLGIbxQCs6pWvK3drN_g1D

I do believe this problem is connected with performance degradation.

Client compiled V7 apk, and Server app V7 downloaded from releases.

My PC system is i5 6 cores, GPU RTX 2070, 16Gb RAM, TP-Link router ethernet cabled to PC, wifi 5Ghz AC-Only fixed at 40Mhz channel width.

ALVR configuration for the test was 50Mbit bitrate, 200Kb buffer, 100% resolution, sliced FFR set 3, no steam audio.

As I said before, I think it is an App related problem.

FingrMastr avatar Oct 18 '19 10:10 FingrMastr

In the past weeks, I tried various client side little optimizations, such as assigning static priority to threads, so diminishing main thread load, and adding the sync code in some not atomic queue calls... But this problem persists, as the performance degradation. Please note however, that my understanding of App structure is limited, and I touched only the java side of code. For now.

FingrMastr avatar Oct 18 '19 10:10 FingrMastr

The problem occours on your system much faster than on mine. I have to play nearly an hour to get to the same point of which makes it very hard to debug the performance issues and errors like this. Can you test something for me? Can you try to enable the video debug output and check if the video file gets corrupted when the issues occour? You can replay the video using ffplay. If the video is okay, the tracking and the encoding are not the source of the problem.

JackD83 avatar Oct 18 '19 12:10 JackD83

Same issue here. When it freezes menu button doesn't work anymore. Sometimes it recovers after a little while, but then it stutters badly until I restart the Apk manually, and sometimes it plainly crashes.

Also one time I had to restart the Quest because after the crash Oculus home was not responding and stuttering.

It seems like a thread that is blocking part of the App instead of releasing control. Even after I close manually, the thread doesn't terminate right away, and after a few seconds there is a crash message box.

Another thing is when I push the menu button while in a game, and it goes back to Quest OS (where I can choose to stop or resume), if I try to resume the App the screen is black (no video stream), but I still hear the sound and the tracking is working. I don't know if it's related or even if it's the intended bahavior.

LibreGit avatar Oct 18 '19 17:10 LibreGit

Ok, I have the capture output video. It is absolutely perfect. No artifacts whatsoever. 6Gigabites of H265 correct encoding, until I quitted steamVR because the Quest app was freezed. This time were 19 minutes.

@JackD83 What do you think, could it be the Android decoder that's buggy? It is the only reasonable cause apart of some main thread related mess on the app. It's the App, anyway, not the server.

FingrMastr avatar Oct 18 '19 17:10 FingrMastr

I cannot believe we cannot fix this issue!! c'mon! The only competitor ALVR has is Virtual Desktop and it's much less technologically advanced. And it uses TCP for streaming (not optimal at all).

FingrMastr avatar Oct 18 '19 17:10 FingrMastr

Maybe we give the decoder bad frames. I have no experience with video or even android.

For a test we could write the h265 stream in a file on the quest and see if that’s working. Detecting the nal could also be faulty and causing problems

JackD83 avatar Oct 18 '19 18:10 JackD83

Look, V1 experimental with the manual resolution fix is working flawlessly. Thanks to the DAS I'm now able tot play Skyrim for hours on end and yesterday i played for 3 hours straight without a single hickup... Maybe you guys should restart from scratch and take up where V1 ended... Or use it for referencing...

TC-VR avatar Oct 19 '19 10:10 TC-VR

@TC-VR could you please describe with detail used ALVR settings and also your PC specs? Thank you

FingrMastr avatar Oct 19 '19 11:10 FingrMastr

@JackD83 are you able to isolate exactly which changes were made from V1 to V2? This way we could create a V7 without the V2 changes. I know it is not exactly the best way to debug but this beast is very nasty. This afternoon also I will use android studio debugger and wait for the freeze with a breakpoint on the “NALQueue is full” and try to go up in the executor. But checking content of queues and identity of NAL packets this way is not simple...

FingrMastr avatar Oct 19 '19 11:10 FingrMastr

@FingrMastr : not home right now, I'll provide you with my full specs later.

PC: Gigabyte H370 HD3 mobo, Intel i5 8400 cpu, 16GB DDR4 ram, Gigabyte GTX 1070 Network : Gigabit Ethernet (Intel® GbE LAN), WIFI AC Router 5Ghz, placed in line of sight, computer connected via ethernet to router, connection speed 867 Mbs (as reported by Virtual Desktop). Software: Win 10, latest release - ALVR streamer V1, Oculus Quest 9.0, ALVR Client V1 experimental

Notes: Someone suggested I uninstalled the GeForce Experience software because it could interfere with bandwidth, so i did....

Order of startup:

  1. Restart the Quest

  2. Run the adb commands for the correct Quest resolution (with USB C cable connected to USB 3.1 port) adb shell setprop debug.oculus.textureWidth 1440 adb shell setprop debug.oculus.textureHeight 1600

  3. Disconnect the Quest and start the client first so the streamer reports gets the correct resolution straight away.

  4. Start ALVR streamer Settings:

  • Codec: H.265 HEVC
  • Birate: 40 Mbps
  • Video Resimution 100% 2880x1600
  • Buffer 200 Kb
  1. Restart Steam and run the Steam Server from ALVR streamer.

Results:

  • In Skyrim with some mods and Super sampling set to 200% in-game, the textures look very good and crisp with just moderate compression when running.
  • The Lab looks gorgious and plays just like my Rift S (which i swapped for the Quest). Maybe the controllers are a bit off angle but nothing I can't adapt to. No compression visible.
  • Pavlov VR looks very good with just minor noticable lag on gun movement.
  • Google Earth VR looks gorgious with a very crisp image and no artefacts or compression, very impressive.

Some compression but NO frames lost in + 3 hours. No stutters. Impressive.

Up next: Elite Dangerous...

I run a Hackintosh, so if you want i could test it on MacOS (High Sierra) using the very same hardware.

Thanks for the hard work!

TC-VR avatar Oct 19 '19 11:10 TC-VR

@FingrMastr there where not many commits on the client overall. The one commit that stands out is this one It contains changes to the NALQueue and the decoder! I have to admit that I merged it from another repo cause the changes looked good and I had no immediate problems. The rest of the commits are changes to tracking, cleanup/refactoring, mic streaming and then the ffr implementations

JackD83 avatar Oct 19 '19 16:10 JackD83

Yes, I already saw and corrected the code change in NALQueue, it has a pair of bad concurrency errors, the ConcurrentLinkedQueue is thread safe “by factory” only on atomic calls, and requires the synchronized statement on methods that are not atomic. However that problem is not causing the performance degradation. I think it’s the decoder change.

However, in the meantime, I discovered that a change you made in the NVENC configuration was causing an encoding configuration that the android decoder do not like. I reverted that and this afternoon I tested for hours, and degradation is still there but at least freeze seems to be gone. Also, initial performance this way is slightly enhanced.

This night I will revert the decoder change and test for another pair of hours. Then if tests are positive, @JackD83 you’ll guide me on how to push to GitHub and how to do a pull request (I’m pretty new to GitHub)... I feel old ;-)

FingrMastr avatar Oct 19 '19 17:10 FingrMastr

@FingrMastr just fork this repo and push all your changes. You can then easily create a pull request. I’m looking forward to it!

JackD83 avatar Oct 19 '19 19:10 JackD83

Last night I did some more testing.

These two lines of decoder, merged from another repo, are a little too extreme: format.setInteger(MediaFormat.KEY_OPERATING_RATE, Short.MAX_VALUE); format.setInteger(MediaFormat.KEY_PRIORITY, 0);

The first one sets the decode to possibly the max rate. This is fine, as the Android decoder this way has no cap whatsoever. The second one sets the decoder to act “real-time”, so no queue at all. This, in case of lost frames, can cause decoder bad behavior and eventually a crash. I reverted this second line. This mitigated even more the performance degradation, but not resolved (still, sigh). This mod, however, used with “aggressive key frame resend”, in my case is prolonging the playable time a lot.

Regarding the encoder (pc side), NVENC encoding profile was changed after V1, and I reverted to the old one. Android decoder seems not to like that other profile. This in my case resolved completely the freeze problem in my tests.

The remaining optimizations I made are marginal and not affecting performance.

I want to do some more tests, and then I’ll push the changes.

FingrMastr avatar Oct 20 '19 12:10 FingrMastr

After some more tests it seems, as I said, optimizations are resolving the freeze but only mitigating a bit the performance degradation...

I’m almost giving up on this, and thinking about a big rewrite of socket part, separating in two channels TCP and UDP...

FingrMastr avatar Oct 21 '19 08:10 FingrMastr

That sounds like a good but time consuming plan. Can you publish what you've done so far so we can test it and feedback any comments?

Digeeboy avatar Oct 21 '19 09:10 Digeeboy

@FingrMastr That's great work already.

If you managed to find a solution to the freezes and to make it more stable, that means a lot less work to do to resolve the other issues.

Also we need to find a way to include real sliced encoding to reduce latency on the receive/decode/render part. VD's author has been working on it and already has promissing stuff, so we know it's possible.

LibreGit avatar Oct 21 '19 11:10 LibreGit

@FingrMastr please don't give up, we need you ;) I quickly made the same changes than you did and reverted some changes made after ev1 with the same results. Still performance degradation. Then I disabled ffr and played for 1,5h without any problems...this bug is crazy and probably stupid.

Maybe we should be a little more systematic in finding the issue. I started to use the already implemented debug flags to trigger some special output or disable some features. The flags are applied on the server and client on runtime.

Some ideas to test are:

  • disable tracking
  • disable audio client/server
  • disable mic client/server
  • flush nal queue
  • flush/clear socket client/server
  • re-init decoder

Maybe we find a way out of the bad state and can go one from there. After we fixed this, we can go one an think about further improvements @LibreGit

I'm very busy right now and it will be mid November till I can do some implementations.

JackD83 avatar Oct 21 '19 17:10 JackD83

@jackd83 Any chance of a release of your version which is running ok without ffr ??

Digeeboy avatar Oct 21 '19 18:10 Digeeboy

I just set it to disabled. But I think its no indication that this is the cause. I just got lucky. FFR wasn't introduced until ev4

JackD83 avatar Oct 21 '19 19:10 JackD83