Skip to content

Instantly share code, notes, and snippets.

@owahltinez
Created November 2, 2018 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owahltinez/5ef491de0aba98d0123bf28e369449d6 to your computer and use it in GitHub Desktop.
Save owahltinez/5ef491de0aba98d0123bf28e369449d6 to your computer and use it in GitHub Desktop.
val cameraManager: CameraManager = ...
// Get the two output targets from the activity / fragment
val surface1 = ... // from SurfaceView
val surface2 = ... // from SurfaceView
val dualCamera = findShortLongCameraPair(manager)!!
val outputTargets = DualCameraOutputs(
null, mutableListOf(surface1), mutableListOf(surface2))
// Here we open the logical camera, configure the outputs and create a session
createDualCameraSession(manager, dualCamera, targets = outputTargets) { session ->
// Create a single request which will have one target for each physical camera
// NOTE: Each target will only receive frames from its associated physical camera
val requestTemplate = CameraDevice.TEMPLATE_PREVIEW
val captureRequest = session.device.createCaptureRequest(requestTemplate).apply {
arrayOf(surface1, surface2).forEach { addTarget(it) }
}.build()
// Set the sticky request for the session and we are done
session.setRepeatingRequest(captureRequest, null, null)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment