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_TESTS_MOCK_DEVICE_SESSION_HWL_H_ 18 #define HARDWARE_GOOGLE_CAMERA_HAL_TESTS_MOCK_DEVICE_SESSION_HWL_H_ 19 20 #include <camera_device_session.h> 21 #include <gmock/gmock.h> 22 23 #include "profiler.h" 24 #include "session_data_defs.h" 25 26 namespace android { 27 namespace google_camera_hal { 28 29 // Defines a fake CameraDeviceSessionHwl to be called by MockDeviceSessionHwl. 30 class FakeCameraDeviceSessionHwl : public CameraDeviceSessionHwl { 31 public: 32 // Initialize a fake camera device session HWL for a camera ID. 33 // If physical_camera_ids is not empty, it will consist of the physical camera 34 // IDs. 35 FakeCameraDeviceSessionHwl(uint32_t camera_id, 36 const std::vector<uint32_t>& physical_camera_ids); 37 38 virtual ~FakeCameraDeviceSessionHwl() = default; 39 40 status_t ConstructDefaultRequestSettings( 41 RequestTemplate type, 42 std::unique_ptr<HalCameraMetadata>* default_settings) override; 43 44 status_t PrepareConfigureStreams( 45 const StreamConfiguration& request_config) override; 46 47 status_t ConfigurePipeline(uint32_t camera_id, 48 HwlPipelineCallback hwl_pipeline_callback, 49 const StreamConfiguration& request_config, 50 const StreamConfiguration& overall_config, 51 uint32_t* pipeline_id) override; 52 53 status_t BuildPipelines() override; 54 55 // This fake method fills a few dummy streams to streams. 56 // Currently only supports kOfflineSmoothTransitionRole. 57 status_t GetRequiredIntputStreams(const StreamConfiguration& overall_config, 58 HwlOfflinePipelineRole pipeline_role, 59 std::vector<Stream>* streams) override; 60 PreparePipeline(uint32_t,uint32_t)61 status_t PreparePipeline(uint32_t /*pipeline_id*/, uint32_t /*frame_number*/) { 62 return OK; 63 } 64 65 status_t GetConfiguredHalStream( 66 uint32_t pipeline_id, std::vector<HalStream>* hal_streams) const override; 67 68 void DestroyPipelines() override; 69 70 status_t SubmitRequests(uint32_t frame_number, 71 std::vector<HwlPipelineRequest>& requests) override; 72 73 status_t Flush() override; 74 75 uint32_t GetCameraId() const override; 76 77 std::vector<uint32_t> GetPhysicalCameraIds() const override; 78 79 status_t GetCameraCharacteristics( 80 std::unique_ptr<HalCameraMetadata>* characteristics) const override; 81 82 status_t GetPhysicalCameraCharacteristics( 83 uint32_t physical_camera_id, 84 std::unique_ptr<HalCameraMetadata>* characteristics) const override; 85 86 void SetPhysicalCameraIds(const std::vector<uint32_t>& physical_camera_ids); 87 88 status_t SetSessionData(SessionDataKey key, void* value) override; 89 90 status_t GetSessionData(SessionDataKey key, void** value) const override; 91 92 void SetSessionCallback( 93 const HwlSessionCallback& hwl_session_callback) override; 94 95 status_t FilterResultMetadata(HalCameraMetadata* metadata) const override; 96 97 std::unique_ptr<IMulticamCoordinatorHwl> CreateMulticamCoordinatorHwl(); 98 99 status_t IsReconfigurationRequired( 100 const HalCameraMetadata* old_session, const HalCameraMetadata* new_session, 101 bool* reconfiguration_required) const override; 102 103 std::unique_ptr<ZoomRatioMapperHwl> GetZoomRatioMapperHwl() override; 104 105 std::unique_ptr<google::camera_common::Profiler> GetProfiler( 106 uint32_t camera_id, int option) override; 107 108 private: 109 const uint32_t kCameraId; 110 const std::vector<uint32_t> kPhysicalCameraIds; 111 112 mutable std::mutex hwl_pipeline_lock_; 113 114 // Maps from pipeline ID to HWL pipeline callback. 115 // Protected by hwl_pipeline_lock_. 116 std::unordered_map<uint32_t, HwlPipelineCallback> hwl_pipeline_callbacks_; 117 118 // Maps from pipeline ID to HAL streams. Protected by hwl_pipeline_lock_. 119 std::unordered_map<uint32_t, std::vector<HalStream>> pipeline_hal_streams_map_; 120 }; 121 122 // Defines a CameraDeviceSessionHwl mock using gmock. 123 class MockDeviceSessionHwl : public CameraDeviceSessionHwl { 124 public: 125 // Initialize a mock camera device session HWL for a camera ID. 126 // If physical_camera_ids is not empty, it will consist of the physical camera 127 // IDs. 128 MockDeviceSessionHwl(uint32_t camera_id = 3, // Dummy camera ID 129 const std::vector<uint32_t>& physical_camera_ids = 130 std::vector<uint32_t>()); 131 132 MOCK_METHOD2(ConstructDefaultRequestSettings, 133 status_t(RequestTemplate type, 134 std::unique_ptr<HalCameraMetadata>* default_settings)); 135 136 MOCK_METHOD5(ConfigurePipeline, 137 status_t(uint32_t camera_id, 138 HwlPipelineCallback hwl_pipeline_callback, 139 const StreamConfiguration& request_config, 140 const StreamConfiguration& overall_config, 141 uint32_t* pipeline_id)); 142 143 MOCK_METHOD0(BuildPipelines, status_t()); 144 145 MOCK_METHOD2(PreparePipeline, 146 status_t(uint32_t pipeline_id, uint32_t frame_number)); 147 148 MOCK_METHOD3(GetRequiredIntputStreams, 149 status_t(const StreamConfiguration& overall_config, 150 HwlOfflinePipelineRole pipeline_role, 151 std::vector<Stream>* streams)); 152 153 MOCK_CONST_METHOD2(GetConfiguredHalStream, 154 status_t(uint32_t pipeline_id, 155 std::vector<HalStream>* hal_streams)); 156 157 MOCK_METHOD0(DestroyPipelines, void()); 158 159 MOCK_METHOD2(SubmitRequests, 160 status_t(uint32_t frame_number, 161 std::vector<HwlPipelineRequest>& requests)); 162 163 MOCK_METHOD0(Flush, status_t()); 164 165 MOCK_CONST_METHOD0(GetCameraId, uint32_t()); 166 167 MOCK_CONST_METHOD0(GetPhysicalCameraIds, std::vector<uint32_t>()); 168 169 MOCK_CONST_METHOD1( 170 GetCameraCharacteristics, 171 status_t(std::unique_ptr<HalCameraMetadata>* characteristics)); 172 173 MOCK_CONST_METHOD2( 174 GetPhysicalCameraCharacteristics, 175 status_t(uint32_t physical_camera_id, 176 std::unique_ptr<HalCameraMetadata>* characteristics)); 177 178 MOCK_METHOD2(SetSessionData, status_t(SessionDataKey key, void* value)); 179 180 MOCK_CONST_METHOD2(GetSessionData, status_t(SessionDataKey key, void** value)); 181 182 MOCK_CONST_METHOD1(FilterResultMetadata, 183 status_t(HalCameraMetadata* metadata)); 184 185 MOCK_METHOD1(PrepareConfigureStreams, status_t(const StreamConfiguration&)); 186 187 MOCK_METHOD1(SetSessionCallback, 188 void(const HwlSessionCallback& hwl_session_callback)); 189 190 MOCK_METHOD0(CreateMulticamCoordinatorHwl, 191 std::unique_ptr<IMulticamCoordinatorHwl>()); 192 193 MOCK_CONST_METHOD3(IsReconfigurationRequired, 194 status_t(const HalCameraMetadata* old_session, 195 const HalCameraMetadata* new_session, 196 bool* reconfiguration_required)); 197 198 MOCK_METHOD0(GetZoomRatioMapperHwl, std::unique_ptr<ZoomRatioMapperHwl>()); 199 200 MOCK_METHOD2(GetProfiler, std::unique_ptr<google::camera_common::Profiler>( 201 uint32_t camera_id, int option)); 202 203 // Delegate all calls to FakeCameraDeviceSessionHwl. 204 void DelegateCallsToFakeSession(); 205 206 private: 207 FakeCameraDeviceSessionHwl fake_session_hwl_; 208 }; 209 210 } // namespace google_camera_hal 211 } // namespace android 212 213 #endif // HARDWARE_GOOGLE_CAMERA_HAL_TESTS_MOCK_DEVICE_SESSION_HWL_H_ 214