Repository navigation
fix(android): synchronize viewfinder inversion with mirror stream state - #65
Merged
Merged
Conversation
Previously, MainActivity.updateMirrorUi inverted the viewfinder preview logic for front-facing cameras (shouldInvertView = if (isFront) !isMirrored else isMirrored). This caused an inversion defect where the front camera preview displayed inverted (-1f) when mirror mode was OFF and un-inverted (1f) when mirror mode was ON, creating a desync between the live viewfinder and stream mirror state. CameraX PreviewView naturally renders the front camera in selfie orientation and the back camera unmirrored. Applying viewfinderScaleX directly ensures: - Mirror OFF (isMirrored = false): scaleX = 1f (CameraX natural orientation) - Mirror ON (isMirrored = true): scaleX = -1f (inverted preview matching stream flip) Consolidate the viewfinder scale calculation in CameraMirror.viewfinderScaleX() and add unit test coverage in CameraMirrorTest.
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
Resolves an inversion defect where the phone's live viewfinder and RTP/H.264 stream mirror states fell out of sync when using the front-facing camera.
Problem Description
CameraX
PreviewViewnaturally renders front-facing camera feeds mirrored (selfie mode) and rear camera feeds unmirrored.Previously,
MainActivity.updateMirrorUievaluated:This inverted logic caused:
isMirrored = false):scaleX = -1f(front viewfinder was inverted, desynced from natural preview and stream).isMirrored = true):scaleX = 1f(front viewfinder was un-inverted, opposite of stream flip).Solution
CameraMirror.viewfinderScaleX(isMirrored: Boolean): Float:isMirrored = false->scaleX = 1f(natural CameraX orientation for both front and back lenses)isMirrored = true->scaleX = -1f(horizontal flip matching stream mirror transform)MainActivity.updateMirrorUito bind directly toCameraMirror.viewfinderScaleX(isMirrored).CameraMirrorTest.ktverifying static scale logic and instance state transitions.Verification
JAVA_HOME=/usr/lib/jvm/java-17-openjdk ./gradlew test --rerun-tasksPASSED (51/51 tasks executed).go test ./...PASSED.fix/mirror-preview-sync.