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