Created
November 2, 2018 21:27
-
-
Save owahltinez/f79c3355f11ce822c4a26154421f3031 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Helper class used to encapsulate a logical camera and two underlying | |
* physical cameras | |
*/ | |
data class DualCamera(val logicalId: String, val physicalId1: String, val physicalId2: String) | |
fun findDualCameras(manager: CameraManager, facing: Int? = null): Array<DualCamera> { | |
val dualCameras = ArrayList<DualCamera>() | |
// Iterate over all the available camera characteristics | |
manager.cameraIdList.map { | |
Pair(manager.getCameraCharacteristics(it), it) | |
}.filter { | |
// Filter by cameras facing the requested direction | |
facing == null || it.first.get(CameraCharacteristics.LENS_FACING) == facing | |
}.filter { | |
// Filter by logical cameras | |
it.first.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES)!!.contains( | |
CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA) | |
}.forEach { | |
// All possible pairs from the list of physical cameras are valid results | |
// NOTE: There could be N physical cameras as part of a logical camera grouping | |
val physicalCameras = it.first.physicalCameraIds.toTypedArray() | |
for (idx1 in 0 until physicalCameras.size) { | |
for (idx2 in (idx1 + 1) until physicalCameras.size) { | |
dualCameras.add(DualCamera( | |
it.second, physicalCameras[idx1], physicalCameras[idx2])) | |
} | |
} | |
} | |
return dualCameras.toTypedArray() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment