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