• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DUAL_IR_RESULT_PROCESSOR_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_DUAL_IR_RESULT_PROCESSOR_H_
19 
20 #include <map>
21 
22 #include "request_processor.h"
23 #include "result_processor.h"
24 
25 namespace android {
26 namespace google_camera_hal {
27 
28 // DualIrResultRequestProcessor implements a ResultProcessor for a logical
29 // camera that consists of two IR cameras. It also implements a RequestProcessor
30 // for the logical camera to generate depth.
31 class DualIrResultRequestProcessor : public ResultProcessor,
32                                      public RequestProcessor {
33  public:
34   // Create a DualIrResultRequestProcessor.
35   // device_session_hwl is owned by the client and must be valid during the life
36   // cycle of this DualIrResultRequestProcessor.
37   // stream_config is the stream configuration set by the framework. It's not
38   // the process block's stream configuration.
39   // lead_camera_id is the ID of the lead IR camera.
40   static std::unique_ptr<DualIrResultRequestProcessor> Create(
41       CameraDeviceSessionHwl* device_session_hwl,
42       const StreamConfiguration& stream_config, uint32_t lead_camera_id);
43 
44   virtual ~DualIrResultRequestProcessor() = default;
45 
46   // Override functions of ResultProcessor start.
47   void SetResultCallback(
48       ProcessCaptureResultFunc process_capture_result, NotifyFunc notify,
49       ProcessBatchCaptureResultFunc process_batch_capture_result) override;
50 
51   status_t AddPendingRequests(
52       const std::vector<ProcessBlockRequest>& process_block_requests,
53       const CaptureRequest& remaining_session_request) override;
54 
55   void ProcessResult(ProcessBlockResult block_result) override;
56 
57   void Notify(const ProcessBlockNotifyMessage& block_message) override;
58 
59   status_t FlushPendingRequests() override;
60   // Override functions of ResultProcessor end.
61 
62   // Override functions of RequestProcessor start.
63   status_t ConfigureStreams(
64       InternalStreamManager* internal_stream_manager,
65       const StreamConfiguration& stream_config,
66       StreamConfiguration* process_block_stream_config) override;
67 
68   status_t SetProcessBlock(std::unique_ptr<ProcessBlock> process_block) override;
69 
70   status_t ProcessRequest(const CaptureRequest& request) override;
71 
72   status_t Flush() override;
73   // Override functions of RequestProcessor end.
74 
75  protected:
76   DualIrResultRequestProcessor(const StreamConfiguration& stream_config,
77                                uint32_t logical_camera_id,
78                                uint32_t lead_camera_id);
79 
80  private:
81   const uint32_t kLogicalCameraId;
82   const uint32_t kLeadCameraId;
83 
84   // Define a pending result metadata
85   struct PendingResultMetadata {
86     // Result metadata for the logical camera.
87     std::unique_ptr<HalCameraMetadata> metadata;
88     // Map from a physical camera ID to the physical camera's result metadata.
89     std::map<uint32_t, std::unique_ptr<HalCameraMetadata>> physical_metadata;
90   };
91 
92   // If a stream is a physical stream configured by the framework.
93   // stream_id is the ID of the stream.
94   // physical_camera_id will be filled with the physical camera ID if this
95   // method return true.
96   bool IsFrameworkPhyiscalStream(int32_t stream_id,
97                                  uint32_t* physical_camera_id) const;
98 
99   // Add pending physical camera's result metadata to the map.
100   // block_request is a block request used figure out pending results.
101   // physical_metadata is the map to add the pending physical camera's result
102   // metadata to.
103   status_t AddPendingPhysicalCameraMetadata(
104       const ProcessBlockRequest& block_request,
105       std::map<uint32_t, std::unique_ptr<HalCameraMetadata>>* physical_metadata);
106 
107   // Try to send result metadata for a frame number if all of it's result
108   // metadata are ready. Must have pending_result_metadata_mutex_ locked.
109   void TrySendingResultMetadataLocked(uint32_t frame_number);
110 
111   // Process a result metadata and update the pending result metadata map.
112   status_t ProcessResultMetadata(
113       uint32_t frame_number, uint32_t physical_camera_id,
114       std::unique_ptr<HalCameraMetadata> result_metadata);
115 
116   // Map from a stream ID to a camera ID based on framework stream configuration.
117   std::map<int32_t, uint32_t> stream_camera_ids_;
118 
119   std::mutex pending_result_metadata_mutex_;
120 
121   // Map from a frame number to the pending result metadata. Must be protected
122   // by pending_result_metadata_mutex_.
123   std::map<uint32_t, PendingResultMetadata> pending_result_metadata_;
124 
125   std::mutex callback_lock_;
126 
127   // The following callbacks must be protected by callback_lock_.
128   ProcessCaptureResultFunc process_capture_result_;
129   NotifyFunc notify_;
130 };
131 
132 }  // namespace google_camera_hal
133 }  // namespace android
134 
135 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_DUAL_IR_RESULT_PROCESSOR_H_
136