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