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