Skip to content

Turn off works while the camera is still connecting - #5

Merged
Qwinty merged 1 commit into
mainfrom
claude/camera-turn-off-bug-2f3db4
Sep 29, 2026
Merged

Qwinty merged 1 commit into
mainfrom
claude/camera-turn-off-bug-2f3db4

Conversation

@Qwinty

@Qwinty Qwinty commented Sep 29, 2026

Copy link
Copy Markdown
Owner

Reported by a tester: sometimes Turn off doesn't stop the phone camera, only pulling the cable does. It happened most often after switching front/back and waiting a moment.

Cause

Pipeline::stop() sets the stop flag and shuts down the video socket to wake the pipeline thread. While server::start is still running (status "Connecting"), there is no socket yet. When the start finishes, stream() begins reading. That loop only checked the flag after a failed read, and a healthy stream never fails one. So stop() waited in join() forever while holding the lifecycle lock. The phone kept streaming and "Plugcam Camera" kept getting frames until the cable was pulled. A later Turn on would also hang. Switching front/back restarts the pipeline, which opens that Connecting window again.

Fix

The stream loop checks the stop flag before every packet. The one-line change is in src-tauri/src/pipeline.rs, plus comments.

Checks

  • Reproduced before the fix on a OnePlus 11R over USB, using a throwaway example (not committed) that drives the real Pipeline. Stopping 0.3 s after start (still Connecting) went 2/2 like this: the phone started streaming after the stop, stop() was still blocked after 20 s, and it returned only after the server was killed on the phone.
  • After the fix: stops at 0, 0.3 and 0.6 s into Connecting went 6/6. stop() returned in 0.4–1.0 s and no scrcpy server was left on the phone. Control stops while streaming still return in ~0.25 s.
  • cargo test --release: 63 passed. cargo clippy --all-targets: no new warnings.

Not in this PR: a stop during Connecting still waits for server::start to finish (about 1 s normally, up to ~13 s in the worst case) before it returns.

Pressing Turn off (or switching front/back, which restarts the camera)
while the server was starting left the phone streaming: stop() had no
socket to shut down yet, and the stream loop only looked at the stop
flag when a read failed, which a healthy stream never does. stop() then
waited forever, holding the lifecycle lock, and "Plugcam Camera" kept
getting frames until the cable was pulled.

The stream loop now checks the stop flag on every packet.

Co-authored-by: Claude <noreply@anthropic.com>
@Qwinty
Qwinty merged commit d2d2d3f into main Sep 29, 2026
1 of 2 checks passed
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.

1 participant