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