Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 ANDROID_SERVERS_CAMERA_CAMERAPROVIDER_H |
| 18 | #define ANDROID_SERVERS_CAMERA_CAMERAPROVIDER_H |
| 19 | |
| 20 | #include <vector> |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 21 | #include <unordered_map> |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 22 | #include <unordered_set> |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 23 | #include <set> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 24 | #include <string> |
| 25 | #include <mutex> |
Shuzhen Wang | 394ad70 | 2020-07-23 13:01:54 -0700 | [diff] [blame] | 26 | #include <future> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 27 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 28 | #include <camera/camera2/ConcurrentCamera.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 29 | #include <camera/CameraParameters2.h> |
| 30 | #include <camera/CameraMetadata.h> |
| 31 | #include <camera/CameraBase.h> |
| 32 | #include <utils/Errors.h> |
| 33 | #include <android/hardware/camera/common/1.0/types.h> |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 34 | #include <android/hardware/camera/provider/2.5/ICameraProvider.h> |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 35 | #include <android/hardware/camera/provider/2.6/ICameraProviderCallback.h> |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 36 | #include <android/hardware/camera/provider/2.6/ICameraProvider.h> |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 37 | #include <android/hardware/camera/provider/2.7/ICameraProvider.h> |
| 38 | #include <android/hardware/camera/device/3.7/types.h> |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame^] | 39 | #include <android/hardware/camera/device/3.8/types.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 40 | #include <android/hidl/manager/1.0/IServiceNotification.h> |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 41 | #include <camera/VendorTagDescriptor.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 42 | |
| 43 | namespace android { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 44 | /** |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 45 | * The vendor tag descriptor class that takes HIDL vendor tag information as |
| 46 | * input. Not part of VendorTagDescriptor class because that class is used |
| 47 | * in AIDL generated sources which don't have access to HIDL headers. |
| 48 | */ |
| 49 | class HidlVendorTagDescriptor : public VendorTagDescriptor { |
| 50 | public: |
| 51 | /** |
| 52 | * Create a VendorTagDescriptor object from the HIDL VendorTagSection |
| 53 | * vector. |
| 54 | * |
| 55 | * Returns OK on success, or a negative error code. |
| 56 | */ |
| 57 | static status_t createDescriptorFromHidl( |
| 58 | const hardware::hidl_vec<hardware::camera::common::V1_0::VendorTagSection>& vts, |
| 59 | /*out*/ |
| 60 | sp<VendorTagDescriptor>& descriptor); |
| 61 | }; |
| 62 | |
Jayant Chowdhary | 5216b21 | 2019-07-17 09:26:23 -0700 | [diff] [blame] | 63 | enum SystemCameraKind { |
| 64 | /** |
| 65 | * These camera devices are visible to all apps and system components alike |
| 66 | */ |
| 67 | PUBLIC = 0, |
| 68 | |
| 69 | /** |
| 70 | * These camera devices are visible only to processes having the |
| 71 | * android.permission.SYSTEM_CAMERA permission. They are not exposed to 3P |
| 72 | * apps. |
| 73 | */ |
| 74 | SYSTEM_ONLY_CAMERA, |
| 75 | |
| 76 | /** |
| 77 | * These camera devices are visible only to HAL clients (that try to connect |
| 78 | * on a hwbinder thread). |
| 79 | */ |
| 80 | HIDDEN_SECURE_CAMERA |
| 81 | }; |
| 82 | |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 83 | #define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0) |
| 84 | #define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0) |
| 85 | #define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1) |
| 86 | #define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2) |
| 87 | #define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3) |
| 88 | #define CAMERA_DEVICE_API_VERSION_3_4 HARDWARE_DEVICE_API_VERSION(3, 4) |
| 89 | #define CAMERA_DEVICE_API_VERSION_3_5 HARDWARE_DEVICE_API_VERSION(3, 5) |
| 90 | #define CAMERA_DEVICE_API_VERSION_3_6 HARDWARE_DEVICE_API_VERSION(3, 6) |
| 91 | #define CAMERA_DEVICE_API_VERSION_3_7 HARDWARE_DEVICE_API_VERSION(3, 7) |
Shuzhen Wang | 90708ea | 2021-11-04 11:40:49 -0700 | [diff] [blame] | 92 | #define CAMERA_DEVICE_API_VERSION_3_8 HARDWARE_DEVICE_API_VERSION(3, 8) |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 93 | |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 94 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 95 | * A manager for all camera providers available on an Android device. |
| 96 | * |
| 97 | * Responsible for enumerating providers and the individual camera devices |
| 98 | * they export, both at startup and as providers and devices are added/removed. |
| 99 | * |
| 100 | * Provides methods for requesting information about individual devices and for |
| 101 | * opening them for active use. |
| 102 | * |
| 103 | */ |
| 104 | class CameraProviderManager : virtual public hidl::manager::V1_0::IServiceNotification { |
| 105 | public: |
| 106 | |
| 107 | ~CameraProviderManager(); |
| 108 | |
| 109 | // Tiny proxy for the static methods in a HIDL interface that communicate with the hardware |
| 110 | // service manager, to be replacable in unit tests with a fake. |
| 111 | struct ServiceInteractionProxy { |
| 112 | virtual bool registerForNotifications( |
| 113 | const std::string &serviceName, |
| 114 | const sp<hidl::manager::V1_0::IServiceNotification> |
| 115 | ¬ification) = 0; |
Eino-Ville Talvala | ec96060 | 2019-10-15 11:46:16 -0700 | [diff] [blame] | 116 | // Will not wait for service to start if it's not already running |
| 117 | virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService( |
| 118 | const std::string &serviceName) = 0; |
| 119 | // Will block for service if it exists but isn't running |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 120 | virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService( |
| 121 | const std::string &serviceName) = 0; |
Yin-Chia Yeh | 177b0c1 | 2019-06-25 10:53:03 -0700 | [diff] [blame] | 122 | virtual hardware::hidl_vec<hardware::hidl_string> listServices() = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 123 | virtual ~ServiceInteractionProxy() {} |
| 124 | }; |
| 125 | |
| 126 | // Standard use case - call into the normal generated static methods which invoke |
| 127 | // the real hardware service manager |
| 128 | struct HardwareServiceInteractionProxy : public ServiceInteractionProxy { |
| 129 | virtual bool registerForNotifications( |
| 130 | const std::string &serviceName, |
| 131 | const sp<hidl::manager::V1_0::IServiceNotification> |
| 132 | ¬ification) override { |
| 133 | return hardware::camera::provider::V2_4::ICameraProvider::registerForNotifications( |
| 134 | serviceName, notification); |
| 135 | } |
Eino-Ville Talvala | ec96060 | 2019-10-15 11:46:16 -0700 | [diff] [blame] | 136 | virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService( |
| 137 | const std::string &serviceName) override { |
| 138 | return hardware::camera::provider::V2_4::ICameraProvider::tryGetService(serviceName); |
| 139 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 140 | virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService( |
| 141 | const std::string &serviceName) override { |
| 142 | return hardware::camera::provider::V2_4::ICameraProvider::getService(serviceName); |
| 143 | } |
Yin-Chia Yeh | 177b0c1 | 2019-06-25 10:53:03 -0700 | [diff] [blame] | 144 | |
| 145 | virtual hardware::hidl_vec<hardware::hidl_string> listServices() override; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | /** |
| 149 | * Listener interface for device/torch status changes |
| 150 | */ |
| 151 | struct StatusListener : virtual public RefBase { |
| 152 | ~StatusListener() {} |
| 153 | |
| 154 | virtual void onDeviceStatusChanged(const String8 &cameraId, |
| 155 | hardware::camera::common::V1_0::CameraDeviceStatus newStatus) = 0; |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 156 | virtual void onDeviceStatusChanged(const String8 &cameraId, |
| 157 | const String8 &physicalCameraId, |
| 158 | hardware::camera::common::V1_0::CameraDeviceStatus newStatus) = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 159 | virtual void onTorchStatusChanged(const String8 &cameraId, |
Jayant Chowdhary | 46ef0f5 | 2021-10-05 14:36:13 -0700 | [diff] [blame] | 160 | hardware::camera::common::V1_0::TorchModeStatus newStatus, |
| 161 | SystemCameraKind kind) = 0; |
| 162 | virtual void onTorchStatusChanged(const String8 &cameraId, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 163 | hardware::camera::common::V1_0::TorchModeStatus newStatus) = 0; |
Emilian Peev | aee727d | 2017-05-04 16:35:48 +0100 | [diff] [blame] | 164 | virtual void onNewProviderRegistered() = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | /** |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 168 | * Represents the mode a camera device is currently in |
| 169 | */ |
| 170 | enum class DeviceMode { |
| 171 | TORCH, |
| 172 | CAMERA |
| 173 | }; |
| 174 | |
| 175 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 176 | * Initialize the manager and give it a status listener; optionally accepts a service |
| 177 | * interaction proxy. |
| 178 | * |
| 179 | * The default proxy communicates via the hardware service manager; alternate proxies can be |
| 180 | * used for testing. The lifetime of the proxy must exceed the lifetime of the manager. |
| 181 | */ |
| 182 | status_t initialize(wp<StatusListener> listener, |
| 183 | ServiceInteractionProxy *proxy = &sHardwareServiceInteractionProxy); |
| 184 | |
| 185 | /** |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 186 | * Retrieve the total number of available cameras. |
| 187 | * This value may change dynamically as cameras are added or removed. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 188 | */ |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 189 | std::pair<int, int> getCameraCount() const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 190 | |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 191 | std::vector<std::string> getCameraDeviceIds() const; |
| 192 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 193 | /** |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 194 | * Retrieve the number of API1 compatible cameras; these are internal and |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 195 | * backwards-compatible. This is the set of cameras that will be |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 196 | * accessible via the old camera API. |
| 197 | * The return value may change dynamically due to external camera hotplug. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 198 | */ |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 199 | std::vector<std::string> getAPI1CompatibleCameraDeviceIds() const; |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 200 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 201 | /** |
| 202 | * Return true if a device with a given ID and major version exists |
| 203 | */ |
| 204 | bool isValidDevice(const std::string &id, uint16_t majorVersion) const; |
| 205 | |
| 206 | /** |
| 207 | * Return true if a device with a given ID has a flash unit. Returns false |
| 208 | * for devices that are unknown. |
| 209 | */ |
| 210 | bool hasFlashUnit(const std::string &id) const; |
| 211 | |
| 212 | /** |
Shuzhen Wang | dbdf72b | 2019-11-13 11:22:12 -0800 | [diff] [blame] | 213 | * Return true if the camera device has native zoom ratio support. |
| 214 | */ |
| 215 | bool supportNativeZoomRatio(const std::string &id) const; |
| 216 | |
| 217 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 218 | * Return the resource cost of this camera device |
| 219 | */ |
| 220 | status_t getResourceCost(const std::string &id, |
| 221 | hardware::camera::common::V1_0::CameraResourceCost* cost) const; |
| 222 | |
| 223 | /** |
| 224 | * Return the old camera API camera info |
| 225 | */ |
| 226 | status_t getCameraInfo(const std::string &id, |
| 227 | hardware::CameraInfo* info) const; |
| 228 | |
| 229 | /** |
| 230 | * Return API2 camera characteristics - returns NAME_NOT_FOUND if a device ID does |
| 231 | * not have a v3 or newer HAL version. |
| 232 | */ |
| 233 | status_t getCameraCharacteristics(const std::string &id, |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 234 | bool overrideForPerfClass, CameraMetadata* characteristics) const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 235 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 236 | status_t isConcurrentSessionConfigurationSupported( |
| 237 | const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration> |
| 238 | &cameraIdsAndSessionConfigs, |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 239 | const std::set<std::string>& perfClassPrimaryCameraIds, |
| 240 | int targetSdkVersion, bool *isSupported); |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 241 | |
Jayant Chowdhary | cad23c2 | 2020-03-10 15:04:59 -0700 | [diff] [blame] | 242 | std::vector<std::unordered_set<std::string>> getConcurrentCameraIds() const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 243 | /** |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 244 | * Check for device support of specific stream combination. |
| 245 | */ |
| 246 | status_t isSessionConfigurationSupported(const std::string& id, |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame^] | 247 | const hardware::camera::device::V3_8::StreamConfiguration &configuration, |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 248 | bool *status /*out*/) const; |
| 249 | |
| 250 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 251 | * Return the highest supported device interface version for this ID |
| 252 | */ |
| 253 | status_t getHighestSupportedVersion(const std::string &id, |
| 254 | hardware::hidl_version *v); |
| 255 | |
| 256 | /** |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 257 | * Check if a given camera device support setTorchMode API. |
| 258 | */ |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 259 | bool supportSetTorchMode(const std::string &id) const; |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 260 | |
| 261 | /** |
Rucha Katakwar | 3828452 | 2021-11-10 11:25:21 -0800 | [diff] [blame] | 262 | * Check if torch strength update should be skipped or not. |
| 263 | */ |
| 264 | bool shouldSkipTorchStrengthUpdate(const std::string &id, int32_t torchStrength) const; |
| 265 | |
| 266 | /** |
| 267 | * Return the default torch strength level if the torch strength control |
| 268 | * feature is supported. |
| 269 | */ |
| 270 | int32_t getTorchDefaultStrengthLevel(const std::string &id) const; |
| 271 | |
| 272 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 273 | * Turn on or off the flashlight on a given camera device. |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 274 | * May fail if the device does not support this API, is in active use, or if the device |
| 275 | * doesn't exist, etc. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 276 | */ |
| 277 | status_t setTorchMode(const std::string &id, bool enabled); |
| 278 | |
| 279 | /** |
Rucha Katakwar | 3828452 | 2021-11-10 11:25:21 -0800 | [diff] [blame] | 280 | * Change the brightness level of the flash unit associated with the cameraId and |
| 281 | * set it to the value in torchStrength. |
| 282 | * If the torch is OFF and torchStrength > 0, the torch will be turned ON with the |
| 283 | * specified strength level. If the torch is ON, only the brightness level will be |
| 284 | * changed. |
| 285 | * |
| 286 | * This operation will fail if the device does not have flash unit, has flash unit |
| 287 | * but does not support this API, torchStrength is invalid or if the device doesn't |
| 288 | * exist etc. |
| 289 | */ |
| 290 | status_t turnOnTorchWithStrengthLevel(const std::string &id, int32_t torchStrength); |
| 291 | |
| 292 | /** |
| 293 | * Return the torch strength level of this camera device. |
| 294 | */ |
| 295 | status_t getTorchStrengthLevel(const std::string &id, int32_t* torchStrength); |
| 296 | |
| 297 | /** |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 298 | * Setup vendor tags for all registered providers |
| 299 | */ |
| 300 | status_t setUpVendorTags(); |
| 301 | |
| 302 | /** |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 303 | * Inform registered providers about a device state change, such as folding or unfolding |
| 304 | */ |
| 305 | status_t notifyDeviceStateChange( |
| 306 | android::hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> newState); |
| 307 | |
| 308 | /** |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 309 | * Open an active session to a camera device. |
| 310 | * |
| 311 | * This fully powers on the camera device hardware, and returns a handle to a |
| 312 | * session to be used for hardware configuration and operation. |
| 313 | */ |
| 314 | status_t openSession(const std::string &id, |
| 315 | const sp<hardware::camera::device::V3_2::ICameraDeviceCallback>& callback, |
| 316 | /*out*/ |
| 317 | sp<hardware::camera::device::V3_2::ICameraDeviceSession> *session); |
| 318 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 319 | /** |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 320 | * Notify that the camera or torch is no longer being used by a camera client |
| 321 | */ |
| 322 | void removeRef(DeviceMode usageType, const std::string &cameraId); |
| 323 | |
| 324 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 325 | * IServiceNotification::onRegistration |
| 326 | * Invoked by the hardware service manager when a new camera provider is registered |
| 327 | */ |
| 328 | virtual hardware::Return<void> onRegistration(const hardware::hidl_string& fqName, |
| 329 | const hardware::hidl_string& name, |
| 330 | bool preexisting) override; |
| 331 | |
| 332 | /** |
| 333 | * Dump out information about available providers and devices |
| 334 | */ |
| 335 | status_t dump(int fd, const Vector<String16>& args); |
| 336 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 337 | /** |
| 338 | * Conversion methods between HAL Status and status_t and strings |
| 339 | */ |
| 340 | static status_t mapToStatusT(const hardware::camera::common::V1_0::Status& s); |
| 341 | static const char* statusToString(const hardware::camera::common::V1_0::Status& s); |
| 342 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 343 | /* |
| 344 | * Return provider type for a specific device. |
| 345 | */ |
| 346 | metadata_vendor_id_t getProviderTagIdLocked(const std::string& id, |
| 347 | hardware::hidl_version minVersion = hardware::hidl_version{0,0}, |
| 348 | hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const; |
| 349 | |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 350 | /* |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 351 | * Check if a camera is a logical camera. And if yes, return |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 352 | * the physical camera ids. |
| 353 | */ |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 354 | bool isLogicalCamera(const std::string& id, std::vector<std::string>* physicalCameraIds); |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 355 | |
Jayant Chowdhary | 33e8ef8 | 2019-09-27 09:20:42 -0700 | [diff] [blame] | 356 | status_t getSystemCameraKind(const std::string& id, SystemCameraKind *kind) const; |
| 357 | bool isHiddenPhysicalCamera(const std::string& cameraId) const; |
Emilian Peev | 538c90e | 2018-12-17 18:03:19 +0000 | [diff] [blame] | 358 | |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 359 | status_t filterSmallJpegSizes(const std::string& cameraId); |
Shuzhen Wang | 89db299 | 2021-05-20 13:09:48 -0700 | [diff] [blame] | 360 | |
Emilian Peev | 538c90e | 2018-12-17 18:03:19 +0000 | [diff] [blame] | 361 | static const float kDepthARTolerance; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 362 | private: |
| 363 | // All private members, unless otherwise noted, expect mInterfaceMutex to be locked before use |
| 364 | mutable std::mutex mInterfaceMutex; |
| 365 | |
| 366 | wp<StatusListener> mListener; |
| 367 | ServiceInteractionProxy* mServiceProxy; |
| 368 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 369 | // Current overall Android device physical status |
| 370 | android::hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> mDeviceState; |
| 371 | |
Shuzhen Wang | 6ba8eb2 | 2018-07-08 13:10:44 -0700 | [diff] [blame] | 372 | // mProviderLifecycleLock is locked during onRegistration and removeProvider |
| 373 | mutable std::mutex mProviderLifecycleLock; |
| 374 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 375 | static HardwareServiceInteractionProxy sHardwareServiceInteractionProxy; |
| 376 | |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 377 | // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the |
| 378 | // ICameraProvider alive while it is in use by the camera with the given ID for camera |
| 379 | // capabilities |
| 380 | std::unordered_map<std::string, sp<hardware::camera::provider::V2_4::ICameraProvider>> |
| 381 | mCameraProviderByCameraId; |
| 382 | |
| 383 | // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the |
| 384 | // ICameraProvider alive while it is in use by the camera with the given ID for torch |
| 385 | // capabilities |
| 386 | std::unordered_map<std::string, sp<hardware::camera::provider::V2_4::ICameraProvider>> |
| 387 | mTorchProviderByCameraId; |
| 388 | |
| 389 | // Lock for accessing mCameraProviderByCameraId and mTorchProviderByCameraId |
| 390 | std::mutex mProviderInterfaceMapLock; |
| 391 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 392 | struct ProviderInfo : |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 393 | virtual public hardware::camera::provider::V2_6::ICameraProviderCallback, |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 394 | virtual public hardware::hidl_death_recipient |
| 395 | { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 396 | const std::string mProviderName; |
Emilian Peev | c93cac2 | 2020-08-17 16:00:10 -0700 | [diff] [blame] | 397 | const std::string mProviderInstance; |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 398 | const metadata_vendor_id_t mProviderTagid; |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 399 | int mMinorVersion; |
Peter Kalauskas | 1b3c907 | 2018-11-07 12:41:53 -0800 | [diff] [blame] | 400 | sp<VendorTagDescriptor> mVendorTagDescriptor; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 401 | bool mSetTorchModeSupported; |
| 402 | bool mIsRemote; |
| 403 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 404 | // Current overall Android device physical status |
| 405 | hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> mDeviceState; |
| 406 | |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 407 | // This pointer is used to keep a reference to the ICameraProvider that was last accessed. |
| 408 | wp<hardware::camera::provider::V2_4::ICameraProvider> mActiveInterface; |
| 409 | |
| 410 | sp<hardware::camera::provider::V2_4::ICameraProvider> mSavedInterface; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 411 | |
Emilian Peev | c93cac2 | 2020-08-17 16:00:10 -0700 | [diff] [blame] | 412 | ProviderInfo(const std::string &providerName, const std::string &providerInstance, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 413 | CameraProviderManager *manager); |
| 414 | ~ProviderInfo(); |
| 415 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 416 | status_t initialize(sp<hardware::camera::provider::V2_4::ICameraProvider>& interface, |
| 417 | hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> |
| 418 | currentDeviceState); |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 419 | |
| 420 | const sp<hardware::camera::provider::V2_4::ICameraProvider> startProviderInterface(); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 421 | |
| 422 | const std::string& getType() const; |
| 423 | |
| 424 | status_t addDevice(const std::string& name, |
| 425 | hardware::camera::common::V1_0::CameraDeviceStatus initialStatus = |
| 426 | hardware::camera::common::V1_0::CameraDeviceStatus::PRESENT, |
| 427 | /*out*/ std::string *parsedId = nullptr); |
| 428 | |
| 429 | status_t dump(int fd, const Vector<String16>& args) const; |
| 430 | |
| 431 | // ICameraProviderCallbacks interface - these lock the parent mInterfaceMutex |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 432 | hardware::Return<void> cameraDeviceStatusChange( |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 433 | const hardware::hidl_string& cameraDeviceName, |
| 434 | hardware::camera::common::V1_0::CameraDeviceStatus newStatus) override; |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 435 | hardware::Return<void> torchModeStatusChange( |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 436 | const hardware::hidl_string& cameraDeviceName, |
| 437 | hardware::camera::common::V1_0::TorchModeStatus newStatus) override; |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 438 | hardware::Return<void> physicalCameraDeviceStatusChange( |
| 439 | const hardware::hidl_string& cameraDeviceName, |
| 440 | const hardware::hidl_string& physicalCameraDeviceName, |
| 441 | hardware::camera::common::V1_0::CameraDeviceStatus newStatus) override; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 442 | |
Shuzhen Wang | 394ad70 | 2020-07-23 13:01:54 -0700 | [diff] [blame] | 443 | status_t cameraDeviceStatusChangeLocked( |
| 444 | std::string* id, const hardware::hidl_string& cameraDeviceName, |
| 445 | hardware::camera::common::V1_0::CameraDeviceStatus newStatus); |
| 446 | status_t physicalCameraDeviceStatusChangeLocked( |
| 447 | std::string* id, std::string* physicalId, |
| 448 | const hardware::hidl_string& cameraDeviceName, |
| 449 | const hardware::hidl_string& physicalCameraDeviceName, |
| 450 | hardware::camera::common::V1_0::CameraDeviceStatus newStatus); |
| 451 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 452 | // hidl_death_recipient interface - this locks the parent mInterfaceMutex |
| 453 | virtual void serviceDied(uint64_t cookie, const wp<hidl::base::V1_0::IBase>& who) override; |
| 454 | |
Peter Kalauskas | 1b3c907 | 2018-11-07 12:41:53 -0800 | [diff] [blame] | 455 | /** |
| 456 | * Setup vendor tags for this provider |
| 457 | */ |
| 458 | status_t setUpVendorTags(); |
| 459 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 460 | /** |
| 461 | * Notify provider about top-level device physical state changes |
Emilian Peev | 7fe6c42 | 2021-09-08 13:43:20 -0700 | [diff] [blame] | 462 | * |
| 463 | * Note that 'mInterfaceMutex' should not be held when calling this method. |
| 464 | * It is possible for camera providers to add/remove devices and try to |
| 465 | * acquire it. |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 466 | */ |
| 467 | status_t notifyDeviceStateChange( |
| 468 | hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> |
| 469 | newDeviceState); |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 470 | |
| 471 | std::vector<std::unordered_set<std::string>> getConcurrentCameraIdCombinations(); |
| 472 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 473 | /** |
Emilian Peev | b50402e | 2021-09-24 17:41:57 -0700 | [diff] [blame] | 474 | * Notify 'DeviceInfo' instanced about top-level device physical state changes |
| 475 | * |
| 476 | * Note that 'mInterfaceMutex' should be held when calling this method. |
| 477 | */ |
| 478 | void notifyDeviceInfoStateChangeLocked( |
| 479 | hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> |
| 480 | newDeviceState); |
| 481 | |
| 482 | /** |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 483 | * Query the camera provider for concurrent stream configuration support |
| 484 | */ |
| 485 | status_t isConcurrentSessionConfigurationSupported( |
| 486 | const hardware::hidl_vec< |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 487 | hardware::camera::provider::V2_7::CameraIdAndStreamCombination> |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 488 | &halCameraIdsAndStreamCombinations, |
| 489 | bool *isSupported); |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 490 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 491 | // Basic device information, common to all camera devices |
| 492 | struct DeviceInfo { |
| 493 | const std::string mName; // Full instance name |
| 494 | const std::string mId; // ID section of full name |
| 495 | const hardware::hidl_version mVersion; |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 496 | const metadata_vendor_id_t mProviderTagid; |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 497 | bool mIsLogicalCamera; |
| 498 | std::vector<std::string> mPhysicalIds; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 499 | hardware::CameraInfo mInfo; |
| 500 | sp<IBase> mSavedInterface; |
Jayant Chowdhary | 5216b21 | 2019-07-17 09:26:23 -0700 | [diff] [blame] | 501 | SystemCameraKind mSystemCameraKind = SystemCameraKind::PUBLIC; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 502 | |
| 503 | const hardware::camera::common::V1_0::CameraResourceCost mResourceCost; |
| 504 | |
| 505 | hardware::camera::common::V1_0::CameraDeviceStatus mStatus; |
| 506 | |
Shuzhen Wang | 7968043 | 2020-03-05 11:53:46 -0800 | [diff] [blame] | 507 | wp<ProviderInfo> mParentProvider; |
Rucha Katakwar | 3828452 | 2021-11-10 11:25:21 -0800 | [diff] [blame] | 508 | // Torch strength default, maximum levels if the torch strength control |
| 509 | // feature is supported. |
| 510 | int32_t mTorchStrengthLevel; |
| 511 | int32_t mTorchMaximumStrengthLevel; |
| 512 | int32_t mTorchDefaultStrengthLevel; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 513 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 514 | bool hasFlashUnit() const { return mHasFlashUnit; } |
Shuzhen Wang | dbdf72b | 2019-11-13 11:22:12 -0800 | [diff] [blame] | 515 | bool supportNativeZoomRatio() const { return mSupportNativeZoomRatio; } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 516 | virtual status_t setTorchMode(bool enabled) = 0; |
Rucha Katakwar | 3828452 | 2021-11-10 11:25:21 -0800 | [diff] [blame] | 517 | virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) = 0; |
| 518 | virtual status_t getTorchStrengthLevel(int32_t *torchStrength) = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 519 | virtual status_t getCameraInfo(hardware::CameraInfo *info) const = 0; |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 520 | virtual bool isAPI1Compatible() const = 0; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 521 | virtual status_t dumpState(int fd) = 0; |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 522 | virtual status_t getCameraCharacteristics(bool overrideForPerfClass, |
| 523 | CameraMetadata *characteristics) const { |
| 524 | (void) overrideForPerfClass; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 525 | (void) characteristics; |
| 526 | return INVALID_OPERATION; |
| 527 | } |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 528 | virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId, |
| 529 | CameraMetadata *characteristics) const { |
| 530 | (void) physicalCameraId; |
| 531 | (void) characteristics; |
| 532 | return INVALID_OPERATION; |
| 533 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 534 | |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 535 | virtual status_t isSessionConfigurationSupported( |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame^] | 536 | const hardware::camera::device::V3_8::StreamConfiguration &/*configuration*/, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 537 | bool * /*status*/) { |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 538 | return INVALID_OPERATION; |
| 539 | } |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 540 | virtual status_t filterSmallJpegSizes() = 0; |
Emilian Peev | b50402e | 2021-09-24 17:41:57 -0700 | [diff] [blame] | 541 | virtual void notifyDeviceStateChange( |
| 542 | hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> |
| 543 | /*newState*/) {} |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 544 | |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 545 | template<class InterfaceT> |
| 546 | sp<InterfaceT> startDeviceInterface(); |
| 547 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 548 | DeviceInfo(const std::string& name, const metadata_vendor_id_t tagId, |
| 549 | const std::string &id, const hardware::hidl_version& version, |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 550 | const std::vector<std::string>& publicCameraIds, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 551 | const hardware::camera::common::V1_0::CameraResourceCost& resourceCost, |
| 552 | sp<ProviderInfo> parentProvider) : |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 553 | mName(name), mId(id), mVersion(version), mProviderTagid(tagId), |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 554 | mIsLogicalCamera(false), mResourceCost(resourceCost), |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 555 | mStatus(hardware::camera::common::V1_0::CameraDeviceStatus::PRESENT), |
Rucha Katakwar | 3c6714d | 2021-12-15 13:56:55 -0800 | [diff] [blame] | 556 | mParentProvider(parentProvider), mTorchStrengthLevel(0), |
| 557 | mTorchMaximumStrengthLevel(0), mTorchDefaultStrengthLevel(0), |
| 558 | mHasFlashUnit(false), mSupportNativeZoomRatio(false), |
| 559 | mPublicCameraIds(publicCameraIds) {} |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 560 | virtual ~DeviceInfo(); |
| 561 | protected: |
Shuzhen Wang | dbdf72b | 2019-11-13 11:22:12 -0800 | [diff] [blame] | 562 | bool mHasFlashUnit; // const after constructor |
| 563 | bool mSupportNativeZoomRatio; // const after constructor |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 564 | const std::vector<std::string>& mPublicCameraIds; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 565 | |
| 566 | template<class InterfaceT> |
| 567 | static status_t setTorchMode(InterfaceT& interface, bool enabled); |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 568 | |
| 569 | template<class InterfaceT> |
| 570 | status_t setTorchModeForDevice(bool enabled) { |
| 571 | // Don't save the ICameraProvider interface here because we assume that this was |
| 572 | // called from CameraProviderManager::setTorchMode(), which does save it. |
| 573 | const sp<InterfaceT> interface = startDeviceInterface<InterfaceT>(); |
| 574 | return DeviceInfo::setTorchMode(interface, enabled); |
| 575 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 576 | }; |
| 577 | std::vector<std::unique_ptr<DeviceInfo>> mDevices; |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 578 | std::unordered_set<std::string> mUniqueCameraIds; |
Yin-Chia Yeh | e8e9e19 | 2017-03-16 15:23:51 -0700 | [diff] [blame] | 579 | int mUniqueDeviceCount; |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 580 | std::vector<std::string> mUniqueAPI1CompatibleCameraIds; |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 581 | // The initial public camera IDs published by the camera provider. |
| 582 | // Currently logical multi-camera is not supported for hot-plug camera. |
| 583 | // And we use this list to keep track of initial public camera IDs |
| 584 | // advertised by the provider, and to distinguish against "hidden" |
| 585 | // physical camera IDs. |
| 586 | std::vector<std::string> mProviderPublicCameraIds; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 587 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 588 | // HALv3-specific camera fields, including the actual device interface |
| 589 | struct DeviceInfo3 : public DeviceInfo { |
| 590 | typedef hardware::camera::device::V3_2::ICameraDevice InterfaceT; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 591 | |
| 592 | virtual status_t setTorchMode(bool enabled) override; |
Rucha Katakwar | 3828452 | 2021-11-10 11:25:21 -0800 | [diff] [blame] | 593 | virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) override; |
| 594 | virtual status_t getTorchStrengthLevel(int32_t *torchStrength) override; |
| 595 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 596 | virtual status_t getCameraInfo(hardware::CameraInfo *info) const override; |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 597 | virtual bool isAPI1Compatible() const override; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 598 | virtual status_t dumpState(int fd) override; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 599 | virtual status_t getCameraCharacteristics( |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 600 | bool overrideForPerfClass, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 601 | CameraMetadata *characteristics) const override; |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 602 | virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId, |
| 603 | CameraMetadata *characteristics) const override; |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 604 | virtual status_t isSessionConfigurationSupported( |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame^] | 605 | const hardware::camera::device::V3_8::StreamConfiguration &configuration, |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 606 | bool *status /*out*/) |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 607 | override; |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 608 | virtual status_t filterSmallJpegSizes() override; |
Emilian Peev | b50402e | 2021-09-24 17:41:57 -0700 | [diff] [blame] | 609 | virtual void notifyDeviceStateChange( |
| 610 | hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> |
| 611 | newState) override; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 612 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 613 | DeviceInfo3(const std::string& name, const metadata_vendor_id_t tagId, |
| 614 | const std::string &id, uint16_t minorVersion, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 615 | const hardware::camera::common::V1_0::CameraResourceCost& resourceCost, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 616 | sp<ProviderInfo> parentProvider, |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 617 | const std::vector<std::string>& publicCameraIds, sp<InterfaceT> interface); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 618 | virtual ~DeviceInfo3(); |
| 619 | private: |
| 620 | CameraMetadata mCameraCharacteristics; |
Emilian Peev | b50402e | 2021-09-24 17:41:57 -0700 | [diff] [blame] | 621 | // Map device states to sensor orientations |
| 622 | std::unordered_map<int64_t, int32_t> mDeviceStateOrientationMap; |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 623 | // A copy of mCameraCharacteristics without performance class |
| 624 | // override |
| 625 | std::unique_ptr<CameraMetadata> mCameraCharNoPCOverride; |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 626 | std::unordered_map<std::string, CameraMetadata> mPhysicalCameraCharacteristics; |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 627 | void queryPhysicalCameraIds(); |
Jayant Chowdhary | 5216b21 | 2019-07-17 09:26:23 -0700 | [diff] [blame] | 628 | SystemCameraKind getSystemCameraKind(); |
Shuzhen Wang | 268a136 | 2018-10-16 16:32:59 -0700 | [diff] [blame] | 629 | status_t fixupMonochromeTags(); |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 630 | status_t addDynamicDepthTags(bool maxResolution = false); |
| 631 | status_t deriveHeicTags(bool maxResolution = false); |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 632 | status_t addRotateCropTags(); |
Shuzhen Wang | 9bf8a6f | 2020-05-01 09:49:04 -0700 | [diff] [blame] | 633 | status_t addPreCorrectionActiveArraySize(); |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 634 | |
Emilian Peev | 4c6d2b5 | 2019-01-04 17:13:56 +0000 | [diff] [blame] | 635 | static void getSupportedSizes(const CameraMetadata& ch, uint32_t tag, |
| 636 | android_pixel_format_t format, |
| 637 | std::vector<std::tuple<size_t, size_t>> *sizes /*out*/); |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 638 | static void getSupportedDurations( const CameraMetadata& ch, uint32_t tag, |
Emilian Peev | 4c6d2b5 | 2019-01-04 17:13:56 +0000 | [diff] [blame] | 639 | android_pixel_format_t format, |
| 640 | const std::vector<std::tuple<size_t, size_t>>& sizes, |
| 641 | std::vector<int64_t> *durations/*out*/); |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 642 | static void getSupportedDynamicDepthDurations( |
| 643 | const std::vector<int64_t>& depthDurations, |
Emilian Peev | 4c6d2b5 | 2019-01-04 17:13:56 +0000 | [diff] [blame] | 644 | const std::vector<int64_t>& blobDurations, |
| 645 | std::vector<int64_t> *dynamicDepthDurations /*out*/); |
| 646 | static void getSupportedDynamicDepthSizes( |
| 647 | const std::vector<std::tuple<size_t, size_t>>& blobSizes, |
| 648 | const std::vector<std::tuple<size_t, size_t>>& depthSizes, |
| 649 | std::vector<std::tuple<size_t, size_t>> *dynamicDepthSizes /*out*/, |
| 650 | std::vector<std::tuple<size_t, size_t>> *internalDepthSizes /*out*/); |
Shuzhen Wang | 268a136 | 2018-10-16 16:32:59 -0700 | [diff] [blame] | 651 | status_t removeAvailableKeys(CameraMetadata& c, const std::vector<uint32_t>& keys, |
| 652 | uint32_t keyTag); |
Shuzhen Wang | 68ac7ad | 2019-01-30 14:03:28 -0800 | [diff] [blame] | 653 | status_t fillHeicStreamCombinations(std::vector<int32_t>* outputs, |
| 654 | std::vector<int64_t>* durations, |
| 655 | std::vector<int64_t>* stallDurations, |
| 656 | const camera_metadata_entry& halStreamConfigs, |
| 657 | const camera_metadata_entry& halStreamDurations); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 658 | }; |
| 659 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 660 | private: |
| 661 | std::string mType; |
| 662 | uint32_t mId; |
| 663 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 664 | std::mutex mLock; |
| 665 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 666 | CameraProviderManager *mManager; |
| 667 | |
Shuzhen Wang | 394ad70 | 2020-07-23 13:01:54 -0700 | [diff] [blame] | 668 | struct CameraStatusInfoT { |
| 669 | bool isPhysicalCameraStatus = false; |
| 670 | hardware::hidl_string cameraId; |
| 671 | hardware::hidl_string physicalCameraId; |
| 672 | hardware::camera::common::V1_0::CameraDeviceStatus status; |
| 673 | CameraStatusInfoT(bool isForPhysicalCamera, const hardware::hidl_string& id, |
| 674 | const hardware::hidl_string& physicalId, |
| 675 | hardware::camera::common::V1_0::CameraDeviceStatus s) : |
| 676 | isPhysicalCameraStatus(isForPhysicalCamera), cameraId(id), |
| 677 | physicalCameraId(physicalId), status(s) {} |
| 678 | }; |
| 679 | |
| 680 | // Lock to synchronize between initialize() and camera status callbacks |
| 681 | std::mutex mInitLock; |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 682 | bool mInitialized = false; |
Shuzhen Wang | 394ad70 | 2020-07-23 13:01:54 -0700 | [diff] [blame] | 683 | std::vector<CameraStatusInfoT> mCachedStatus; |
| 684 | // End of scope for mInitLock |
| 685 | |
| 686 | std::future<void> mInitialStatusCallbackFuture; |
| 687 | void notifyInitialStatusChange(sp<StatusListener> listener, |
| 688 | std::unique_ptr<std::vector<CameraStatusInfoT>> cachedStatus); |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 689 | |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 690 | std::vector<std::unordered_set<std::string>> mConcurrentCameraIdCombinations; |
| 691 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 692 | // Templated method to instantiate the right kind of DeviceInfo and call the |
| 693 | // right CameraProvider getCameraDeviceInterface_* method. |
| 694 | template<class DeviceInfoT> |
| 695 | std::unique_ptr<DeviceInfo> initializeDeviceInfo(const std::string &name, |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 696 | const metadata_vendor_id_t tagId, const std::string &id, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 697 | uint16_t minorVersion); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 698 | |
| 699 | // Helper for initializeDeviceInfo to use the right CameraProvider get method. |
| 700 | template<class InterfaceT> |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 701 | sp<InterfaceT> startDeviceInterface(const std::string &name); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 702 | |
| 703 | // Parse provider instance name for type and id |
| 704 | static status_t parseProviderName(const std::string& name, |
| 705 | std::string *type, uint32_t *id); |
| 706 | |
| 707 | // Parse device instance name for device version, type, and id. |
| 708 | static status_t parseDeviceName(const std::string& name, |
| 709 | uint16_t *major, uint16_t *minor, std::string *type, std::string *id); |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 710 | |
| 711 | // Generate vendor tag id |
| 712 | static metadata_vendor_id_t generateVendorTagId(const std::string &name); |
Guennadi Liakhovetski | 6034bf5 | 2017-12-07 10:28:29 +0100 | [diff] [blame] | 713 | |
| 714 | void removeDevice(std::string id); |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 715 | |
| 716 | // Expects to have mLock locked |
| 717 | status_t reCacheConcurrentStreamingCameraIdsLocked(); |
| 718 | // Expects to have mLock locked |
Jayant Chowdhary | cad23c2 | 2020-03-10 15:04:59 -0700 | [diff] [blame] | 719 | status_t getConcurrentCameraIdsInternalLocked( |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 720 | sp<hardware::camera::provider::V2_6::ICameraProvider> &interface2_6); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 721 | }; |
| 722 | |
Emilian Peev | 7fe6c42 | 2021-09-08 13:43:20 -0700 | [diff] [blame] | 723 | /** |
| 724 | * Save the ICameraProvider while it is being used by a camera or torch client |
| 725 | */ |
| 726 | void saveRef(DeviceMode usageType, const std::string &cameraId, |
| 727 | sp<hardware::camera::provider::V2_4::ICameraProvider> provider); |
| 728 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 729 | // Utility to find a DeviceInfo by ID; pointer is only valid while mInterfaceMutex is held |
| 730 | // and the calling code doesn't mutate the list of providers or their lists of devices. |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 731 | // Finds the first device of the given ID that falls within the requested version range |
| 732 | // minVersion <= deviceVersion < maxVersion |
| 733 | // No guarantees on the order of traversal |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 734 | ProviderInfo::DeviceInfo* findDeviceInfoLocked(const std::string& id, |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 735 | hardware::hidl_version minVersion = hardware::hidl_version{0,0}, |
| 736 | hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 737 | |
Emilian Peev | c93cac2 | 2020-08-17 16:00:10 -0700 | [diff] [blame] | 738 | status_t addProviderLocked(const std::string& newProvider, bool preexisting = false); |
| 739 | |
| 740 | status_t tryToInitializeProviderLocked(const std::string& providerName, |
| 741 | const sp<ProviderInfo>& providerInfo); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 742 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 743 | bool isLogicalCameraLocked(const std::string& id, std::vector<std::string>* physicalCameraIds); |
| 744 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 745 | status_t removeProvider(const std::string& provider); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 746 | sp<StatusListener> getStatusListener() const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 747 | |
| 748 | bool isValidDeviceLocked(const std::string &id, uint16_t majorVersion) const; |
| 749 | |
Emilian Peev | c93cac2 | 2020-08-17 16:00:10 -0700 | [diff] [blame] | 750 | size_t mProviderInstanceId = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 751 | std::vector<sp<ProviderInfo>> mProviders; |
| 752 | |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 753 | void addProviderToMap( |
| 754 | const std::string &cameraId, |
| 755 | sp<hardware::camera::provider::V2_4::ICameraProvider> provider, |
| 756 | bool isTorchUsage); |
| 757 | void removeCameraIdFromMap( |
| 758 | std::unordered_map<std::string, sp<hardware::camera::provider::V2_4::ICameraProvider>> &map, |
| 759 | const std::string &cameraId); |
| 760 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 761 | static const char* deviceStatusToString( |
| 762 | const hardware::camera::common::V1_0::CameraDeviceStatus&); |
| 763 | static const char* torchStatusToString( |
| 764 | const hardware::camera::common::V1_0::TorchModeStatus&); |
| 765 | |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 766 | status_t getCameraCharacteristicsLocked(const std::string &id, bool overrideForPerfClass, |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 767 | CameraMetadata* characteristics) const; |
| 768 | void filterLogicalCameraIdsLocked(std::vector<std::string>& deviceIds) const; |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 769 | |
Jayant Chowdhary | 33e8ef8 | 2019-09-27 09:20:42 -0700 | [diff] [blame] | 770 | status_t getSystemCameraKindLocked(const std::string& id, SystemCameraKind *kind) const; |
| 771 | std::pair<bool, ProviderInfo::DeviceInfo *> isHiddenPhysicalCameraInternal(const std::string& cameraId) const; |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 772 | |
| 773 | void collectDeviceIdsLocked(const std::vector<std::string> deviceIds, |
| 774 | std::vector<std::string>& normalDeviceIds, |
| 775 | std::vector<std::string>& systemCameraDeviceIds) const; |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 776 | |
| 777 | status_t convertToHALStreamCombinationAndCameraIdsLocked( |
| 778 | const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration> |
| 779 | &cameraIdsAndSessionConfigs, |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 780 | const std::set<std::string>& perfClassPrimaryCameraIds, |
| 781 | int targetSdkVersion, |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 782 | hardware::hidl_vec<hardware::camera::provider::V2_7::CameraIdAndStreamCombination> |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 783 | *halCameraIdsAndStreamCombinations, |
| 784 | bool *earlyExit); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 785 | }; |
| 786 | |
| 787 | } // namespace android |
| 788 | |
| 789 | #endif |