Fix MJPEG fallback glitch: serialize pipeline + guard decoder#44
Merged
Conversation
- Serialize rebuildPipeline with a Mutex and make currentCodecMode @volatile so viewport rebuilds and codec switches can't race into dual encoders (VideoEncoder + JpegEncoder) with a last-write-wins VD surface. - Collapse onCodecModeRequest into a delegate that sets the mode and reruns rebuildPipeline under the lock — single code path for encoder/VD setup. - Client: MJPEG decoder drops non-JPEG payloads (magic-byte check) to avoid InvalidStateError spam during the codec-switch startup window. - Client: for MJPEG mode, open the control socket and wait for it before connecting video, so the server receives the codec preference before streaming starts. - Split drawer: group apps by category (Navigation/Video/Music/Apps) with colored section headers. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The "should a codec-mode request trigger a rebuild?" decision was inline inside MirrorForegroundService.onCodecModeRequest, which is an Android Service and therefore not reachable from JVM unit tests. Moving the three-line guard into a CodecModeTransition pure object lets the decision table be covered directly (non-mjpeg rejected, already-mjpeg-with-encoder no-op, and the stale-mode recovery case where the mode flag is "mjpeg" but the JpegEncoder is missing). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Suprhimp
added a commit
that referenced
this pull request
Apr 24, 2026
* Fix MJPEG fallback glitch: serialize pipeline + guard decoder - Serialize rebuildPipeline with a Mutex and make currentCodecMode @volatile so viewport rebuilds and codec switches can't race into dual encoders (VideoEncoder + JpegEncoder) with a last-write-wins VD surface. - Collapse onCodecModeRequest into a delegate that sets the mode and reruns rebuildPipeline under the lock — single code path for encoder/VD setup. - Client: MJPEG decoder drops non-JPEG payloads (magic-byte check) to avoid InvalidStateError spam during the codec-switch startup window. - Client: for MJPEG mode, open the control socket and wait for it before connecting video, so the server receives the codec preference before streaming starts. - Split drawer: group apps by category (Navigation/Video/Music/Apps) with colored section headers. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * Extract codec-mode transition guard into testable pure policy The "should a codec-mode request trigger a rebuild?" decision was inline inside MirrorForegroundService.onCodecModeRequest, which is an Android Service and therefore not reachable from JVM unit tests. Moving the three-line guard into a CodecModeTransition pure object lets the decision table be covered directly (non-mjpeg rejected, already-mjpeg-with-encoder no-op, and the stale-mode recovery case where the mode flag is "mjpeg" but the JpegEncoder is missing). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <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.
Summary
rebuildPipelineis now serialized with aMutex, andcurrentCodecModeis@Volatile. Previously, a viewport resize and acodec: mjpegswitch could run concurrently onDispatchers.Default, leaving bothVideoEncoderandJpegEncoderalive while the VD surface was last-write-wins — clients requested MJPEG but received H.264 (or vice versa).onCodecModeRequestnow just sets the mode and delegates torebuildPipelineunder the same lock, removing the duplicated encoder/VD bring-up logic that diverged from the primary path.fallback.jsdrops payloads that don't start with the JPEG SOI (FF D8) to silence theInvalidStateErrorspam that appeared during the brief startup window before the server acknowledgedcodec: mjpeg.Navigation / Video / Music / Appswith colored section headers.Test plan
InvalidStateErrorspam.🤖 Generated with Claude Code