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