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