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