thestr4ng3r / chiaki

Moved to https://git.sr.ht/~thestr4ng3r/chiaki - Free and Open Source PS4 Remote Play Client
https://git.sr.ht/~thestr4ng3r/chiaki
2.17k stars 373 forks source link

Controller input gets stuck in loop spamming PS4 and locking user input. #383

Closed Fredrum closed 3 years ago

Fredrum commented 3 years ago

Environment

Describe the bug A couple of times every day Iv'e had this happening, sometimes when I restart chiaki or starting a new game session the in-game is stuck in an input loop, in the game I'm testing with most running on the spot. Whatever is happening is also stopping any further input from the controller reaching the PS4 so I'm not able to break the loop. So far I have been 'fixing' it by un-plugging and re-plugging the controller, and shutting down Chiaki and waiting a bit before starting up again. But now Iv'e been trying to see if I could corner the sequence of events that makes this happen and I think I more or less have it...

To Reproduce Steps to reproduce the behavior:

  1. Start playing a game using a PS4 controller, wired or bluetooth.
  2. Keep the Left or Right trigger pressed in while closing the game stream window.
  3. Close the Main chiaki window straight after to shut Chiaki down.
  4. Wait 3-4 seconds to let the remote wind down, the start the game up again.

It seems if I follow these steps then 75% of the times I can get that loop happening.

I think it seems like I can do this procedure again to unlock the loop. But it seems a bit lower chance for making that work.

Expected behavior The controller input should never be blocked.

Log Files pi@sensitpi:~/chiaki/chiaki/build $ gui/chiaki qt5ct: using qt5ct plugin QEGLPlatformContext: Failed to create context: 3009 [I] Discovery Service detected new host with id 709E29C0519B [I] Logging to file /home/pi/.local/share/Chiaki/Chiaki/log/chiaki_session_2020-11-22_22-35-26-022022.log [I] Chiaki Version 1.3.0 [I] Raspberry Pi Decoder initialized PulseAudioService: pa_context_connect() failed [I] Controller 1 opened: "PS4 Controller" [I] Starting session request [I] Trying to request session from 192.168.1.248:9295 [I] Connected to 192.168.1.248:9295 [I] Sending session request [I] Session request successful [I] Starting ctrl [I] Ctrl connected to 192.168.1.248:9295 [I] Sending ctrl request [I] Ctrl received http header as response [I] Ctrl received ctrl request http response [I] Ctrl connected [I] Ctrl received Login message: success [W] Received Ctrl Message with unknown type 0x6 [W] offset 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef [W] 0 00 00 ..
[I] Ctrl received valid Session Id: 1606113326IZCEAV6ILCSZWQUZLN77VTTYKVH5I4RJGWZWMNAQXUU4NWOZO4FPMLC5WD6PIFIY [I] Starting Senkusha [I] Takion connecting (version 7) [I] Takion enabled Don't Fragment Bit [I] Takion sent init [I] Takion received init ack with remote tag 0x164d97d4, outbound streams: 0x64, inbound streams: 0x64 [I] Takion sent cookie [I] Takion received cookie ack [I] Takion connected [I] Senkusha sending big [I] Senkusha successfully received bang [I] Senkusha Ping Test with count 10 starting [I] Senkusha enabled echo [I] Senkusha sending Ping 0 of test index 0 [I] Senkusha received Pong, RTT = 0.513 ms [I] Senkusha sending Ping 1 of test index 0 [I] Senkusha received Pong, RTT = 0.570 ms [I] Senkusha sending Ping 2 of test index 0 [I] Senkusha received Pong, RTT = 0.495 ms [I] Senkusha sending Ping 3 of test index 0 [I] Senkusha received Pong, RTT = 0.488 ms [I] Senkusha sending Ping 4 of test index 0 [I] Senkusha received Pong, RTT = 0.496 ms [I] Senkusha sending Ping 5 of test index 0 [I] Senkusha received Pong, RTT = 0.543 ms [I] Senkusha sending Ping 6 of test index 0 [I] Senkusha received Pong, RTT = 0.524 ms [I] Senkusha sending Ping 7 of test index 0 [I] Senkusha received Pong, RTT = 0.438 ms [I] Senkusha sending Ping 8 of test index 0 [I] Senkusha received Pong, RTT = 0.468 ms [I] Senkusha sending Ping 9 of test index 0 [I] Senkusha received Pong, RTT = 0.661 ms [I] Senkusha disabled echo [I] Senkusha determined average RTT = 0.519 ms [I] Senkusha starting MTU in test with min 576, max 1454, retries 3, timeout 5 ms [I] Senkusha MTU request 1454 (min 576, max 1454), id 1, attempt 0 [I] Senkusha MTU 1454 success [I] Senkusha determined inbound MTU 1454 [I] Senkusha starting MTU out test with min 576, max 1454, retries 3, timeout 5 ms [I] Senkusha sent initial client MTU command [I] Senkusha received expected Client MTU Command [I] Senkusha MTU 1454 out ping attempt 0 [I] Senkusha MTU ping 1454 success [I] Senkusha determined outbound MTU 1454 [I] Senkusha sending final Client MTU Command [I] Senkusha is disconnecting [I] Senkusha closed takion [I] Senkusha completed successfully [I] Takion connecting (version 9) [I] Takion sent init [I] Takion received init ack with remote tag 0x4b8853, outbound streams: 0x64, inbound streams: 0x64 [I] Takion sent cookie [I] Takion received cookie ack [I] Takion connected [I] StreamConnection sending big [I] BANG received [I] StreamConnection successfully received bang [I] Crypt has become available. Re-checking MACs of 0 packets [D] StreamConnection received audio header: [D] offset 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef [D] 0 02 10 00 00 bb 80 00 00 01 e0 00 00 00 01 ..............
[I] Audio Header: [I] channels = 2 [I] bits = 16 [I] rate = 48000 [I] frame size = 480 [I] unknown = 1 [I] ChiakiOpusDecoder initialized [I] Audio Device default opened with 2 channels @ 48000 Hz, buffer size 19200 [I] Video Profiles: [I] 0: 1280x720 [I] StreamConnection successfully received streaminfo [I] Switched to profile 0, resolution: 1280x720 [I] StreamConnection is disconnecting [I] StreamConnection sending Disconnect [I] StreamConnection was requested to stop [I] StreamConnection closed takion [I] StreamConnection completed successfully [I] Ctrl requested to stop [I] Ctrl stopped [I] Session has quit

