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