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