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_CAMERA_DEVICE_H_ 18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_CAMERA_DEVICE_H_ 19 20 #include <map> 21 22 #include "camera_buffer_allocator_hwl.h" 23 #include "camera_device_hwl.h" 24 #include "camera_device_session.h" 25 #include "hal_camera_metadata.h" 26 #include "hwl_types.h" 27 #include "profiler.h" 28 29 namespace android { 30 namespace google_camera_hal { 31 32 // Camera Device implements ICameraDevice. It provides methods to query static 33 // information about a camera device and create a camera device session for 34 // active use. It does not hold any states of the camera device. 35 class CameraDevice { 36 public: 37 // Create a camera device given a camera device HWL. 38 // camera_device_hwl must be valid. 39 // camera_allocator_hwl is owned by the caller and must be valid during the 40 // lifetime of CameraDevice 41 static std::unique_ptr<CameraDevice> Create( 42 std::unique_ptr<CameraDeviceHwl> camera_device_hwl, 43 CameraBufferAllocatorHwl* camera_allocator_hwl = nullptr); 44 45 virtual ~CameraDevice(); 46 47 // Get the resource cost of this camera device. 48 status_t GetResourceCost(CameraResourceCost* cost); 49 50 // Get the characteristics of this camera device. 51 // characteristics will be filled with this camera device's characteristics. 52 status_t GetCameraCharacteristics( 53 std::unique_ptr<HalCameraMetadata>* characteristics); 54 55 // For certain feature combinations, some keys in camera characteristics 56 // have more limited support range compared with that returned by 57 // GetCameraCharacterics. This function will return the limited values of the 58 // keys listed in CameraCharacteristics#getAvailableSessionCharacteristicsKeys 59 // for the input StreamConfiguration. 60 // 61 // stream_config includes the requested streams and session settings for 62 // which we are going to fetch the characteristics. 63 // 64 // session_characteristic will be filled with the session characteristics keys 65 // with their limited ranges. 66 status_t GetSessionCharacteristics( 67 const StreamConfiguration& stream_config, 68 std::unique_ptr<HalCameraMetadata>& session_characteristics); 69 70 // Get the characteristics of this camera device's physical camera if the 71 // physical_camera_id belongs to this camera device. 72 // characteristics will be filled with the physical camera ID's 73 // characteristics. 74 status_t GetPhysicalCameraCharacteristics( 75 uint32_t physical_camera_id, 76 std::unique_ptr<HalCameraMetadata>* characteristics); 77 78 // Set the torch mode of the camera device. The torch mode status remains 79 // unchanged after this CameraDevice instance is destroyed. 80 status_t SetTorchMode(TorchMode mode); 81 82 // Change the brightness level of the flash unit in Torch mode. 83 // If the torch is OFF and torchStrength > 0, the torch will be turned ON. 84 status_t TurnOnTorchWithStrengthLevel(int32_t torch_strength); 85 86 // Get the flash unit strength level of this camera device. 87 status_t GetTorchStrengthLevel(int32_t& torch_strength) const; 88 89 // Construct default request settings 90 status_t ConstructDefaultRequestSettings( 91 RequestTemplate type, 92 std::unique_ptr<HalCameraMetadata>* request_settings); 93 94 // Create a CameraDeviceSession to handle capture requests. This method will 95 // return ALREADY_EXISTS if previous session has not been destroyed. 96 // Created CameraDeviceSession remain valid even after this CameraDevice 97 // instance is destroyed. 98 status_t CreateCameraDeviceSession( 99 std::unique_ptr<CameraDeviceSession>* session); 100 101 // Dump the camera device states in fd, using dprintf() or write(). 102 status_t DumpState(int fd); 103 104 // Get the public camera ID for this camera device. GetPublicCameraId()105 uint32_t GetPublicCameraId() const { 106 return public_camera_id_; 107 }; 108 109 // Get the applied memory config for this camera device. GetAppliedMemoryConfig()110 HwlMemoryConfig GetAppliedMemoryConfig() { 111 HwlMemoryConfig memory_config = applied_memory_config_; 112 return memory_config; 113 } 114 115 // Set the applied memory config for this camera device. SetAppliedMemoryConfig(HwlMemoryConfig memory_config)116 void SetAppliedMemoryConfig(HwlMemoryConfig memory_config) { 117 applied_memory_config_ = memory_config; 118 } 119 120 // Query whether a particular streams configuration is supported. 121 // stream_config: It contains the stream info and a set of features, which are 122 // described in the form of session settings. 123 // check_settings: When check_settings is true, this function will check if 124 // the input features combination in stream_config is supported. The feature 125 // set camera hwl has to scan for reporting support status is defined in 126 // framework by CameraCharacteristics#INFO_SESSION_CONFIGURATION_QUERY_VERSION. 127 bool IsStreamCombinationSupported(const StreamConfiguration& stream_config, 128 bool check_settings); 129 130 status_t LoadExternalCaptureSession(); 131 132 std::unique_ptr<google::camera_common::Profiler> GetProfiler(uint32_t camere_id, 133 int option); 134 135 protected: 136 CameraDevice() = default; 137 138 private: 139 status_t Initialize(std::unique_ptr<CameraDeviceHwl> camera_device_hwl, 140 CameraBufferAllocatorHwl* camera_allocator_hwl); 141 142 static HwlMemoryConfig applied_memory_config_; 143 static std::mutex applied_memory_config_mutex_; 144 145 uint32_t public_camera_id_ = 0; 146 147 std::unique_ptr<CameraDeviceHwl> camera_device_hwl_; 148 149 // hwl allocator 150 CameraBufferAllocatorHwl* camera_allocator_hwl_ = nullptr; 151 152 std::vector<GetCaptureSessionFactoryFunc> external_session_factory_entries_; 153 // Opened library handles that should be closed on destruction 154 std::vector<void*> external_capture_session_lib_handles_; 155 // Stream use cases supported by this camera device 156 std::map<uint32_t, std::set<int64_t>> camera_id_to_stream_use_cases_; 157 }; 158 159 } // namespace google_camera_hal 160 } // namespace android 161 162 #endif // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_CAMERA_DEVICE_H_ 163