Repository navigation
VideoInjection: emulate AVCaptureSession.connections and the preview layer's coordinate conversions - #990
VideoInjection: emulate AVCaptureSession.connections and the preview layer's coordinate conversions#990gelasdev wants to merge 2 commits into
Conversation
…layer's coordinate conversions Answer -[AVCaptureSession connections] with the native connections plus the virtual outputs' connections that have input ports. For a preview layer bound to a virtual session, convert rects and points between the layer and the normalised native frame through one transform: the frame placed by videoGravity, turned by the connection's rotation, and mirrored when the connection is mirrored. Move frameSize(_:) out of VirtualCamera so the preview layer uses the same frame shape as its contents, add a CameraFixture roi mode, and update the shim README.
|
Hi @gelasdev! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
…n-connections-roi # Conflicts: # Shims/Shimulator/VideoInjection/VirtualCamera.swift
Motivation
Apps that check
AVCaptureSession.connectionsbefore a photo capture, or that convert between preview-layer and capture-device coordinates, do not work withidb camera injectyet. The Onfido iOS SDK does both in its document capture step:AVCaptureSession.connectionsreturned[]for a session holding the virtual input, so Onfido refused to capture ("Couldn't establish active camera connection on photo capture"). The README lists a session'sconnectionsas not covered.metadataOutputRectConverted(fromLayerRect:)returned the layer rect un-normalised. Onfido computes its crop rect with it, so the crop fell outside the photo ("Something went wrong whilst cropping the captured image").The same conversions are what apps use to set
rectOfInterest, to crop video-data-output frames to an on-screen guide, and to turn a tap into a focus or exposure point.Fixes #989.
This change:
-[AVCaptureSession connections]: for a session with virtual state it returns the native connections plus the connections of the virtual outputs that have input ports, likeinputsandoutputsalready do;metadataOutputRectOfInterestForRect:,rectForMetadataOutputRectOfInterest:,captureDevicePointOfInterestForPoint:andpointForCaptureDevicePointOfInterest:onAVCaptureVideoPreviewLayer: for a layer bound to a virtual session they use one transform from the normalised native frame to the layer (the frame placed byvideoGravity, turned by the preview connection's rotation, mirrored when the connection is mirrored) and its inverse; other layers use the original implementation;frameSize(_:)out ofVirtualCameraso the preview layer uses the same frame shape as itscontents;roimode toCameraFixture;transformedMetadataObjectForMetadataObject:and a preview layer's connection inconnections).Test Plan
iPhone 17 Pro simulator (iOS 26.5), Xcode 26.6, macOS 26.6.2.
./build.sh build Shimulator-iOS.xcrun -sdk iphonesimulator swiftc -parse-as-library -target arm64-apple-ios17.0-simulator CameraFixture/CameraFixture.swift -o CameraFixture.SIMCTL_CHILD_IDB_VIDEO_INJECTION=1 SIMCTL_CHILD_DYLD_INSERT_LIBRARIES=<libShimulator-iOS.dylib> xcrun simctl spawn <UDID> ./CameraFixture roi, then again withSIMCTL_CHILD_CAMFIXTURE_FRONT=1.The layer is 300x600 pt, the rect is (30, 150, 120, 200) and the point is (75, 450). With
resizeAspectat 90 degrees the 1080x1920 frame fills 300x533.3 pt from y = 33.3, so the expected rect is (0.2188, 0.5, 0.375, 0.4). Back camera (excerpt):Front camera (preview mirrored), same input:
Both runs print all 12 gravity and angle combinations and exit 0. The round trip goes through
layerRectConverted(fromMetadataOutputRect:)andlayerPointConverted(fromCaptureDevicePoint:).Onfido iOS SDK 32.6.3, with
idb camera inject document.mp4 --loopand the app launched through the companion: before, the shutter fails at once; after theconnectionschange alone, cropping fails. LLDB values before the change:With both changes Onfido passes its connection check, crops the photo to the document frame, accepts the front and the back, and moves to its selfie step.
Related PRs
None.