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