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