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> |
Shuzhen Wang | 394ad70 | 2020-07-23 13:01:54 -0700 | [diff] [blame] | 25 | #include <future> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 26 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 27 | #include <camera/camera2/ConcurrentCamera.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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> |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 33 | #include <android/hardware/camera/provider/2.5/ICameraProvider.h> |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 34 | #include <android/hardware/camera/provider/2.6/ICameraProviderCallback.h> |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 35 | #include <android/hardware/camera/provider/2.6/ICameraProvider.h> |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 36 | #include <android/hardware/camera/device/3.4/ICameraDeviceSession.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 37 | #include <android/hidl/manager/1.0/IServiceNotification.h> |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 38 | #include <camera/VendorTagDescriptor.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 39 | |
| 40 | namespace android { |
| 41 | |
| 42 | /** |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 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 | |
Jayant Chowdhary | 5216b21 | 2019-07-17 09:26:23 -0700 | [diff] [blame] | 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 | |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 81 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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; |
Eino-Ville Talvala | ec96060 | 2019-10-15 11:46:16 -0700 | [diff] [blame] | 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 |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 107 | virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService( |
| 108 | const std::string &serviceName) = 0; |
Yin-Chia Yeh | 177b0c1 | 2019-06-25 10:53:03 -0700 | [diff] [blame] | 109 | virtual hardware::hidl_vec<hardware::hidl_string> listServices() = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 110 | 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 { |
| 116 | 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 | } |
Eino-Ville Talvala | ec96060 | 2019-10-15 11:46:16 -0700 | [diff] [blame] | 123 | 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 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 127 | 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 | } |
Yin-Chia Yeh | 177b0c1 | 2019-06-25 10:53:03 -0700 | [diff] [blame] | 131 | |
| 132 | virtual hardware::hidl_vec<hardware::hidl_string> listServices() override; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | /** |
| 136 | * Listener interface for device/torch status changes |
| 137 | */ |
| 138 | struct StatusListener : virtual public RefBase { |
| 139 | ~StatusListener() {} |
| 140 | |
| 141 | virtual void onDeviceStatusChanged(const String8 &cameraId, |
| 142 | hardware::camera::common::V1_0::CameraDeviceStatus newStatus) = 0; |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 143 | virtual void onDeviceStatusChanged(const String8 &cameraId, |
| 144 | const String8 &physicalCameraId, |
| 145 | hardware::camera::common::V1_0::CameraDeviceStatus newStatus) = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 146 | virtual void onTorchStatusChanged(const String8 &cameraId, |
| 147 | hardware::camera::common::V1_0::TorchModeStatus newStatus) = 0; |
Emilian Peev | aee727d | 2017-05-04 16:35:48 +0100 | [diff] [blame] | 148 | virtual void onNewProviderRegistered() = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | /** |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 152 | * Represents the mode a camera device is currently in |
| 153 | */ |
| 154 | enum class DeviceMode { |
| 155 | TORCH, |
| 156 | CAMERA |
| 157 | }; |
| 158 | |
| 159 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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 | /** |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 170 | * Retrieve the total number of available cameras. |
| 171 | * This value may change dynamically as cameras are added or removed. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 172 | */ |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 173 | std::pair<int, int> getCameraCount() const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 174 | |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 175 | std::vector<std::string> getCameraDeviceIds() const; |
| 176 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 177 | /** |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 178 | * Retrieve the number of API1 compatible cameras; these are internal and |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 179 | * backwards-compatible. This is the set of cameras that will be |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 180 | * accessible via the old camera API. |
| 181 | * The return value may change dynamically due to external camera hotplug. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 182 | */ |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 183 | std::vector<std::string> getAPI1CompatibleCameraDeviceIds() const; |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 184 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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 | /** |
Shuzhen Wang | dbdf72b | 2019-11-13 11:22:12 -0800 | [diff] [blame] | 197 | * Return true if the camera device has native zoom ratio support. |
| 198 | */ |
| 199 | bool supportNativeZoomRatio(const std::string &id) const; |
| 200 | |
| 201 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 220 | status_t isConcurrentSessionConfigurationSupported( |
| 221 | const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration> |
| 222 | &cameraIdsAndSessionConfigs, |
| 223 | bool *isSupported); |
| 224 | |
Jayant Chowdhary | cad23c2 | 2020-03-10 15:04:59 -0700 | [diff] [blame] | 225 | std::vector<std::unordered_set<std::string>> getConcurrentCameraIds() const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 226 | /** |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 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 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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 | /** |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 240 | * Check if a given camera device support setTorchMode API. |
| 241 | */ |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 242 | bool supportSetTorchMode(const std::string &id) const; |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 243 | |
| 244 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 245 | * Turn on or off the flashlight on a given camera device. |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 246 | * May fail if the device does not support this API, is in active use, or if the device |
| 247 | * doesn't exist, etc. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 248 | */ |
| 249 | status_t setTorchMode(const std::string &id, bool enabled); |
| 250 | |
| 251 | /** |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 252 | * Setup vendor tags for all registered providers |
| 253 | */ |
| 254 | status_t setUpVendorTags(); |
| 255 | |
| 256 | /** |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 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 | /** |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 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 | /** |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 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 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 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 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 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 | |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 315 | /* |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 316 | * Check if a camera is a logical camera. And if yes, return |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 317 | * the physical camera ids. |
| 318 | */ |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 319 | bool isLogicalCamera(const std::string& id, std::vector<std::string>* physicalCameraIds); |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 320 | |
Jayant Chowdhary | 33e8ef8 | 2019-09-27 09:20:42 -0700 | [diff] [blame] | 321 | status_t getSystemCameraKind(const std::string& id, SystemCameraKind *kind) const; |
| 322 | bool isHiddenPhysicalCamera(const std::string& cameraId) const; |
Emilian Peev | 538c90e | 2018-12-17 18:03:19 +0000 | [diff] [blame] | 323 | |
| 324 | static const float kDepthARTolerance; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 325 | private: |
| 326 | // All private members, unless otherwise noted, expect mInterfaceMutex to be locked before use |
| 327 | mutable std::mutex mInterfaceMutex; |
| 328 | |
Yin-Chia Yeh | 52778d4 | 2016-12-22 18:20:43 -0800 | [diff] [blame] | 329 | // the status listener update callbacks will lock mStatusMutex |
| 330 | mutable std::mutex mStatusListenerMutex; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 331 | wp<StatusListener> mListener; |
| 332 | ServiceInteractionProxy* mServiceProxy; |
| 333 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 334 | // Current overall Android device physical status |
| 335 | android::hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> mDeviceState; |
| 336 | |
Shuzhen Wang | 6ba8eb2 | 2018-07-08 13:10:44 -0700 | [diff] [blame] | 337 | // mProviderLifecycleLock is locked during onRegistration and removeProvider |
| 338 | mutable std::mutex mProviderLifecycleLock; |
| 339 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 340 | static HardwareServiceInteractionProxy sHardwareServiceInteractionProxy; |
| 341 | |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 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 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 357 | struct ProviderInfo : |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 358 | virtual public hardware::camera::provider::V2_6::ICameraProviderCallback, |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 359 | virtual public hardware::hidl_death_recipient |
| 360 | { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 361 | const std::string mProviderName; |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 362 | const metadata_vendor_id_t mProviderTagid; |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 363 | int mMinorVersion; |
Peter Kalauskas | 1b3c907 | 2018-11-07 12:41:53 -0800 | [diff] [blame] | 364 | sp<VendorTagDescriptor> mVendorTagDescriptor; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 365 | bool mSetTorchModeSupported; |
| 366 | bool mIsRemote; |
| 367 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 368 | // Current overall Android device physical status |
| 369 | hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> mDeviceState; |
| 370 | |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 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; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 375 | |
| 376 | ProviderInfo(const std::string &providerName, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 377 | CameraProviderManager *manager); |
| 378 | ~ProviderInfo(); |
| 379 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 380 | status_t initialize(sp<hardware::camera::provider::V2_4::ICameraProvider>& interface, |
| 381 | hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> |
| 382 | currentDeviceState); |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 383 | |
| 384 | const sp<hardware::camera::provider::V2_4::ICameraProvider> startProviderInterface(); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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 |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 396 | hardware::Return<void> cameraDeviceStatusChange( |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 397 | const hardware::hidl_string& cameraDeviceName, |
| 398 | hardware::camera::common::V1_0::CameraDeviceStatus newStatus) override; |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 399 | hardware::Return<void> torchModeStatusChange( |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 400 | const hardware::hidl_string& cameraDeviceName, |
| 401 | hardware::camera::common::V1_0::TorchModeStatus newStatus) override; |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 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; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 406 | |
Shuzhen Wang | 394ad70 | 2020-07-23 13:01:54 -0700 | [diff] [blame] | 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 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 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 | |
Peter Kalauskas | 1b3c907 | 2018-11-07 12:41:53 -0800 | [diff] [blame] | 419 | /** |
| 420 | * Setup vendor tags for this provider |
| 421 | */ |
| 422 | status_t setUpVendorTags(); |
| 423 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 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); |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 430 | |
| 431 | std::vector<std::unordered_set<std::string>> getConcurrentCameraIdCombinations(); |
| 432 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 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); |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 441 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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; |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 447 | const metadata_vendor_id_t mProviderTagid; |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 448 | bool mIsLogicalCamera; |
| 449 | std::vector<std::string> mPhysicalIds; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 450 | hardware::CameraInfo mInfo; |
| 451 | sp<IBase> mSavedInterface; |
Jayant Chowdhary | 5216b21 | 2019-07-17 09:26:23 -0700 | [diff] [blame] | 452 | SystemCameraKind mSystemCameraKind = SystemCameraKind::PUBLIC; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 453 | |
| 454 | const hardware::camera::common::V1_0::CameraResourceCost mResourceCost; |
| 455 | |
| 456 | hardware::camera::common::V1_0::CameraDeviceStatus mStatus; |
| 457 | |
Shuzhen Wang | 7968043 | 2020-03-05 11:53:46 -0800 | [diff] [blame] | 458 | wp<ProviderInfo> mParentProvider; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 459 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 460 | bool hasFlashUnit() const { return mHasFlashUnit; } |
Shuzhen Wang | dbdf72b | 2019-11-13 11:22:12 -0800 | [diff] [blame] | 461 | bool supportNativeZoomRatio() const { return mSupportNativeZoomRatio; } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 462 | virtual status_t setTorchMode(bool enabled) = 0; |
| 463 | virtual status_t getCameraInfo(hardware::CameraInfo *info) const = 0; |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 464 | virtual bool isAPI1Compatible() const = 0; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 465 | virtual status_t dumpState(int fd) = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 466 | virtual status_t getCameraCharacteristics(CameraMetadata *characteristics) const { |
| 467 | (void) characteristics; |
| 468 | return INVALID_OPERATION; |
| 469 | } |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 470 | virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId, |
| 471 | CameraMetadata *characteristics) const { |
| 472 | (void) physicalCameraId; |
| 473 | (void) characteristics; |
| 474 | return INVALID_OPERATION; |
| 475 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 476 | |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 477 | virtual status_t isSessionConfigurationSupported( |
| 478 | const hardware::camera::device::V3_4::StreamConfiguration &/*configuration*/, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 479 | bool * /*status*/) { |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 480 | return INVALID_OPERATION; |
| 481 | } |
| 482 | |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 483 | template<class InterfaceT> |
| 484 | sp<InterfaceT> startDeviceInterface(); |
| 485 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 486 | DeviceInfo(const std::string& name, const metadata_vendor_id_t tagId, |
| 487 | const std::string &id, const hardware::hidl_version& version, |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 488 | const std::vector<std::string>& publicCameraIds, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 489 | const hardware::camera::common::V1_0::CameraResourceCost& resourceCost, |
| 490 | sp<ProviderInfo> parentProvider) : |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 491 | mName(name), mId(id), mVersion(version), mProviderTagid(tagId), |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 492 | mIsLogicalCamera(false), mResourceCost(resourceCost), |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 493 | mStatus(hardware::camera::common::V1_0::CameraDeviceStatus::PRESENT), |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 494 | mParentProvider(parentProvider), mHasFlashUnit(false), |
Shuzhen Wang | dbdf72b | 2019-11-13 11:22:12 -0800 | [diff] [blame] | 495 | mSupportNativeZoomRatio(false), mPublicCameraIds(publicCameraIds) {} |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 496 | virtual ~DeviceInfo(); |
| 497 | protected: |
Shuzhen Wang | dbdf72b | 2019-11-13 11:22:12 -0800 | [diff] [blame] | 498 | bool mHasFlashUnit; // const after constructor |
| 499 | bool mSupportNativeZoomRatio; // const after constructor |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 500 | const std::vector<std::string>& mPublicCameraIds; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 501 | |
| 502 | template<class InterfaceT> |
| 503 | static status_t setTorchMode(InterfaceT& interface, bool enabled); |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 504 | |
| 505 | template<class InterfaceT> |
| 506 | 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 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 512 | }; |
| 513 | std::vector<std::unique_ptr<DeviceInfo>> mDevices; |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 514 | std::unordered_set<std::string> mUniqueCameraIds; |
Yin-Chia Yeh | e8e9e19 | 2017-03-16 15:23:51 -0700 | [diff] [blame] | 515 | int mUniqueDeviceCount; |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 516 | std::vector<std::string> mUniqueAPI1CompatibleCameraIds; |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 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; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 523 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 524 | // HALv1-specific camera fields, including the actual device interface |
| 525 | struct DeviceInfo1 : public DeviceInfo { |
| 526 | typedef hardware::camera::device::V1_0::ICameraDevice InterfaceT; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 527 | |
| 528 | virtual status_t setTorchMode(bool enabled) override; |
| 529 | virtual status_t getCameraInfo(hardware::CameraInfo *info) const override; |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 530 | //In case of Device1Info assume that we are always API1 compatible |
| 531 | virtual bool isAPI1Compatible() const override { return true; } |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 532 | virtual status_t dumpState(int fd) override; |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 533 | DeviceInfo1(const std::string& name, const metadata_vendor_id_t tagId, |
| 534 | const std::string &id, uint16_t minorVersion, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 535 | const hardware::camera::common::V1_0::CameraResourceCost& resourceCost, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 536 | sp<ProviderInfo> parentProvider, |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 537 | const std::vector<std::string>& publicCameraIds, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 538 | sp<InterfaceT> interface); |
| 539 | virtual ~DeviceInfo1(); |
| 540 | private: |
| 541 | CameraParameters2 mDefaultParameters; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 542 | status_t cacheCameraInfo(sp<InterfaceT> interface); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 548 | |
| 549 | virtual status_t setTorchMode(bool enabled) override; |
| 550 | virtual status_t getCameraInfo(hardware::CameraInfo *info) const override; |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 551 | virtual bool isAPI1Compatible() const override; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 552 | virtual status_t dumpState(int fd) override; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 553 | virtual status_t getCameraCharacteristics( |
| 554 | CameraMetadata *characteristics) const override; |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 555 | virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId, |
| 556 | CameraMetadata *characteristics) const override; |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 557 | virtual status_t isSessionConfigurationSupported( |
| 558 | const hardware::camera::device::V3_4::StreamConfiguration &configuration, |
| 559 | bool *status /*out*/) |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 560 | override; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 561 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 562 | DeviceInfo3(const std::string& name, const metadata_vendor_id_t tagId, |
| 563 | const std::string &id, uint16_t minorVersion, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 564 | const hardware::camera::common::V1_0::CameraResourceCost& resourceCost, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 565 | sp<ProviderInfo> parentProvider, |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 566 | const std::vector<std::string>& publicCameraIds, sp<InterfaceT> interface); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 567 | virtual ~DeviceInfo3(); |
| 568 | private: |
| 569 | CameraMetadata mCameraCharacteristics; |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 570 | std::unordered_map<std::string, CameraMetadata> mPhysicalCameraCharacteristics; |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 571 | void queryPhysicalCameraIds(); |
Jayant Chowdhary | 5216b21 | 2019-07-17 09:26:23 -0700 | [diff] [blame] | 572 | SystemCameraKind getSystemCameraKind(); |
Shuzhen Wang | 268a136 | 2018-10-16 16:32:59 -0700 | [diff] [blame] | 573 | status_t fixupMonochromeTags(); |
Emilian Peev | 4c6d2b5 | 2019-01-04 17:13:56 +0000 | [diff] [blame] | 574 | status_t addDynamicDepthTags(); |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 575 | status_t deriveHeicTags(); |
| 576 | status_t addRotateCropTags(); |
Shuzhen Wang | 9bf8a6f | 2020-05-01 09:49:04 -0700 | [diff] [blame] | 577 | status_t addPreCorrectionActiveArraySize(); |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 578 | |
Emilian Peev | 4c6d2b5 | 2019-01-04 17:13:56 +0000 | [diff] [blame] | 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*/); |
Shuzhen Wang | 268a136 | 2018-10-16 16:32:59 -0700 | [diff] [blame] | 594 | status_t removeAvailableKeys(CameraMetadata& c, const std::vector<uint32_t>& keys, |
| 595 | uint32_t keyTag); |
Shuzhen Wang | 68ac7ad | 2019-01-30 14:03:28 -0800 | [diff] [blame] | 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); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 601 | }; |
| 602 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 603 | private: |
| 604 | std::string mType; |
| 605 | uint32_t mId; |
| 606 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 607 | std::mutex mLock; |
| 608 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 609 | CameraProviderManager *mManager; |
| 610 | |
Shuzhen Wang | 394ad70 | 2020-07-23 13:01:54 -0700 | [diff] [blame] | 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; |
| 616 | 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; |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 625 | bool mInitialized = false; |
Shuzhen Wang | 394ad70 | 2020-07-23 13:01:54 -0700 | [diff] [blame] | 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); |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 632 | |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 633 | std::vector<std::unordered_set<std::string>> mConcurrentCameraIdCombinations; |
| 634 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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, |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 639 | const metadata_vendor_id_t tagId, const std::string &id, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 640 | uint16_t minorVersion); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 641 | |
| 642 | // Helper for initializeDeviceInfo to use the right CameraProvider get method. |
| 643 | template<class InterfaceT> |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 644 | sp<InterfaceT> startDeviceInterface(const std::string &name); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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); |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 653 | |
| 654 | // Generate vendor tag id |
| 655 | static metadata_vendor_id_t generateVendorTagId(const std::string &name); |
Guennadi Liakhovetski | 6034bf5 | 2017-12-07 10:28:29 +0100 | [diff] [blame] | 656 | |
| 657 | void removeDevice(std::string id); |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 658 | |
| 659 | // Expects to have mLock locked |
| 660 | status_t reCacheConcurrentStreamingCameraIdsLocked(); |
| 661 | // Expects to have mLock locked |
Jayant Chowdhary | cad23c2 | 2020-03-10 15:04:59 -0700 | [diff] [blame] | 662 | status_t getConcurrentCameraIdsInternalLocked( |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 663 | sp<hardware::camera::provider::V2_6::ICameraProvider> &interface2_6); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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. |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 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 |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 671 | ProviderInfo::DeviceInfo* findDeviceInfoLocked(const std::string& id, |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 672 | hardware::hidl_version minVersion = hardware::hidl_version{0,0}, |
| 673 | hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 674 | |
Yin-Chia Yeh | 177b0c1 | 2019-06-25 10:53:03 -0700 | [diff] [blame] | 675 | status_t addProviderLocked(const std::string& newProvider); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 676 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 677 | bool isLogicalCameraLocked(const std::string& id, std::vector<std::string>* physicalCameraIds); |
| 678 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 679 | status_t removeProvider(const std::string& provider); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 680 | sp<StatusListener> getStatusListener() const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 681 | |
| 682 | bool isValidDeviceLocked(const std::string &id, uint16_t majorVersion) const; |
| 683 | |
| 684 | std::vector<sp<ProviderInfo>> mProviders; |
| 685 | |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 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 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 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 | |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 699 | status_t getCameraCharacteristicsLocked(const std::string &id, |
| 700 | CameraMetadata* characteristics) const; |
| 701 | void filterLogicalCameraIdsLocked(std::vector<std::string>& deviceIds) const; |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 702 | |
Jayant Chowdhary | 33e8ef8 | 2019-09-27 09:20:42 -0700 | [diff] [blame] | 703 | status_t getSystemCameraKindLocked(const std::string& id, SystemCameraKind *kind) const; |
| 704 | std::pair<bool, ProviderInfo::DeviceInfo *> isHiddenPhysicalCameraInternal(const std::string& cameraId) const; |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 705 | |
| 706 | void collectDeviceIdsLocked(const std::vector<std::string> deviceIds, |
| 707 | std::vector<std::string>& normalDeviceIds, |
| 708 | std::vector<std::string>& systemCameraDeviceIds) const; |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 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); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 716 | }; |
| 717 | |
| 718 | } // namespace android |
| 719 | |
| 720 | #endif |