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> |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 21 | #include <unordered_set> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 22 | #include <string> |
| 23 | #include <mutex> |
| 24 | |
| 25 | #include <camera/CameraParameters2.h> |
| 26 | #include <camera/CameraMetadata.h> |
| 27 | #include <camera/CameraBase.h> |
| 28 | #include <utils/Errors.h> |
| 29 | #include <android/hardware/camera/common/1.0/types.h> |
| 30 | #include <android/hardware/camera/provider/2.4/ICameraProvider.h> |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 31 | #include <android/hardware/camera/device/3.4/ICameraDeviceSession.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 32 | //#include <android/hardware/camera/provider/2.4/ICameraProviderCallbacks.h> |
| 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 | /** |
| 114 | * Initialize the manager and give it a status listener; optionally accepts a service |
| 115 | * interaction proxy. |
| 116 | * |
| 117 | * The default proxy communicates via the hardware service manager; alternate proxies can be |
| 118 | * used for testing. The lifetime of the proxy must exceed the lifetime of the manager. |
| 119 | */ |
| 120 | status_t initialize(wp<StatusListener> listener, |
| 121 | ServiceInteractionProxy *proxy = &sHardwareServiceInteractionProxy); |
| 122 | |
| 123 | /** |
| 124 | * Retrieve the total number of available cameras. This value may change dynamically as cameras |
| 125 | * are added or removed. |
| 126 | */ |
| 127 | int getCameraCount() const; |
| 128 | |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 129 | std::vector<std::string> getCameraDeviceIds() const; |
| 130 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 131 | /** |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 132 | * Retrieve the number of API1 compatible cameras; these are internal and |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 133 | * backwards-compatible. This is the set of cameras that will be |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 134 | * accessible via the old camera API. |
| 135 | * The return value may change dynamically due to external camera hotplug. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 136 | */ |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 137 | std::vector<std::string> getAPI1CompatibleCameraDeviceIds() const; |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 138 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 139 | /** |
| 140 | * Return true if a device with a given ID and major version exists |
| 141 | */ |
| 142 | bool isValidDevice(const std::string &id, uint16_t majorVersion) const; |
| 143 | |
| 144 | /** |
| 145 | * Return true if a device with a given ID has a flash unit. Returns false |
| 146 | * for devices that are unknown. |
| 147 | */ |
| 148 | bool hasFlashUnit(const std::string &id) const; |
| 149 | |
| 150 | /** |
| 151 | * Return the resource cost of this camera device |
| 152 | */ |
| 153 | status_t getResourceCost(const std::string &id, |
| 154 | hardware::camera::common::V1_0::CameraResourceCost* cost) const; |
| 155 | |
| 156 | /** |
| 157 | * Return the old camera API camera info |
| 158 | */ |
| 159 | status_t getCameraInfo(const std::string &id, |
| 160 | hardware::CameraInfo* info) const; |
| 161 | |
| 162 | /** |
| 163 | * Return API2 camera characteristics - returns NAME_NOT_FOUND if a device ID does |
| 164 | * not have a v3 or newer HAL version. |
| 165 | */ |
| 166 | status_t getCameraCharacteristics(const std::string &id, |
| 167 | CameraMetadata* characteristics) const; |
| 168 | |
| 169 | /** |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 170 | * Check for device support of specific stream combination. |
| 171 | */ |
| 172 | status_t isSessionConfigurationSupported(const std::string& id, |
| 173 | const hardware::camera::device::V3_4::StreamConfiguration &configuration, |
| 174 | bool *status /*out*/) const; |
| 175 | |
| 176 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 177 | * Return the highest supported device interface version for this ID |
| 178 | */ |
| 179 | status_t getHighestSupportedVersion(const std::string &id, |
| 180 | hardware::hidl_version *v); |
| 181 | |
| 182 | /** |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 183 | * Check if a given camera device support setTorchMode API. |
| 184 | */ |
| 185 | bool supportSetTorchMode(const std::string &id); |
| 186 | |
| 187 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 188 | * Turn on or off the flashlight on a given camera device. |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 189 | * May fail if the device does not support this API, is in active use, or if the device |
| 190 | * doesn't exist, etc. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 191 | */ |
| 192 | status_t setTorchMode(const std::string &id, bool enabled); |
| 193 | |
| 194 | /** |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 195 | * Setup vendor tags for all registered providers |
| 196 | */ |
| 197 | status_t setUpVendorTags(); |
| 198 | |
| 199 | /** |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 200 | * Open an active session to a camera device. |
| 201 | * |
| 202 | * This fully powers on the camera device hardware, and returns a handle to a |
| 203 | * session to be used for hardware configuration and operation. |
| 204 | */ |
| 205 | status_t openSession(const std::string &id, |
| 206 | const sp<hardware::camera::device::V3_2::ICameraDeviceCallback>& callback, |
| 207 | /*out*/ |
| 208 | sp<hardware::camera::device::V3_2::ICameraDeviceSession> *session); |
| 209 | |
| 210 | status_t openSession(const std::string &id, |
| 211 | const sp<hardware::camera::device::V1_0::ICameraDeviceCallback>& callback, |
| 212 | /*out*/ |
| 213 | sp<hardware::camera::device::V1_0::ICameraDevice> *session); |
| 214 | |
| 215 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 216 | * IServiceNotification::onRegistration |
| 217 | * Invoked by the hardware service manager when a new camera provider is registered |
| 218 | */ |
| 219 | virtual hardware::Return<void> onRegistration(const hardware::hidl_string& fqName, |
| 220 | const hardware::hidl_string& name, |
| 221 | bool preexisting) override; |
| 222 | |
| 223 | /** |
| 224 | * Dump out information about available providers and devices |
| 225 | */ |
| 226 | status_t dump(int fd, const Vector<String16>& args); |
| 227 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 228 | /** |
| 229 | * Conversion methods between HAL Status and status_t and strings |
| 230 | */ |
| 231 | static status_t mapToStatusT(const hardware::camera::common::V1_0::Status& s); |
| 232 | static const char* statusToString(const hardware::camera::common::V1_0::Status& s); |
| 233 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 234 | /* |
| 235 | * Return provider type for a specific device. |
| 236 | */ |
| 237 | metadata_vendor_id_t getProviderTagIdLocked(const std::string& id, |
| 238 | hardware::hidl_version minVersion = hardware::hidl_version{0,0}, |
| 239 | hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const; |
| 240 | |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 241 | /* |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 242 | * Check if a camera is a logical camera. And if yes, return |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 243 | * the physical camera ids. |
| 244 | */ |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 245 | bool isLogicalCamera(const std::string& id, std::vector<std::string>* physicalCameraIds); |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 246 | |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 247 | bool isHiddenPhysicalCamera(const std::string& cameraId); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 248 | private: |
| 249 | // All private members, unless otherwise noted, expect mInterfaceMutex to be locked before use |
| 250 | mutable std::mutex mInterfaceMutex; |
| 251 | |
Yin-Chia Yeh | 52778d4 | 2016-12-22 18:20:43 -0800 | [diff] [blame] | 252 | // the status listener update callbacks will lock mStatusMutex |
| 253 | mutable std::mutex mStatusListenerMutex; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 254 | wp<StatusListener> mListener; |
| 255 | ServiceInteractionProxy* mServiceProxy; |
| 256 | |
Shuzhen Wang | 6ba8eb2 | 2018-07-08 13:10:44 -0700 | [diff] [blame] | 257 | // mProviderLifecycleLock is locked during onRegistration and removeProvider |
| 258 | mutable std::mutex mProviderLifecycleLock; |
| 259 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 260 | static HardwareServiceInteractionProxy sHardwareServiceInteractionProxy; |
| 261 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 262 | struct ProviderInfo : |
| 263 | virtual public hardware::camera::provider::V2_4::ICameraProviderCallback, |
| 264 | virtual public hardware::hidl_death_recipient |
| 265 | { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 266 | const std::string mProviderName; |
| 267 | const sp<hardware::camera::provider::V2_4::ICameraProvider> mInterface; |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 268 | const metadata_vendor_id_t mProviderTagid; |
Peter Kalauskas | 1b3c907 | 2018-11-07 12:41:53 -0800 | [diff] [blame] | 269 | sp<VendorTagDescriptor> mVendorTagDescriptor; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 270 | |
| 271 | ProviderInfo(const std::string &providerName, |
| 272 | sp<hardware::camera::provider::V2_4::ICameraProvider>& interface, |
| 273 | CameraProviderManager *manager); |
| 274 | ~ProviderInfo(); |
| 275 | |
| 276 | status_t initialize(); |
| 277 | |
| 278 | const std::string& getType() const; |
| 279 | |
| 280 | status_t addDevice(const std::string& name, |
| 281 | hardware::camera::common::V1_0::CameraDeviceStatus initialStatus = |
| 282 | hardware::camera::common::V1_0::CameraDeviceStatus::PRESENT, |
| 283 | /*out*/ std::string *parsedId = nullptr); |
| 284 | |
| 285 | status_t dump(int fd, const Vector<String16>& args) const; |
| 286 | |
| 287 | // ICameraProviderCallbacks interface - these lock the parent mInterfaceMutex |
| 288 | virtual hardware::Return<void> cameraDeviceStatusChange( |
| 289 | const hardware::hidl_string& cameraDeviceName, |
| 290 | hardware::camera::common::V1_0::CameraDeviceStatus newStatus) override; |
| 291 | virtual hardware::Return<void> torchModeStatusChange( |
| 292 | const hardware::hidl_string& cameraDeviceName, |
| 293 | hardware::camera::common::V1_0::TorchModeStatus newStatus) override; |
| 294 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 295 | // hidl_death_recipient interface - this locks the parent mInterfaceMutex |
| 296 | virtual void serviceDied(uint64_t cookie, const wp<hidl::base::V1_0::IBase>& who) override; |
| 297 | |
Peter Kalauskas | 1b3c907 | 2018-11-07 12:41:53 -0800 | [diff] [blame] | 298 | /** |
| 299 | * Setup vendor tags for this provider |
| 300 | */ |
| 301 | status_t setUpVendorTags(); |
| 302 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 303 | // Basic device information, common to all camera devices |
| 304 | struct DeviceInfo { |
| 305 | const std::string mName; // Full instance name |
| 306 | const std::string mId; // ID section of full name |
| 307 | const hardware::hidl_version mVersion; |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 308 | const metadata_vendor_id_t mProviderTagid; |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 309 | bool mIsLogicalCamera; |
| 310 | std::vector<std::string> mPhysicalIds; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 311 | |
| 312 | const hardware::camera::common::V1_0::CameraResourceCost mResourceCost; |
| 313 | |
| 314 | hardware::camera::common::V1_0::CameraDeviceStatus mStatus; |
| 315 | |
| 316 | bool hasFlashUnit() const { return mHasFlashUnit; } |
| 317 | virtual status_t setTorchMode(bool enabled) = 0; |
| 318 | virtual status_t getCameraInfo(hardware::CameraInfo *info) const = 0; |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 319 | virtual bool isAPI1Compatible() const = 0; |
Yin-Chia Yeh | 487785a | 2018-01-02 12:06:57 -0800 | [diff] [blame] | 320 | virtual status_t dumpState(int fd) const = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 321 | virtual status_t getCameraCharacteristics(CameraMetadata *characteristics) const { |
| 322 | (void) characteristics; |
| 323 | return INVALID_OPERATION; |
| 324 | } |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 325 | virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId, |
| 326 | CameraMetadata *characteristics) const { |
| 327 | (void) physicalCameraId; |
| 328 | (void) characteristics; |
| 329 | return INVALID_OPERATION; |
| 330 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 331 | |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 332 | virtual status_t isSessionConfigurationSupported( |
| 333 | const hardware::camera::device::V3_4::StreamConfiguration &/*configuration*/, |
| 334 | bool * /*status*/) |
| 335 | const { |
| 336 | return INVALID_OPERATION; |
| 337 | } |
| 338 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 339 | DeviceInfo(const std::string& name, const metadata_vendor_id_t tagId, |
| 340 | const std::string &id, const hardware::hidl_version& version, |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 341 | const std::vector<std::string>& publicCameraIds, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 342 | const hardware::camera::common::V1_0::CameraResourceCost& resourceCost) : |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 343 | mName(name), mId(id), mVersion(version), mProviderTagid(tagId), |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 344 | mIsLogicalCamera(false), mResourceCost(resourceCost), |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 345 | mStatus(hardware::camera::common::V1_0::CameraDeviceStatus::PRESENT), |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 346 | mHasFlashUnit(false), mPublicCameraIds(publicCameraIds) {} |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 347 | virtual ~DeviceInfo(); |
| 348 | protected: |
| 349 | bool mHasFlashUnit; |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 350 | const std::vector<std::string>& mPublicCameraIds; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 351 | |
| 352 | template<class InterfaceT> |
| 353 | static status_t setTorchMode(InterfaceT& interface, bool enabled); |
| 354 | }; |
| 355 | std::vector<std::unique_ptr<DeviceInfo>> mDevices; |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 356 | std::unordered_set<std::string> mUniqueCameraIds; |
Yin-Chia Yeh | e8e9e19 | 2017-03-16 15:23:51 -0700 | [diff] [blame] | 357 | int mUniqueDeviceCount; |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 358 | std::vector<std::string> mUniqueAPI1CompatibleCameraIds; |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 359 | // The initial public camera IDs published by the camera provider. |
| 360 | // Currently logical multi-camera is not supported for hot-plug camera. |
| 361 | // And we use this list to keep track of initial public camera IDs |
| 362 | // advertised by the provider, and to distinguish against "hidden" |
| 363 | // physical camera IDs. |
| 364 | std::vector<std::string> mProviderPublicCameraIds; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 365 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 366 | // HALv1-specific camera fields, including the actual device interface |
| 367 | struct DeviceInfo1 : public DeviceInfo { |
| 368 | typedef hardware::camera::device::V1_0::ICameraDevice InterfaceT; |
| 369 | const sp<InterfaceT> mInterface; |
| 370 | |
| 371 | virtual status_t setTorchMode(bool enabled) override; |
| 372 | virtual status_t getCameraInfo(hardware::CameraInfo *info) const override; |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 373 | //In case of Device1Info assume that we are always API1 compatible |
| 374 | virtual bool isAPI1Compatible() const override { return true; } |
Yin-Chia Yeh | 487785a | 2018-01-02 12:06:57 -0800 | [diff] [blame] | 375 | virtual status_t dumpState(int fd) const override; |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 376 | DeviceInfo1(const std::string& name, const metadata_vendor_id_t tagId, |
| 377 | const std::string &id, uint16_t minorVersion, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 378 | const hardware::camera::common::V1_0::CameraResourceCost& resourceCost, |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 379 | const std::vector<std::string>& publicCameraIds, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 380 | sp<InterfaceT> interface); |
| 381 | virtual ~DeviceInfo1(); |
| 382 | private: |
| 383 | CameraParameters2 mDefaultParameters; |
| 384 | }; |
| 385 | |
| 386 | // HALv3-specific camera fields, including the actual device interface |
| 387 | struct DeviceInfo3 : public DeviceInfo { |
| 388 | typedef hardware::camera::device::V3_2::ICameraDevice InterfaceT; |
| 389 | const sp<InterfaceT> mInterface; |
| 390 | |
| 391 | virtual status_t setTorchMode(bool enabled) override; |
| 392 | virtual status_t getCameraInfo(hardware::CameraInfo *info) const override; |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 393 | virtual bool isAPI1Compatible() const override; |
Yin-Chia Yeh | 487785a | 2018-01-02 12:06:57 -0800 | [diff] [blame] | 394 | virtual status_t dumpState(int fd) const override; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 395 | virtual status_t getCameraCharacteristics( |
| 396 | CameraMetadata *characteristics) const override; |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 397 | virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId, |
| 398 | CameraMetadata *characteristics) const override; |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 399 | virtual status_t isSessionConfigurationSupported( |
| 400 | const hardware::camera::device::V3_4::StreamConfiguration &configuration, |
| 401 | bool *status /*out*/) |
| 402 | const override; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 403 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 404 | DeviceInfo3(const std::string& name, const metadata_vendor_id_t tagId, |
| 405 | const std::string &id, uint16_t minorVersion, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 406 | const hardware::camera::common::V1_0::CameraResourceCost& resourceCost, |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 407 | const std::vector<std::string>& publicCameraIds, sp<InterfaceT> interface); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 408 | virtual ~DeviceInfo3(); |
| 409 | private: |
| 410 | CameraMetadata mCameraCharacteristics; |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 411 | std::unordered_map<std::string, CameraMetadata> mPhysicalCameraCharacteristics; |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 412 | void queryPhysicalCameraIds(); |
Shuzhen Wang | 268a136 | 2018-10-16 16:32:59 -0700 | [diff] [blame] | 413 | status_t fixupMonochromeTags(); |
| 414 | status_t removeAvailableKeys(CameraMetadata& c, const std::vector<uint32_t>& keys, |
| 415 | uint32_t keyTag); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 416 | }; |
| 417 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 418 | private: |
| 419 | std::string mType; |
| 420 | uint32_t mId; |
| 421 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 422 | std::mutex mLock; |
| 423 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 424 | CameraProviderManager *mManager; |
| 425 | |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 426 | bool mInitialized = false; |
| 427 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 428 | // Templated method to instantiate the right kind of DeviceInfo and call the |
| 429 | // right CameraProvider getCameraDeviceInterface_* method. |
| 430 | template<class DeviceInfoT> |
| 431 | std::unique_ptr<DeviceInfo> initializeDeviceInfo(const std::string &name, |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 432 | const metadata_vendor_id_t tagId, const std::string &id, |
| 433 | uint16_t minorVersion) const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 434 | |
| 435 | // Helper for initializeDeviceInfo to use the right CameraProvider get method. |
| 436 | template<class InterfaceT> |
| 437 | sp<InterfaceT> getDeviceInterface(const std::string &name) const; |
| 438 | |
| 439 | // Parse provider instance name for type and id |
| 440 | static status_t parseProviderName(const std::string& name, |
| 441 | std::string *type, uint32_t *id); |
| 442 | |
| 443 | // Parse device instance name for device version, type, and id. |
| 444 | static status_t parseDeviceName(const std::string& name, |
| 445 | uint16_t *major, uint16_t *minor, std::string *type, std::string *id); |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 446 | |
| 447 | // Generate vendor tag id |
| 448 | static metadata_vendor_id_t generateVendorTagId(const std::string &name); |
Guennadi Liakhovetski | 6034bf5 | 2017-12-07 10:28:29 +0100 | [diff] [blame] | 449 | |
| 450 | void removeDevice(std::string id); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 451 | }; |
| 452 | |
| 453 | // Utility to find a DeviceInfo by ID; pointer is only valid while mInterfaceMutex is held |
| 454 | // 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] | 455 | // Finds the first device of the given ID that falls within the requested version range |
| 456 | // minVersion <= deviceVersion < maxVersion |
| 457 | // No guarantees on the order of traversal |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 458 | ProviderInfo::DeviceInfo* findDeviceInfoLocked(const std::string& id, |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 459 | hardware::hidl_version minVersion = hardware::hidl_version{0,0}, |
| 460 | hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 461 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 462 | status_t addProviderLocked(const std::string& newProvider, bool expected = true); |
| 463 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 464 | status_t removeProvider(const std::string& provider); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 465 | sp<StatusListener> getStatusListener() const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 466 | |
| 467 | bool isValidDeviceLocked(const std::string &id, uint16_t majorVersion) const; |
| 468 | |
| 469 | std::vector<sp<ProviderInfo>> mProviders; |
| 470 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 471 | static const char* deviceStatusToString( |
| 472 | const hardware::camera::common::V1_0::CameraDeviceStatus&); |
| 473 | static const char* torchStatusToString( |
| 474 | const hardware::camera::common::V1_0::TorchModeStatus&); |
| 475 | |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 476 | status_t getCameraCharacteristicsLocked(const std::string &id, |
| 477 | CameraMetadata* characteristics) const; |
| 478 | void filterLogicalCameraIdsLocked(std::vector<std::string>& deviceIds) const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 479 | }; |
| 480 | |
| 481 | } // namespace android |
| 482 | |
| 483 | #endif |