Fredrum commented 3 years ago

Hi @tomblind would you be able to point me to a good place in the code to start looking into this? (Or else @thestr4ng3r ?)

tomblind commented 3 years ago

controllermanager.cpp is probably where you want to look. Maybe check HandleEvents() or GetState() to see what SDL is reading for input.

Fredrum commented 3 years ago

Hmm...it seems somewhere the SDL_CONTROLLERAXISMOTION get conflated with other inputs... Ie the IMU rotation inputs gets mistaken or copied to other input streams, or something like that. I'll continue looking...

Fredrum commented 3 years ago

Very confusing. I have to see if we need some other mappings maybe? I read some posts about it not working by default but not sure if that's the case here.

Fredrum commented 3 years ago

When Its locked in the spamming state I get IMU (motion) data added to these varaibles,

state.left_x
state.left_y 
state.right_x
state.right_y 

But if I put a print here:

void ControllerManager::HandleEvents()
{
#ifdef CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER
    SDL_Event event;
    while(SDL_PollEvent(&event))
    {
                 PRINT HERE

I never get a printout from moving or rotating the controller. Does anyone know if there's a different handler where those end up?

Hi @thestr4ng3r did you say that Chiaki needs SDL2 v2.0.4 at the least? As I'm getting 2.0 from the default apt install. (I think 2.0.0)

UPDATE: no actually it tells me libsdl2-dev is already the newest version (2.0.9+dfsg1-1+rpt1).

Update2: Just noticed if I shake the controller really hard (maybe while holding a button) I can get it out of the spamming lock, err...sometimes.

Fredrum commented 3 years ago

Hi @thestr4ng3r I seem now to have something that works with fixing this and probably also the thing in my other issue. It's a bit of a change in approach to how it was before so it would be awesome if you had some time to check it out before I try to put a PR together?

https://github.com/Fredrum/test_01/blob/master/gui/include/controllermanager.h https://github.com/Fredrum/test_01/blob/master/gui/src/controllermanager.cpp https://github.com/Fredrum/test_01/blob/master/gui/include/streamsession.h https://github.com/Fredrum/test_01/blob/master/gui/src/streamsession.cpp

Fredrum commented 3 years ago

I'm right now looking at merging the motion data with the regular input. My first approach is to have a new Controller* member called 'coController'. In Controller init I would connect motion+regular controller to each other. This would enable me to query the motion controller from the GetState() of the regular controller and enable merge.