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