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> |
Valentin Iftime | 29e2e15 | 2021-08-13 15:17:33 +0200 | [diff] [blame] | 32 | #include <utils/Condition.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 33 | #include <utils/Errors.h> |
Valentin Iftime | 29e2e15 | 2021-08-13 15:17:33 +0200 | [diff] [blame] | 34 | #include <android/hardware/ICameraService.h> |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 35 | #include <utils/IPCTransport.h> |
Shuzhen Wang | a79a64d | 2022-04-24 19:56:30 -0700 | [diff] [blame] | 36 | #include <utils/SessionConfigurationUtils.h> |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 37 | #include <aidl/android/hardware/camera/provider/ICameraProvider.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 38 | #include <android/hardware/camera/common/1.0/types.h> |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 39 | #include <android/hardware/camera/provider/2.5/ICameraProvider.h> |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 40 | #include <android/hardware/camera/provider/2.6/ICameraProviderCallback.h> |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 41 | #include <android/hardware/camera/provider/2.6/ICameraProvider.h> |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 42 | #include <android/hardware/camera/provider/2.7/ICameraProvider.h> |
| 43 | #include <android/hardware/camera/device/3.7/types.h> |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame] | 44 | #include <android/hardware/camera/device/3.8/types.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 45 | #include <android/hidl/manager/1.0/IServiceNotification.h> |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 46 | #include <binder/IServiceManager.h> |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 47 | #include <camera/VendorTagDescriptor.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 48 | |
| 49 | namespace android { |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 50 | |
| 51 | using hardware::camera2::utils::CameraIdAndSessionConfiguration; |
| 52 | |
| 53 | enum class CameraDeviceStatus : uint32_t { |
| 54 | NOT_PRESENT = 0, |
| 55 | PRESENT = 1, |
| 56 | ENUMERATING = 2 |
| 57 | }; |
| 58 | |
| 59 | enum class TorchModeStatus : uint32_t { |
| 60 | NOT_AVAILABLE = 0, |
| 61 | AVAILABLE_OFF = 1, |
| 62 | AVAILABLE_ON = 2 |
| 63 | }; |
| 64 | |
| 65 | struct CameraResourceCost { |
| 66 | uint32_t resourceCost; |
| 67 | std::vector<std::string> conflictingDevices; |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 68 | }; |
| 69 | |
Jayant Chowdhary | 5216b21 | 2019-07-17 09:26:23 -0700 | [diff] [blame] | 70 | enum SystemCameraKind { |
| 71 | /** |
| 72 | * These camera devices are visible to all apps and system components alike |
| 73 | */ |
| 74 | PUBLIC = 0, |
| 75 | |
| 76 | /** |
| 77 | * These camera devices are visible only to processes having the |
| 78 | * android.permission.SYSTEM_CAMERA permission. They are not exposed to 3P |
| 79 | * apps. |
| 80 | */ |
| 81 | SYSTEM_ONLY_CAMERA, |
| 82 | |
| 83 | /** |
| 84 | * These camera devices are visible only to HAL clients (that try to connect |
| 85 | * on a hwbinder thread). |
| 86 | */ |
| 87 | HIDDEN_SECURE_CAMERA |
| 88 | }; |
| 89 | |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 90 | #define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0) |
| 91 | #define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0) |
| 92 | #define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1) |
| 93 | #define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2) |
| 94 | #define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3) |
| 95 | #define CAMERA_DEVICE_API_VERSION_3_4 HARDWARE_DEVICE_API_VERSION(3, 4) |
| 96 | #define CAMERA_DEVICE_API_VERSION_3_5 HARDWARE_DEVICE_API_VERSION(3, 5) |
| 97 | #define CAMERA_DEVICE_API_VERSION_3_6 HARDWARE_DEVICE_API_VERSION(3, 6) |
| 98 | #define CAMERA_DEVICE_API_VERSION_3_7 HARDWARE_DEVICE_API_VERSION(3, 7) |
Shuzhen Wang | 90708ea | 2021-11-04 11:40:49 -0700 | [diff] [blame] | 99 | #define CAMERA_DEVICE_API_VERSION_3_8 HARDWARE_DEVICE_API_VERSION(3, 8) |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 100 | |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 101 | /** |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 102 | * The vendor tag descriptor class that takes HIDL/AIDL vendor tag information as |
| 103 | * input. Not part of VendorTagDescriptor class because that class is used |
| 104 | * in AIDL generated sources which don't have access to AIDL / HIDL headers. |
| 105 | */ |
| 106 | class IdlVendorTagDescriptor : public VendorTagDescriptor { |
| 107 | public: |
| 108 | /** |
| 109 | * Create a VendorTagDescriptor object from the HIDL/AIDL VendorTagSection |
| 110 | * vector. |
| 111 | * |
| 112 | * Returns OK on success, or a negative error code. |
| 113 | */ |
| 114 | template <class VendorTagSectionVectorType, class VendorTagSectionType> |
| 115 | static status_t createDescriptorFromIdl( |
| 116 | const VendorTagSectionVectorType& vts, |
| 117 | /*out*/ |
| 118 | sp<VendorTagDescriptor>& descriptor); |
| 119 | }; |
| 120 | |
| 121 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 122 | * A manager for all camera providers available on an Android device. |
| 123 | * |
| 124 | * Responsible for enumerating providers and the individual camera devices |
| 125 | * they export, both at startup and as providers and devices are added/removed. |
| 126 | * |
| 127 | * Provides methods for requesting information about individual devices and for |
| 128 | * opening them for active use. |
| 129 | * |
| 130 | */ |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 131 | class CameraProviderManager : virtual public hidl::manager::V1_0::IServiceNotification, |
| 132 | public virtual IServiceManager::LocalRegistrationCallback { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 133 | public: |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 134 | // needs to be made friend strict since HidlProviderInfo needs to inherit |
| 135 | // from CameraProviderManager::ProviderInfo which isn't a public member. |
| 136 | friend struct HidlProviderInfo; |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 137 | friend struct AidlProviderInfo; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 138 | ~CameraProviderManager(); |
| 139 | |
| 140 | // Tiny proxy for the static methods in a HIDL interface that communicate with the hardware |
| 141 | // service manager, to be replacable in unit tests with a fake. |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 142 | struct HidlServiceInteractionProxy { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 143 | virtual bool registerForNotifications( |
| 144 | const std::string &serviceName, |
| 145 | const sp<hidl::manager::V1_0::IServiceNotification> |
| 146 | ¬ification) = 0; |
Eino-Ville Talvala | ec96060 | 2019-10-15 11:46:16 -0700 | [diff] [blame] | 147 | // Will not wait for service to start if it's not already running |
| 148 | virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService( |
| 149 | const std::string &serviceName) = 0; |
| 150 | // Will block for service if it exists but isn't running |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 151 | virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService( |
| 152 | const std::string &serviceName) = 0; |
Yin-Chia Yeh | 177b0c1 | 2019-06-25 10:53:03 -0700 | [diff] [blame] | 153 | virtual hardware::hidl_vec<hardware::hidl_string> listServices() = 0; |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 154 | virtual ~HidlServiceInteractionProxy() {} |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | // Standard use case - call into the normal generated static methods which invoke |
| 158 | // the real hardware service manager |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 159 | struct HidlServiceInteractionProxyImpl : public HidlServiceInteractionProxy { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 160 | virtual bool registerForNotifications( |
| 161 | const std::string &serviceName, |
| 162 | const sp<hidl::manager::V1_0::IServiceNotification> |
| 163 | ¬ification) override { |
| 164 | return hardware::camera::provider::V2_4::ICameraProvider::registerForNotifications( |
| 165 | serviceName, notification); |
| 166 | } |
Eino-Ville Talvala | ec96060 | 2019-10-15 11:46:16 -0700 | [diff] [blame] | 167 | virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService( |
| 168 | const std::string &serviceName) override { |
| 169 | return hardware::camera::provider::V2_4::ICameraProvider::tryGetService(serviceName); |
| 170 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 171 | virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService( |
| 172 | const std::string &serviceName) override { |
| 173 | return hardware::camera::provider::V2_4::ICameraProvider::getService(serviceName); |
| 174 | } |
Yin-Chia Yeh | 177b0c1 | 2019-06-25 10:53:03 -0700 | [diff] [blame] | 175 | |
| 176 | virtual hardware::hidl_vec<hardware::hidl_string> listServices() override; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | /** |
| 180 | * Listener interface for device/torch status changes |
| 181 | */ |
| 182 | struct StatusListener : virtual public RefBase { |
| 183 | ~StatusListener() {} |
| 184 | |
| 185 | virtual void onDeviceStatusChanged(const String8 &cameraId, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 186 | CameraDeviceStatus newStatus) = 0; |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 187 | virtual void onDeviceStatusChanged(const String8 &cameraId, |
| 188 | const String8 &physicalCameraId, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 189 | CameraDeviceStatus newStatus) = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 190 | virtual void onTorchStatusChanged(const String8 &cameraId, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 191 | TorchModeStatus newStatus, |
Jayant Chowdhary | 46ef0f5 | 2021-10-05 14:36:13 -0700 | [diff] [blame] | 192 | SystemCameraKind kind) = 0; |
| 193 | virtual void onTorchStatusChanged(const String8 &cameraId, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 194 | TorchModeStatus newStatus) = 0; |
Emilian Peev | aee727d | 2017-05-04 16:35:48 +0100 | [diff] [blame] | 195 | virtual void onNewProviderRegistered() = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | /** |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 199 | * Represents the mode a camera device is currently in |
| 200 | */ |
| 201 | enum class DeviceMode { |
| 202 | TORCH, |
| 203 | CAMERA |
| 204 | }; |
| 205 | |
| 206 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 207 | * Initialize the manager and give it a status listener; optionally accepts a service |
| 208 | * interaction proxy. |
| 209 | * |
| 210 | * The default proxy communicates via the hardware service manager; alternate proxies can be |
| 211 | * used for testing. The lifetime of the proxy must exceed the lifetime of the manager. |
| 212 | */ |
| 213 | status_t initialize(wp<StatusListener> listener, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 214 | HidlServiceInteractionProxy *hidlProxy = &sHidlServiceInteractionProxy); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 215 | |
Jayant Chowdhary | 22441f3 | 2021-12-26 18:35:41 -0800 | [diff] [blame] | 216 | status_t getCameraIdIPCTransport(const std::string &id, |
| 217 | IPCTransport *providerTransport) const; |
| 218 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 219 | /** |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 220 | * Retrieve the total number of available cameras. |
| 221 | * This value may change dynamically as cameras are added or removed. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 222 | */ |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 223 | std::pair<int, int> getCameraCount() const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 224 | |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 225 | std::vector<std::string> getCameraDeviceIds() const; |
| 226 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 227 | /** |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 228 | * Retrieve the number of API1 compatible cameras; these are internal and |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 229 | * backwards-compatible. This is the set of cameras that will be |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 230 | * accessible via the old camera API. |
| 231 | * The return value may change dynamically due to external camera hotplug. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 232 | */ |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 233 | std::vector<std::string> getAPI1CompatibleCameraDeviceIds() const; |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 234 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 235 | /** |
| 236 | * Return true if a device with a given ID and major version exists |
| 237 | */ |
| 238 | bool isValidDevice(const std::string &id, uint16_t majorVersion) const; |
| 239 | |
| 240 | /** |
| 241 | * Return true if a device with a given ID has a flash unit. Returns false |
| 242 | * for devices that are unknown. |
| 243 | */ |
| 244 | bool hasFlashUnit(const std::string &id) const; |
| 245 | |
| 246 | /** |
Shuzhen Wang | dbdf72b | 2019-11-13 11:22:12 -0800 | [diff] [blame] | 247 | * Return true if the camera device has native zoom ratio support. |
| 248 | */ |
| 249 | bool supportNativeZoomRatio(const std::string &id) const; |
| 250 | |
| 251 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 252 | * Return the resource cost of this camera device |
| 253 | */ |
| 254 | status_t getResourceCost(const std::string &id, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 255 | CameraResourceCost* cost) const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 256 | |
| 257 | /** |
| 258 | * Return the old camera API camera info |
| 259 | */ |
| 260 | status_t getCameraInfo(const std::string &id, |
| 261 | hardware::CameraInfo* info) const; |
| 262 | |
| 263 | /** |
| 264 | * Return API2 camera characteristics - returns NAME_NOT_FOUND if a device ID does |
| 265 | * not have a v3 or newer HAL version. |
| 266 | */ |
| 267 | status_t getCameraCharacteristics(const std::string &id, |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 268 | bool overrideForPerfClass, CameraMetadata* characteristics) const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 269 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 270 | status_t isConcurrentSessionConfigurationSupported( |
| 271 | const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration> |
| 272 | &cameraIdsAndSessionConfigs, |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 273 | const std::set<std::string>& perfClassPrimaryCameraIds, |
| 274 | int targetSdkVersion, bool *isSupported); |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 275 | |
Jayant Chowdhary | cad23c2 | 2020-03-10 15:04:59 -0700 | [diff] [blame] | 276 | std::vector<std::unordered_set<std::string>> getConcurrentCameraIds() const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 277 | /** |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 278 | * Check for device support of specific stream combination. |
| 279 | */ |
| 280 | status_t isSessionConfigurationSupported(const std::string& id, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 281 | const SessionConfiguration &configuration, |
Shuzhen Wang | a79a64d | 2022-04-24 19:56:30 -0700 | [diff] [blame] | 282 | bool overrideForPerfClass, camera3::metadataGetter getMetadata, |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 283 | bool *status /*out*/) const; |
| 284 | |
| 285 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 286 | * Return the highest supported device interface version for this ID |
| 287 | */ |
| 288 | status_t getHighestSupportedVersion(const std::string &id, |
| 289 | hardware::hidl_version *v); |
| 290 | |
| 291 | /** |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 292 | * Check if a given camera device support setTorchMode API. |
| 293 | */ |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 294 | bool supportSetTorchMode(const std::string &id) const; |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 295 | |
| 296 | /** |
Rucha Katakwar | 3828452 | 2021-11-10 11:25:21 -0800 | [diff] [blame] | 297 | * Check if torch strength update should be skipped or not. |
| 298 | */ |
| 299 | bool shouldSkipTorchStrengthUpdate(const std::string &id, int32_t torchStrength) const; |
| 300 | |
| 301 | /** |
| 302 | * Return the default torch strength level if the torch strength control |
| 303 | * feature is supported. |
| 304 | */ |
| 305 | int32_t getTorchDefaultStrengthLevel(const std::string &id) const; |
| 306 | |
| 307 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 308 | * Turn on or off the flashlight on a given camera device. |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 309 | * May fail if the device does not support this API, is in active use, or if the device |
| 310 | * doesn't exist, etc. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 311 | */ |
| 312 | status_t setTorchMode(const std::string &id, bool enabled); |
| 313 | |
| 314 | /** |
Rucha Katakwar | 3828452 | 2021-11-10 11:25:21 -0800 | [diff] [blame] | 315 | * Change the brightness level of the flash unit associated with the cameraId and |
| 316 | * set it to the value in torchStrength. |
| 317 | * If the torch is OFF and torchStrength > 0, the torch will be turned ON with the |
| 318 | * specified strength level. If the torch is ON, only the brightness level will be |
| 319 | * changed. |
| 320 | * |
| 321 | * This operation will fail if the device does not have flash unit, has flash unit |
| 322 | * but does not support this API, torchStrength is invalid or if the device doesn't |
| 323 | * exist etc. |
| 324 | */ |
| 325 | status_t turnOnTorchWithStrengthLevel(const std::string &id, int32_t torchStrength); |
| 326 | |
| 327 | /** |
| 328 | * Return the torch strength level of this camera device. |
| 329 | */ |
| 330 | status_t getTorchStrengthLevel(const std::string &id, int32_t* torchStrength); |
| 331 | |
| 332 | /** |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 333 | * Setup vendor tags for all registered providers |
| 334 | */ |
| 335 | status_t setUpVendorTags(); |
| 336 | |
| 337 | /** |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 338 | * Inform registered providers about a device state change, such as folding or unfolding |
| 339 | */ |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 340 | status_t notifyDeviceStateChange(int64_t newState); |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 341 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 342 | status_t openAidlSession(const std::string &id, |
| 343 | const std::shared_ptr< |
| 344 | aidl::android::hardware::camera::device::ICameraDeviceCallback>& callback, |
| 345 | /*out*/ |
| 346 | std::shared_ptr<aidl::android::hardware::camera::device::ICameraDeviceSession> *session); |
| 347 | |
Jayant Chowdhary | 35642f2 | 2022-01-08 00:39:39 +0000 | [diff] [blame] | 348 | status_t openAidlInjectionSession(const std::string &id, |
| 349 | const std::shared_ptr< |
| 350 | aidl::android::hardware::camera::device::ICameraDeviceCallback>& callback, |
| 351 | /*out*/ |
| 352 | std::shared_ptr<aidl::android::hardware::camera::device::ICameraInjectionSession> *session); |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 353 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 354 | /** |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 355 | * Open an active session to a camera device. |
| 356 | * |
| 357 | * This fully powers on the camera device hardware, and returns a handle to a |
| 358 | * session to be used for hardware configuration and operation. |
| 359 | */ |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 360 | status_t openHidlSession(const std::string &id, |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 361 | const sp<hardware::camera::device::V3_2::ICameraDeviceCallback>& callback, |
| 362 | /*out*/ |
| 363 | sp<hardware::camera::device::V3_2::ICameraDeviceSession> *session); |
| 364 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 365 | /** |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 366 | * Notify that the camera or torch is no longer being used by a camera client |
| 367 | */ |
| 368 | void removeRef(DeviceMode usageType, const std::string &cameraId); |
| 369 | |
| 370 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 371 | * IServiceNotification::onRegistration |
| 372 | * Invoked by the hardware service manager when a new camera provider is registered |
| 373 | */ |
| 374 | virtual hardware::Return<void> onRegistration(const hardware::hidl_string& fqName, |
| 375 | const hardware::hidl_string& name, |
| 376 | bool preexisting) override; |
| 377 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 378 | // LocalRegistrationCallback::onServiceRegistration |
| 379 | virtual void onServiceRegistration(const String16& name, const sp<IBinder> &binder) override; |
| 380 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 381 | /** |
| 382 | * Dump out information about available providers and devices |
| 383 | */ |
| 384 | status_t dump(int fd, const Vector<String16>& args); |
| 385 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 386 | /** |
| 387 | * Conversion methods between HAL Status and status_t and strings |
| 388 | */ |
| 389 | static status_t mapToStatusT(const hardware::camera::common::V1_0::Status& s); |
| 390 | static const char* statusToString(const hardware::camera::common::V1_0::Status& s); |
| 391 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 392 | /* |
| 393 | * Return provider type for a specific device. |
| 394 | */ |
| 395 | metadata_vendor_id_t getProviderTagIdLocked(const std::string& id, |
| 396 | hardware::hidl_version minVersion = hardware::hidl_version{0,0}, |
| 397 | hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const; |
| 398 | |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 399 | /* |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 400 | * Check if a camera is a logical camera. And if yes, return |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 401 | * the physical camera ids. |
| 402 | */ |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 403 | bool isLogicalCamera(const std::string& id, std::vector<std::string>* physicalCameraIds); |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 404 | |
Jayant Chowdhary | 33e8ef8 | 2019-09-27 09:20:42 -0700 | [diff] [blame] | 405 | status_t getSystemCameraKind(const std::string& id, SystemCameraKind *kind) const; |
| 406 | bool isHiddenPhysicalCamera(const std::string& cameraId) const; |
Emilian Peev | 538c90e | 2018-12-17 18:03:19 +0000 | [diff] [blame] | 407 | |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 408 | status_t filterSmallJpegSizes(const std::string& cameraId); |
Shuzhen Wang | 89db299 | 2021-05-20 13:09:48 -0700 | [diff] [blame] | 409 | |
Valentin Iftime | 29e2e15 | 2021-08-13 15:17:33 +0200 | [diff] [blame] | 410 | status_t notifyUsbDeviceEvent(int32_t eventId, const std::string &usbDeviceId); |
| 411 | |
Emilian Peev | 538c90e | 2018-12-17 18:03:19 +0000 | [diff] [blame] | 412 | static const float kDepthARTolerance; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 413 | private: |
| 414 | // All private members, unless otherwise noted, expect mInterfaceMutex to be locked before use |
| 415 | mutable std::mutex mInterfaceMutex; |
| 416 | |
| 417 | wp<StatusListener> mListener; |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 418 | HidlServiceInteractionProxy* mHidlServiceProxy; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 419 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 420 | // Current overall Android device physical status |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 421 | int64_t mDeviceState; |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 422 | |
Shuzhen Wang | 6ba8eb2 | 2018-07-08 13:10:44 -0700 | [diff] [blame] | 423 | // mProviderLifecycleLock is locked during onRegistration and removeProvider |
| 424 | mutable std::mutex mProviderLifecycleLock; |
| 425 | |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 426 | static HidlServiceInteractionProxyImpl sHidlServiceInteractionProxy; |
| 427 | |
| 428 | struct HalCameraProvider { |
| 429 | // Empty parent struct for storing either aidl / hidl camera provider reference |
| 430 | HalCameraProvider(const char *descriptor) : mDescriptor(descriptor) { }; |
| 431 | virtual ~HalCameraProvider() {}; |
| 432 | std::string mDescriptor; |
| 433 | }; |
| 434 | |
| 435 | struct HidlHalCameraProvider : public HalCameraProvider { |
| 436 | HidlHalCameraProvider( |
| 437 | const sp<hardware::camera::provider::V2_4::ICameraProvider> &provider, |
| 438 | const char *descriptor) : |
| 439 | HalCameraProvider(descriptor), mCameraProvider(provider) { }; |
| 440 | private: |
| 441 | sp<hardware::camera::provider::V2_4::ICameraProvider> mCameraProvider; |
| 442 | }; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 443 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 444 | struct AidlHalCameraProvider : public HalCameraProvider { |
| 445 | AidlHalCameraProvider( |
| 446 | const std::shared_ptr< |
| 447 | aidl::android::hardware::camera::provider::ICameraProvider> &provider, |
| 448 | const char *descriptor) : |
| 449 | HalCameraProvider(descriptor), mCameraProvider(provider) { }; |
| 450 | private: |
| 451 | std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider> mCameraProvider; |
| 452 | }; |
| 453 | |
| 454 | |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 455 | // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the |
| 456 | // ICameraProvider alive while it is in use by the camera with the given ID for camera |
| 457 | // capabilities |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 458 | std::unordered_map<std::string, std::shared_ptr<HalCameraProvider>> |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 459 | mCameraProviderByCameraId; |
| 460 | |
| 461 | // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the |
| 462 | // ICameraProvider alive while it is in use by the camera with the given ID for torch |
| 463 | // capabilities |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 464 | std::unordered_map<std::string, std::shared_ptr<HalCameraProvider>> |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 465 | mTorchProviderByCameraId; |
| 466 | |
| 467 | // Lock for accessing mCameraProviderByCameraId and mTorchProviderByCameraId |
| 468 | std::mutex mProviderInterfaceMapLock; |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 469 | struct ProviderInfo : public virtual RefBase { |
| 470 | friend struct HidlProviderInfo; |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 471 | friend struct AidlProviderInfo; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 472 | const std::string mProviderName; |
Emilian Peev | c93cac2 | 2020-08-17 16:00:10 -0700 | [diff] [blame] | 473 | const std::string mProviderInstance; |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 474 | const metadata_vendor_id_t mProviderTagid; |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 475 | int32_t mMinorVersion; |
Peter Kalauskas | 1b3c907 | 2018-11-07 12:41:53 -0800 | [diff] [blame] | 476 | sp<VendorTagDescriptor> mVendorTagDescriptor; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 477 | bool mSetTorchModeSupported; |
| 478 | bool mIsRemote; |
| 479 | |
Emilian Peev | c93cac2 | 2020-08-17 16:00:10 -0700 | [diff] [blame] | 480 | ProviderInfo(const std::string &providerName, const std::string &providerInstance, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 481 | CameraProviderManager *manager); |
| 482 | ~ProviderInfo(); |
| 483 | |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 484 | virtual IPCTransport getIPCTransport() = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 485 | |
| 486 | const std::string& getType() const; |
| 487 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 488 | status_t dump(int fd, const Vector<String16>& args) const; |
| 489 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 490 | void initializeProviderInfoCommon(const std::vector<std::string> &devices); |
Peter Kalauskas | 1b3c907 | 2018-11-07 12:41:53 -0800 | [diff] [blame] | 491 | /** |
| 492 | * Setup vendor tags for this provider |
| 493 | */ |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 494 | virtual status_t setUpVendorTags() = 0; |
Peter Kalauskas | 1b3c907 | 2018-11-07 12:41:53 -0800 | [diff] [blame] | 495 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 496 | /** |
| 497 | * Notify provider about top-level device physical state changes |
Emilian Peev | 7fe6c42 | 2021-09-08 13:43:20 -0700 | [diff] [blame] | 498 | * |
| 499 | * Note that 'mInterfaceMutex' should not be held when calling this method. |
| 500 | * It is possible for camera providers to add/remove devices and try to |
| 501 | * acquire it. |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 502 | */ |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 503 | virtual status_t notifyDeviceStateChange(int64_t newDeviceState) = 0; |
| 504 | |
| 505 | virtual bool successfullyStartedProviderInterface() = 0; |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 506 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 507 | virtual int64_t getDeviceState() = 0; |
| 508 | |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 509 | std::vector<std::unordered_set<std::string>> getConcurrentCameraIdCombinations(); |
| 510 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 511 | /** |
Emilian Peev | b50402e | 2021-09-24 17:41:57 -0700 | [diff] [blame] | 512 | * Notify 'DeviceInfo' instanced about top-level device physical state changes |
| 513 | * |
| 514 | * Note that 'mInterfaceMutex' should be held when calling this method. |
| 515 | */ |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 516 | void notifyDeviceInfoStateChangeLocked(int64_t newDeviceState); |
Emilian Peev | b50402e | 2021-09-24 17:41:57 -0700 | [diff] [blame] | 517 | |
| 518 | /** |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 519 | * Query the camera provider for concurrent stream configuration support |
| 520 | */ |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 521 | virtual status_t isConcurrentSessionConfigurationSupported( |
| 522 | const std::vector<CameraIdAndSessionConfiguration> &cameraIdsAndSessionConfigs, |
| 523 | const std::set<std::string>& perfClassPrimaryCameraIds, |
| 524 | int targetSdkVersion, bool *isSupported) = 0; |
| 525 | |
Valentin Iftime | 29e2e15 | 2021-08-13 15:17:33 +0200 | [diff] [blame] | 526 | /** |
| 527 | * Remove all devices associated with this provider and notify listeners |
| 528 | * with NOT_PRESENT state. |
| 529 | */ |
| 530 | void removeAllDevices(); |
| 531 | |
| 532 | /** |
| 533 | * Provider is an external lazy HAL |
| 534 | */ |
| 535 | bool isExternalLazyHAL() const; |
| 536 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 537 | // Basic device information, common to all camera devices |
| 538 | struct DeviceInfo { |
| 539 | const std::string mName; // Full instance name |
| 540 | const std::string mId; // ID section of full name |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 541 | //Both hidl and aidl DeviceInfos. Aidl deviceInfos get {3, 8} to |
| 542 | //start off. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 543 | const hardware::hidl_version mVersion; |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 544 | const metadata_vendor_id_t mProviderTagid; |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 545 | bool mIsLogicalCamera; |
| 546 | std::vector<std::string> mPhysicalIds; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 547 | hardware::CameraInfo mInfo; |
Jayant Chowdhary | 5216b21 | 2019-07-17 09:26:23 -0700 | [diff] [blame] | 548 | SystemCameraKind mSystemCameraKind = SystemCameraKind::PUBLIC; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 549 | |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 550 | const CameraResourceCost mResourceCost; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 551 | |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 552 | CameraDeviceStatus mStatus; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 553 | |
Shuzhen Wang | 7968043 | 2020-03-05 11:53:46 -0800 | [diff] [blame] | 554 | wp<ProviderInfo> mParentProvider; |
Rucha Katakwar | 3828452 | 2021-11-10 11:25:21 -0800 | [diff] [blame] | 555 | // Torch strength default, maximum levels if the torch strength control |
| 556 | // feature is supported. |
| 557 | int32_t mTorchStrengthLevel; |
| 558 | int32_t mTorchMaximumStrengthLevel; |
| 559 | int32_t mTorchDefaultStrengthLevel; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 560 | |
Valentin Iftime | 29e2e15 | 2021-08-13 15:17:33 +0200 | [diff] [blame] | 561 | // Wait for lazy HALs to confirm device availability |
| 562 | static const nsecs_t kDeviceAvailableTimeout = 2000e6; // 2000 ms |
| 563 | Mutex mDeviceAvailableLock; |
| 564 | Condition mDeviceAvailableSignal; |
| 565 | bool mIsDeviceAvailable = true; |
| 566 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 567 | bool hasFlashUnit() const { return mHasFlashUnit; } |
Shuzhen Wang | dbdf72b | 2019-11-13 11:22:12 -0800 | [diff] [blame] | 568 | bool supportNativeZoomRatio() const { return mSupportNativeZoomRatio; } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 569 | virtual status_t setTorchMode(bool enabled) = 0; |
Rucha Katakwar | 3828452 | 2021-11-10 11:25:21 -0800 | [diff] [blame] | 570 | virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) = 0; |
| 571 | virtual status_t getTorchStrengthLevel(int32_t *torchStrength) = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 572 | virtual status_t getCameraInfo(hardware::CameraInfo *info) const = 0; |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 573 | virtual bool isAPI1Compatible() const = 0; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 574 | virtual status_t dumpState(int fd) = 0; |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 575 | virtual status_t getCameraCharacteristics(bool overrideForPerfClass, |
| 576 | CameraMetadata *characteristics) const { |
| 577 | (void) overrideForPerfClass; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 578 | (void) characteristics; |
| 579 | return INVALID_OPERATION; |
| 580 | } |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 581 | virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId, |
| 582 | CameraMetadata *characteristics) const { |
| 583 | (void) physicalCameraId; |
| 584 | (void) characteristics; |
| 585 | return INVALID_OPERATION; |
| 586 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 587 | |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 588 | virtual status_t isSessionConfigurationSupported( |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 589 | const SessionConfiguration &/*configuration*/, |
| 590 | bool /*overrideForPerfClass*/, |
Shuzhen Wang | a79a64d | 2022-04-24 19:56:30 -0700 | [diff] [blame] | 591 | camera3::metadataGetter /*getMetadata*/, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 592 | bool * /*status*/) { |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 593 | return INVALID_OPERATION; |
| 594 | } |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 595 | virtual status_t filterSmallJpegSizes() = 0; |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 596 | virtual void notifyDeviceStateChange(int64_t /*newState*/) {} |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 597 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 598 | DeviceInfo(const std::string& name, const metadata_vendor_id_t tagId, |
| 599 | const std::string &id, const hardware::hidl_version& version, |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 600 | const std::vector<std::string>& publicCameraIds, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 601 | const CameraResourceCost& resourceCost, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 602 | sp<ProviderInfo> parentProvider) : |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 603 | mName(name), mId(id), mVersion(version), mProviderTagid(tagId), |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 604 | mIsLogicalCamera(false), mResourceCost(resourceCost), |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 605 | mStatus(CameraDeviceStatus::PRESENT), |
Rucha Katakwar | 3c6714d | 2021-12-15 13:56:55 -0800 | [diff] [blame] | 606 | mParentProvider(parentProvider), mTorchStrengthLevel(0), |
| 607 | mTorchMaximumStrengthLevel(0), mTorchDefaultStrengthLevel(0), |
| 608 | mHasFlashUnit(false), mSupportNativeZoomRatio(false), |
| 609 | mPublicCameraIds(publicCameraIds) {} |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 610 | virtual ~DeviceInfo() {} |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 611 | protected: |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 612 | |
Shuzhen Wang | dbdf72b | 2019-11-13 11:22:12 -0800 | [diff] [blame] | 613 | bool mHasFlashUnit; // const after constructor |
| 614 | bool mSupportNativeZoomRatio; // const after constructor |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 615 | const std::vector<std::string>& mPublicCameraIds; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 616 | }; |
| 617 | std::vector<std::unique_ptr<DeviceInfo>> mDevices; |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 618 | std::unordered_set<std::string> mUniqueCameraIds; |
Yin-Chia Yeh | e8e9e19 | 2017-03-16 15:23:51 -0700 | [diff] [blame] | 619 | int mUniqueDeviceCount; |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 620 | std::vector<std::string> mUniqueAPI1CompatibleCameraIds; |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 621 | // The initial public camera IDs published by the camera provider. |
| 622 | // Currently logical multi-camera is not supported for hot-plug camera. |
| 623 | // And we use this list to keep track of initial public camera IDs |
| 624 | // advertised by the provider, and to distinguish against "hidden" |
| 625 | // physical camera IDs. |
| 626 | std::vector<std::string> mProviderPublicCameraIds; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 627 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 628 | // HALv3-specific camera fields, including the actual device interface |
| 629 | struct DeviceInfo3 : public DeviceInfo { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 630 | |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 631 | virtual status_t setTorchMode(bool enabled) = 0; |
| 632 | virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) = 0; |
| 633 | virtual status_t getTorchStrengthLevel(int32_t *torchStrength) = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 634 | virtual status_t getCameraInfo(hardware::CameraInfo *info) const override; |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 635 | virtual bool isAPI1Compatible() const override; |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 636 | virtual status_t dumpState(int fd) = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 637 | virtual status_t getCameraCharacteristics( |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 638 | bool overrideForPerfClass, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 639 | CameraMetadata *characteristics) const override; |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 640 | virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId, |
| 641 | CameraMetadata *characteristics) const override; |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 642 | virtual status_t isSessionConfigurationSupported( |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 643 | const SessionConfiguration &configuration, bool /*overrideForPerfClass*/, |
Shuzhen Wang | a79a64d | 2022-04-24 19:56:30 -0700 | [diff] [blame] | 644 | camera3::metadataGetter /*getMetadata*/, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 645 | bool *status /*out*/) = 0; |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 646 | virtual status_t filterSmallJpegSizes() override; |
Emilian Peev | b50402e | 2021-09-24 17:41:57 -0700 | [diff] [blame] | 647 | virtual void notifyDeviceStateChange( |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 648 | int64_t newState) override; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 649 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 650 | DeviceInfo3(const std::string& name, const metadata_vendor_id_t tagId, |
| 651 | const std::string &id, uint16_t minorVersion, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 652 | const CameraResourceCost& resourceCost, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 653 | sp<ProviderInfo> parentProvider, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 654 | const std::vector<std::string>& publicCameraIds); |
| 655 | virtual ~DeviceInfo3() {}; |
| 656 | protected: |
| 657 | // Modified by derived transport specific (hidl / aidl) class |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 658 | CameraMetadata mCameraCharacteristics; |
Emilian Peev | b50402e | 2021-09-24 17:41:57 -0700 | [diff] [blame] | 659 | // Map device states to sensor orientations |
| 660 | std::unordered_map<int64_t, int32_t> mDeviceStateOrientationMap; |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 661 | // A copy of mCameraCharacteristics without performance class |
| 662 | // override |
| 663 | std::unique_ptr<CameraMetadata> mCameraCharNoPCOverride; |
Shuzhen Wang | a79a64d | 2022-04-24 19:56:30 -0700 | [diff] [blame] | 664 | // Only contains characteristics for hidden physical cameras, |
| 665 | // not for public physical cameras. |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 666 | std::unordered_map<std::string, CameraMetadata> mPhysicalCameraCharacteristics; |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 667 | void queryPhysicalCameraIds(); |
Jayant Chowdhary | 5216b21 | 2019-07-17 09:26:23 -0700 | [diff] [blame] | 668 | SystemCameraKind getSystemCameraKind(); |
Shuzhen Wang | 268a136 | 2018-10-16 16:32:59 -0700 | [diff] [blame] | 669 | status_t fixupMonochromeTags(); |
Rucha Katakwar | 31fbf3a | 2022-05-02 13:23:56 -0700 | [diff] [blame] | 670 | status_t fixupTorchStrengthTags(); |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 671 | status_t addDynamicDepthTags(bool maxResolution = false); |
| 672 | status_t deriveHeicTags(bool maxResolution = false); |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 673 | status_t addRotateCropTags(); |
Shuzhen Wang | 9bf8a6f | 2020-05-01 09:49:04 -0700 | [diff] [blame] | 674 | status_t addPreCorrectionActiveArraySize(); |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 675 | |
Emilian Peev | 4c6d2b5 | 2019-01-04 17:13:56 +0000 | [diff] [blame] | 676 | static void getSupportedSizes(const CameraMetadata& ch, uint32_t tag, |
| 677 | android_pixel_format_t format, |
| 678 | std::vector<std::tuple<size_t, size_t>> *sizes /*out*/); |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 679 | static void getSupportedDurations( const CameraMetadata& ch, uint32_t tag, |
Emilian Peev | 4c6d2b5 | 2019-01-04 17:13:56 +0000 | [diff] [blame] | 680 | android_pixel_format_t format, |
| 681 | const std::vector<std::tuple<size_t, size_t>>& sizes, |
| 682 | std::vector<int64_t> *durations/*out*/); |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 683 | static void getSupportedDynamicDepthDurations( |
| 684 | const std::vector<int64_t>& depthDurations, |
Emilian Peev | 4c6d2b5 | 2019-01-04 17:13:56 +0000 | [diff] [blame] | 685 | const std::vector<int64_t>& blobDurations, |
| 686 | std::vector<int64_t> *dynamicDepthDurations /*out*/); |
| 687 | static void getSupportedDynamicDepthSizes( |
| 688 | const std::vector<std::tuple<size_t, size_t>>& blobSizes, |
| 689 | const std::vector<std::tuple<size_t, size_t>>& depthSizes, |
| 690 | std::vector<std::tuple<size_t, size_t>> *dynamicDepthSizes /*out*/, |
| 691 | std::vector<std::tuple<size_t, size_t>> *internalDepthSizes /*out*/); |
Shuzhen Wang | 268a136 | 2018-10-16 16:32:59 -0700 | [diff] [blame] | 692 | status_t removeAvailableKeys(CameraMetadata& c, const std::vector<uint32_t>& keys, |
| 693 | uint32_t keyTag); |
Shuzhen Wang | 68ac7ad | 2019-01-30 14:03:28 -0800 | [diff] [blame] | 694 | status_t fillHeicStreamCombinations(std::vector<int32_t>* outputs, |
| 695 | std::vector<int64_t>* durations, |
| 696 | std::vector<int64_t>* stallDurations, |
| 697 | const camera_metadata_entry& halStreamConfigs, |
| 698 | const camera_metadata_entry& halStreamDurations); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 699 | }; |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 700 | protected: |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 701 | std::string mType; |
| 702 | uint32_t mId; |
| 703 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 704 | std::mutex mLock; |
| 705 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 706 | CameraProviderManager *mManager; |
| 707 | |
Shuzhen Wang | 394ad70 | 2020-07-23 13:01:54 -0700 | [diff] [blame] | 708 | struct CameraStatusInfoT { |
| 709 | bool isPhysicalCameraStatus = false; |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 710 | std::string cameraId; |
| 711 | std::string physicalCameraId; |
| 712 | CameraDeviceStatus status; |
| 713 | CameraStatusInfoT(bool isForPhysicalCamera, const std::string& id, |
| 714 | const std::string& physicalId, |
| 715 | CameraDeviceStatus s) : |
Shuzhen Wang | 394ad70 | 2020-07-23 13:01:54 -0700 | [diff] [blame] | 716 | isPhysicalCameraStatus(isForPhysicalCamera), cameraId(id), |
| 717 | physicalCameraId(physicalId), status(s) {} |
| 718 | }; |
| 719 | |
| 720 | // Lock to synchronize between initialize() and camera status callbacks |
| 721 | std::mutex mInitLock; |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 722 | bool mInitialized = false; |
Shuzhen Wang | 394ad70 | 2020-07-23 13:01:54 -0700 | [diff] [blame] | 723 | std::vector<CameraStatusInfoT> mCachedStatus; |
| 724 | // End of scope for mInitLock |
| 725 | |
| 726 | std::future<void> mInitialStatusCallbackFuture; |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 727 | |
| 728 | std::unique_ptr<ProviderInfo::DeviceInfo> |
| 729 | virtual initializeDeviceInfo( |
| 730 | const std::string &name, const metadata_vendor_id_t tagId, |
| 731 | const std::string &id, uint16_t minorVersion) = 0; |
| 732 | |
| 733 | virtual status_t reCacheConcurrentStreamingCameraIdsLocked() = 0; |
| 734 | |
Shuzhen Wang | 394ad70 | 2020-07-23 13:01:54 -0700 | [diff] [blame] | 735 | void notifyInitialStatusChange(sp<StatusListener> listener, |
| 736 | std::unique_ptr<std::vector<CameraStatusInfoT>> cachedStatus); |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 737 | |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 738 | std::vector<std::unordered_set<std::string>> mConcurrentCameraIdCombinations; |
| 739 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 740 | // Parse provider instance name for type and id |
| 741 | static status_t parseProviderName(const std::string& name, |
| 742 | std::string *type, uint32_t *id); |
| 743 | |
| 744 | // Parse device instance name for device version, type, and id. |
| 745 | static status_t parseDeviceName(const std::string& name, |
| 746 | uint16_t *major, uint16_t *minor, std::string *type, std::string *id); |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 747 | |
| 748 | // Generate vendor tag id |
| 749 | static metadata_vendor_id_t generateVendorTagId(const std::string &name); |
Guennadi Liakhovetski | 6034bf5 | 2017-12-07 10:28:29 +0100 | [diff] [blame] | 750 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 751 | status_t addDevice( |
| 752 | const std::string& name, CameraDeviceStatus initialStatus, |
| 753 | /*out*/ std::string* parsedId); |
| 754 | |
| 755 | void cameraDeviceStatusChangeInternal(const std::string& cameraDeviceName, |
| 756 | CameraDeviceStatus newStatus); |
| 757 | |
| 758 | status_t cameraDeviceStatusChangeLocked( |
| 759 | std::string* id, const std::string& cameraDeviceName, |
| 760 | CameraDeviceStatus newStatus); |
| 761 | |
| 762 | void physicalCameraDeviceStatusChangeInternal(const std::string& cameraDeviceName, |
| 763 | const std::string& physicalCameraDeviceName, |
| 764 | CameraDeviceStatus newStatus); |
| 765 | |
| 766 | status_t physicalCameraDeviceStatusChangeLocked( |
| 767 | std::string* id, std::string* physicalId, |
| 768 | const std::string& cameraDeviceName, |
| 769 | const std::string& physicalCameraDeviceName, |
| 770 | CameraDeviceStatus newStatus); |
| 771 | |
| 772 | void torchModeStatusChangeInternal(const std::string& cameraDeviceName, |
| 773 | TorchModeStatus newStatus); |
| 774 | |
Guennadi Liakhovetski | 6034bf5 | 2017-12-07 10:28:29 +0100 | [diff] [blame] | 775 | void removeDevice(std::string id); |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 776 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 777 | }; |
| 778 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 779 | template <class ProviderInfoType, class HalCameraProviderType> |
| 780 | status_t setTorchModeT(sp<ProviderInfo> &parentProvider, |
| 781 | std::shared_ptr<HalCameraProvider> *halCameraProvider); |
| 782 | |
| 783 | // Try to get hidl provider services declared. Expects mInterfaceMutex to be |
| 784 | // locked. Also registers for hidl provider service notifications. |
| 785 | status_t tryToInitAndAddHidlProvidersLocked(HidlServiceInteractionProxy *hidlProxy); |
| 786 | |
| 787 | // Try to get aidl provider services declared. Expects mInterfaceMutex to be |
| 788 | // locked. Also registers for aidl provider service notifications. |
| 789 | status_t tryToAddAidlProvidersLocked(); |
| 790 | |
Emilian Peev | 7fe6c42 | 2021-09-08 13:43:20 -0700 | [diff] [blame] | 791 | /** |
| 792 | * Save the ICameraProvider while it is being used by a camera or torch client |
| 793 | */ |
| 794 | void saveRef(DeviceMode usageType, const std::string &cameraId, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 795 | std::shared_ptr<HalCameraProvider> provider); |
Emilian Peev | 7fe6c42 | 2021-09-08 13:43:20 -0700 | [diff] [blame] | 796 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 797 | // Utility to find a DeviceInfo by ID; pointer is only valid while mInterfaceMutex is held |
| 798 | // 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] | 799 | // Finds the first device of the given ID that falls within the requested version range |
| 800 | // minVersion <= deviceVersion < maxVersion |
| 801 | // No guarantees on the order of traversal |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 802 | ProviderInfo::DeviceInfo* findDeviceInfoLocked(const std::string& id, |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 803 | hardware::hidl_version minVersion = hardware::hidl_version{0,0}, |
| 804 | hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 805 | |
Valentin Iftime | 29e2e15 | 2021-08-13 15:17:33 +0200 | [diff] [blame] | 806 | // Map external providers to USB devices in order to handle USB hotplug |
| 807 | // events for lazy HALs |
| 808 | std::pair<std::vector<std::string>, sp<ProviderInfo>> |
| 809 | mExternalUsbDevicesForProvider; |
| 810 | sp<ProviderInfo> startExternalLazyProvider() const; |
| 811 | |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 812 | status_t addHidlProviderLocked(const std::string& newProvider, bool preexisting = false); |
Emilian Peev | c93cac2 | 2020-08-17 16:00:10 -0700 | [diff] [blame] | 813 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 814 | status_t addAidlProviderLocked(const std::string& newProvider); |
| 815 | |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 816 | status_t tryToInitializeHidlProviderLocked(const std::string& providerName, |
Emilian Peev | c93cac2 | 2020-08-17 16:00:10 -0700 | [diff] [blame] | 817 | const sp<ProviderInfo>& providerInfo); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 818 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 819 | status_t tryToInitializeAidlProviderLocked(const std::string& providerName, |
| 820 | const sp<ProviderInfo>& providerInfo); |
| 821 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 822 | bool isLogicalCameraLocked(const std::string& id, std::vector<std::string>* physicalCameraIds); |
| 823 | |
Jayant Chowdhary | e8c4b23 | 2022-02-04 18:18:04 +0000 | [diff] [blame] | 824 | // No method corresponding to the same provider / member belonging to the |
| 825 | // same provider should be used after this method is called since it'll lead |
| 826 | // to invalid memory access (especially since this is called by ProviderInfo methods on hal |
| 827 | // service death). |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 828 | status_t removeProvider(const std::string& provider); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 829 | sp<StatusListener> getStatusListener() const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 830 | |
| 831 | bool isValidDeviceLocked(const std::string &id, uint16_t majorVersion) const; |
| 832 | |
Emilian Peev | c93cac2 | 2020-08-17 16:00:10 -0700 | [diff] [blame] | 833 | size_t mProviderInstanceId = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 834 | std::vector<sp<ProviderInfo>> mProviders; |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 835 | // Provider names of AIDL providers with retrieved binders. |
| 836 | std::set<std::string> mAidlProviderWithBinders; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 837 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 838 | static const char* deviceStatusToString( |
| 839 | const hardware::camera::common::V1_0::CameraDeviceStatus&); |
| 840 | static const char* torchStatusToString( |
| 841 | const hardware::camera::common::V1_0::TorchModeStatus&); |
| 842 | |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 843 | status_t getCameraCharacteristicsLocked(const std::string &id, bool overrideForPerfClass, |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 844 | CameraMetadata* characteristics) const; |
| 845 | void filterLogicalCameraIdsLocked(std::vector<std::string>& deviceIds) const; |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 846 | |
Jayant Chowdhary | 33e8ef8 | 2019-09-27 09:20:42 -0700 | [diff] [blame] | 847 | status_t getSystemCameraKindLocked(const std::string& id, SystemCameraKind *kind) const; |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 848 | std::pair<bool, ProviderInfo::DeviceInfo *> isHiddenPhysicalCameraInternal( |
| 849 | const std::string& cameraId) const; |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 850 | |
| 851 | void collectDeviceIdsLocked(const std::vector<std::string> deviceIds, |
| 852 | std::vector<std::string>& normalDeviceIds, |
| 853 | std::vector<std::string>& systemCameraDeviceIds) const; |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 854 | |
Valentin Iftime | 29e2e15 | 2021-08-13 15:17:33 +0200 | [diff] [blame] | 855 | status_t usbDeviceDetached(const std::string &usbDeviceId); |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 856 | ndk::ScopedAStatus onAidlRegistration(const std::string& in_name, |
| 857 | const ::ndk::SpAIBinder& in_binder); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 858 | }; |
| 859 | |
| 860 | } // namespace android |
| 861 | |
| 862 | #endif |