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 #ifndef HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_CAPTURE_SESSION_UTILS_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_CAPTURE_SESSION_UTILS_H_
19 
20 #include <utils/Errors.h>
21 
22 #include "camera_buffer_allocator_hwl.h"
23 #include "camera_device_session_hwl.h"
24 #include "capture_session.h"
25 #include "hal_types.h"
26 #include "hwl_types.h"
27 
28 namespace android {
29 namespace google_camera_hal {
30 
31 // Session function invoked to query if particular stream config supported
32 using StreamConfigSupportedFunc =
33     std::function<bool(CameraDeviceSessionHwl* device_session_hwl,
34                        const StreamConfiguration& stream_config)>;
35 
36 // Session function invoked to create session instance
37 using CaptureSessionCreateFunc = std::function<std::unique_ptr<CaptureSession>(
38     CameraDeviceSessionHwl* device_session_hwl,
39     const StreamConfiguration& stream_config,
40     ProcessCaptureResultFunc process_capture_result, NotifyFunc notify,
41     HwlSessionCallback session_callback,
42     std::vector<HalStream>* hal_configured_streams,
43     CameraBufferAllocatorHwl* camera_allocator_hwl)>;
44 
45 // define entry points to capture session
46 struct CaptureSessionEntryFuncs {
47   StreamConfigSupportedFunc IsStreamConfigurationSupported;
48   CaptureSessionCreateFunc CreateSession;
49 };
50 
51 // Session function invoked to create wrapper capture session instance
52 using WrapperCaptureSessionCreateFunc =
53     std::function<std::unique_ptr<CaptureSession>(
54         const StreamConfiguration& stream_config,
55         const std::vector<ExternalCaptureSessionFactory*>&
56             external_capture_session_entries,
57         const std::vector<CaptureSessionEntryFuncs>& capture_session_entries,
58         HwlSessionCallback hwl_session_callback,
59         CameraBufferAllocatorHwl* camera_buffer_allocator_hwl,
60         CameraDeviceSessionHwl* camera_device_session_hwl,
61         std::vector<HalStream>* hal_configured_streams,
62         ProcessCaptureResultFunc process_capture_result, NotifyFunc notify)>;
63 
64 // define entry points to capture session
65 struct WrapperCaptureSessionEntryFuncs {
66   StreamConfigSupportedFunc IsStreamConfigurationSupported;
67   WrapperCaptureSessionCreateFunc CreateSession;
68 };
69 
70 // Select and create capture session.
71 // When consider_zsl_capture_session is enabled, we will first consider using
72 // ZslCaptureSession as a wrapper capture session when it supports the given
73 // configurations.
74 std::unique_ptr<CaptureSession> CreateCaptureSession(
75     const StreamConfiguration& stream_config,
76     const std::vector<WrapperCaptureSessionEntryFuncs>&
77         wrapper_capture_session_entries,
78     const std::vector<ExternalCaptureSessionFactory*>&
79         external_capture_session_entries,
80     const std::vector<CaptureSessionEntryFuncs>& capture_session_entries,
81     HwlSessionCallback hwl_session_callback,
82     CameraBufferAllocatorHwl* camera_buffer_allocator_hwl,
83     CameraDeviceSessionHwl* camera_device_session_hwl,
84     std::vector<HalStream>* hal_config,
85     ProcessCaptureResultFunc process_capture_result, NotifyFunc notify);
86 
87 }  // namespace google_camera_hal
88 }  // namespace android
89 
90 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_CAPTURE_SESSION_UTILS_H_