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 EMULATOR_CAMERA_HAL_HWL_CAMERA_DEVICE_SESSION_HWL_IMPL_H 18 #define EMULATOR_CAMERA_HAL_HWL_CAMERA_DEVICE_SESSION_HWL_IMPL_H 19 20 #include <camera_device_session_hwl.h> 21 22 #include <set> 23 24 #include "EmulatedCameraDeviceHWLImpl.h" 25 #include "EmulatedRequestProcessor.h" 26 #include "EmulatedTorchState.h" 27 #include "multicam_coordinator_hwl.h" 28 #include "utils/StreamConfigurationMap.h" 29 30 namespace android { 31 32 using google_camera_hal::CameraDeviceHwl; 33 using google_camera_hal::CameraDeviceSessionHwl; 34 using google_camera_hal::HalStream; 35 using google_camera_hal::HwlOfflinePipelineRole; 36 using google_camera_hal::HwlPipelineCallback; 37 using google_camera_hal::HwlPipelineRequest; 38 using google_camera_hal::HwlSessionCallback; 39 using google_camera_hal::IMulticamCoordinatorHwl; 40 using google_camera_hal::StreamConfiguration; 41 using google_camera_hal::RequestTemplate; 42 using google_camera_hal::SessionDataKey; 43 using google_camera_hal::Stream; 44 using google_camera_hal::StreamConfiguration; 45 46 // Implementation of CameraDeviceSessionHwl interface 47 class EmulatedCameraDeviceSessionHwlImpl : public CameraDeviceSessionHwl { 48 public: 49 static std::unique_ptr<EmulatedCameraDeviceSessionHwlImpl> Create( 50 uint32_t camera_id, std::unique_ptr<HalCameraMetadata> static_meta, 51 PhysicalDeviceMapPtr physical_devices, 52 std::shared_ptr<EmulatedTorchState> torch_state); 53 54 virtual ~EmulatedCameraDeviceSessionHwlImpl(); 55 56 // Override functions in CameraDeviceSessionHwl 57 status_t ConstructDefaultRequestSettings( 58 RequestTemplate type, 59 std::unique_ptr<HalCameraMetadata>* default_settings) override; 60 PrepareConfigureStreams(const StreamConfiguration &)61 status_t PrepareConfigureStreams( 62 const StreamConfiguration& /*request_config*/) override { 63 return OK; 64 } // Noop for now 65 66 status_t ConfigurePipeline(uint32_t physical_camera_id, 67 HwlPipelineCallback hwl_pipeline_callback, 68 const StreamConfiguration& request_config, 69 const StreamConfiguration& overall_config, 70 uint32_t* pipeline_id) override; 71 72 status_t BuildPipelines() override; 73 PreparePipeline(uint32_t,uint32_t)74 status_t PreparePipeline(uint32_t /*pipeline_id*/, 75 uint32_t /*frame_number*/) override { 76 return OK; 77 } // Noop for now 78 GetRequiredIntputStreams(const StreamConfiguration &,HwlOfflinePipelineRole,std::vector<Stream> *)79 status_t GetRequiredIntputStreams(const StreamConfiguration& /*overall_config*/, 80 HwlOfflinePipelineRole /*pipeline_role*/, 81 std::vector<Stream>* /*streams*/) override { 82 // N/A 83 return INVALID_OPERATION; 84 } 85 86 status_t GetConfiguredHalStream( 87 uint32_t pipeline_id, std::vector<HalStream>* hal_streams) const override; 88 89 void DestroyPipelines() override; 90 91 status_t SubmitRequests( 92 uint32_t frame_number, 93 const std::vector<HwlPipelineRequest>& requests) override; 94 95 status_t Flush() override; 96 97 uint32_t GetCameraId() const override; 98 99 std::vector<uint32_t> GetPhysicalCameraIds() const override; 100 101 status_t GetCameraCharacteristics( 102 std::unique_ptr<HalCameraMetadata>* characteristics) const override; 103 104 status_t GetPhysicalCameraCharacteristics( 105 uint32_t physical_camera_id, 106 std::unique_ptr<HalCameraMetadata>* characteristics) const override; 107 SetSessionData(SessionDataKey,void *)108 status_t SetSessionData(SessionDataKey /*key*/ 109 , 110 void* /*value*/) override { 111 return OK; 112 } // Noop for now 113 GetSessionData(SessionDataKey,void **)114 status_t GetSessionData(SessionDataKey /*key*/, 115 void** /*value*/) const override { 116 return OK; 117 } // Noop for now 118 SetSessionCallback(const HwlSessionCallback &)119 void SetSessionCallback( 120 const HwlSessionCallback& /*hwl_session_callback*/) override { 121 } 122 FilterResultMetadata(HalCameraMetadata *)123 status_t FilterResultMetadata(HalCameraMetadata* /*metadata*/) const override { 124 return OK; 125 } // Noop for now 126 CreateMulticamCoordinatorHwl()127 std::unique_ptr<IMulticamCoordinatorHwl> CreateMulticamCoordinatorHwl() 128 override { 129 return nullptr; 130 } 131 IsReconfigurationRequired(const HalCameraMetadata *,const HalCameraMetadata *,bool * reconfiguration_required)132 status_t IsReconfigurationRequired( 133 const HalCameraMetadata* /*old_session*/, 134 const HalCameraMetadata* /*new_session*/, 135 bool* reconfiguration_required) const override { 136 if (reconfiguration_required == nullptr) { 137 return BAD_VALUE; 138 } 139 *reconfiguration_required = true; 140 return OK; 141 } 142 GetZoomRatioMapperHwl()143 std::unique_ptr<google_camera_hal::ZoomRatioMapperHwl> GetZoomRatioMapperHwl() 144 override { 145 return nullptr; 146 } 147 // End override functions in CameraDeviceSessionHwl 148 149 private: 150 status_t Initialize(uint32_t camera_id, 151 std::unique_ptr<HalCameraMetadata> static_meta); 152 EmulatedCameraDeviceSessionHwlImpl(PhysicalDeviceMapPtr physical_devices,std::shared_ptr<EmulatedTorchState> torch_state)153 EmulatedCameraDeviceSessionHwlImpl( 154 PhysicalDeviceMapPtr physical_devices, 155 std::shared_ptr<EmulatedTorchState> torch_state) 156 : torch_state_(torch_state), 157 physical_device_map_(std::move(physical_devices)) { 158 } 159 160 uint8_t max_pipeline_depth_ = 0; 161 162 // Protects the API entry points 163 mutable std::mutex api_mutex_; 164 uint32_t camera_id_ = 0; 165 bool error_state_ = false; 166 bool pipelines_built_ = false; 167 std::unique_ptr<HalCameraMetadata> static_metadata_; 168 std::vector<EmulatedPipeline> pipelines_; 169 std::unique_ptr<EmulatedRequestProcessor> request_processor_; 170 std::unique_ptr<StreamConfigurationMap> stream_coniguration_map_; 171 SensorCharacteristics sensor_chars_; 172 std::shared_ptr<EmulatedTorchState> torch_state_; 173 PhysicalDeviceMapPtr physical_device_map_; 174 }; 175 176 } // namespace android 177 178 #endif 179