1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "capture_session_utils.h"
18 
19 #include "zsl_snapshot_capture_session.h"
20 
21 namespace android {
22 namespace google_camera_hal {
23 
CreateCaptureSession(const StreamConfiguration & stream_config,const std::vector<WrapperCaptureSessionEntryFuncs> & wrapper_capture_session_entries,const std::vector<ExternalCaptureSessionFactory * > & external_capture_session_entries,const std::vector<CaptureSessionEntryFuncs> & capture_session_entries,HwlSessionCallback hwl_session_callback,CameraBufferAllocatorHwl * camera_buffer_allocator_hwl,CameraDeviceSessionHwl * camera_device_session_hwl,std::vector<HalStream> * hal_config,ProcessCaptureResultFunc process_capture_result,NotifyFunc notify)24 std::unique_ptr<CaptureSession> CreateCaptureSession(
25     const StreamConfiguration& stream_config,
26     const std::vector<WrapperCaptureSessionEntryFuncs>&
27         wrapper_capture_session_entries,
28     const std::vector<ExternalCaptureSessionFactory*>&
29         external_capture_session_entries,
30     const std::vector<CaptureSessionEntryFuncs>& capture_session_entries,
31     HwlSessionCallback hwl_session_callback,
32     CameraBufferAllocatorHwl* camera_buffer_allocator_hwl,
33     CameraDeviceSessionHwl* camera_device_session_hwl,
34     std::vector<HalStream>* hal_config,
35     ProcessCaptureResultFunc process_capture_result, NotifyFunc notify) {
36   // first pass: check predefined wrapper capture session
37   for (auto sessionEntry : wrapper_capture_session_entries) {
38     if (sessionEntry.IsStreamConfigurationSupported(camera_device_session_hwl,
39                                                     stream_config)) {
40       return sessionEntry.CreateSession(
41           stream_config, external_capture_session_entries,
42           capture_session_entries, hwl_session_callback,
43           camera_buffer_allocator_hwl, camera_device_session_hwl, hal_config,
44           process_capture_result, notify);
45     }
46   }
47 
48   // second pass: check loaded external capture sessions
49   for (auto externalSession : external_capture_session_entries) {
50     if (externalSession->IsStreamConfigurationSupported(
51             camera_device_session_hwl, stream_config)) {
52       return externalSession->CreateSession(
53           camera_device_session_hwl, stream_config, process_capture_result,
54           notify, hwl_session_callback, hal_config, camera_buffer_allocator_hwl);
55     }
56   }
57 
58   // third pass: check predefined capture sessions
59   for (auto sessionEntry : capture_session_entries) {
60     if (sessionEntry.IsStreamConfigurationSupported(camera_device_session_hwl,
61                                                     stream_config)) {
62       return sessionEntry.CreateSession(
63           camera_device_session_hwl, stream_config, process_capture_result,
64           notify, hwl_session_callback, hal_config, camera_buffer_allocator_hwl);
65     }
66   }
67   return nullptr;
68 }
69 
70 }  // namespace google_camera_hal
71 }  // namespace android