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