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_CAPTURE_SESSION_H_ 18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_DUAL_IR_CAPTURE_SESSION_H_ 19 20 #include "camera_device_session_hwl.h" 21 #include "capture_session.h" 22 #include "depth_process_block.h" 23 #include "dual_ir_depth_result_processor.h" 24 #include "dual_ir_request_processor.h" 25 #include "dual_ir_result_request_processor.h" 26 #include "hwl_types.h" 27 #include "multicam_realtime_process_block.h" 28 #include "result_processor.h" 29 30 namespace android { 31 namespace google_camera_hal { 32 33 // DualIrCaptureSession implements a CaptureSession that contains a single 34 // process chain that consists of 35 // 36 // DualIrRequestProcessor -> MultiCameraRtProcessBlock -> 37 // DualIrResultRequestProcessor -> DepthProcessBlock -> 38 // DualIrDepthResultProcessor 39 // 40 // It only supports a camera device session that consists of two IR cameras. 41 class DualIrCaptureSession : public CaptureSession { 42 public: 43 // Return if the device session HWL and stream configuration are supported. 44 static bool IsStreamConfigurationSupported( 45 CameraDeviceSessionHwl* device_session_hwl, 46 const StreamConfiguration& stream_config); 47 48 // Create a DualIrCaptureSession. 49 // 50 // device_session_hwl is owned by the caller and must be valid during the 51 // lifetime of DualIrCaptureSession. 52 // stream_config is the stream configuration. 53 // process_capture_result is the callback function to notify results. 54 // process_batch_capture_result is the callback function to notify batched 55 // results. 56 // notify is the callback function to notify messages. 57 // hal_configured_streams will be filled with HAL configured streams. 58 // camera_allocator_hwl is owned by the caller and must be valid during the 59 // lifetime of DualIrCaptureSession 60 static std::unique_ptr<CaptureSession> Create( 61 CameraDeviceSessionHwl* device_session_hwl, 62 const StreamConfiguration& stream_config, 63 ProcessCaptureResultFunc process_capture_result, 64 ProcessBatchCaptureResultFunc process_batch_capture_result, 65 NotifyFunc notify, HwlSessionCallback session_callback, 66 std::vector<HalStream>* hal_configured_streams, 67 CameraBufferAllocatorHwl* camera_allocator_hwl); 68 69 virtual ~DualIrCaptureSession(); 70 71 // Override functions in CaptureSession start. 72 status_t ProcessRequest(const CaptureRequest& request) override; 73 74 status_t Flush() override; 75 // Override functions in CaptureSession end. 76 77 protected: 78 DualIrCaptureSession(uint32_t lead_camera_id); 79 80 private: 81 const uint32_t kLeadCameraId; 82 83 status_t Initialize(CameraDeviceSessionHwl* device_session_hwl, 84 const StreamConfiguration& stream_config, 85 ProcessCaptureResultFunc process_capture_result, 86 NotifyFunc notify, 87 std::vector<HalStream>* hal_configured_streams); 88 89 status_t CreateProcessChain(const StreamConfiguration& stream_config, 90 ProcessCaptureResultFunc process_capture_result, 91 NotifyFunc notify, 92 std::vector<HalStream>* hal_configured_streams); 93 94 // Connect ProcessBlock and Request/Result processors to form a process chain 95 status_t ConnectProcessChain(RequestProcessor* request_processor, 96 std::unique_ptr<ProcessBlock> process_block, 97 std::unique_ptr<ResultProcessor> result_processor); 98 99 // Check if all streams in stream_config are also in 100 // process_block_stream_config. 101 bool AreAllStreamsConfigured( 102 const StreamConfiguration& stream_config, 103 const StreamConfiguration& process_block_stream_config) const; 104 105 // Configure streams for the process chain. 106 status_t ConfigureStreams(RequestProcessor* request_processor, 107 ProcessBlock* process_block, 108 const StreamConfiguration& overall_config, 109 const StreamConfiguration& stream_config, 110 StreamConfiguration* process_block_stream_config); 111 112 // Make a stream configuration for the depth chaing segment in case a depth 113 // stream is configured by the framework. 114 status_t MakeDepthChainSegmentStreamConfig( 115 const StreamConfiguration& stream_config, 116 StreamConfiguration* rt_process_block_stream_config, 117 StreamConfiguration* depth_chain_segment_stream_config); 118 119 // Purge the hal_configured_streams such that only framework streams are left 120 status_t PurgeHalConfiguredStream( 121 const StreamConfiguration& stream_config, 122 std::vector<HalStream>* hal_configured_streams); 123 124 // Setup the realtime segment of the DualIr process chain. This creates the 125 // related process block and request/result processors. It also calls the 126 // ConfigureStreams for the request processor and the process block. 127 status_t SetupRealtimeSegment( 128 const StreamConfiguration& stream_config, 129 StreamConfiguration* process_block_stream_config, 130 std::unique_ptr<MultiCameraRtProcessBlock>* rt_process_block, 131 std::unique_ptr<DualIrResultRequestProcessor>* rt_result_request_processor); 132 133 // Setup the depth segment of the DualIr process chain. This creates the 134 // related process block and request/result processors. It also calls the 135 // ConfigureStreams for the request processor and the process block. 136 // It generates the stream_config for the depth chain segment internally. 137 // This function should only be invoked when has_depth_stream_ is true 138 status_t SetupDepthSegment( 139 const StreamConfiguration& stream_config, 140 StreamConfiguration* process_block_stream_config, 141 DualIrResultRequestProcessor* rt_result_request_processor, 142 std::unique_ptr<DepthProcessBlock>* depth_process_block, 143 std::unique_ptr<DualIrDepthResultProcessor>* depth_result_processor); 144 145 // This build pipelines for all process blocks. It also collects those 146 // framework streams which are configured by the HAL(i.e. process blocks) 147 status_t BuildPipelines(const StreamConfiguration& stream_config, 148 std::vector<HalStream>* hal_configured_streams, 149 MultiCameraRtProcessBlock* rt_process_block, 150 DepthProcessBlock* depth_process_block); 151 152 // device_session_hwl_ is owned by the client. 153 CameraDeviceSessionHwl* device_session_hwl_ = nullptr; 154 155 std::unique_ptr<DualIrRequestProcessor> request_processor_; 156 157 // Internal stream manager 158 std::unique_ptr<InternalStreamManager> internal_stream_manager_; 159 160 // Whether there is a depth stream configured in the current session 161 bool has_depth_stream_ = false; 162 }; 163 164 } // namespace google_camera_hal 165 } // namespace android 166 167 #endif // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_DUAL_IR_CAPTURE_SESSION_H_ 168