Reputation: 11920
Looking at Camera2 API, it appears that a surface needs to be specified twice. Once it is done during createCaptureSession
, passing in the list of surfaces. At a later point, we once again specify the same surface to the preview-builder's addTarget
method. If we are going to specify the target surfaces later, why do we need to specify the list of surfaces initially during createCaptureSession
call? What does addTarget
really do with the surface that createCaptureSession
is not doing? Regards.
Upvotes: 0
Views: 679
Reputation: 18137
For the capture session, you need to list all the Surfaces you might want to use for your requests. This allows the camera device to configure its hardware processing pipelines to be able to provide all those outputs at the requested sizes and for the requested destinations (such as 1080p preview to SurfaceView/TextureView, full-resolution JPEGs to ImageReaders, 4K video recording buffers to MediaRecorder, and so on)
Then each request includes a subset (or all) of those Surfaces. Not every request will generally want to include every configured Surface; you'd usually only include the full-resolution JPEG ImageReader Surface for snapshots, and only include the MediaRecorder Surface when actively recording video.
If the Surfaces were only included in the capture requests, then the camera pipeline would have to reconfigure itself on the fly when it sees a new Surface that hasn't been used before. This generally causes a 300-600 ms pause as the camera hardware flushes out its data and reconfigures itself.
So to ensure smooth operation, the camera2 API requires the application to specify all the desired outputs for the current session up front.
Upvotes: 6