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_PROCESS_BLOCK_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_PROCESS_BLOCK_H_
19 
20 #include <utils/Errors.h>
21 
22 #include <vector>
23 
24 #include "camera_device_session_hwl.h"
25 #include "hal_types.h"
26 
27 namespace android {
28 namespace google_camera_hal {
29 
30 class ResultProcessor;
31 
32 // Define a process block request.
33 struct ProcessBlockRequest {
34   uint32_t request_id = 0;  // A unique ID of this process block request.
35   CaptureRequest request;
36 };
37 
38 // Define a process block result.
39 struct ProcessBlockResult {
40   // ID of the ProcessBlockRequest that this result belongs to.
41   uint32_t request_id = 0;
42   std::unique_ptr<CaptureResult> result;
43 };
44 
45 // Define a process block notify message.
46 struct ProcessBlockNotifyMessage {
47   // ID of the ProcessBlockRequest that this message belongs to.
48   uint32_t request_id = 0;
49   NotifyMessage message;
50 };
51 
52 // ProcessBlock defines the interface of a process block. A process block can
53 // process capture requests and sends results to a result processor. A process
54 // block can process capture requests using SW, ISP, GPU, or other HW components.
55 class ProcessBlock {
56  public:
57   virtual ~ProcessBlock() = default;
58 
59   // Configure streams. It must be called exactly once before any calls to
60   // ProcessRequest. It will return an error if it's called more than once.
61   // stream_config contains the streams that may be included in a capture
62   // request.
63   // overall_config contains the whole streams received from frameworks.
64   virtual status_t ConfigureStreams(
65       const StreamConfiguration& stream_config,
66       const StreamConfiguration& overall_config) = 0;
67 
68   // Set the result processor to send capture results to.
69   virtual status_t SetResultProcessor(
70       std::unique_ptr<ResultProcessor> result_processor) = 0;
71 
72   // Get HAL streams configured in this process block.
73   virtual status_t GetConfiguredHalStreams(
74       std::vector<HalStream>* hal_streams) const = 0;
75 
76   // Process a capture request.
77   // When this method is called, process block should forward
78   // process_block_requests and remaining_session_request to the result
79   // processor using ResultProcessor::AddPendingRequests() so the result process
80   // knows what results to expect.
81   //
82   // process_block_requests are the requests for this process block. This method
83   // is asynchronous so returning from this call doesn't mean the requests are
84   // completed. If the process block captures from camera sensors, capturing
85   // from camera sensors must be synchronized for all requests in this call.
86   //
87   // remaining_session_request is the remaining request that was sent to the
88   // capture session. It contains all remaining output buffers that have not
89   // been completed by the process chain yet. For the last result process in a
90   // process chain, remaining_session_request should contain only the output
91   // buffers that are present in process_block_requests.
92   // remaining_session_request doesn't contain any internal buffers.
93   virtual status_t ProcessRequests(
94       const std::vector<ProcessBlockRequest>& process_block_requests,
95       const CaptureRequest& remaining_session_request) = 0;
96 
97   // Flush pending requests.
98   virtual status_t Flush() = 0;
99 
100   virtual void RepeatingRequestEnd(int32_t frame_number,
101                                    const std::vector<int32_t>& stream_ids) = 0;
102 };
103 
104 // ExternalProcessBlockFactory defines the interface of an external process
105 // block, in addition to `class ProcessBlock`.
106 class ExternalProcessBlockFactory {
107  public:
108   virtual ~ExternalProcessBlockFactory() = default;
109 
110   // Create is called by the client to create a process block and get a unique
111   // pointer to the process block.
112   virtual std::unique_ptr<ProcessBlock> CreateProcessBlock(
113       CameraDeviceSessionHwl* device_session_hwl) = 0;
114 
115   virtual std::string GetBlockName() const = 0;
116 };
117 
118 #if !GCH_HWL_USE_DLOPEN
119 extern "C" __attribute__((weak)) ExternalProcessBlockFactory*
120 GetSnapshotProcessBlockFactory();
121 
122 extern "C" __attribute__((weak)) ExternalProcessBlockFactory*
123 GetDenoiseProcessBlockFactory();
124 #endif
125 
126 }  // namespace google_camera_hal
127 }  // namespace android
128 
129 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_PROCESS_BLOCK_H_