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