Replace deprecated Android Camera framework with Camera2 #2797
+734
−27
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
SurfaceView
for video preview (initially this is the main reason of not using this framework, but lately realized that we useSurfaceView
for 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').