Last active
November 3, 2018 00:30
-
-
Save owahltinez/fdb0404e019048f9b1e5b00a86b3edab 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 type definition that encapsulates 3 sets of output targets: | |
* | |
* 1. Logical camera | |
* 2. First physical camera | |
* 3. Second physical camera | |
*/ | |
typealias DualCameraOutputs = | |
Triple<MutableList<Surface>?, MutableList<Surface>?, MutableList<Surface>?> | |
fun createDualCameraSession(cameraManager: CameraManager, | |
dualCamera: DualCamera, | |
targets: DualCameraOutputs, | |
executor: Executor = AsyncTask.SERIAL_EXECUTOR, | |
callback: (CameraCaptureSession) -> Unit) { | |
// Create 3 sets of output configurations: one for the logical camera, and | |
// one for each of the physical cameras. | |
val outputConfigsLogical = targets.first?.map { OutputConfiguration(it) } | |
val outputConfigsPhysical1 = targets.second?.map { | |
OutputConfiguration(it).apply { setPhysicalCameraId(dualCamera.physicalId1) } } | |
val outputConfigsPhysical2 = targets.third?.map { | |
OutputConfiguration(it).apply { setPhysicalCameraId(dualCamera.physicalId2) } } | |
// Put all the output configurations into a single flat array | |
val outputConfigsAll = arrayOf( | |
outputConfigsLogical, outputConfigsPhysical1, outputConfigsPhysical2) | |
.filterNotNull().flatMap { it } | |
// Instantiate a session configuration that can be used to create a session | |
val sessionConfiguration = SessionConfiguration(SessionConfiguration.SESSION_REGULAR, | |
outputConfigsAll, executor, object : CameraCaptureSession.StateCallback() { | |
override fun onConfigured(session: CameraCaptureSession) = callback(session) | |
// Omitting for brevity... | |
override fun onConfigureFailed(session: CameraCaptureSession) = session.device.close() | |
}) | |
// Open the logical camera using our previously defined function | |
openDualCamera(cameraManager, dualCamera, executor = executor) { | |
// Finally create the session and return via callback | |
it.createCaptureSession(sessionConfiguration) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment