Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Dynamically determine sensorOrientation based on default output-connection-orientation #3046

Merged
merged 15 commits into from
Jul 3, 2024

Conversation

mrousavy
Copy link
Owner

@mrousavy mrousavy commented Jul 3, 2024

What

Previously, we just assumed a default sensor orientation of landscapeLeft on iOS.

While this worked on my iPhone 15 Pro and was also posted as a safe-to-assume default value in Apple Developer Forums, it is apparently not safe to assume that this is the default value. 🤦

On my iPhone 8, the preview was rotated by 90deg.

So instead, this PR now attempts to dynamically get the sensor orientation value by creating a dummy capture session, adding an output to it, and getting it's default orientation value.

This then needs to be rotated by 90deg (I don't know why), and then we have a default orientation value for all phones - I think.

I'd need to test this on iPads and other iPhones first though

Changes

Tested on

Related issues

Copy link

vercel bot commented Jul 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-native-vision-camera ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2024 1:59pm

@mrousavy
Copy link
Owner Author

mrousavy commented Jul 3, 2024

Something interesting I found out is that the new iOS 17 API videoRotationAngle does not do the same thing as the old API videoOrientation.

videoRotationAngle is by default always 0, and setting it to 90 will rotate the output by 90 degrees.

videoOrientation has a default value, for example landscapeRight for back-, and landscapeLeft for front-cameras. Setting this from landscapeRight to portrait will cause it to rotate the output by 90 degrees.

The reason why this is a problem is because with videoRotationAngle we don't know what it's default orientation is. It's like a black-box. We can't just set videoRotationAngle = 90, because what if the output is actually naturally landscapeLeft? Then it would need to be set to 270, not 90. But there is no API to find that out! 🤦

So right now I removed those new APIs, since they won't work with our case. I keep using videoOrientation at least until Apple adds an API for getting the device's native sensor orientation.

@mrousavy mrousavy force-pushed the fix/dynamically-get-sensor-orientation branch from 9873e58 to 3a77305 Compare July 3, 2024 13:57
@mrousavy mrousavy merged commit fadd2f1 into main Jul 3, 2024
8 checks passed
@mrousavy mrousavy deleted the fix/dynamically-get-sensor-orientation branch July 3, 2024 14:00
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.

None yet

1 participant