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_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_CAPTURE_SESSION_H_
19 
20 #include <utils/Errors.h>
21 
22 #include <vector>
23 
24 #include "camera_buffer_allocator_hwl.h"
25 #include "camera_device_session_hwl.h"
26 #include "hal_types.h"
27 #include "hwl_types.h"
28 
29 namespace android {
30 namespace google_camera_hal {
31 
32 // CaptureSession defines the interface of a capture session. Each capture
33 // session is associated with a certain stream configuration.
34 // Classes that inherit this interface class should provide a
35 //   1. IsStreamConfigurationSupported() for the client to query whether a
36 //      stream configuration is supported by this capture session.
37 //   2. Create() for the client to create a capture session and get a unique
38 //      pointer to the capture session.
39 //
40 // A capture session can use RequestProcessor, ProcessBlock, and ResultProcessor
41 // to form chains of process blocks. A simple capture session can create a
42 // simple chain like
43 //
44 //   RequestProcessor -> ProcessBlock -> ResultProcessor
45 //
46 // If additional post-processing is needed, more ProcessBlock can be added to
47 // the process chain like
48 //
49 //   RequestProcessor -> ProcessBlock_0 -> Result/RequestProcessor ->
50 //   ProcessBlock_1 -> ResultProcessor
51 //
52 // Each implementation of RequestProcess, ProcessBlock, and ResultProcessor must
53 // clearly define their capabilities.
54 class CaptureSession {
55  public:
56   virtual ~CaptureSession() = default;
57 
58   // Process a capture request.
59   virtual status_t ProcessRequest(const CaptureRequest& request) = 0;
60 
61   // Flush all pending capture requests.
62   virtual status_t Flush() = 0;
63 
64   virtual void RepeatingRequestEnd(int32_t frame_number,
65                                    const std::vector<int32_t>& stream_ids) = 0;
66 };
67 
68 // ExternalCaptureSessionFactory defines the interface of an external capture
69 // session, in addition to `class CaptureSession`.
70 class ExternalCaptureSessionFactory {
71  public:
72   virtual ~ExternalCaptureSessionFactory() = default;
73 
74   // IsStreamConfigurationSupported is called by the client to query whether a
75   // stream configuration is supported by this capture session.
76   virtual bool IsStreamConfigurationSupported(
77       CameraDeviceSessionHwl* device_session_hwl,
78       const StreamConfiguration& stream_config) = 0;
79 
80   // Create is called by the client to create a capture session and get a unique
81   // pointer to the capture session.
82   virtual std::unique_ptr<CaptureSession> CreateSession(
83       CameraDeviceSessionHwl* device_session_hwl,
84       const StreamConfiguration& stream_config,
85       ProcessCaptureResultFunc process_capture_result, NotifyFunc notify,
86       HwlSessionCallback session_callback,
87       std::vector<HalStream>* hal_configured_streams,
88       CameraBufferAllocatorHwl* camera_allocator_hwl) = 0;
89 };
90 
91 #if !GCH_HWL_USE_DLOPEN
92 extern "C" __attribute__((weak)) ExternalCaptureSessionFactory*
93 GetCaptureSessionFactory();
94 #endif
95 
96 }  // namespace google_camera_hal
97 }  // namespace android
98 
99 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_CAPTURE_SESSION_H_