Turn off works while the camera is still connecting - #5
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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. Whileserver::startis 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. Sostop()waited injoin()forever while holding thelifecyclelock. 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
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.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::startto finish (about 1 s normally, up to ~13 s in the worst case) before it returns.