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

Replace deprecated Android Camera framework with Camera2 #2797

Merged
merged 2 commits into from
Feb 8, 2022

Conversation

nanangizz
Copy link
Member

@nanangizz nanangizz commented Aug 13, 2021

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 use SurfaceView 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').

pjmedia/src/pjmedia-videodev/android/PjCamera2.java Outdated Show resolved Hide resolved

/* 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants