Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_SERVERS_CAMERA_CAMERAPROVIDER_H |
| 18 | #define ANDROID_SERVERS_CAMERA_CAMERAPROVIDER_H |
| 19 | |
| 20 | #include <vector> |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 21 | #include <unordered_map> |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 22 | #include <unordered_set> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 23 | #include <string> |
| 24 | #include <mutex> |
| 25 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 26 | #include <camera/camera2/ConcurrentCamera.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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> |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 32 | #include <android/hardware/camera/provider/2.5/ICameraProvider.h> |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 33 | #include <android/hardware/camera/provider/2.6/ICameraProviderCallback.h> |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 34 | #include <android/hardware/camera/provider/2.6/ICameraProvider.h> |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 35 | #include <android/hardware/camera/device/3.4/ICameraDeviceSession.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 36 | #include <android/hidl/manager/1.0/IServiceNotification.h> |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 37 | #include <camera/VendorTagDescriptor.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 38 | |
| 39 | namespace android { |
| 40 | |
| 41 | /** |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 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 | |
Jayant Chowdhary | 5216b21 | 2019-07-17 09:26:23 -0700 | [diff] [blame] | 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 | |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 80 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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; |
Eino-Ville Talvala | ec96060 | 2019-10-15 11:46:16 -0700 | [diff] [blame] | 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 |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 106 | virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService( |
| 107 | const std::string &serviceName) = 0; |
Yin-Chia Yeh | 177b0c1 | 2019-06-25 10:53:03 -0700 | [diff] [blame] | 108 | virtual hardware::hidl_vec<hardware::hidl_string> listServices() = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 109 | 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 { |
| 115 | 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 | } |
Eino-Ville Talvala | ec96060 | 2019-10-15 11:46:16 -0700 | [diff] [blame] | 122 | 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 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 126 | 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 | } |
Yin-Chia Yeh | 177b0c1 | 2019-06-25 10:53:03 -0700 | [diff] [blame] | 130 | |
| 131 | virtual hardware::hidl_vec<hardware::hidl_string> listServices() override; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | /** |
| 135 | * Listener interface for device/torch status changes |
| 136 | */ |
| 137 | struct StatusListener : virtual public RefBase { |
| 138 | ~StatusListener() {} |
| 139 | |
| 140 | virtual void onDeviceStatusChanged(const String8 &cameraId, |
| 141 | hardware::camera::common::V1_0::CameraDeviceStatus newStatus) = 0; |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 142 | virtual void onDeviceStatusChanged(const String8 &cameraId, |
| 143 | const String8 &physicalCameraId, |
| 144 | hardware::camera::common::V1_0::CameraDeviceStatus newStatus) = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 145 | virtual void onTorchStatusChanged(const String8 &cameraId, |
| 146 | hardware::camera::common::V1_0::TorchModeStatus newStatus) = 0; |
Emilian Peev | aee727d | 2017-05-04 16:35:48 +0100 | [diff] [blame] | 147 | virtual void onNewProviderRegistered() = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | /** |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 151 | * Represents the mode a camera device is currently in |
| 152 | */ |
| 153 | enum class DeviceMode { |
| 154 | TORCH, |
| 155 | CAMERA |
| 156 | }; |
| 157 | |
| 158 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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 | /** |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 169 | * Retrieve the total number of available cameras. |
| 170 | * This value may change dynamically as cameras are added or removed. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 171 | */ |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 172 | std::pair<int, int> getCameraCount() const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 173 | |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 174 | std::vector<std::string> getCameraDeviceIds() const; |
| 175 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 176 | /** |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 177 | * Retrieve the number of API1 compatible cameras; these are internal and |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 178 | * backwards-compatible. This is the set of cameras that will be |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 179 | * accessible via the old camera API. |
| 180 | * The return value may change dynamically due to external camera hotplug. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 181 | */ |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 182 | std::vector<std::string> getAPI1CompatibleCameraDeviceIds() const; |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 183 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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 | /** |
Shuzhen Wang | dbdf72b | 2019-11-13 11:22:12 -0800 | [diff] [blame] | 196 | * Return true if the camera device has native zoom ratio support. |
| 197 | */ |
| 198 | bool supportNativeZoomRatio(const std::string &id) const; |
| 199 | |
| 200 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 219 | status_t isConcurrentSessionConfigurationSupported( |
| 220 | const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration> |
| 221 | &cameraIdsAndSessionConfigs, |
| 222 | bool *isSupported); |
| 223 | |
Jayant Chowdhary | cad23c2 | 2020-03-10 15:04:59 -0700 | [diff] [blame] | 224 | std::vector<std::unordered_set<std::string>> getConcurrentCameraIds() const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 225 | /** |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 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 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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 | /** |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 239 | * Check if a given camera device support setTorchMode API. |
| 240 | */ |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 241 | bool supportSetTorchMode(const std::string &id) const; |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 242 | |
| 243 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 244 | * Turn on or off the flashlight on a given camera device. |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 245 | * May fail if the device does not support this API, is in active use, or if the device |
| 246 | * doesn't exist, etc. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 247 | */ |
| 248 | status_t setTorchMode(const std::string &id, bool enabled); |
| 249 | |
| 250 | /** |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 251 | * Setup vendor tags for all registered providers |
| 252 | */ |
| 253 | status_t setUpVendorTags(); |
| 254 | |
| 255 | /** |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 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 | /** |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 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 | /** |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 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 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 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 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 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 | |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 314 | /* |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 315 | * Check if a camera is a logical camera. And if yes, return |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 316 | * the physical camera ids. |
| 317 | */ |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 318 | bool isLogicalCamera(const std::string& id, std::vector<std::string>* physicalCameraIds); |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 319 | |
Jayant Chowdhary | 33e8ef8 | 2019-09-27 09:20:42 -0700 | [diff] [blame] | 320 | status_t getSystemCameraKind(const std::string& id, SystemCameraKind *kind) const; |
| 321 | bool isHiddenPhysicalCamera(const std::string& cameraId) const; |
Emilian Peev | 538c90e | 2018-12-17 18:03:19 +0000 | [diff] [blame] | 322 | |
| 323 | static const float kDepthARTolerance; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 324 | private: |
| 325 | // All private members, unless otherwise noted, expect mInterfaceMutex to be locked before use |
| 326 | mutable std::mutex mInterfaceMutex; |
| 327 | |
Yin-Chia Yeh | 52778d4 | 2016-12-22 18:20:43 -0800 | [diff] [blame] | 328 | // the status listener update callbacks will lock mStatusMutex |
| 329 | mutable std::mutex mStatusListenerMutex; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 330 | wp<StatusListener> mListener; |
| 331 | ServiceInteractionProxy* mServiceProxy; |
| 332 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 333 | // Current overall Android device physical status |
| 334 | android::hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> mDeviceState; |
| 335 | |
Shuzhen Wang | 6ba8eb2 | 2018-07-08 13:10:44 -0700 | [diff] [blame] | 336 | // mProviderLifecycleLock is locked during onRegistration and removeProvider |
| 337 | mutable std::mutex mProviderLifecycleLock; |
| 338 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 339 | static HardwareServiceInteractionProxy sHardwareServiceInteractionProxy; |
| 340 | |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 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 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 356 | struct ProviderInfo : |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 357 | virtual public hardware::camera::provider::V2_6::ICameraProviderCallback, |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 358 | virtual public hardware::hidl_death_recipient |
| 359 | { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 360 | const std::string mProviderName; |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 361 | const metadata_vendor_id_t mProviderTagid; |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 362 | int mMinorVersion; |
Peter Kalauskas | 1b3c907 | 2018-11-07 12:41:53 -0800 | [diff] [blame] | 363 | sp<VendorTagDescriptor> mVendorTagDescriptor; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 364 | bool mSetTorchModeSupported; |
| 365 | bool mIsRemote; |
| 366 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 367 | // Current overall Android device physical status |
| 368 | hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> mDeviceState; |
| 369 | |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 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; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 374 | |
| 375 | ProviderInfo(const std::string &providerName, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 376 | CameraProviderManager *manager); |
| 377 | ~ProviderInfo(); |
| 378 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 379 | status_t initialize(sp<hardware::camera::provider::V2_4::ICameraProvider>& interface, |
| 380 | hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> |
| 381 | currentDeviceState); |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 382 | |
| 383 | const sp<hardware::camera::provider::V2_4::ICameraProvider> startProviderInterface(); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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 |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 395 | hardware::Return<void> cameraDeviceStatusChange( |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 396 | const hardware::hidl_string& cameraDeviceName, |
| 397 | hardware::camera::common::V1_0::CameraDeviceStatus newStatus) override; |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 398 | hardware::Return<void> torchModeStatusChange( |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 399 | const hardware::hidl_string& cameraDeviceName, |
| 400 | hardware::camera::common::V1_0::TorchModeStatus newStatus) override; |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 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; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 405 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 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 | |
Peter Kalauskas | 1b3c907 | 2018-11-07 12:41:53 -0800 | [diff] [blame] | 409 | /** |
| 410 | * Setup vendor tags for this provider |
| 411 | */ |
| 412 | status_t setUpVendorTags(); |
| 413 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 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); |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 420 | |
| 421 | std::vector<std::unordered_set<std::string>> getConcurrentCameraIdCombinations(); |
| 422 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 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); |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 431 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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; |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 437 | const metadata_vendor_id_t mProviderTagid; |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 438 | bool mIsLogicalCamera; |
| 439 | std::vector<std::string> mPhysicalIds; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 440 | hardware::CameraInfo mInfo; |
| 441 | sp<IBase> mSavedInterface; |
Jayant Chowdhary | 5216b21 | 2019-07-17 09:26:23 -0700 | [diff] [blame] | 442 | SystemCameraKind mSystemCameraKind = SystemCameraKind::PUBLIC; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 443 | |
| 444 | const hardware::camera::common::V1_0::CameraResourceCost mResourceCost; |
| 445 | |
| 446 | hardware::camera::common::V1_0::CameraDeviceStatus mStatus; |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 447 | std::map<std::string, hardware::camera::common::V1_0::CameraDeviceStatus> |
| 448 | mPhysicalStatus; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 449 | |
Shuzhen Wang | 7968043 | 2020-03-05 11:53:46 -0800 | [diff] [blame] | 450 | wp<ProviderInfo> mParentProvider; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 451 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 452 | bool hasFlashUnit() const { return mHasFlashUnit; } |
Shuzhen Wang | dbdf72b | 2019-11-13 11:22:12 -0800 | [diff] [blame] | 453 | bool supportNativeZoomRatio() const { return mSupportNativeZoomRatio; } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 454 | virtual status_t setTorchMode(bool enabled) = 0; |
| 455 | virtual status_t getCameraInfo(hardware::CameraInfo *info) const = 0; |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 456 | virtual bool isAPI1Compatible() const = 0; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 457 | virtual status_t dumpState(int fd) = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 458 | virtual status_t getCameraCharacteristics(CameraMetadata *characteristics) const { |
| 459 | (void) characteristics; |
| 460 | return INVALID_OPERATION; |
| 461 | } |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 462 | virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId, |
| 463 | CameraMetadata *characteristics) const { |
| 464 | (void) physicalCameraId; |
| 465 | (void) characteristics; |
| 466 | return INVALID_OPERATION; |
| 467 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 468 | |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 469 | virtual status_t isSessionConfigurationSupported( |
| 470 | const hardware::camera::device::V3_4::StreamConfiguration &/*configuration*/, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 471 | bool * /*status*/) { |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 472 | return INVALID_OPERATION; |
| 473 | } |
| 474 | |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 475 | template<class InterfaceT> |
| 476 | sp<InterfaceT> startDeviceInterface(); |
| 477 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 478 | DeviceInfo(const std::string& name, const metadata_vendor_id_t tagId, |
| 479 | const std::string &id, const hardware::hidl_version& version, |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 480 | const std::vector<std::string>& publicCameraIds, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 481 | const hardware::camera::common::V1_0::CameraResourceCost& resourceCost, |
| 482 | sp<ProviderInfo> parentProvider) : |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 483 | mName(name), mId(id), mVersion(version), mProviderTagid(tagId), |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 484 | mIsLogicalCamera(false), mResourceCost(resourceCost), |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 485 | mStatus(hardware::camera::common::V1_0::CameraDeviceStatus::PRESENT), |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 486 | mParentProvider(parentProvider), mHasFlashUnit(false), |
Shuzhen Wang | dbdf72b | 2019-11-13 11:22:12 -0800 | [diff] [blame] | 487 | mSupportNativeZoomRatio(false), mPublicCameraIds(publicCameraIds) {} |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 488 | virtual ~DeviceInfo(); |
| 489 | protected: |
Shuzhen Wang | dbdf72b | 2019-11-13 11:22:12 -0800 | [diff] [blame] | 490 | bool mHasFlashUnit; // const after constructor |
| 491 | bool mSupportNativeZoomRatio; // const after constructor |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 492 | const std::vector<std::string>& mPublicCameraIds; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 493 | |
| 494 | template<class InterfaceT> |
| 495 | static status_t setTorchMode(InterfaceT& interface, bool enabled); |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 496 | |
| 497 | template<class InterfaceT> |
| 498 | 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 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 504 | }; |
| 505 | std::vector<std::unique_ptr<DeviceInfo>> mDevices; |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 506 | std::unordered_set<std::string> mUniqueCameraIds; |
Yin-Chia Yeh | e8e9e19 | 2017-03-16 15:23:51 -0700 | [diff] [blame] | 507 | int mUniqueDeviceCount; |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 508 | std::vector<std::string> mUniqueAPI1CompatibleCameraIds; |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 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; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 515 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 516 | // HALv1-specific camera fields, including the actual device interface |
| 517 | struct DeviceInfo1 : public DeviceInfo { |
| 518 | typedef hardware::camera::device::V1_0::ICameraDevice InterfaceT; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 519 | |
| 520 | virtual status_t setTorchMode(bool enabled) override; |
| 521 | virtual status_t getCameraInfo(hardware::CameraInfo *info) const override; |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 522 | //In case of Device1Info assume that we are always API1 compatible |
| 523 | virtual bool isAPI1Compatible() const override { return true; } |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 524 | virtual status_t dumpState(int fd) override; |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 525 | DeviceInfo1(const std::string& name, const metadata_vendor_id_t tagId, |
| 526 | const std::string &id, uint16_t minorVersion, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 527 | const hardware::camera::common::V1_0::CameraResourceCost& resourceCost, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 528 | sp<ProviderInfo> parentProvider, |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 529 | const std::vector<std::string>& publicCameraIds, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 530 | sp<InterfaceT> interface); |
| 531 | virtual ~DeviceInfo1(); |
| 532 | private: |
| 533 | CameraParameters2 mDefaultParameters; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 534 | status_t cacheCameraInfo(sp<InterfaceT> interface); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 540 | |
| 541 | virtual status_t setTorchMode(bool enabled) override; |
| 542 | virtual status_t getCameraInfo(hardware::CameraInfo *info) const override; |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 543 | virtual bool isAPI1Compatible() const override; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 544 | virtual status_t dumpState(int fd) override; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 545 | virtual status_t getCameraCharacteristics( |
| 546 | CameraMetadata *characteristics) const override; |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 547 | virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId, |
| 548 | CameraMetadata *characteristics) const override; |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 549 | virtual status_t isSessionConfigurationSupported( |
| 550 | const hardware::camera::device::V3_4::StreamConfiguration &configuration, |
| 551 | bool *status /*out*/) |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 552 | override; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 553 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 554 | DeviceInfo3(const std::string& name, const metadata_vendor_id_t tagId, |
| 555 | const std::string &id, uint16_t minorVersion, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 556 | const hardware::camera::common::V1_0::CameraResourceCost& resourceCost, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 557 | sp<ProviderInfo> parentProvider, |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 558 | const std::vector<std::string>& publicCameraIds, sp<InterfaceT> interface); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 559 | virtual ~DeviceInfo3(); |
| 560 | private: |
| 561 | CameraMetadata mCameraCharacteristics; |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 562 | std::unordered_map<std::string, CameraMetadata> mPhysicalCameraCharacteristics; |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 563 | void queryPhysicalCameraIds(); |
Jayant Chowdhary | 5216b21 | 2019-07-17 09:26:23 -0700 | [diff] [blame] | 564 | SystemCameraKind getSystemCameraKind(); |
Shuzhen Wang | 268a136 | 2018-10-16 16:32:59 -0700 | [diff] [blame] | 565 | status_t fixupMonochromeTags(); |
Emilian Peev | 4c6d2b5 | 2019-01-04 17:13:56 +0000 | [diff] [blame] | 566 | status_t addDynamicDepthTags(); |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 567 | status_t deriveHeicTags(); |
| 568 | status_t addRotateCropTags(); |
Shuzhen Wang | 9bf8a6f | 2020-05-01 09:49:04 -0700 | [diff] [blame] | 569 | status_t addPreCorrectionActiveArraySize(); |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 570 | |
Emilian Peev | 4c6d2b5 | 2019-01-04 17:13:56 +0000 | [diff] [blame] | 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*/); |
Shuzhen Wang | 268a136 | 2018-10-16 16:32:59 -0700 | [diff] [blame] | 586 | status_t removeAvailableKeys(CameraMetadata& c, const std::vector<uint32_t>& keys, |
| 587 | uint32_t keyTag); |
Shuzhen Wang | 68ac7ad | 2019-01-30 14:03:28 -0800 | [diff] [blame] | 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); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 593 | }; |
| 594 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 595 | private: |
| 596 | std::string mType; |
| 597 | uint32_t mId; |
| 598 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 599 | std::mutex mLock; |
| 600 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 601 | CameraProviderManager *mManager; |
| 602 | |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 603 | bool mInitialized = false; |
| 604 | |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 605 | std::vector<std::unordered_set<std::string>> mConcurrentCameraIdCombinations; |
| 606 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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, |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 611 | const metadata_vendor_id_t tagId, const std::string &id, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 612 | uint16_t minorVersion); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 613 | |
| 614 | // Helper for initializeDeviceInfo to use the right CameraProvider get method. |
| 615 | template<class InterfaceT> |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 616 | sp<InterfaceT> startDeviceInterface(const std::string &name); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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); |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 625 | |
| 626 | // Generate vendor tag id |
| 627 | static metadata_vendor_id_t generateVendorTagId(const std::string &name); |
Guennadi Liakhovetski | 6034bf5 | 2017-12-07 10:28:29 +0100 | [diff] [blame] | 628 | |
| 629 | void removeDevice(std::string id); |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 630 | |
| 631 | // Expects to have mLock locked |
| 632 | status_t reCacheConcurrentStreamingCameraIdsLocked(); |
| 633 | // Expects to have mLock locked |
Jayant Chowdhary | cad23c2 | 2020-03-10 15:04:59 -0700 | [diff] [blame] | 634 | status_t getConcurrentCameraIdsInternalLocked( |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 635 | sp<hardware::camera::provider::V2_6::ICameraProvider> &interface2_6); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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. |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 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 |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 643 | ProviderInfo::DeviceInfo* findDeviceInfoLocked(const std::string& id, |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 644 | hardware::hidl_version minVersion = hardware::hidl_version{0,0}, |
| 645 | hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 646 | |
Yin-Chia Yeh | 177b0c1 | 2019-06-25 10:53:03 -0700 | [diff] [blame] | 647 | status_t addProviderLocked(const std::string& newProvider); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 648 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 649 | bool isLogicalCameraLocked(const std::string& id, std::vector<std::string>* physicalCameraIds); |
| 650 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 651 | status_t removeProvider(const std::string& provider); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 652 | sp<StatusListener> getStatusListener() const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 653 | |
| 654 | bool isValidDeviceLocked(const std::string &id, uint16_t majorVersion) const; |
| 655 | |
| 656 | std::vector<sp<ProviderInfo>> mProviders; |
| 657 | |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 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 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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 | |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 671 | status_t getCameraCharacteristicsLocked(const std::string &id, |
| 672 | CameraMetadata* characteristics) const; |
| 673 | void filterLogicalCameraIdsLocked(std::vector<std::string>& deviceIds) const; |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 674 | |
Jayant Chowdhary | 33e8ef8 | 2019-09-27 09:20:42 -0700 | [diff] [blame] | 675 | status_t getSystemCameraKindLocked(const std::string& id, SystemCameraKind *kind) const; |
| 676 | std::pair<bool, ProviderInfo::DeviceInfo *> isHiddenPhysicalCameraInternal(const std::string& cameraId) const; |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 677 | |
| 678 | void collectDeviceIdsLocked(const std::vector<std::string> deviceIds, |
| 679 | std::vector<std::string>& normalDeviceIds, |
| 680 | std::vector<std::string>& systemCameraDeviceIds) const; |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 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); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 688 | }; |
| 689 | |
| 690 | } // namespace android |
| 691 | |
| 692 | #endif |