Search code examples
androidandroid-camera2

Camera2 replacing one logical stream with two physical streams in Android API 29


When Android 9(API 28) was released, I was very happy to discover that the physical cameras of the phones with multiple cameras would be exposed, I had been very frustrated to not be able to access them. Today I stumbled upon the android Q documentation which says:

Starting from API level 29, some or all physical cameras may not be independently exposed to the application, in which case the physical camera IDs will not be available in CameraManager.getCameraIdList(). But the application can still query the physical cameras' characteristics by calling CameraManager.getCameraCharacteristics(String).

This statement confuses me, does it mean that Android is backtracking? what's the purpose of the change?

I'm interested in managing cameras at a very fine level, will this change prevent me from doing what I'm able to do today with Android 9?

It says that the IDs may not be listed any more but that the characteristics can still be queried, how are we supposed to get the characteristics of cameras without having their IDs? I guess we are supposed to get the physical cameras' IDs via getPhysicalCameraIds() on logical cameras, but does it means that if we wanted to use a "hidden" camera, we'd have to test a bunch of random ID strings?

enter image description here

And will we still be able to create capture sessions with SessionConfiguration on physical cameras that are not exposed?

Can someone shed some light on this?


Solution

  • This is not backtracking. Actually, this generalization is an important step to provide you with better control of complex camera setups.

    Before API 29, if the manufacturer could not provide separate cameraDevice for each of the lenses that constitute a composite camera, they had no way to expose the lens parameters to the developer. Their only choice was to expose the composite camera as whole.

    The question is not

    And will we still be able to create capture sessions with SessionConfiguration on physical cameras that are not exposed?

    but rather,

    And now we can read the characteristics of physical cameras that could not be exposed before‼

    With the new change, the manufacturer can give you all available info on "Back camera1", "Back camera2", etc. even if there is no way to start separate capture sessions on them.

    getPhysicalCameraIds() reference explains:

    Prior to API level 29, all returned IDs are guaranteed to be returned by CameraManager.getCameraIdList(), and can be opened directly by CameraManager.openCamera(). Starting from API level 29, for each of the returned ID, if it's also returned by CameraManager.getCameraIdList(), it can be used as a standalone camera by CameraManager.openCamera(). Otherwise, the camera ID can only be used as part of the current logical camera.

    This means that you can use any id returned by getPhysicalCameraIds() in CameraManager.getCameraCharacteristics(id):

    From API level 29, this function can also be used to query the capabilities of physical cameras that can only be used as part of logical multi-camera. These cameras cannot not be opened directly via openCamera(String, CameraDevice.StateCallback, Handler).