Replace deprecated Android Camera framework with Camera2#2797
Merged
Replace deprecated Android Camera framework with Camera2#2797
Conversation
… Android API level 21).
sauwming
approved these changes
Aug 16, 2021
|
|
||
| /* Check if we need conversion here, this is the tricky part of camera2. | ||
| * When we request I420, the returned buffer may not be actually I420, | ||
| * for example it is NV21 in Samsung S10. The camera2 'cheats' us via |
Member
There was a problem hiding this comment.
Maybe it's better to move device-specific testing to the issue desc/comment instead. One reason is that there will be timestamp that can be easily tracked in the issue page.
Member
Author
There was a problem hiding this comment.
The code comment is about a sample case & details of the buffer trick by camera2 which is closely related to the conversion checks done in the following code, instead of a specific device test result. Anyway, the device may exhibit different behavior in the future which can be confusing, so I just stripped it out.
- Strip out device name. - A bit optimization: query p0/1/2_len only when needed, cache the address of end-of-plane-0 in p0_end.
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.
Camera2 is the latest Android camera framework API that replaces the deprecated camera framework libraries, as described here. This framework is added in API level 21 (or Android 5.0 released in Oct 2014). In this framework, enumerating cameras and their capabilities (e.g: format, size) does not seem to need camera permission, so application can request for user permission only when about to use it (instead of in the library initialization).
PS: there is also CameraX framework as jetpack support library, which seems to be a wrapper of both Camera & camera2 frameworks, but it seems to be still in alpha version. Also it does not seem to work (straightforwardly) with
SurfaceViewfor video preview (initially this is the main reason of not using this framework, but lately realized that we useSurfaceViewfor debugging purpose only).An interesting fact when testing camera2 in Samsung S10, it does not report NV21 format capability as in older framework Camera, it reports I420/YUV_420_888 capability (along with few private formats). However, when capturing using I420 format, the returned frame buffer is actually in NV21 format, but represented as I420 via camera2 Plane structure, which has 'pixel stride' attribute (note: it is different from 'row stride').