Skip to content

Fix: Streaming stops working after device sleep/wake#33

Merged
b1ume merged 1 commit into
b1ume:mainfrom
danielvanpaass:fix-not-streaming-after-sleep
May 17, 2026
Merged

Fix: Streaming stops working after device sleep/wake#33
b1ume merged 1 commit into
b1ume:mainfrom
danielvanpaass:fix-not-streaming-after-sleep

Conversation

@danielvanpaass

@danielvanpaass danielvanpaass commented May 12, 2026

Copy link
Copy Markdown
Contributor

Fix: Streaming stops working after device sleep/wake

Problem

After putting the device to sleep and waking it up, the Hyperion LEDs would stop responding even though the app UI showed streaming as active.

Root cause

The Hyperion FlatBuffers client kept the TCP socket open during sleep. On wake the encoder was still running its capture loop, but Hyperion's priority source had been removed server-side because no new image data was received. The previous approach of calling clearLights() on screen off — which sent an explicit Clear command over the socket — was racing with in-flight setImage() calls on the same non-thread-safe FlatBufferBuilder, producing corrupted frames that Hyperion discarded, leaving the LEDs permanently off until the app was restarted.

Solution

Clean pause on screen off, clean reconnect on screen on.

  • ACTION_SCREEN_OFF → stop the capture loop (pauseRecording) + close the socket (pauseConnection)
  • ACTION_SCREEN_ON → open a fresh socket (resumeConnection) + restart the capture loop (resumeRecording)

The VirtualDisplay and ImageReader are kept alive across sleep so no MediaProjection permission prompt is shown on wake.

Changes

HyperionThread.kt

  • Added pauseConnection(): cancels any pending frame task, closes the socket, clears clientRef — leaves the executor running so it's ready for reconnect
  • Added resumeConnection(): submits a new createClient() call on the executor; fires onConnected() on success

HyperionScreenEncoder.java / HyperionScreenEncoderBase.java

  • Added pauseRecording() (abstract in base, implemented in encoder): stops the capture runnable and sets mRunning = false without releasing the VirtualDisplay or ImageReader

HyperionScreenService.java

  • ACTION_SCREEN_OFF: replaced clearLights() with pauseRecording() + pauseConnection()
  • ACTION_SCREEN_ON: replaced the stale !isCapturing() guard with unconditional resumeConnection() + resumeRecording()

Tested on Shield 2017 with Android 11

@b1ume

b1ume commented May 17, 2026

Copy link
Copy Markdown
Owner

thank you so much man, i have been busy with ur exams and appreciate ur updates, thank you so much for fixing issues :D

@b1ume
b1ume merged commit 5c4c64f into b1ume:main May 17, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants