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

[MEDIUM] Smartscan: Update to vision camera v3 #30732

Closed
puneetlath opened this issue Nov 1, 2023 · 28 comments
Closed

[MEDIUM] Smartscan: Update to vision camera v3 #30732

puneetlath opened this issue Nov 1, 2023 · 28 comments
Assignees
Labels
Monthly KSv2 NewFeature Something to build that is a new item.

Comments

@puneetlath
Copy link
Contributor

puneetlath commented Nov 1, 2023

Some important changes about V3:

  • Fully rewritten codebase for Android (now uses the low-level Camera API "Camera2" in favor of the more limiting alternative "CameraX")
  • Fully rewritten Frame Processors implementation (now uses react-native-worklets-core, FPs are disabled if Worklets is not installed; should fix a ton of build issues)
  • Fully rewritten Camera Devices API (useCameraDevice(..); useCameraFormat(..) - always have a device, never null)
  • Muuuuch faster (Camera device selection is now instant, and Camera is faster in general)
  • See full changelog here: mrousavy/react-native-vision-camera@v2.16.2...v3.3.0
  • Requires that we bump the min supported Android version and block ~7% of potential users 😬 -- please remove this if we can drop this requirement (@Julesssss )
@puneetlath puneetlath added Weekly KSv2 NewFeature Something to build that is a new item. labels Nov 1, 2023
@puneetlath puneetlath self-assigned this Nov 1, 2023
Copy link

melvin-bot bot commented Nov 1, 2023

Current assignee @puneetlath is eligible for the NewFeature assigner, not assigning anyone new.

@puneetlath
Copy link
Contributor Author

FYI @mrousavy I created a new issue here, since this PR is linked to an issue for iPhone 15 crashing which is no longer happening.

@puneetlath
Copy link
Contributor Author

@mrousavy what do you think are the next steps here? Are we still trying to make v3 happen?

@melvin-bot melvin-bot bot removed the Overdue label Nov 15, 2023
@mrousavy
Copy link
Contributor

mrousavy commented Nov 17, 2023

Hey @puneetlath - yup I got a bunch of other stuff on my plate and the Camera is running fine for now - but I'll try to implement Flash capture soon. I just implemented a basic HAL flash trigger which works on some phones, but for a proper implementation we need a custom precapture sequence that enables the torch, then waits for AE/AF to adjust, then lock AE/AF to that value, turn off the torch again, then capture with a single flash burst, and then turn the torch off again, and return to auto-AE/AF. This is quite complex, so I didn't implement it yet. I'll try to find the time next week.

Once that's done we can update Expensify to VisionCamera V3 :)

@puneetlath
Copy link
Contributor Author

Sounds good!

@puneetlath puneetlath added Monthly KSv2 and removed Weekly KSv2 labels Nov 21, 2023
@Julesssss
Copy link
Contributor

Before moving forward we need to discuss the Android mimimum SDk bump. Losing 5% of our potential users is not worth an improved camera IMO.

@mrousavy
Copy link
Contributor

I think I could also lower the minSdk to 23 or even 21 if needed, I was mostly focused on the video capturing feature when I set it to 26. Should be max. 2 hour effort to make it work on SDK 23/21

@Julesssss
Copy link
Contributor

That's great, we should definitely reduce to 23.

@roryabraham
Copy link
Contributor

Looks like we're adding a vision-camera patch in https://github.com/Expensify/App/pull/31558/files, can we make sure we have an upstream issue and can work to remove the patch in vision-camera v3?

@mrousavy
Copy link
Contributor

Yep - V3 already has a safe fix for this which crashes with a proper error message (only happening if running in bridge-less mode, I'm working on a workaround for that but bridge-less is a while to come).

Just backported the fix to V2.

@puneetlath
Copy link
Contributor Author

Ok so what's the urgency on this? It sounds like the main benefit is that the camera is much faster? If so, should we include this in wave5 since it'll improve the camera speed for SmartScan? cc @dylanexpensify

@melvin-bot melvin-bot bot removed the Overdue label Jan 2, 2024
@dylanexpensify
Copy link
Contributor

@puneetlath agree with this being wave5!

@dylanexpensify dylanexpensify changed the title Update to vision camera v3 HIGH: Update to vision camera v3 Jan 2, 2024
@mrousavy
Copy link
Contributor

Update from Slack:

Yes there are still blockers on my side - sorry about that.
If I remember correctly, those are:

There are also some people saying that there are issues with the Preview View being stretched, although I haven't found a way to reproduce that yet. I do have a fix in mind which requires a bit of a refactor of the CameraSession.kt class, but I wanted to do this for a while now to make sure everything is stable and is better organized in code.

@mrousavy
Copy link
Contributor

Regarding the minSdkVersion; quite a lot of code requires minSdk 26, for example the entire Video Pipeline (video + frameProcessor) would no longer work on SDK <26.

I think it is not a good idea to bring this upstream, but we should be able to roll with a patched version, since photo capture is not affected by this. I think that might work. Do you have so many users on SDK 23?

@Julesssss
Copy link
Contributor

Do you have so many users on SDK 23?

Nope, very few of our users are running 6.0 and below, so SDK 23 is a much more reasonable min version than SDK 26👍

@mrousavy
Copy link
Contributor

Oh I see - you are currently on SDK 21:

minSdkVersion = 21

VisionCamera requires SDK 26: https://github.com/mrousavy/react-native-vision-camera/blob/f400487a8d24711c9998418d746bbab06f54a690/package/android/build.gradle#L107

We thought that bumping the SDK from 23 to SDK 26 is a fair requirement for VisionCamera, since only around 3.3% of Android phones worldwide are on SDK 23, 24, or 25.

image

Afaik, according to Expensify's Google Analytics data for the past week, we have 0 users on SDK 25 or lower.

I think it'd be a fair requirement to bump the minSdk to 26, but it's your call.

I would probably not merge mrousavy/react-native-vision-camera#2414 into main, as fundamental pieces of VisionCamera will need to be wrapped with ifs and they will throw if the user is not on SDK 26 yet - e.g. video capture, frame processing, etc etc.
I'll think about it, but I'd find it weird if there is an error thrown on some phones that aren't on SDK 26 yet for video capture. Instead a hard requirement is much safer. Plus, the JNI HardwareBuffer APIs are available then, I need those.

@Julesssss
Copy link
Contributor

Julesssss commented Jan 19, 2024

Could you share the source for that table, please? I've been using Google's data, which shows a reduction in supported devices from 99.6 to 95.0 (Android Studio > New Project > Help Me Choose), but I'd be interested to check out an alternate source.

In Google Play, our users have a higher device version than the above suggests (1000 active users are on 25 and below), but this is because our existing app supports specific English-speaking countries. With the new app we want to extend our app reach as wide as possible for P2P IOUs and chat. That's why I'm hesitant to block a large amount of potential users for the sake of a few hour work (if that is still true).

@Julesssss
Copy link
Contributor

Julesssss commented Jan 19, 2024

Oh sorry, you're sharing the difference between 23 & 26, not 21 & 26. In that case the Google data shows a lower amount of blocked users, but I still believe it's significant:

Screenshot 2024-01-19 at 10 19 46

@mrousavy
Copy link
Contributor

mrousavy commented Feb 1, 2024

Update: I've merged a ton of stability PRs for Android recently, and will now tackle the blackscreen issues (task 1). I'll probably write a custom CameraCaptureSession wrapper, which will also make it easier to implement flash then (task 2).

As for the minSDK discussion - we can probably patch it in Expensify to have it working for minSDK 23.

@puneetlath
Copy link
Contributor Author

Sounds like a good plan to me. Shall I assign you this issue?

@mrousavy
Copy link
Contributor

mrousavy commented Feb 5, 2024

Sure! 👍

@puneetlath
Copy link
Contributor Author

Hey @mrousavy. Checking in on this. How's it going?

@mrousavy
Copy link
Contributor

Hey! Made some great progress on the Android side, got focus() implemented, got flash implemented, fixed many black screen errors and partially fixed preview stretching. Will take a look at that tomorrow to hopefully finalize everything there, hoping to get a Expensify PR up by end of next week?

@puneetlath
Copy link
Contributor Author

Next week sounds great, thanks for the update.

@mrousavy
Copy link
Contributor

update: I just got a prototype running on my end that works on API 21, so we don’t need to drop the minSdk requirement! 💪

@puneetlath
Copy link
Contributor Author

@mrousavy still on pace for Friday?

@mrousavy
Copy link
Contributor

@puneetlath not sure, we are currently working on a new release and I did encounter an issue on Android. iOS works fine. See #37483

@melvin-bot melvin-bot bot added the Overdue label Apr 1, 2024
@puneetlath
Copy link
Contributor Author

I believe this is no longer relevant since we are upgrading to v4. I'm going to close this out, but feel free to comment or reopen if I'm mistaken!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Monthly KSv2 NewFeature Something to build that is a new item.
Projects
Archived in project
Development

No branches or pull requests

5 participants