Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | #include <aidl/Vintf.h> |
| 18 | #include <aidl/android/hardware/camera/common/VendorTagSection.h> |
| 19 | #include <aidl/android/hardware/camera/device/ICameraDevice.h> |
| 20 | #include <aidlcommonsupport/NativeHandle.h> |
| 21 | #include <camera_aidl_test.h> |
| 22 | #include <cutils/properties.h> |
| 23 | #include <device_cb.h> |
| 24 | #include <empty_device_cb.h> |
| 25 | #include <grallocusage/GrallocUsageConversion.h> |
| 26 | #include <gtest/gtest.h> |
| 27 | #include <hardware/gralloc.h> |
| 28 | #include <hardware/gralloc1.h> |
| 29 | #include <hidl/GtestPrinter.h> |
| 30 | #include <hidl/HidlSupport.h> |
| 31 | #include <torch_provider_cb.h> |
| 32 | #include <list> |
| 33 | |
| 34 | using ::aidl::android::hardware::camera::common::CameraDeviceStatus; |
| 35 | using ::aidl::android::hardware::camera::common::CameraResourceCost; |
| 36 | using ::aidl::android::hardware::camera::common::TorchModeStatus; |
| 37 | using ::aidl::android::hardware::camera::common::VendorTagSection; |
| 38 | using ::aidl::android::hardware::camera::device::ICameraDevice; |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 39 | using ::aidl::android::hardware::camera::metadata::RequestAvailableDynamicRangeProfilesMap; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 40 | using ::aidl::android::hardware::camera::metadata::SensorPixelMode; |
| 41 | using ::aidl::android::hardware::camera::provider::CameraIdAndStreamCombination; |
Avichal Rakesh | 4bf91c7 | 2022-05-23 20:44:02 +0000 | [diff] [blame] | 42 | using ::aidl::android::hardware::camera::provider::BnCameraProviderCallback; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 43 | |
| 44 | using ::ndk::ScopedAStatus; |
| 45 | |
| 46 | namespace { |
| 47 | const int32_t kBurstFrameCount = 10; |
| 48 | const uint32_t kMaxStillWidth = 2048; |
| 49 | const uint32_t kMaxStillHeight = 1536; |
| 50 | |
| 51 | const int64_t kEmptyFlushTimeoutMSec = 200; |
| 52 | |
Shuzhen Wang | 36efa71 | 2022-03-08 10:10:44 -0800 | [diff] [blame] | 53 | const static std::vector<int64_t> kMandatoryUseCases = { |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 54 | ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT, |
| 55 | ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_PREVIEW, |
| 56 | ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_STILL_CAPTURE, |
| 57 | ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_VIDEO_RECORD, |
| 58 | ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_PREVIEW_VIDEO_STILL, |
| 59 | ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_VIDEO_CALL}; |
| 60 | } // namespace |
| 61 | |
| 62 | TEST_P(CameraAidlTest, getCameraIdList) { |
| 63 | std::vector<std::string> idList; |
| 64 | ScopedAStatus ret = mProvider->getCameraIdList(&idList); |
| 65 | ASSERT_TRUE(ret.isOk()); |
| 66 | |
| 67 | for (size_t i = 0; i < idList.size(); i++) { |
| 68 | ALOGI("Camera Id[%zu] is %s", i, idList[i].c_str()); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // Test if ICameraProvider::getVendorTags returns Status::OK |
| 73 | TEST_P(CameraAidlTest, getVendorTags) { |
| 74 | std::vector<VendorTagSection> vendorTags; |
| 75 | ScopedAStatus ret = mProvider->getVendorTags(&vendorTags); |
| 76 | |
| 77 | ASSERT_TRUE(ret.isOk()); |
| 78 | for (size_t i = 0; i < vendorTags.size(); i++) { |
| 79 | ALOGI("Vendor tag section %zu name %s", i, vendorTags[i].sectionName.c_str()); |
| 80 | for (auto& tag : vendorTags[i].tags) { |
| 81 | ALOGI("Vendor tag id %u name %s type %d", tag.tagId, tag.tagName.c_str(), |
| 82 | (int)tag.tagType); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // Test if ICameraProvider::setCallback returns Status::OK |
| 88 | TEST_P(CameraAidlTest, setCallback) { |
Avichal Rakesh | 4bf91c7 | 2022-05-23 20:44:02 +0000 | [diff] [blame] | 89 | struct ProviderCb : public BnCameraProviderCallback { |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 90 | ScopedAStatus cameraDeviceStatusChange(const std::string& cameraDeviceName, |
| 91 | CameraDeviceStatus newStatus) override { |
| 92 | ALOGI("camera device status callback name %s, status %d", cameraDeviceName.c_str(), |
| 93 | (int)newStatus); |
| 94 | return ScopedAStatus::ok(); |
| 95 | } |
| 96 | ScopedAStatus torchModeStatusChange(const std::string& cameraDeviceName, |
| 97 | TorchModeStatus newStatus) override { |
| 98 | ALOGI("Torch mode status callback name %s, status %d", cameraDeviceName.c_str(), |
| 99 | (int)newStatus); |
| 100 | return ScopedAStatus::ok(); |
| 101 | } |
| 102 | ScopedAStatus physicalCameraDeviceStatusChange(const std::string& cameraDeviceName, |
| 103 | const std::string& physicalCameraDeviceName, |
| 104 | CameraDeviceStatus newStatus) override { |
| 105 | ALOGI("physical camera device status callback name %s, physical camera name %s," |
| 106 | " status %d", |
| 107 | cameraDeviceName.c_str(), physicalCameraDeviceName.c_str(), (int)newStatus); |
| 108 | return ScopedAStatus::ok(); |
| 109 | } |
| 110 | }; |
| 111 | |
Avichal Rakesh | 4bf91c7 | 2022-05-23 20:44:02 +0000 | [diff] [blame] | 112 | std::shared_ptr<ProviderCb> cb = ndk::SharedRefBase::make<ProviderCb>(); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 113 | ScopedAStatus ret = mProvider->setCallback(cb); |
| 114 | ASSERT_TRUE(ret.isOk()); |
| 115 | ret = mProvider->setCallback(nullptr); |
Avichal Rakesh | 4bf91c7 | 2022-05-23 20:44:02 +0000 | [diff] [blame] | 116 | ASSERT_EQ(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT), ret.getServiceSpecificError()); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | // Test if ICameraProvider::getCameraDeviceInterface returns Status::OK and non-null device |
| 120 | TEST_P(CameraAidlTest, getCameraDeviceInterface) { |
| 121 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 122 | |
| 123 | for (const auto& name : cameraDeviceNames) { |
| 124 | std::shared_ptr<ICameraDevice> cameraDevice; |
| 125 | ScopedAStatus ret = mProvider->getCameraDeviceInterface(name, &cameraDevice); |
| 126 | ALOGI("getCameraDeviceInterface returns: %d:%d", ret.getExceptionCode(), |
| 127 | ret.getServiceSpecificError()); |
| 128 | ASSERT_TRUE(ret.isOk()); |
| 129 | ASSERT_NE(cameraDevice, nullptr); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // Verify that the device resource cost can be retrieved and the values are |
| 134 | // correct. |
| 135 | TEST_P(CameraAidlTest, getResourceCost) { |
| 136 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 137 | |
| 138 | for (const auto& deviceName : cameraDeviceNames) { |
| 139 | std::shared_ptr<ICameraDevice> cameraDevice; |
| 140 | ScopedAStatus ret = mProvider->getCameraDeviceInterface(deviceName, &cameraDevice); |
| 141 | ALOGI("getCameraDeviceInterface returns: %d:%d", ret.getExceptionCode(), |
| 142 | ret.getServiceSpecificError()); |
| 143 | ASSERT_TRUE(ret.isOk()); |
| 144 | ASSERT_NE(cameraDevice, nullptr); |
| 145 | |
| 146 | CameraResourceCost resourceCost; |
| 147 | ret = cameraDevice->getResourceCost(&resourceCost); |
| 148 | ALOGI("getResourceCost returns: %d:%d", ret.getExceptionCode(), |
| 149 | ret.getServiceSpecificError()); |
| 150 | ASSERT_TRUE(ret.isOk()); |
| 151 | |
| 152 | ALOGI(" Resource cost is %d", resourceCost.resourceCost); |
| 153 | ASSERT_LE(resourceCost.resourceCost, 100u); |
| 154 | |
| 155 | for (const auto& name : resourceCost.conflictingDevices) { |
| 156 | ALOGI(" Conflicting device: %s", name.c_str()); |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | TEST_P(CameraAidlTest, systemCameraTest) { |
| 162 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 163 | std::map<std::string, std::vector<SystemCameraKind>> hiddenPhysicalIdToLogicalMap; |
| 164 | for (const auto& name : cameraDeviceNames) { |
| 165 | std::shared_ptr<ICameraDevice> device; |
Avichal Rakesh | fbcf7ea | 2022-03-09 01:00:34 +0000 | [diff] [blame] | 166 | ALOGI("systemCameraTest: Testing camera device %s", name.c_str()); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 167 | ndk::ScopedAStatus ret = mProvider->getCameraDeviceInterface(name, &device); |
| 168 | ASSERT_TRUE(ret.isOk()); |
| 169 | ASSERT_NE(device, nullptr); |
| 170 | |
| 171 | CameraMetadata cameraCharacteristics; |
| 172 | ret = device->getCameraCharacteristics(&cameraCharacteristics); |
| 173 | ASSERT_TRUE(ret.isOk()); |
| 174 | |
| 175 | const camera_metadata_t* staticMeta = |
| 176 | reinterpret_cast<const camera_metadata_t*>(cameraCharacteristics.metadata.data()); |
| 177 | Status rc = isLogicalMultiCamera(staticMeta); |
| 178 | if (rc == Status::OPERATION_NOT_SUPPORTED) { |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | ASSERT_EQ(rc, Status::OK); |
| 183 | std::unordered_set<std::string> physicalIds; |
| 184 | ASSERT_EQ(getPhysicalCameraIds(staticMeta, &physicalIds), Status::OK); |
| 185 | SystemCameraKind systemCameraKind = SystemCameraKind::PUBLIC; |
| 186 | Status retStatus = getSystemCameraKind(staticMeta, &systemCameraKind); |
| 187 | ASSERT_EQ(retStatus, Status::OK); |
| 188 | |
| 189 | for (auto physicalId : physicalIds) { |
| 190 | bool isPublicId = false; |
| 191 | for (auto& deviceName : cameraDeviceNames) { |
| 192 | std::string publicVersion, publicId; |
| 193 | ASSERT_TRUE(matchDeviceName(deviceName, mProviderType, &publicVersion, &publicId)); |
| 194 | if (physicalId == publicId) { |
| 195 | isPublicId = true; |
| 196 | break; |
| 197 | } |
| 198 | } |
Avichal Rakesh | fbcf7ea | 2022-03-09 01:00:34 +0000 | [diff] [blame] | 199 | |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 200 | // For hidden physical cameras, collect their associated logical cameras |
| 201 | // and store the system camera kind. |
| 202 | if (!isPublicId) { |
| 203 | auto it = hiddenPhysicalIdToLogicalMap.find(physicalId); |
| 204 | if (it == hiddenPhysicalIdToLogicalMap.end()) { |
| 205 | hiddenPhysicalIdToLogicalMap.insert(std::make_pair( |
Avichal Rakesh | fbcf7ea | 2022-03-09 01:00:34 +0000 | [diff] [blame] | 206 | physicalId, std::vector<SystemCameraKind>({systemCameraKind}))); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 207 | } else { |
| 208 | it->second.push_back(systemCameraKind); |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | // Check that the system camera kind of the logical cameras associated with |
| 215 | // each hidden physical camera is the same. |
| 216 | for (const auto& it : hiddenPhysicalIdToLogicalMap) { |
| 217 | SystemCameraKind neededSystemCameraKind = it.second.front(); |
| 218 | for (auto foundSystemCamera : it.second) { |
| 219 | ASSERT_EQ(neededSystemCameraKind, foundSystemCamera); |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | // Verify that the static camera characteristics can be retrieved |
| 225 | // successfully. |
| 226 | TEST_P(CameraAidlTest, getCameraCharacteristics) { |
| 227 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 228 | |
| 229 | for (const auto& name : cameraDeviceNames) { |
| 230 | std::shared_ptr<ICameraDevice> device; |
| 231 | ALOGI("getCameraCharacteristics: Testing camera device %s", name.c_str()); |
| 232 | ndk::ScopedAStatus ret = mProvider->getCameraDeviceInterface(name, &device); |
| 233 | ALOGI("getCameraDeviceInterface returns: %d:%d", ret.getExceptionCode(), |
| 234 | ret.getServiceSpecificError()); |
| 235 | ASSERT_TRUE(ret.isOk()); |
| 236 | ASSERT_NE(device, nullptr); |
| 237 | |
| 238 | CameraMetadata chars; |
| 239 | ret = device->getCameraCharacteristics(&chars); |
| 240 | ASSERT_TRUE(ret.isOk()); |
| 241 | verifyCameraCharacteristics(chars); |
| 242 | verifyMonochromeCharacteristics(chars); |
| 243 | verifyRecommendedConfigs(chars); |
Kwangkyu Park | 4b7fd45 | 2023-05-12 00:22:22 +0900 | [diff] [blame^] | 244 | verifyHighSpeedRecordingCharacteristics(name, chars); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 245 | verifyLogicalOrUltraHighResCameraMetadata(name, device, chars, cameraDeviceNames); |
| 246 | |
| 247 | ASSERT_TRUE(ret.isOk()); |
| 248 | |
| 249 | // getPhysicalCameraCharacteristics will fail for publicly |
| 250 | // advertised camera IDs. |
| 251 | std::string version, cameraId; |
| 252 | ASSERT_TRUE(matchDeviceName(name, mProviderType, &version, &cameraId)); |
| 253 | CameraMetadata devChars; |
| 254 | ret = device->getPhysicalCameraCharacteristics(cameraId, &devChars); |
| 255 | ASSERT_EQ(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT), ret.getServiceSpecificError()); |
| 256 | ASSERT_EQ(0, devChars.metadata.size()); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | // Verify that the torch strength level can be set and retrieved successfully. |
| 261 | TEST_P(CameraAidlTest, turnOnTorchWithStrengthLevel) { |
| 262 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 263 | |
| 264 | std::shared_ptr<TorchProviderCb> cb = ndk::SharedRefBase::make<TorchProviderCb>(this); |
| 265 | ndk::ScopedAStatus ret = mProvider->setCallback(cb); |
| 266 | ASSERT_TRUE(ret.isOk()); |
| 267 | |
| 268 | for (const auto& name : cameraDeviceNames) { |
| 269 | int32_t defaultLevel; |
| 270 | std::shared_ptr<ICameraDevice> device; |
| 271 | ALOGI("%s: Testing camera device %s", __FUNCTION__, name.c_str()); |
| 272 | |
| 273 | ret = mProvider->getCameraDeviceInterface(name, &device); |
| 274 | ASSERT_TRUE(ret.isOk()); |
| 275 | ASSERT_NE(device, nullptr); |
| 276 | |
| 277 | CameraMetadata chars; |
| 278 | ret = device->getCameraCharacteristics(&chars); |
| 279 | ASSERT_TRUE(ret.isOk()); |
| 280 | |
| 281 | const camera_metadata_t* staticMeta = |
| 282 | reinterpret_cast<const camera_metadata_t*>(chars.metadata.data()); |
| 283 | bool torchStrengthControlSupported = isTorchStrengthControlSupported(staticMeta); |
| 284 | camera_metadata_ro_entry entry; |
| 285 | int rc = find_camera_metadata_ro_entry(staticMeta, |
| 286 | ANDROID_FLASH_INFO_STRENGTH_DEFAULT_LEVEL, &entry); |
| 287 | if (torchStrengthControlSupported) { |
| 288 | ASSERT_EQ(rc, 0); |
| 289 | ASSERT_GT(entry.count, 0); |
| 290 | defaultLevel = *entry.data.i32; |
| 291 | ALOGI("Default level is:%d", defaultLevel); |
| 292 | } |
| 293 | |
| 294 | mTorchStatus = TorchModeStatus::NOT_AVAILABLE; |
| 295 | ret = device->turnOnTorchWithStrengthLevel(2); |
| 296 | ALOGI("turnOnTorchWithStrengthLevel returns status: %d", ret.getServiceSpecificError()); |
| 297 | // OPERATION_NOT_SUPPORTED check |
| 298 | if (!torchStrengthControlSupported) { |
| 299 | ALOGI("Torch strength control not supported."); |
| 300 | ASSERT_EQ(static_cast<int32_t>(Status::OPERATION_NOT_SUPPORTED), |
| 301 | ret.getServiceSpecificError()); |
| 302 | } else { |
| 303 | { |
| 304 | ASSERT_TRUE(ret.isOk()); |
| 305 | std::unique_lock<std::mutex> l(mTorchLock); |
| 306 | while (TorchModeStatus::NOT_AVAILABLE == mTorchStatus) { |
| 307 | auto timeout = std::chrono::system_clock::now() + |
| 308 | std::chrono::seconds(kTorchTimeoutSec); |
| 309 | ASSERT_NE(std::cv_status::timeout, mTorchCond.wait_until(l, timeout)); |
| 310 | } |
| 311 | ASSERT_EQ(TorchModeStatus::AVAILABLE_ON, mTorchStatus); |
| 312 | mTorchStatus = TorchModeStatus::NOT_AVAILABLE; |
| 313 | } |
| 314 | ALOGI("getTorchStrengthLevel: Testing"); |
| 315 | int32_t strengthLevel; |
| 316 | ret = device->getTorchStrengthLevel(&strengthLevel); |
| 317 | ASSERT_TRUE(ret.isOk()); |
| 318 | ALOGI("Torch strength level is : %d", strengthLevel); |
| 319 | ASSERT_EQ(strengthLevel, 2); |
| 320 | |
| 321 | // Turn OFF the torch and verify torch strength level is reset to default level. |
| 322 | ALOGI("Testing torch strength level reset after turning the torch OFF."); |
| 323 | ret = device->setTorchMode(false); |
| 324 | ASSERT_TRUE(ret.isOk()); |
| 325 | { |
| 326 | std::unique_lock<std::mutex> l(mTorchLock); |
| 327 | while (TorchModeStatus::NOT_AVAILABLE == mTorchStatus) { |
| 328 | auto timeout = std::chrono::system_clock::now() + |
| 329 | std::chrono::seconds(kTorchTimeoutSec); |
| 330 | ASSERT_NE(std::cv_status::timeout, mTorchCond.wait_until(l, timeout)); |
| 331 | } |
| 332 | ASSERT_EQ(TorchModeStatus::AVAILABLE_OFF, mTorchStatus); |
| 333 | } |
| 334 | |
| 335 | ret = device->getTorchStrengthLevel(&strengthLevel); |
| 336 | ASSERT_TRUE(ret.isOk()); |
| 337 | ALOGI("Torch strength level after turning OFF torch is : %d", strengthLevel); |
| 338 | ASSERT_EQ(strengthLevel, defaultLevel); |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | // In case it is supported verify that torch can be enabled. |
| 344 | // Check for corresponding torch callbacks as well. |
| 345 | TEST_P(CameraAidlTest, setTorchMode) { |
| 346 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 347 | |
| 348 | std::shared_ptr<TorchProviderCb> cb = ndk::SharedRefBase::make<TorchProviderCb>(this); |
| 349 | ndk::ScopedAStatus ret = mProvider->setCallback(cb); |
| 350 | ALOGI("setCallback returns status: %d", ret.getServiceSpecificError()); |
| 351 | ASSERT_TRUE(ret.isOk()); |
| 352 | ASSERT_NE(cb, nullptr); |
| 353 | |
| 354 | for (const auto& name : cameraDeviceNames) { |
| 355 | std::shared_ptr<ICameraDevice> device; |
| 356 | ALOGI("setTorchMode: Testing camera device %s", name.c_str()); |
| 357 | ret = mProvider->getCameraDeviceInterface(name, &device); |
| 358 | ALOGI("getCameraDeviceInterface returns status:%d:%d", ret.getExceptionCode(), |
| 359 | ret.getServiceSpecificError()); |
| 360 | ASSERT_TRUE(ret.isOk()); |
| 361 | ASSERT_NE(device, nullptr); |
| 362 | |
| 363 | CameraMetadata metadata; |
| 364 | ret = device->getCameraCharacteristics(&metadata); |
| 365 | ALOGI("getCameraCharacteristics returns status:%d", ret.getServiceSpecificError()); |
| 366 | ASSERT_TRUE(ret.isOk()); |
| 367 | camera_metadata_t* staticMeta = |
| 368 | reinterpret_cast<camera_metadata_t*>(metadata.metadata.data()); |
| 369 | bool torchSupported = isTorchSupported(staticMeta); |
| 370 | |
| 371 | mTorchStatus = TorchModeStatus::NOT_AVAILABLE; |
| 372 | ret = device->setTorchMode(true); |
| 373 | ALOGI("setTorchMode returns status: %d", ret.getServiceSpecificError()); |
| 374 | if (!torchSupported) { |
| 375 | ASSERT_EQ(static_cast<int32_t>(Status::OPERATION_NOT_SUPPORTED), |
| 376 | ret.getServiceSpecificError()); |
| 377 | } else { |
| 378 | ASSERT_TRUE(ret.isOk()); |
| 379 | { |
| 380 | std::unique_lock<std::mutex> l(mTorchLock); |
| 381 | while (TorchModeStatus::NOT_AVAILABLE == mTorchStatus) { |
| 382 | auto timeout = std::chrono::system_clock::now() + |
| 383 | std::chrono::seconds(kTorchTimeoutSec); |
| 384 | ASSERT_NE(std::cv_status::timeout, mTorchCond.wait_until(l, timeout)); |
| 385 | } |
| 386 | ASSERT_EQ(TorchModeStatus::AVAILABLE_ON, mTorchStatus); |
| 387 | mTorchStatus = TorchModeStatus::NOT_AVAILABLE; |
| 388 | } |
| 389 | |
| 390 | ret = device->setTorchMode(false); |
| 391 | ASSERT_TRUE(ret.isOk()); |
| 392 | { |
| 393 | std::unique_lock<std::mutex> l(mTorchLock); |
| 394 | while (TorchModeStatus::NOT_AVAILABLE == mTorchStatus) { |
| 395 | auto timeout = std::chrono::system_clock::now() + |
| 396 | std::chrono::seconds(kTorchTimeoutSec); |
| 397 | ASSERT_NE(std::cv_status::timeout, mTorchCond.wait_until(l, timeout)); |
| 398 | } |
| 399 | ASSERT_EQ(TorchModeStatus::AVAILABLE_OFF, mTorchStatus); |
| 400 | } |
| 401 | } |
| 402 | } |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | // Check dump functionality. |
| 406 | TEST_P(CameraAidlTest, dump) { |
| 407 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 408 | |
| 409 | for (const auto& name : cameraDeviceNames) { |
| 410 | std::shared_ptr<ICameraDevice> device; |
| 411 | ALOGI("dump: Testing camera device %s", name.c_str()); |
| 412 | |
| 413 | ndk::ScopedAStatus ret = mProvider->getCameraDeviceInterface(name, &device); |
| 414 | ALOGI("getCameraDeviceInterface returns status:%d:%d", ret.getExceptionCode(), |
| 415 | ret.getServiceSpecificError()); |
| 416 | ASSERT_TRUE(ret.isOk()); |
| 417 | ASSERT_NE(device, nullptr); |
| 418 | |
| 419 | int raw_handle = open(kDumpOutput, O_RDWR); |
| 420 | ASSERT_GE(raw_handle, 0); |
| 421 | |
| 422 | auto retStatus = device->dump(raw_handle, nullptr, 0); |
| 423 | ASSERT_EQ(retStatus, ::android::OK); |
| 424 | close(raw_handle); |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | // Open, dump, then close |
| 429 | TEST_P(CameraAidlTest, openClose) { |
| 430 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 431 | |
| 432 | for (const auto& name : cameraDeviceNames) { |
| 433 | std::shared_ptr<ICameraDevice> device; |
| 434 | ALOGI("openClose: Testing camera device %s", name.c_str()); |
| 435 | ndk::ScopedAStatus ret = mProvider->getCameraDeviceInterface(name, &device); |
| 436 | ALOGI("getCameraDeviceInterface returns status:%d:%d", ret.getExceptionCode(), |
| 437 | ret.getServiceSpecificError()); |
| 438 | ASSERT_TRUE(ret.isOk()); |
| 439 | ASSERT_NE(device, nullptr); |
| 440 | |
| 441 | std::shared_ptr<EmptyDeviceCb> cb = ndk::SharedRefBase::make<EmptyDeviceCb>(); |
| 442 | |
| 443 | ret = device->open(cb, &mSession); |
| 444 | ASSERT_TRUE(ret.isOk()); |
| 445 | ALOGI("device::open returns status:%d:%d", ret.getExceptionCode(), |
| 446 | ret.getServiceSpecificError()); |
| 447 | ASSERT_NE(mSession, nullptr); |
| 448 | int raw_handle = open(kDumpOutput, O_RDWR); |
| 449 | ASSERT_GE(raw_handle, 0); |
| 450 | |
| 451 | auto retStatus = device->dump(raw_handle, nullptr, 0); |
| 452 | ASSERT_EQ(retStatus, ::android::OK); |
| 453 | close(raw_handle); |
| 454 | |
| 455 | ret = mSession->close(); |
| 456 | mSession = nullptr; |
| 457 | ASSERT_TRUE(ret.isOk()); |
| 458 | // TODO: test all session API calls return INTERNAL_ERROR after close |
| 459 | // TODO: keep a wp copy here and verify session cannot be promoted out of this scope |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | // Check whether all common default request settings can be successfully |
| 464 | // constructed. |
| 465 | TEST_P(CameraAidlTest, constructDefaultRequestSettings) { |
| 466 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 467 | |
| 468 | for (const auto& name : cameraDeviceNames) { |
| 469 | std::shared_ptr<ICameraDevice> device; |
| 470 | ALOGI("constructDefaultRequestSettings: Testing camera device %s", name.c_str()); |
| 471 | ndk::ScopedAStatus ret = mProvider->getCameraDeviceInterface(name, &device); |
| 472 | ALOGI("getCameraDeviceInterface returns status:%d:%d", ret.getExceptionCode(), |
| 473 | ret.getServiceSpecificError()); |
| 474 | ASSERT_TRUE(ret.isOk()); |
| 475 | ASSERT_NE(device, nullptr); |
| 476 | |
| 477 | std::shared_ptr<EmptyDeviceCb> cb = ndk::SharedRefBase::make<EmptyDeviceCb>(); |
| 478 | ret = device->open(cb, &mSession); |
| 479 | ALOGI("device::open returns status:%d:%d", ret.getExceptionCode(), |
| 480 | ret.getServiceSpecificError()); |
| 481 | ASSERT_TRUE(ret.isOk()); |
| 482 | ASSERT_NE(mSession, nullptr); |
| 483 | |
| 484 | for (int32_t t = (int32_t)RequestTemplate::PREVIEW; t <= (int32_t)RequestTemplate::MANUAL; |
| 485 | t++) { |
| 486 | RequestTemplate reqTemplate = (RequestTemplate)t; |
| 487 | CameraMetadata rawMetadata; |
| 488 | ret = mSession->constructDefaultRequestSettings(reqTemplate, &rawMetadata); |
| 489 | ALOGI("constructDefaultRequestSettings returns status:%d:%d", ret.getExceptionCode(), |
| 490 | ret.getServiceSpecificError()); |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 491 | |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 492 | if (reqTemplate == RequestTemplate::ZERO_SHUTTER_LAG || |
| 493 | reqTemplate == RequestTemplate::MANUAL) { |
| 494 | // optional templates |
| 495 | ASSERT_TRUE(ret.isOk() || static_cast<int32_t>(Status::ILLEGAL_ARGUMENT) == |
| 496 | ret.getServiceSpecificError()); |
| 497 | } else { |
| 498 | ASSERT_TRUE(ret.isOk()); |
| 499 | } |
| 500 | |
| 501 | if (ret.isOk()) { |
| 502 | const camera_metadata_t* metadata = (camera_metadata_t*)rawMetadata.metadata.data(); |
| 503 | size_t expectedSize = rawMetadata.metadata.size(); |
| 504 | int result = validate_camera_metadata_structure(metadata, &expectedSize); |
| 505 | ASSERT_TRUE((result == 0) || (result == CAMERA_METADATA_VALIDATION_SHIFTED)); |
| 506 | verifyRequestTemplate(metadata, reqTemplate); |
| 507 | } else { |
| 508 | ASSERT_EQ(0u, rawMetadata.metadata.size()); |
| 509 | } |
| 510 | } |
| 511 | ret = mSession->close(); |
| 512 | mSession = nullptr; |
| 513 | ASSERT_TRUE(ret.isOk()); |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | // Verify that all supported stream formats and sizes can be configured |
| 518 | // successfully. |
| 519 | TEST_P(CameraAidlTest, configureStreamsAvailableOutputs) { |
| 520 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 521 | std::vector<AvailableStream> outputStreams; |
| 522 | |
| 523 | for (const auto& name : cameraDeviceNames) { |
| 524 | CameraMetadata meta; |
| 525 | std::shared_ptr<ICameraDevice> device; |
| 526 | |
| 527 | openEmptyDeviceSession(name, mProvider, &mSession /*out*/, &meta /*out*/, &device /*out*/); |
| 528 | |
| 529 | camera_metadata_t* staticMeta = reinterpret_cast<camera_metadata_t*>(meta.metadata.data()); |
| 530 | outputStreams.clear(); |
| 531 | ASSERT_EQ(Status::OK, getAvailableOutputStreams(staticMeta, outputStreams)); |
| 532 | ASSERT_NE(0u, outputStreams.size()); |
| 533 | |
| 534 | int32_t jpegBufferSize = 0; |
| 535 | ASSERT_EQ(Status::OK, getJpegBufferSize(staticMeta, &jpegBufferSize)); |
| 536 | ASSERT_NE(0u, jpegBufferSize); |
| 537 | |
| 538 | int32_t streamId = 0; |
| 539 | int32_t streamConfigCounter = 0; |
| 540 | for (auto& it : outputStreams) { |
| 541 | Stream stream; |
| 542 | Dataspace dataspace = getDataspace(static_cast<PixelFormat>(it.format)); |
| 543 | stream.id = streamId; |
| 544 | stream.streamType = StreamType::OUTPUT; |
| 545 | stream.width = it.width; |
| 546 | stream.height = it.height; |
| 547 | stream.format = static_cast<PixelFormat>(it.format); |
| 548 | stream.dataSpace = dataspace; |
| 549 | stream.usage = static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 550 | GRALLOC1_CONSUMER_USAGE_HWCOMPOSER); |
| 551 | stream.rotation = StreamRotation::ROTATION_0; |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 552 | stream.dynamicRangeProfile = RequestAvailableDynamicRangeProfilesMap:: |
| 553 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 554 | |
| 555 | std::vector<Stream> streams = {stream}; |
| 556 | StreamConfiguration config; |
| 557 | createStreamConfiguration(streams, StreamConfigurationMode::NORMAL_MODE, &config, |
| 558 | jpegBufferSize); |
| 559 | |
| 560 | bool expectStreamCombQuery = (isLogicalMultiCamera(staticMeta) == Status::OK); |
| 561 | verifyStreamCombination(device, config, /*expectedStatus*/ true, expectStreamCombQuery); |
| 562 | |
| 563 | config.streamConfigCounter = streamConfigCounter++; |
| 564 | std::vector<HalStream> halConfigs; |
| 565 | ndk::ScopedAStatus ret = mSession->configureStreams(config, &halConfigs); |
| 566 | ASSERT_TRUE(ret.isOk()); |
| 567 | ASSERT_EQ(halConfigs.size(), 1); |
| 568 | ASSERT_EQ(halConfigs[0].id, streamId); |
| 569 | |
| 570 | streamId++; |
| 571 | } |
| 572 | |
| 573 | ndk::ScopedAStatus ret = mSession->close(); |
| 574 | mSession = nullptr; |
| 575 | ASSERT_TRUE(ret.isOk()); |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | // Verify that mandatory concurrent streams and outputs are supported. |
| 580 | TEST_P(CameraAidlTest, configureConcurrentStreamsAvailableOutputs) { |
| 581 | struct CameraTestInfo { |
| 582 | CameraMetadata staticMeta; |
| 583 | std::shared_ptr<ICameraDeviceSession> session; |
| 584 | std::shared_ptr<ICameraDevice> cameraDevice; |
| 585 | StreamConfiguration config; |
| 586 | }; |
| 587 | |
| 588 | std::map<std::string, std::string> idToNameMap = getCameraDeviceIdToNameMap(mProvider); |
| 589 | std::vector<ConcurrentCameraIdCombination> concurrentDeviceCombinations = |
| 590 | getConcurrentDeviceCombinations(mProvider); |
| 591 | std::vector<AvailableStream> outputStreams; |
| 592 | for (const auto& cameraDeviceIds : concurrentDeviceCombinations) { |
| 593 | std::vector<CameraIdAndStreamCombination> cameraIdsAndStreamCombinations; |
| 594 | std::vector<CameraTestInfo> cameraTestInfos; |
| 595 | size_t i = 0; |
| 596 | for (const auto& id : cameraDeviceIds.combination) { |
| 597 | CameraTestInfo cti; |
| 598 | auto it = idToNameMap.find(id); |
| 599 | ASSERT_TRUE(idToNameMap.end() != it); |
| 600 | std::string name = it->second; |
| 601 | |
| 602 | openEmptyDeviceSession(name, mProvider, &cti.session /*out*/, &cti.staticMeta /*out*/, |
| 603 | &cti.cameraDevice /*out*/); |
| 604 | |
| 605 | outputStreams.clear(); |
| 606 | camera_metadata_t* staticMeta = |
| 607 | reinterpret_cast<camera_metadata_t*>(cti.staticMeta.metadata.data()); |
| 608 | ASSERT_EQ(Status::OK, getMandatoryConcurrentStreams(staticMeta, &outputStreams)); |
| 609 | ASSERT_NE(0u, outputStreams.size()); |
| 610 | |
| 611 | int32_t jpegBufferSize = 0; |
| 612 | ASSERT_EQ(Status::OK, getJpegBufferSize(staticMeta, &jpegBufferSize)); |
| 613 | ASSERT_NE(0u, jpegBufferSize); |
| 614 | |
| 615 | int32_t streamId = 0; |
| 616 | std::vector<Stream> streams(outputStreams.size()); |
| 617 | size_t j = 0; |
| 618 | for (const auto& s : outputStreams) { |
| 619 | Stream stream; |
| 620 | Dataspace dataspace = getDataspace(static_cast<PixelFormat>(s.format)); |
| 621 | stream.id = streamId++; |
| 622 | stream.streamType = StreamType::OUTPUT; |
| 623 | stream.width = s.width; |
| 624 | stream.height = s.height; |
| 625 | stream.format = static_cast<PixelFormat>(s.format); |
| 626 | stream.usage = static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 627 | GRALLOC1_CONSUMER_USAGE_HWCOMPOSER); |
| 628 | stream.dataSpace = dataspace; |
| 629 | stream.rotation = StreamRotation::ROTATION_0; |
| 630 | stream.sensorPixelModesUsed = {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}; |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 631 | stream.dynamicRangeProfile = RequestAvailableDynamicRangeProfilesMap:: |
| 632 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 633 | streams[j] = stream; |
| 634 | j++; |
| 635 | } |
| 636 | |
| 637 | // Add the created stream configs to cameraIdsAndStreamCombinations |
| 638 | createStreamConfiguration(streams, StreamConfigurationMode::NORMAL_MODE, &cti.config, |
| 639 | jpegBufferSize); |
| 640 | |
| 641 | cti.config.streamConfigCounter = outputStreams.size(); |
| 642 | CameraIdAndStreamCombination cameraIdAndStreamCombination; |
| 643 | cameraIdAndStreamCombination.cameraId = id; |
| 644 | cameraIdAndStreamCombination.streamConfiguration = cti.config; |
| 645 | cameraIdsAndStreamCombinations.push_back(cameraIdAndStreamCombination); |
| 646 | i++; |
| 647 | cameraTestInfos.push_back(cti); |
| 648 | } |
| 649 | // Now verify that concurrent streams are supported |
| 650 | bool combinationSupported; |
| 651 | ndk::ScopedAStatus ret = mProvider->isConcurrentStreamCombinationSupported( |
| 652 | cameraIdsAndStreamCombinations, &combinationSupported); |
| 653 | ASSERT_TRUE(ret.isOk()); |
| 654 | ASSERT_EQ(combinationSupported, true); |
| 655 | |
| 656 | // Test the stream can actually be configured |
| 657 | for (auto& cti : cameraTestInfos) { |
| 658 | if (cti.session != nullptr) { |
| 659 | camera_metadata_t* staticMeta = |
| 660 | reinterpret_cast<camera_metadata_t*>(cti.staticMeta.metadata.data()); |
| 661 | bool expectStreamCombQuery = (isLogicalMultiCamera(staticMeta) == Status::OK); |
| 662 | verifyStreamCombination(cti.cameraDevice, cti.config, /*expectedStatus*/ true, |
| 663 | expectStreamCombQuery); |
| 664 | } |
| 665 | |
| 666 | if (cti.session != nullptr) { |
| 667 | std::vector<HalStream> streamConfigs; |
| 668 | ret = cti.session->configureStreams(cti.config, &streamConfigs); |
| 669 | ASSERT_TRUE(ret.isOk()); |
| 670 | ASSERT_EQ(cti.config.streams.size(), streamConfigs.size()); |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | for (auto& cti : cameraTestInfos) { |
| 675 | ret = cti.session->close(); |
| 676 | ASSERT_TRUE(ret.isOk()); |
| 677 | } |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | // Check for correct handling of invalid/incorrect configuration parameters. |
| 682 | TEST_P(CameraAidlTest, configureStreamsInvalidOutputs) { |
| 683 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 684 | std::vector<AvailableStream> outputStreams; |
| 685 | |
| 686 | for (const auto& name : cameraDeviceNames) { |
| 687 | CameraMetadata meta; |
| 688 | std::shared_ptr<ICameraDevice> cameraDevice; |
| 689 | |
| 690 | openEmptyDeviceSession(name, mProvider, &mSession /*out*/, &meta /*out*/, |
| 691 | &cameraDevice /*out*/); |
| 692 | camera_metadata_t* staticMeta = reinterpret_cast<camera_metadata_t*>(meta.metadata.data()); |
| 693 | outputStreams.clear(); |
| 694 | |
| 695 | ASSERT_EQ(Status::OK, getAvailableOutputStreams(staticMeta, outputStreams)); |
| 696 | ASSERT_NE(0u, outputStreams.size()); |
| 697 | |
| 698 | int32_t jpegBufferSize = 0; |
| 699 | ASSERT_EQ(Status::OK, getJpegBufferSize(staticMeta, &jpegBufferSize)); |
| 700 | ASSERT_NE(0u, jpegBufferSize); |
| 701 | |
| 702 | int32_t streamId = 0; |
| 703 | Stream stream = {streamId++, |
| 704 | StreamType::OUTPUT, |
| 705 | static_cast<uint32_t>(0), |
| 706 | static_cast<uint32_t>(0), |
| 707 | static_cast<PixelFormat>(outputStreams[0].format), |
| 708 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 709 | GRALLOC1_CONSUMER_USAGE_HWCOMPOSER), |
| 710 | Dataspace::UNKNOWN, |
| 711 | StreamRotation::ROTATION_0, |
| 712 | std::string(), |
| 713 | jpegBufferSize, |
| 714 | -1, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 715 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 716 | RequestAvailableDynamicRangeProfilesMap:: |
| 717 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 718 | int32_t streamConfigCounter = 0; |
| 719 | std::vector<Stream> streams = {stream}; |
| 720 | StreamConfiguration config; |
| 721 | createStreamConfiguration(streams, StreamConfigurationMode::NORMAL_MODE, &config, |
| 722 | jpegBufferSize); |
| 723 | |
| 724 | verifyStreamCombination(cameraDevice, config, /*expectedStatus*/ false, |
| 725 | /*expectStreamCombQuery*/ false); |
| 726 | |
| 727 | config.streamConfigCounter = streamConfigCounter++; |
| 728 | std::vector<HalStream> halConfigs; |
| 729 | ndk::ScopedAStatus ret = mSession->configureStreams(config, &halConfigs); |
| 730 | ASSERT_TRUE(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT) == |
| 731 | ret.getServiceSpecificError() || |
| 732 | static_cast<int32_t>(Status::INTERNAL_ERROR) == ret.getServiceSpecificError()); |
| 733 | |
| 734 | stream = {streamId++, |
| 735 | StreamType::OUTPUT, |
| 736 | /*width*/ INT32_MAX, |
| 737 | /*height*/ INT32_MAX, |
| 738 | static_cast<PixelFormat>(outputStreams[0].format), |
| 739 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 740 | GRALLOC1_CONSUMER_USAGE_HWCOMPOSER), |
| 741 | Dataspace::UNKNOWN, |
| 742 | StreamRotation::ROTATION_0, |
| 743 | std::string(), |
| 744 | jpegBufferSize, |
| 745 | -1, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 746 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 747 | RequestAvailableDynamicRangeProfilesMap:: |
| 748 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 749 | |
| 750 | streams[0] = stream; |
| 751 | createStreamConfiguration(streams, StreamConfigurationMode::NORMAL_MODE, &config, |
| 752 | jpegBufferSize); |
| 753 | |
| 754 | config.streamConfigCounter = streamConfigCounter++; |
| 755 | halConfigs.clear(); |
| 756 | ret = mSession->configureStreams(config, &halConfigs); |
| 757 | ASSERT_EQ(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT), ret.getServiceSpecificError()); |
| 758 | |
| 759 | for (auto& it : outputStreams) { |
| 760 | stream = {streamId++, |
| 761 | StreamType::OUTPUT, |
| 762 | it.width, |
| 763 | it.height, |
| 764 | static_cast<PixelFormat>(UINT32_MAX), |
| 765 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 766 | GRALLOC1_CONSUMER_USAGE_HWCOMPOSER), |
| 767 | Dataspace::UNKNOWN, |
| 768 | StreamRotation::ROTATION_0, |
| 769 | std::string(), |
| 770 | jpegBufferSize, |
| 771 | -1, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 772 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 773 | RequestAvailableDynamicRangeProfilesMap:: |
| 774 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 775 | |
| 776 | streams[0] = stream; |
| 777 | createStreamConfiguration(streams, StreamConfigurationMode::NORMAL_MODE, &config, |
| 778 | jpegBufferSize); |
| 779 | config.streamConfigCounter = streamConfigCounter++; |
| 780 | halConfigs.clear(); |
| 781 | ret = mSession->configureStreams(config, &halConfigs); |
| 782 | ASSERT_EQ(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT), |
| 783 | ret.getServiceSpecificError()); |
| 784 | |
| 785 | stream = {streamId++, |
| 786 | StreamType::OUTPUT, |
| 787 | it.width, |
| 788 | it.height, |
| 789 | static_cast<PixelFormat>(it.format), |
| 790 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 791 | GRALLOC1_CONSUMER_USAGE_HWCOMPOSER), |
| 792 | Dataspace::UNKNOWN, |
| 793 | static_cast<StreamRotation>(UINT32_MAX), |
| 794 | std::string(), |
| 795 | jpegBufferSize, |
| 796 | -1, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 797 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 798 | RequestAvailableDynamicRangeProfilesMap:: |
| 799 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 800 | |
| 801 | streams[0] = stream; |
| 802 | createStreamConfiguration(streams, StreamConfigurationMode::NORMAL_MODE, &config, |
| 803 | jpegBufferSize); |
| 804 | |
| 805 | config.streamConfigCounter = streamConfigCounter++; |
| 806 | halConfigs.clear(); |
| 807 | ret = mSession->configureStreams(config, &halConfigs); |
| 808 | ASSERT_EQ(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT), |
| 809 | ret.getServiceSpecificError()); |
| 810 | } |
| 811 | |
| 812 | ret = mSession->close(); |
| 813 | mSession = nullptr; |
| 814 | ASSERT_TRUE(ret.isOk()); |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | // Check whether all supported ZSL output stream combinations can be |
| 819 | // configured successfully. |
| 820 | TEST_P(CameraAidlTest, configureStreamsZSLInputOutputs) { |
| 821 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 822 | std::vector<AvailableStream> inputStreams; |
| 823 | std::vector<AvailableZSLInputOutput> inputOutputMap; |
| 824 | |
| 825 | for (const auto& name : cameraDeviceNames) { |
| 826 | CameraMetadata meta; |
| 827 | std::shared_ptr<ICameraDevice> cameraDevice; |
| 828 | |
| 829 | openEmptyDeviceSession(name, mProvider, &mSession /*out*/, &meta /*out*/, |
| 830 | &cameraDevice /*out*/); |
| 831 | camera_metadata_t* staticMeta = reinterpret_cast<camera_metadata_t*>(meta.metadata.data()); |
| 832 | |
| 833 | Status rc = isZSLModeAvailable(staticMeta); |
| 834 | if (Status::OPERATION_NOT_SUPPORTED == rc) { |
| 835 | ndk::ScopedAStatus ret = mSession->close(); |
| 836 | mSession = nullptr; |
| 837 | ASSERT_TRUE(ret.isOk()); |
| 838 | continue; |
| 839 | } |
| 840 | ASSERT_EQ(Status::OK, rc); |
| 841 | |
| 842 | inputStreams.clear(); |
| 843 | ASSERT_EQ(Status::OK, getAvailableOutputStreams(staticMeta, inputStreams)); |
| 844 | ASSERT_NE(0u, inputStreams.size()); |
| 845 | |
| 846 | inputOutputMap.clear(); |
| 847 | ASSERT_EQ(Status::OK, getZSLInputOutputMap(staticMeta, inputOutputMap)); |
| 848 | ASSERT_NE(0u, inputOutputMap.size()); |
| 849 | |
| 850 | bool supportMonoY8 = false; |
| 851 | if (Status::OK == isMonochromeCamera(staticMeta)) { |
| 852 | for (auto& it : inputStreams) { |
| 853 | if (it.format == static_cast<uint32_t>(PixelFormat::Y8)) { |
| 854 | supportMonoY8 = true; |
| 855 | break; |
| 856 | } |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | int32_t jpegBufferSize = 0; |
| 861 | ASSERT_EQ(Status::OK, getJpegBufferSize(staticMeta, &jpegBufferSize)); |
| 862 | ASSERT_NE(0u, jpegBufferSize); |
| 863 | |
| 864 | int32_t streamId = 0; |
| 865 | bool hasPrivToY8 = false, hasY8ToY8 = false, hasY8ToBlob = false; |
| 866 | uint32_t streamConfigCounter = 0; |
| 867 | for (auto& inputIter : inputOutputMap) { |
| 868 | AvailableStream input; |
| 869 | ASSERT_EQ(Status::OK, findLargestSize(inputStreams, inputIter.inputFormat, input)); |
| 870 | ASSERT_NE(0u, inputStreams.size()); |
| 871 | |
| 872 | if (inputIter.inputFormat == |
| 873 | static_cast<uint32_t>(PixelFormat::IMPLEMENTATION_DEFINED) && |
| 874 | inputIter.outputFormat == static_cast<uint32_t>(PixelFormat::Y8)) { |
| 875 | hasPrivToY8 = true; |
| 876 | } else if (inputIter.inputFormat == static_cast<uint32_t>(PixelFormat::Y8)) { |
| 877 | if (inputIter.outputFormat == static_cast<uint32_t>(PixelFormat::BLOB)) { |
| 878 | hasY8ToBlob = true; |
| 879 | } else if (inputIter.outputFormat == static_cast<uint32_t>(PixelFormat::Y8)) { |
| 880 | hasY8ToY8 = true; |
| 881 | } |
| 882 | } |
| 883 | AvailableStream outputThreshold = {INT32_MAX, INT32_MAX, inputIter.outputFormat}; |
| 884 | std::vector<AvailableStream> outputStreams; |
| 885 | ASSERT_EQ(Status::OK, |
| 886 | getAvailableOutputStreams(staticMeta, outputStreams, &outputThreshold)); |
| 887 | for (auto& outputIter : outputStreams) { |
| 888 | Dataspace outputDataSpace = |
| 889 | getDataspace(static_cast<PixelFormat>(outputIter.format)); |
| 890 | Stream zslStream = { |
| 891 | streamId++, |
| 892 | StreamType::OUTPUT, |
| 893 | input.width, |
| 894 | input.height, |
| 895 | static_cast<PixelFormat>(input.format), |
| 896 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 897 | GRALLOC_USAGE_HW_CAMERA_ZSL), |
| 898 | Dataspace::UNKNOWN, |
| 899 | StreamRotation::ROTATION_0, |
| 900 | std::string(), |
| 901 | jpegBufferSize, |
| 902 | -1, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 903 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 904 | RequestAvailableDynamicRangeProfilesMap:: |
| 905 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 906 | Stream inputStream = { |
| 907 | streamId++, |
| 908 | StreamType::INPUT, |
| 909 | input.width, |
| 910 | input.height, |
| 911 | static_cast<PixelFormat>(input.format), |
| 912 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>(0), |
| 913 | Dataspace::UNKNOWN, |
| 914 | StreamRotation::ROTATION_0, |
| 915 | std::string(), |
| 916 | jpegBufferSize, |
| 917 | -1, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 918 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 919 | RequestAvailableDynamicRangeProfilesMap:: |
| 920 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 921 | Stream outputStream = { |
| 922 | streamId++, |
| 923 | StreamType::OUTPUT, |
| 924 | outputIter.width, |
| 925 | outputIter.height, |
| 926 | static_cast<PixelFormat>(outputIter.format), |
| 927 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 928 | GRALLOC1_CONSUMER_USAGE_HWCOMPOSER), |
| 929 | outputDataSpace, |
| 930 | StreamRotation::ROTATION_0, |
| 931 | std::string(), |
| 932 | jpegBufferSize, |
| 933 | -1, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 934 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 935 | RequestAvailableDynamicRangeProfilesMap:: |
| 936 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 937 | |
| 938 | std::vector<Stream> streams = {inputStream, zslStream, outputStream}; |
| 939 | |
| 940 | StreamConfiguration config; |
| 941 | createStreamConfiguration(streams, StreamConfigurationMode::NORMAL_MODE, &config, |
| 942 | jpegBufferSize); |
| 943 | |
| 944 | verifyStreamCombination(cameraDevice, config, /*expectedStatus*/ true, |
| 945 | /*expectStreamCombQuery*/ false); |
| 946 | |
| 947 | config.streamConfigCounter = streamConfigCounter++; |
| 948 | std::vector<HalStream> halConfigs; |
| 949 | ndk::ScopedAStatus ret = mSession->configureStreams(config, &halConfigs); |
| 950 | ASSERT_TRUE(ret.isOk()); |
| 951 | ASSERT_EQ(3u, halConfigs.size()); |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | if (supportMonoY8) { |
| 956 | if (Status::OK == isZSLModeAvailable(staticMeta, PRIV_REPROCESS)) { |
| 957 | ASSERT_TRUE(hasPrivToY8); |
| 958 | } |
| 959 | if (Status::OK == isZSLModeAvailable(staticMeta, YUV_REPROCESS)) { |
| 960 | ASSERT_TRUE(hasY8ToY8); |
| 961 | ASSERT_TRUE(hasY8ToBlob); |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | ndk::ScopedAStatus ret = mSession->close(); |
| 966 | mSession = nullptr; |
| 967 | ASSERT_TRUE(ret.isOk()); |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | // Check whether session parameters are supported. If Hal support for them |
| 972 | // exist, then try to configure a preview stream using them. |
| 973 | TEST_P(CameraAidlTest, configureStreamsWithSessionParameters) { |
| 974 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 975 | std::vector<AvailableStream> outputPreviewStreams; |
| 976 | AvailableStream previewThreshold = {kMaxPreviewWidth, kMaxPreviewHeight, |
| 977 | static_cast<int32_t>(PixelFormat::IMPLEMENTATION_DEFINED)}; |
| 978 | |
| 979 | for (const auto& name : cameraDeviceNames) { |
| 980 | CameraMetadata meta; |
| 981 | |
| 982 | std::shared_ptr<ICameraDevice> unusedCameraDevice; |
| 983 | openEmptyDeviceSession(name, mProvider, &mSession /*out*/, &meta /*out*/, |
| 984 | &unusedCameraDevice /*out*/); |
| 985 | camera_metadata_t* staticMetaBuffer = |
| 986 | reinterpret_cast<camera_metadata_t*>(meta.metadata.data()); |
| 987 | |
| 988 | std::unordered_set<int32_t> availableSessionKeys; |
| 989 | auto rc = getSupportedKeys(staticMetaBuffer, ANDROID_REQUEST_AVAILABLE_SESSION_KEYS, |
| 990 | &availableSessionKeys); |
| 991 | ASSERT_TRUE(Status::OK == rc); |
| 992 | if (availableSessionKeys.empty()) { |
| 993 | ndk::ScopedAStatus ret = mSession->close(); |
| 994 | mSession = nullptr; |
| 995 | ASSERT_TRUE(ret.isOk()); |
| 996 | continue; |
| 997 | } |
| 998 | |
| 999 | android::hardware::camera::common::V1_0::helper::CameraMetadata previewRequestSettings; |
| 1000 | android::hardware::camera::common::V1_0::helper::CameraMetadata sessionParams, |
| 1001 | modifiedSessionParams; |
| 1002 | constructFilteredSettings(mSession, availableSessionKeys, RequestTemplate::PREVIEW, |
| 1003 | &previewRequestSettings, &sessionParams); |
| 1004 | if (sessionParams.isEmpty()) { |
| 1005 | ndk::ScopedAStatus ret = mSession->close(); |
| 1006 | mSession = nullptr; |
| 1007 | ASSERT_TRUE(ret.isOk()); |
| 1008 | continue; |
| 1009 | } |
| 1010 | |
| 1011 | outputPreviewStreams.clear(); |
| 1012 | |
| 1013 | ASSERT_EQ(Status::OK, getAvailableOutputStreams(staticMetaBuffer, outputPreviewStreams, |
| 1014 | &previewThreshold)); |
| 1015 | ASSERT_NE(0u, outputPreviewStreams.size()); |
| 1016 | |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 1017 | Stream previewStream = { |
| 1018 | 0, |
| 1019 | StreamType::OUTPUT, |
| 1020 | outputPreviewStreams[0].width, |
| 1021 | outputPreviewStreams[0].height, |
| 1022 | static_cast<PixelFormat>(outputPreviewStreams[0].format), |
| 1023 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 1024 | GRALLOC1_CONSUMER_USAGE_HWCOMPOSER), |
| 1025 | Dataspace::UNKNOWN, |
| 1026 | StreamRotation::ROTATION_0, |
| 1027 | std::string(), |
| 1028 | /*bufferSize*/ 0, |
| 1029 | /*groupId*/ -1, |
| 1030 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 1031 | RequestAvailableDynamicRangeProfilesMap:: |
| 1032 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1033 | |
| 1034 | std::vector<Stream> streams = {previewStream}; |
| 1035 | StreamConfiguration config; |
| 1036 | |
| 1037 | config.streams = streams; |
| 1038 | config.operationMode = StreamConfigurationMode::NORMAL_MODE; |
| 1039 | modifiedSessionParams = sessionParams; |
| 1040 | auto sessionParamsBuffer = sessionParams.release(); |
| 1041 | std::vector<uint8_t> rawSessionParam = |
| 1042 | std::vector(reinterpret_cast<uint8_t*>(sessionParamsBuffer), |
| 1043 | reinterpret_cast<uint8_t*>(sessionParamsBuffer) + |
| 1044 | get_camera_metadata_size(sessionParamsBuffer)); |
| 1045 | |
| 1046 | config.sessionParams.metadata = rawSessionParam; |
| 1047 | config.streamConfigCounter = 0; |
| 1048 | config.streams = {previewStream}; |
| 1049 | config.streamConfigCounter = 0; |
| 1050 | config.multiResolutionInputImage = false; |
| 1051 | |
| 1052 | bool newSessionParamsAvailable = false; |
| 1053 | for (const auto& it : availableSessionKeys) { |
| 1054 | if (modifiedSessionParams.exists(it)) { |
| 1055 | modifiedSessionParams.erase(it); |
| 1056 | newSessionParamsAvailable = true; |
| 1057 | break; |
| 1058 | } |
| 1059 | } |
| 1060 | if (newSessionParamsAvailable) { |
| 1061 | auto modifiedSessionParamsBuffer = modifiedSessionParams.release(); |
| 1062 | verifySessionReconfigurationQuery(mSession, sessionParamsBuffer, |
| 1063 | modifiedSessionParamsBuffer); |
| 1064 | modifiedSessionParams.acquire(modifiedSessionParamsBuffer); |
| 1065 | } |
| 1066 | |
| 1067 | std::vector<HalStream> halConfigs; |
| 1068 | ndk::ScopedAStatus ret = mSession->configureStreams(config, &halConfigs); |
| 1069 | ASSERT_TRUE(ret.isOk()); |
| 1070 | ASSERT_EQ(1u, halConfigs.size()); |
| 1071 | |
| 1072 | sessionParams.acquire(sessionParamsBuffer); |
| 1073 | ret = mSession->close(); |
| 1074 | mSession = nullptr; |
| 1075 | ASSERT_TRUE(ret.isOk()); |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | // Verify that all supported preview + still capture stream combinations |
| 1080 | // can be configured successfully. |
| 1081 | TEST_P(CameraAidlTest, configureStreamsPreviewStillOutputs) { |
| 1082 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 1083 | std::vector<AvailableStream> outputBlobStreams; |
| 1084 | std::vector<AvailableStream> outputPreviewStreams; |
| 1085 | AvailableStream previewThreshold = {kMaxPreviewWidth, kMaxPreviewHeight, |
| 1086 | static_cast<int32_t>(PixelFormat::IMPLEMENTATION_DEFINED)}; |
| 1087 | AvailableStream blobThreshold = {INT32_MAX, INT32_MAX, static_cast<int32_t>(PixelFormat::BLOB)}; |
| 1088 | |
| 1089 | for (const auto& name : cameraDeviceNames) { |
| 1090 | CameraMetadata meta; |
| 1091 | |
| 1092 | std::shared_ptr<ICameraDevice> cameraDevice; |
| 1093 | openEmptyDeviceSession(name, mProvider, &mSession /*out*/, &meta /*out*/, |
| 1094 | &cameraDevice /*out*/); |
| 1095 | |
| 1096 | camera_metadata_t* staticMeta = reinterpret_cast<camera_metadata_t*>(meta.metadata.data()); |
| 1097 | |
| 1098 | // Check if camera support depth only |
| 1099 | if (isDepthOnly(staticMeta)) { |
| 1100 | ndk::ScopedAStatus ret = mSession->close(); |
| 1101 | mSession = nullptr; |
| 1102 | ASSERT_TRUE(ret.isOk()); |
| 1103 | continue; |
| 1104 | } |
| 1105 | |
| 1106 | outputBlobStreams.clear(); |
| 1107 | ASSERT_EQ(Status::OK, |
| 1108 | getAvailableOutputStreams(staticMeta, outputBlobStreams, &blobThreshold)); |
| 1109 | ASSERT_NE(0u, outputBlobStreams.size()); |
| 1110 | |
| 1111 | outputPreviewStreams.clear(); |
| 1112 | ASSERT_EQ(Status::OK, |
| 1113 | getAvailableOutputStreams(staticMeta, outputPreviewStreams, &previewThreshold)); |
| 1114 | ASSERT_NE(0u, outputPreviewStreams.size()); |
| 1115 | |
| 1116 | int32_t jpegBufferSize = 0; |
| 1117 | ASSERT_EQ(Status::OK, getJpegBufferSize(staticMeta, &jpegBufferSize)); |
| 1118 | ASSERT_NE(0u, jpegBufferSize); |
| 1119 | |
| 1120 | int32_t streamId = 0; |
| 1121 | uint32_t streamConfigCounter = 0; |
| 1122 | |
| 1123 | for (auto& blobIter : outputBlobStreams) { |
| 1124 | for (auto& previewIter : outputPreviewStreams) { |
| 1125 | Stream previewStream = { |
| 1126 | streamId++, |
| 1127 | StreamType::OUTPUT, |
| 1128 | previewIter.width, |
| 1129 | previewIter.height, |
| 1130 | static_cast<PixelFormat>(previewIter.format), |
| 1131 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 1132 | GRALLOC1_CONSUMER_USAGE_HWCOMPOSER), |
| 1133 | Dataspace::UNKNOWN, |
| 1134 | StreamRotation::ROTATION_0, |
| 1135 | std::string(), |
| 1136 | /*bufferSize*/ 0, |
| 1137 | /*groupId*/ -1, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 1138 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 1139 | RequestAvailableDynamicRangeProfilesMap:: |
| 1140 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1141 | Stream blobStream = { |
| 1142 | streamId++, |
| 1143 | StreamType::OUTPUT, |
| 1144 | blobIter.width, |
| 1145 | blobIter.height, |
| 1146 | static_cast<PixelFormat>(blobIter.format), |
| 1147 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 1148 | GRALLOC1_CONSUMER_USAGE_CPU_READ), |
| 1149 | Dataspace::JFIF, |
| 1150 | StreamRotation::ROTATION_0, |
| 1151 | std::string(), |
| 1152 | /*bufferSize*/ 0, |
| 1153 | /*groupId*/ -1, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 1154 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 1155 | RequestAvailableDynamicRangeProfilesMap:: |
| 1156 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1157 | std::vector<Stream> streams = {previewStream, blobStream}; |
| 1158 | StreamConfiguration config; |
| 1159 | |
| 1160 | createStreamConfiguration(streams, StreamConfigurationMode::NORMAL_MODE, &config, |
| 1161 | jpegBufferSize); |
| 1162 | config.streamConfigCounter = streamConfigCounter++; |
| 1163 | verifyStreamCombination(cameraDevice, config, /*expectedStatus*/ true, |
| 1164 | /*expectStreamCombQuery*/ false); |
| 1165 | |
| 1166 | std::vector<HalStream> halConfigs; |
| 1167 | ndk::ScopedAStatus ret = mSession->configureStreams(config, &halConfigs); |
| 1168 | ASSERT_TRUE(ret.isOk()); |
| 1169 | ASSERT_EQ(2u, halConfigs.size()); |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | ndk::ScopedAStatus ret = mSession->close(); |
| 1174 | mSession = nullptr; |
| 1175 | ASSERT_TRUE(ret.isOk()); |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | // In case constrained mode is supported, test whether it can be |
| 1180 | // configured. Additionally check for common invalid inputs when |
| 1181 | // using this mode. |
| 1182 | TEST_P(CameraAidlTest, configureStreamsConstrainedOutputs) { |
| 1183 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 1184 | |
| 1185 | for (const auto& name : cameraDeviceNames) { |
| 1186 | CameraMetadata meta; |
| 1187 | std::shared_ptr<ICameraDevice> cameraDevice; |
| 1188 | |
| 1189 | openEmptyDeviceSession(name, mProvider, &mSession /*out*/, &meta /*out*/, |
| 1190 | &cameraDevice /*out*/); |
| 1191 | camera_metadata_t* staticMeta = reinterpret_cast<camera_metadata_t*>(meta.metadata.data()); |
| 1192 | |
| 1193 | Status rc = isConstrainedModeAvailable(staticMeta); |
| 1194 | if (Status::OPERATION_NOT_SUPPORTED == rc) { |
| 1195 | ndk::ScopedAStatus ret = mSession->close(); |
| 1196 | mSession = nullptr; |
| 1197 | ASSERT_TRUE(ret.isOk()); |
| 1198 | continue; |
| 1199 | } |
| 1200 | ASSERT_EQ(Status::OK, rc); |
| 1201 | |
| 1202 | AvailableStream hfrStream; |
| 1203 | rc = pickConstrainedModeSize(staticMeta, hfrStream); |
| 1204 | ASSERT_EQ(Status::OK, rc); |
| 1205 | |
| 1206 | int32_t streamId = 0; |
| 1207 | uint32_t streamConfigCounter = 0; |
| 1208 | Stream stream = {streamId, |
| 1209 | StreamType::OUTPUT, |
| 1210 | hfrStream.width, |
| 1211 | hfrStream.height, |
| 1212 | static_cast<PixelFormat>(hfrStream.format), |
| 1213 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 1214 | GRALLOC1_CONSUMER_USAGE_VIDEO_ENCODER), |
| 1215 | Dataspace::UNKNOWN, |
| 1216 | StreamRotation::ROTATION_0, |
| 1217 | std::string(), |
| 1218 | /*bufferSize*/ 0, |
| 1219 | /*groupId*/ -1, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 1220 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 1221 | RequestAvailableDynamicRangeProfilesMap:: |
| 1222 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1223 | std::vector<Stream> streams = {stream}; |
| 1224 | StreamConfiguration config; |
| 1225 | createStreamConfiguration(streams, StreamConfigurationMode::CONSTRAINED_HIGH_SPEED_MODE, |
| 1226 | &config); |
| 1227 | |
| 1228 | verifyStreamCombination(cameraDevice, config, /*expectedStatus*/ true, |
| 1229 | /*expectStreamCombQuery*/ false); |
| 1230 | |
| 1231 | config.streamConfigCounter = streamConfigCounter++; |
| 1232 | std::vector<HalStream> halConfigs; |
| 1233 | ndk::ScopedAStatus ret = mSession->configureStreams(config, &halConfigs); |
| 1234 | ASSERT_TRUE(ret.isOk()); |
| 1235 | ASSERT_EQ(1u, halConfigs.size()); |
| 1236 | ASSERT_EQ(halConfigs[0].id, streamId); |
| 1237 | |
| 1238 | stream = {streamId++, |
| 1239 | StreamType::OUTPUT, |
| 1240 | static_cast<uint32_t>(0), |
| 1241 | static_cast<uint32_t>(0), |
| 1242 | static_cast<PixelFormat>(hfrStream.format), |
| 1243 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 1244 | GRALLOC1_CONSUMER_USAGE_VIDEO_ENCODER), |
| 1245 | Dataspace::UNKNOWN, |
| 1246 | StreamRotation::ROTATION_0, |
| 1247 | std::string(), |
| 1248 | /*bufferSize*/ 0, |
| 1249 | /*groupId*/ -1, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 1250 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 1251 | RequestAvailableDynamicRangeProfilesMap:: |
| 1252 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1253 | streams[0] = stream; |
| 1254 | createStreamConfiguration(streams, StreamConfigurationMode::CONSTRAINED_HIGH_SPEED_MODE, |
| 1255 | &config); |
| 1256 | |
| 1257 | config.streamConfigCounter = streamConfigCounter++; |
| 1258 | std::vector<HalStream> halConfig; |
| 1259 | ret = mSession->configureStreams(config, &halConfig); |
| 1260 | ASSERT_TRUE(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT) == |
| 1261 | ret.getServiceSpecificError() || |
| 1262 | static_cast<int32_t>(Status::INTERNAL_ERROR) == ret.getServiceSpecificError()); |
| 1263 | |
| 1264 | stream = {streamId++, |
| 1265 | StreamType::OUTPUT, |
| 1266 | INT32_MAX, |
| 1267 | INT32_MAX, |
| 1268 | static_cast<PixelFormat>(hfrStream.format), |
| 1269 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 1270 | GRALLOC1_CONSUMER_USAGE_VIDEO_ENCODER), |
| 1271 | Dataspace::UNKNOWN, |
| 1272 | StreamRotation::ROTATION_0, |
| 1273 | std::string(), |
| 1274 | /*bufferSize*/ 0, |
| 1275 | /*groupId*/ -1, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 1276 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 1277 | RequestAvailableDynamicRangeProfilesMap:: |
| 1278 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1279 | streams[0] = stream; |
| 1280 | createStreamConfiguration(streams, StreamConfigurationMode::CONSTRAINED_HIGH_SPEED_MODE, |
| 1281 | &config); |
| 1282 | |
| 1283 | config.streamConfigCounter = streamConfigCounter++; |
| 1284 | halConfigs.clear(); |
| 1285 | ret = mSession->configureStreams(config, &halConfigs); |
| 1286 | ASSERT_EQ(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT), ret.getServiceSpecificError()); |
| 1287 | |
| 1288 | stream = {streamId++, |
| 1289 | StreamType::OUTPUT, |
| 1290 | hfrStream.width, |
| 1291 | hfrStream.height, |
| 1292 | static_cast<PixelFormat>(UINT32_MAX), |
| 1293 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 1294 | GRALLOC1_CONSUMER_USAGE_VIDEO_ENCODER), |
| 1295 | Dataspace::UNKNOWN, |
| 1296 | StreamRotation::ROTATION_0, |
| 1297 | std::string(), |
| 1298 | /*bufferSize*/ 0, |
| 1299 | /*groupId*/ -1, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 1300 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 1301 | RequestAvailableDynamicRangeProfilesMap:: |
| 1302 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1303 | streams[0] = stream; |
| 1304 | createStreamConfiguration(streams, StreamConfigurationMode::CONSTRAINED_HIGH_SPEED_MODE, |
| 1305 | &config); |
| 1306 | |
| 1307 | config.streamConfigCounter = streamConfigCounter++; |
| 1308 | halConfigs.clear(); |
| 1309 | ret = mSession->configureStreams(config, &halConfigs); |
| 1310 | ASSERT_EQ(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT), ret.getServiceSpecificError()); |
| 1311 | |
| 1312 | ret = mSession->close(); |
| 1313 | mSession = nullptr; |
| 1314 | ASSERT_TRUE(ret.isOk()); |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | // Verify that all supported video + snapshot stream combinations can |
| 1319 | // be configured successfully. |
| 1320 | TEST_P(CameraAidlTest, configureStreamsVideoStillOutputs) { |
| 1321 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 1322 | std::vector<AvailableStream> outputBlobStreams; |
| 1323 | std::vector<AvailableStream> outputVideoStreams; |
| 1324 | AvailableStream videoThreshold = {kMaxVideoWidth, kMaxVideoHeight, |
| 1325 | static_cast<int32_t>(PixelFormat::IMPLEMENTATION_DEFINED)}; |
| 1326 | AvailableStream blobThreshold = {kMaxVideoWidth, kMaxVideoHeight, |
| 1327 | static_cast<int32_t>(PixelFormat::BLOB)}; |
| 1328 | |
| 1329 | for (const auto& name : cameraDeviceNames) { |
| 1330 | CameraMetadata meta; |
| 1331 | std::shared_ptr<ICameraDevice> cameraDevice; |
| 1332 | |
| 1333 | openEmptyDeviceSession(name, mProvider, &mSession /*out*/, &meta /*out*/, |
| 1334 | &cameraDevice /*out*/); |
| 1335 | |
| 1336 | camera_metadata_t* staticMeta = reinterpret_cast<camera_metadata_t*>(meta.metadata.data()); |
| 1337 | |
| 1338 | // Check if camera support depth only |
| 1339 | if (isDepthOnly(staticMeta)) { |
| 1340 | ndk::ScopedAStatus ret = mSession->close(); |
| 1341 | mSession = nullptr; |
| 1342 | ASSERT_TRUE(ret.isOk()); |
| 1343 | continue; |
| 1344 | } |
| 1345 | |
| 1346 | outputBlobStreams.clear(); |
| 1347 | ASSERT_EQ(Status::OK, |
| 1348 | getAvailableOutputStreams(staticMeta, outputBlobStreams, &blobThreshold)); |
| 1349 | ASSERT_NE(0u, outputBlobStreams.size()); |
| 1350 | |
| 1351 | outputVideoStreams.clear(); |
| 1352 | ASSERT_EQ(Status::OK, |
| 1353 | getAvailableOutputStreams(staticMeta, outputVideoStreams, &videoThreshold)); |
| 1354 | ASSERT_NE(0u, outputVideoStreams.size()); |
| 1355 | |
| 1356 | int32_t jpegBufferSize = 0; |
| 1357 | ASSERT_EQ(Status::OK, getJpegBufferSize(staticMeta, &jpegBufferSize)); |
| 1358 | ASSERT_NE(0u, jpegBufferSize); |
| 1359 | |
| 1360 | int32_t streamId = 0; |
| 1361 | uint32_t streamConfigCounter = 0; |
| 1362 | for (auto& blobIter : outputBlobStreams) { |
| 1363 | for (auto& videoIter : outputVideoStreams) { |
| 1364 | Stream videoStream = { |
| 1365 | streamId++, |
| 1366 | StreamType::OUTPUT, |
| 1367 | videoIter.width, |
| 1368 | videoIter.height, |
| 1369 | static_cast<PixelFormat>(videoIter.format), |
| 1370 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 1371 | GRALLOC1_CONSUMER_USAGE_VIDEO_ENCODER), |
| 1372 | Dataspace::UNKNOWN, |
| 1373 | StreamRotation::ROTATION_0, |
| 1374 | std::string(), |
| 1375 | jpegBufferSize, |
| 1376 | /*groupId*/ -1, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 1377 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 1378 | RequestAvailableDynamicRangeProfilesMap:: |
| 1379 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1380 | Stream blobStream = { |
| 1381 | streamId++, |
| 1382 | StreamType::OUTPUT, |
| 1383 | blobIter.width, |
| 1384 | blobIter.height, |
| 1385 | static_cast<PixelFormat>(blobIter.format), |
| 1386 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 1387 | GRALLOC1_CONSUMER_USAGE_CPU_READ), |
| 1388 | Dataspace::JFIF, |
| 1389 | StreamRotation::ROTATION_0, |
| 1390 | std::string(), |
| 1391 | jpegBufferSize, |
| 1392 | /*groupId*/ -1, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 1393 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 1394 | RequestAvailableDynamicRangeProfilesMap:: |
| 1395 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1396 | std::vector<Stream> streams = {videoStream, blobStream}; |
| 1397 | StreamConfiguration config; |
| 1398 | |
| 1399 | createStreamConfiguration(streams, StreamConfigurationMode::NORMAL_MODE, &config, |
| 1400 | jpegBufferSize); |
| 1401 | verifyStreamCombination(cameraDevice, config, /*expectedStatus*/ true, |
| 1402 | /*expectStreamCombQuery*/ false); |
| 1403 | |
| 1404 | config.streamConfigCounter = streamConfigCounter++; |
| 1405 | std::vector<HalStream> halConfigs; |
| 1406 | ndk::ScopedAStatus ret = mSession->configureStreams(config, &halConfigs); |
| 1407 | ASSERT_TRUE(ret.isOk()); |
| 1408 | ASSERT_EQ(2u, halConfigs.size()); |
| 1409 | } |
| 1410 | } |
| 1411 | |
| 1412 | ndk::ScopedAStatus ret = mSession->close(); |
| 1413 | mSession = nullptr; |
| 1414 | ASSERT_TRUE(ret.isOk()); |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | // Generate and verify a camera capture request |
| 1419 | TEST_P(CameraAidlTest, processCaptureRequestPreview) { |
| 1420 | // TODO(b/220897574): Failing with BUFFER_ERROR |
| 1421 | processCaptureRequestInternal(GRALLOC1_CONSUMER_USAGE_HWCOMPOSER, RequestTemplate::PREVIEW, |
| 1422 | false /*secureOnlyCameras*/); |
| 1423 | } |
| 1424 | |
| 1425 | // Generate and verify a secure camera capture request |
| 1426 | TEST_P(CameraAidlTest, processSecureCaptureRequest) { |
| 1427 | processCaptureRequestInternal(GRALLOC1_PRODUCER_USAGE_PROTECTED, RequestTemplate::STILL_CAPTURE, |
| 1428 | true /*secureOnlyCameras*/); |
| 1429 | } |
| 1430 | |
| 1431 | TEST_P(CameraAidlTest, processCaptureRequestPreviewStabilization) { |
| 1432 | std::unordered_map<std::string, nsecs_t> cameraDeviceToTimeLag; |
| 1433 | processPreviewStabilizationCaptureRequestInternal(/*previewStabilizationOn*/ false, |
| 1434 | cameraDeviceToTimeLag); |
| 1435 | processPreviewStabilizationCaptureRequestInternal(/*previewStabilizationOn*/ true, |
| 1436 | cameraDeviceToTimeLag); |
| 1437 | } |
| 1438 | |
| 1439 | // Generate and verify a multi-camera capture request |
| 1440 | TEST_P(CameraAidlTest, processMultiCaptureRequestPreview) { |
| 1441 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 1442 | AvailableStream previewThreshold = {kMaxPreviewWidth, kMaxPreviewHeight, |
| 1443 | static_cast<int32_t>(PixelFormat::YCBCR_420_888)}; |
| 1444 | int64_t bufferId = 1; |
| 1445 | uint32_t frameNumber = 1; |
| 1446 | std::vector<uint8_t> settings; |
| 1447 | std::vector<uint8_t> emptySettings; |
| 1448 | std::string invalidPhysicalId = "-1"; |
| 1449 | |
| 1450 | for (const auto& name : cameraDeviceNames) { |
| 1451 | std::string version, deviceId; |
Avichal Rakesh | fbcf7ea | 2022-03-09 01:00:34 +0000 | [diff] [blame] | 1452 | ALOGI("processMultiCaptureRequestPreview: Test device %s", name.c_str()); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1453 | ASSERT_TRUE(matchDeviceName(name, mProviderType, &version, &deviceId)); |
| 1454 | CameraMetadata metadata; |
| 1455 | |
| 1456 | std::shared_ptr<ICameraDevice> unusedDevice; |
| 1457 | openEmptyDeviceSession(name, mProvider, &mSession /*out*/, &metadata /*out*/, |
| 1458 | &unusedDevice /*out*/); |
| 1459 | |
| 1460 | camera_metadata_t* staticMeta = |
| 1461 | reinterpret_cast<camera_metadata_t*>(metadata.metadata.data()); |
| 1462 | Status rc = isLogicalMultiCamera(staticMeta); |
| 1463 | if (Status::OPERATION_NOT_SUPPORTED == rc) { |
| 1464 | ndk::ScopedAStatus ret = mSession->close(); |
| 1465 | mSession = nullptr; |
| 1466 | ASSERT_TRUE(ret.isOk()); |
| 1467 | continue; |
| 1468 | } |
Avichal Rakesh | fbcf7ea | 2022-03-09 01:00:34 +0000 | [diff] [blame] | 1469 | ASSERT_EQ(Status::OK, rc); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1470 | |
| 1471 | std::unordered_set<std::string> physicalIds; |
| 1472 | rc = getPhysicalCameraIds(staticMeta, &physicalIds); |
| 1473 | ASSERT_TRUE(Status::OK == rc); |
| 1474 | ASSERT_TRUE(physicalIds.size() > 1); |
| 1475 | |
| 1476 | std::unordered_set<int32_t> physicalRequestKeyIDs; |
| 1477 | rc = getSupportedKeys(staticMeta, ANDROID_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS, |
| 1478 | &physicalRequestKeyIDs); |
| 1479 | ASSERT_TRUE(Status::OK == rc); |
| 1480 | if (physicalRequestKeyIDs.empty()) { |
| 1481 | ndk::ScopedAStatus ret = mSession->close(); |
| 1482 | mSession = nullptr; |
| 1483 | ASSERT_TRUE(ret.isOk()); |
| 1484 | // The logical camera doesn't support any individual physical requests. |
| 1485 | continue; |
| 1486 | } |
| 1487 | |
| 1488 | android::hardware::camera::common::V1_0::helper::CameraMetadata defaultPreviewSettings; |
| 1489 | android::hardware::camera::common::V1_0::helper::CameraMetadata filteredSettings; |
| 1490 | constructFilteredSettings(mSession, physicalRequestKeyIDs, RequestTemplate::PREVIEW, |
| 1491 | &defaultPreviewSettings, &filteredSettings); |
| 1492 | if (filteredSettings.isEmpty()) { |
| 1493 | // No physical device settings in default request. |
| 1494 | ndk::ScopedAStatus ret = mSession->close(); |
| 1495 | mSession = nullptr; |
| 1496 | ASSERT_TRUE(ret.isOk()); |
| 1497 | continue; |
| 1498 | } |
| 1499 | |
| 1500 | const camera_metadata_t* settingsBuffer = defaultPreviewSettings.getAndLock(); |
| 1501 | uint8_t* rawSettingsBuffer = (uint8_t*)settingsBuffer; |
| 1502 | settings.assign(rawSettingsBuffer, |
| 1503 | rawSettingsBuffer + get_camera_metadata_size(settingsBuffer)); |
| 1504 | CameraMetadata settingsMetadata = {settings}; |
| 1505 | overrideRotateAndCrop(&settingsMetadata); |
| 1506 | |
| 1507 | ndk::ScopedAStatus ret = mSession->close(); |
| 1508 | mSession = nullptr; |
| 1509 | ASSERT_TRUE(ret.isOk()); |
| 1510 | |
| 1511 | // Leave only 2 physical devices in the id set. |
| 1512 | auto it = physicalIds.begin(); |
| 1513 | std::string physicalDeviceId = *it; |
| 1514 | it++; |
| 1515 | physicalIds.erase(++it, physicalIds.end()); |
| 1516 | ASSERT_EQ(physicalIds.size(), 2u); |
| 1517 | |
| 1518 | std::vector<HalStream> halStreams; |
| 1519 | bool supportsPartialResults = false; |
| 1520 | bool useHalBufManager = false; |
| 1521 | int32_t partialResultCount = 0; |
| 1522 | Stream previewStream; |
| 1523 | std::shared_ptr<DeviceCb> cb; |
| 1524 | |
Avichal Rakesh | fbcf7ea | 2022-03-09 01:00:34 +0000 | [diff] [blame] | 1525 | configurePreviewStreams( |
| 1526 | name, mProvider, &previewThreshold, physicalIds, &mSession, &previewStream, |
| 1527 | &halStreams /*out*/, &supportsPartialResults /*out*/, &partialResultCount /*out*/, |
| 1528 | &useHalBufManager /*out*/, &cb /*out*/, 0 /*streamConfigCounter*/, true); |
| 1529 | if (mSession == nullptr) { |
| 1530 | // stream combination not supported by HAL, skip test for device |
| 1531 | continue; |
| 1532 | } |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1533 | |
| 1534 | ::aidl::android::hardware::common::fmq::MQDescriptor< |
| 1535 | int8_t, aidl::android::hardware::common::fmq::SynchronizedReadWrite> |
| 1536 | descriptor; |
| 1537 | auto resultQueueRet = mSession->getCaptureResultMetadataQueue(&descriptor); |
| 1538 | ASSERT_TRUE(resultQueueRet.isOk()); |
| 1539 | std::shared_ptr<ResultMetadataQueue> resultQueue = |
| 1540 | std::make_shared<ResultMetadataQueue>(descriptor); |
| 1541 | if (!resultQueue->isValid() || resultQueue->availableToWrite() <= 0) { |
| 1542 | ALOGE("%s: HAL returns empty result metadata fmq, not use it", __func__); |
| 1543 | resultQueue = nullptr; |
| 1544 | // Don't use the queue onwards. |
| 1545 | } |
| 1546 | |
| 1547 | std::shared_ptr<InFlightRequest> inflightReq = std::make_shared<InFlightRequest>( |
| 1548 | static_cast<ssize_t>(halStreams.size()), false, supportsPartialResults, |
| 1549 | partialResultCount, physicalIds, resultQueue); |
| 1550 | |
| 1551 | std::vector<CaptureRequest> requests(1); |
| 1552 | CaptureRequest& request = requests[0]; |
| 1553 | request.frameNumber = frameNumber; |
| 1554 | request.fmqSettingsSize = 0; |
Emilian Peev | 3d919f9 | 2022-04-20 13:50:59 -0700 | [diff] [blame] | 1555 | request.settings = settingsMetadata; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1556 | |
| 1557 | std::vector<StreamBuffer>& outputBuffers = request.outputBuffers; |
| 1558 | |
| 1559 | std::vector<buffer_handle_t> graphicBuffers; |
| 1560 | graphicBuffers.reserve(halStreams.size()); |
| 1561 | outputBuffers.resize(halStreams.size()); |
| 1562 | size_t k = 0; |
| 1563 | for (const auto& halStream : halStreams) { |
| 1564 | buffer_handle_t buffer_handle; |
| 1565 | if (useHalBufManager) { |
| 1566 | outputBuffers[k] = {halStream.id, /*bufferId*/ 0, NativeHandle(), |
| 1567 | BufferStatus::OK, NativeHandle(), NativeHandle()}; |
| 1568 | } else { |
| 1569 | allocateGraphicBuffer(previewStream.width, previewStream.height, |
| 1570 | android_convertGralloc1To0Usage( |
| 1571 | static_cast<uint64_t>(halStream.producerUsage), |
| 1572 | static_cast<uint64_t>(halStream.consumerUsage)), |
| 1573 | halStream.overrideFormat, &buffer_handle); |
| 1574 | graphicBuffers.push_back(buffer_handle); |
| 1575 | outputBuffers[k] = { |
| 1576 | halStream.id, bufferId, ::android::makeToAidl(buffer_handle), |
| 1577 | BufferStatus::OK, NativeHandle(), NativeHandle()}; |
| 1578 | bufferId++; |
| 1579 | } |
| 1580 | k++; |
| 1581 | } |
| 1582 | |
| 1583 | std::vector<PhysicalCameraSetting> camSettings(1); |
| 1584 | const camera_metadata_t* filteredSettingsBuffer = filteredSettings.getAndLock(); |
| 1585 | uint8_t* rawFilteredSettingsBuffer = (uint8_t*)filteredSettingsBuffer; |
| 1586 | camSettings[0].settings = {std::vector( |
| 1587 | rawFilteredSettingsBuffer, |
| 1588 | rawFilteredSettingsBuffer + get_camera_metadata_size(filteredSettingsBuffer))}; |
| 1589 | overrideRotateAndCrop(&camSettings[0].settings); |
| 1590 | camSettings[0].fmqSettingsSize = 0; |
| 1591 | camSettings[0].physicalCameraId = physicalDeviceId; |
| 1592 | |
| 1593 | request.inputBuffer = { |
| 1594 | -1, 0, NativeHandle(), BufferStatus::ERROR, NativeHandle(), NativeHandle()}; |
| 1595 | request.physicalCameraSettings = camSettings; |
| 1596 | |
| 1597 | { |
| 1598 | std::unique_lock<std::mutex> l(mLock); |
| 1599 | mInflightMap.clear(); |
| 1600 | mInflightMap[frameNumber] = inflightReq; |
| 1601 | } |
| 1602 | |
| 1603 | int32_t numRequestProcessed = 0; |
| 1604 | std::vector<BufferCache> cachesToRemove; |
| 1605 | ndk::ScopedAStatus returnStatus = |
| 1606 | mSession->processCaptureRequest(requests, cachesToRemove, &numRequestProcessed); |
| 1607 | ASSERT_TRUE(returnStatus.isOk()); |
| 1608 | ASSERT_EQ(numRequestProcessed, 1u); |
| 1609 | |
| 1610 | { |
| 1611 | std::unique_lock<std::mutex> l(mLock); |
| 1612 | while (!inflightReq->errorCodeValid && |
| 1613 | ((0 < inflightReq->numBuffersLeft) || (!inflightReq->haveResultMetadata))) { |
| 1614 | auto timeout = std::chrono::system_clock::now() + |
| 1615 | std::chrono::seconds(kStreamBufferTimeoutSec); |
| 1616 | ASSERT_NE(std::cv_status::timeout, mResultCondition.wait_until(l, timeout)); |
| 1617 | } |
| 1618 | |
| 1619 | ASSERT_FALSE(inflightReq->errorCodeValid); |
| 1620 | ASSERT_NE(inflightReq->resultOutputBuffers.size(), 0u); |
| 1621 | |
| 1622 | request.frameNumber++; |
| 1623 | // Empty settings should be supported after the first call |
| 1624 | // for repeating requests. |
| 1625 | request.settings.metadata.clear(); |
| 1626 | request.physicalCameraSettings[0].settings.metadata.clear(); |
| 1627 | // The buffer has been registered to HAL by bufferId, so per |
| 1628 | // API contract we should send a null handle for this buffer |
| 1629 | request.outputBuffers[0].buffer = NativeHandle(); |
| 1630 | mInflightMap.clear(); |
| 1631 | inflightReq = std::make_shared<InFlightRequest>( |
| 1632 | static_cast<ssize_t>(physicalIds.size()), false, supportsPartialResults, |
| 1633 | partialResultCount, physicalIds, resultQueue); |
| 1634 | mInflightMap[request.frameNumber] = inflightReq; |
| 1635 | } |
| 1636 | |
| 1637 | returnStatus = |
| 1638 | mSession->processCaptureRequest(requests, cachesToRemove, &numRequestProcessed); |
| 1639 | ASSERT_TRUE(returnStatus.isOk()); |
| 1640 | ASSERT_EQ(numRequestProcessed, 1u); |
| 1641 | |
| 1642 | { |
| 1643 | std::unique_lock<std::mutex> l(mLock); |
| 1644 | while (!inflightReq->errorCodeValid && |
| 1645 | ((0 < inflightReq->numBuffersLeft) || (!inflightReq->haveResultMetadata))) { |
| 1646 | auto timeout = std::chrono::system_clock::now() + |
| 1647 | std::chrono::seconds(kStreamBufferTimeoutSec); |
| 1648 | ASSERT_NE(std::cv_status::timeout, mResultCondition.wait_until(l, timeout)); |
| 1649 | } |
| 1650 | |
| 1651 | ASSERT_FALSE(inflightReq->errorCodeValid); |
| 1652 | ASSERT_NE(inflightReq->resultOutputBuffers.size(), 0u); |
| 1653 | } |
| 1654 | |
| 1655 | // Invalid physical camera id should fail process requests |
| 1656 | frameNumber++; |
| 1657 | camSettings[0].physicalCameraId = invalidPhysicalId; |
| 1658 | camSettings[0].settings.metadata = settings; |
| 1659 | |
| 1660 | request.physicalCameraSettings = camSettings; // Invalid camera settings |
| 1661 | returnStatus = |
| 1662 | mSession->processCaptureRequest(requests, cachesToRemove, &numRequestProcessed); |
| 1663 | ASSERT_EQ(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT), |
| 1664 | returnStatus.getServiceSpecificError()); |
| 1665 | |
| 1666 | defaultPreviewSettings.unlock(settingsBuffer); |
| 1667 | filteredSettings.unlock(filteredSettingsBuffer); |
| 1668 | |
| 1669 | if (useHalBufManager) { |
| 1670 | std::vector<int32_t> streamIds(halStreams.size()); |
| 1671 | for (size_t i = 0; i < streamIds.size(); i++) { |
| 1672 | streamIds[i] = halStreams[i].id; |
| 1673 | } |
| 1674 | verifyBuffersReturned(mSession, streamIds, cb); |
| 1675 | } |
| 1676 | |
| 1677 | ret = mSession->close(); |
| 1678 | mSession = nullptr; |
| 1679 | ASSERT_TRUE(ret.isOk()); |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | // Generate and verify an ultra high resolution capture request |
| 1684 | TEST_P(CameraAidlTest, processUltraHighResolutionRequest) { |
| 1685 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 1686 | int64_t bufferId = 1; |
| 1687 | int32_t frameNumber = 1; |
| 1688 | CameraMetadata settings; |
| 1689 | |
| 1690 | for (const auto& name : cameraDeviceNames) { |
| 1691 | std::string version, deviceId; |
| 1692 | ASSERT_TRUE(matchDeviceName(name, mProviderType, &version, &deviceId)); |
| 1693 | CameraMetadata meta; |
| 1694 | |
| 1695 | std::shared_ptr<ICameraDevice> unusedDevice; |
| 1696 | openEmptyDeviceSession(name, mProvider, &mSession, &meta, &unusedDevice); |
| 1697 | camera_metadata_t* staticMeta = reinterpret_cast<camera_metadata_t*>(meta.metadata.data()); |
| 1698 | if (!isUltraHighResolution(staticMeta)) { |
| 1699 | ndk::ScopedAStatus ret = mSession->close(); |
| 1700 | mSession = nullptr; |
| 1701 | ASSERT_TRUE(ret.isOk()); |
| 1702 | continue; |
| 1703 | } |
| 1704 | CameraMetadata req; |
| 1705 | android::hardware::camera::common::V1_0::helper::CameraMetadata defaultSettings; |
| 1706 | ndk::ScopedAStatus ret = |
| 1707 | mSession->constructDefaultRequestSettings(RequestTemplate::STILL_CAPTURE, &req); |
| 1708 | ASSERT_TRUE(ret.isOk()); |
| 1709 | |
| 1710 | const camera_metadata_t* metadata = |
| 1711 | reinterpret_cast<const camera_metadata_t*>(req.metadata.data()); |
| 1712 | size_t expectedSize = req.metadata.size(); |
| 1713 | int result = validate_camera_metadata_structure(metadata, &expectedSize); |
| 1714 | ASSERT_TRUE((result == 0) || (result == CAMERA_METADATA_VALIDATION_SHIFTED)); |
| 1715 | |
| 1716 | size_t entryCount = get_camera_metadata_entry_count(metadata); |
| 1717 | ASSERT_GT(entryCount, 0u); |
| 1718 | defaultSettings = metadata; |
| 1719 | uint8_t sensorPixelMode = |
| 1720 | static_cast<uint8_t>(ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION); |
| 1721 | ASSERT_EQ(::android::OK, |
| 1722 | defaultSettings.update(ANDROID_SENSOR_PIXEL_MODE, &sensorPixelMode, 1)); |
| 1723 | |
| 1724 | const camera_metadata_t* settingsBuffer = defaultSettings.getAndLock(); |
| 1725 | uint8_t* rawSettingsBuffer = (uint8_t*)settingsBuffer; |
| 1726 | settings.metadata = std::vector( |
| 1727 | rawSettingsBuffer, rawSettingsBuffer + get_camera_metadata_size(settingsBuffer)); |
| 1728 | overrideRotateAndCrop(&settings); |
| 1729 | |
| 1730 | ret = mSession->close(); |
| 1731 | mSession = nullptr; |
| 1732 | ASSERT_TRUE(ret.isOk()); |
| 1733 | |
| 1734 | std::vector<HalStream> halStreams; |
| 1735 | bool supportsPartialResults = false; |
| 1736 | bool useHalBufManager = false; |
| 1737 | int32_t partialResultCount = 0; |
| 1738 | Stream previewStream; |
| 1739 | std::shared_ptr<DeviceCb> cb; |
| 1740 | |
| 1741 | std::list<PixelFormat> pixelFormats = {PixelFormat::YCBCR_420_888, PixelFormat::RAW16}; |
| 1742 | for (PixelFormat format : pixelFormats) { |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 1743 | previewStream.usage = |
| 1744 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 1745 | GRALLOC1_CONSUMER_USAGE_CPU_READ); |
| 1746 | previewStream.dataSpace = Dataspace::UNKNOWN; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1747 | configureStreams(name, mProvider, format, &mSession, &previewStream, &halStreams, |
| 1748 | &supportsPartialResults, &partialResultCount, &useHalBufManager, &cb, |
| 1749 | 0, /*maxResolution*/ true); |
| 1750 | ASSERT_NE(mSession, nullptr); |
| 1751 | |
| 1752 | ::aidl::android::hardware::common::fmq::MQDescriptor< |
| 1753 | int8_t, aidl::android::hardware::common::fmq::SynchronizedReadWrite> |
| 1754 | descriptor; |
| 1755 | auto resultQueueRet = mSession->getCaptureResultMetadataQueue(&descriptor); |
| 1756 | ASSERT_TRUE(resultQueueRet.isOk()); |
| 1757 | |
| 1758 | std::shared_ptr<ResultMetadataQueue> resultQueue = |
| 1759 | std::make_shared<ResultMetadataQueue>(descriptor); |
| 1760 | if (!resultQueue->isValid() || resultQueue->availableToWrite() <= 0) { |
| 1761 | ALOGE("%s: HAL returns empty result metadata fmq, not use it", __func__); |
| 1762 | resultQueue = nullptr; |
| 1763 | // Don't use the queue onwards. |
| 1764 | } |
| 1765 | |
| 1766 | std::vector<buffer_handle_t> graphicBuffers; |
| 1767 | graphicBuffers.reserve(halStreams.size()); |
| 1768 | std::shared_ptr<InFlightRequest> inflightReq = std::make_shared<InFlightRequest>( |
| 1769 | static_cast<ssize_t>(halStreams.size()), false, supportsPartialResults, |
| 1770 | partialResultCount, std::unordered_set<std::string>(), resultQueue); |
| 1771 | |
| 1772 | std::vector<CaptureRequest> requests(1); |
| 1773 | CaptureRequest& request = requests[0]; |
| 1774 | std::vector<StreamBuffer>& outputBuffers = request.outputBuffers; |
| 1775 | outputBuffers.resize(halStreams.size()); |
| 1776 | |
| 1777 | size_t k = 0; |
| 1778 | for (const auto& halStream : halStreams) { |
| 1779 | buffer_handle_t buffer_handle; |
| 1780 | if (useHalBufManager) { |
| 1781 | outputBuffers[k] = {halStream.id, 0, |
| 1782 | NativeHandle(), BufferStatus::OK, |
| 1783 | NativeHandle(), NativeHandle()}; |
| 1784 | } else { |
| 1785 | allocateGraphicBuffer(previewStream.width, previewStream.height, |
| 1786 | android_convertGralloc1To0Usage( |
| 1787 | static_cast<uint64_t>(halStream.producerUsage), |
| 1788 | static_cast<uint64_t>(halStream.consumerUsage)), |
| 1789 | halStream.overrideFormat, &buffer_handle); |
| 1790 | graphicBuffers.push_back(buffer_handle); |
| 1791 | outputBuffers[k] = { |
| 1792 | halStream.id, bufferId, ::android::makeToAidl(buffer_handle), |
| 1793 | BufferStatus::OK, NativeHandle(), NativeHandle()}; |
| 1794 | bufferId++; |
| 1795 | } |
| 1796 | k++; |
| 1797 | } |
| 1798 | |
| 1799 | request.inputBuffer = { |
| 1800 | -1, 0, NativeHandle(), BufferStatus::ERROR, NativeHandle(), NativeHandle()}; |
| 1801 | request.frameNumber = frameNumber; |
| 1802 | request.fmqSettingsSize = 0; |
| 1803 | request.settings = settings; |
| 1804 | request.inputWidth = 0; |
| 1805 | request.inputHeight = 0; |
| 1806 | |
| 1807 | { |
| 1808 | std::unique_lock<std::mutex> l(mLock); |
| 1809 | mInflightMap.clear(); |
| 1810 | mInflightMap[frameNumber] = inflightReq; |
| 1811 | } |
| 1812 | |
| 1813 | int32_t numRequestProcessed = 0; |
| 1814 | std::vector<BufferCache> cachesToRemove; |
| 1815 | ndk::ScopedAStatus returnStatus = |
| 1816 | mSession->processCaptureRequest(requests, cachesToRemove, &numRequestProcessed); |
| 1817 | ASSERT_TRUE(returnStatus.isOk()); |
| 1818 | ASSERT_EQ(numRequestProcessed, 1u); |
| 1819 | |
| 1820 | { |
| 1821 | std::unique_lock<std::mutex> l(mLock); |
| 1822 | while (!inflightReq->errorCodeValid && |
| 1823 | ((0 < inflightReq->numBuffersLeft) || (!inflightReq->haveResultMetadata))) { |
| 1824 | auto timeout = std::chrono::system_clock::now() + |
| 1825 | std::chrono::seconds(kStreamBufferTimeoutSec); |
| 1826 | ASSERT_NE(std::cv_status::timeout, mResultCondition.wait_until(l, timeout)); |
| 1827 | } |
| 1828 | |
| 1829 | ASSERT_FALSE(inflightReq->errorCodeValid); |
| 1830 | ASSERT_NE(inflightReq->resultOutputBuffers.size(), 0u); |
| 1831 | } |
| 1832 | if (useHalBufManager) { |
| 1833 | std::vector<int32_t> streamIds(halStreams.size()); |
| 1834 | for (size_t i = 0; i < streamIds.size(); i++) { |
| 1835 | streamIds[i] = halStreams[i].id; |
| 1836 | } |
| 1837 | verifyBuffersReturned(mSession, streamIds, cb); |
| 1838 | } |
| 1839 | |
| 1840 | ret = mSession->close(); |
| 1841 | mSession = nullptr; |
| 1842 | ASSERT_TRUE(ret.isOk()); |
| 1843 | } |
| 1844 | } |
| 1845 | } |
| 1846 | |
| 1847 | // Generate and verify 10-bit dynamic range request |
| 1848 | TEST_P(CameraAidlTest, process10BitDynamicRangeRequest) { |
| 1849 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1850 | CameraMetadata settings; |
| 1851 | |
| 1852 | for (const auto& name : cameraDeviceNames) { |
| 1853 | std::string version, deviceId; |
| 1854 | ASSERT_TRUE(matchDeviceName(name, mProviderType, &version, &deviceId)); |
| 1855 | CameraMetadata meta; |
| 1856 | std::shared_ptr<ICameraDevice> device; |
| 1857 | openEmptyDeviceSession(name, mProvider, &mSession, &meta, &device); |
| 1858 | camera_metadata_t* staticMeta = reinterpret_cast<camera_metadata_t*>(meta.metadata.data()); |
| 1859 | if (!is10BitDynamicRangeCapable(staticMeta)) { |
| 1860 | ndk::ScopedAStatus ret = mSession->close(); |
| 1861 | mSession = nullptr; |
| 1862 | ASSERT_TRUE(ret.isOk()); |
| 1863 | continue; |
| 1864 | } |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 1865 | std::vector<RequestAvailableDynamicRangeProfilesMap> profileList; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1866 | get10BitDynamicRangeProfiles(staticMeta, &profileList); |
| 1867 | ASSERT_FALSE(profileList.empty()); |
| 1868 | |
| 1869 | CameraMetadata req; |
| 1870 | android::hardware::camera::common::V1_0::helper::CameraMetadata defaultSettings; |
| 1871 | ndk::ScopedAStatus ret = |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 1872 | mSession->constructDefaultRequestSettings(RequestTemplate::PREVIEW, &req); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1873 | ASSERT_TRUE(ret.isOk()); |
| 1874 | |
| 1875 | const camera_metadata_t* metadata = |
| 1876 | reinterpret_cast<const camera_metadata_t*>(req.metadata.data()); |
| 1877 | size_t expectedSize = req.metadata.size(); |
| 1878 | int result = validate_camera_metadata_structure(metadata, &expectedSize); |
| 1879 | ASSERT_TRUE((result == 0) || (result == CAMERA_METADATA_VALIDATION_SHIFTED)); |
| 1880 | |
| 1881 | size_t entryCount = get_camera_metadata_entry_count(metadata); |
| 1882 | ASSERT_GT(entryCount, 0u); |
| 1883 | defaultSettings = metadata; |
| 1884 | |
| 1885 | const camera_metadata_t* settingsBuffer = defaultSettings.getAndLock(); |
| 1886 | uint8_t* rawSettingsBuffer = (uint8_t*)settingsBuffer; |
| 1887 | settings.metadata = std::vector( |
| 1888 | rawSettingsBuffer, rawSettingsBuffer + get_camera_metadata_size(settingsBuffer)); |
| 1889 | overrideRotateAndCrop(&settings); |
| 1890 | |
| 1891 | ret = mSession->close(); |
| 1892 | mSession = nullptr; |
| 1893 | ASSERT_TRUE(ret.isOk()); |
| 1894 | |
| 1895 | std::vector<HalStream> halStreams; |
| 1896 | bool supportsPartialResults = false; |
| 1897 | bool useHalBufManager = false; |
| 1898 | int32_t partialResultCount = 0; |
| 1899 | Stream previewStream; |
| 1900 | std::shared_ptr<DeviceCb> cb; |
| 1901 | for (const auto& profile : profileList) { |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 1902 | previewStream.usage = |
| 1903 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 1904 | GRALLOC1_CONSUMER_USAGE_HWCOMPOSER); |
| 1905 | previewStream.dataSpace = getDataspace(PixelFormat::IMPLEMENTATION_DEFINED); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1906 | configureStreams(name, mProvider, PixelFormat::IMPLEMENTATION_DEFINED, &mSession, |
| 1907 | &previewStream, &halStreams, &supportsPartialResults, |
| 1908 | &partialResultCount, &useHalBufManager, &cb, 0, |
| 1909 | /*maxResolution*/ false, profile); |
| 1910 | ASSERT_NE(mSession, nullptr); |
| 1911 | |
| 1912 | ::aidl::android::hardware::common::fmq::MQDescriptor< |
| 1913 | int8_t, aidl::android::hardware::common::fmq::SynchronizedReadWrite> |
| 1914 | descriptor; |
| 1915 | auto resultQueueRet = mSession->getCaptureResultMetadataQueue(&descriptor); |
| 1916 | ASSERT_TRUE(resultQueueRet.isOk()); |
| 1917 | |
| 1918 | std::shared_ptr<ResultMetadataQueue> resultQueue = |
| 1919 | std::make_shared<ResultMetadataQueue>(descriptor); |
| 1920 | if (!resultQueue->isValid() || resultQueue->availableToWrite() <= 0) { |
| 1921 | ALOGE("%s: HAL returns empty result metadata fmq, not use it", __func__); |
| 1922 | resultQueue = nullptr; |
| 1923 | // Don't use the queue onwards. |
| 1924 | } |
| 1925 | |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 1926 | mInflightMap.clear(); |
| 1927 | // Stream as long as needed to fill the Hal inflight queue |
| 1928 | std::vector<CaptureRequest> requests(halStreams[0].maxBuffers); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1929 | |
Emilian Peev | 470d138 | 2023-01-18 11:09:09 -0800 | [diff] [blame] | 1930 | for (int32_t requestId = 0; requestId < requests.size(); requestId++) { |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 1931 | std::shared_ptr<InFlightRequest> inflightReq = std::make_shared<InFlightRequest>( |
| 1932 | static_cast<ssize_t>(halStreams.size()), false, supportsPartialResults, |
| 1933 | partialResultCount, std::unordered_set<std::string>(), resultQueue); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1934 | |
Emilian Peev | 470d138 | 2023-01-18 11:09:09 -0800 | [diff] [blame] | 1935 | CaptureRequest& request = requests[requestId]; |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 1936 | std::vector<StreamBuffer>& outputBuffers = request.outputBuffers; |
| 1937 | outputBuffers.resize(halStreams.size()); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1938 | |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 1939 | size_t k = 0; |
| 1940 | inflightReq->mOutstandingBufferIds.resize(halStreams.size()); |
| 1941 | std::vector<buffer_handle_t> graphicBuffers; |
| 1942 | graphicBuffers.reserve(halStreams.size()); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1943 | |
Emilian Peev | 470d138 | 2023-01-18 11:09:09 -0800 | [diff] [blame] | 1944 | auto bufferId = requestId + 1; // Buffer id value 0 is not valid |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 1945 | for (const auto& halStream : halStreams) { |
| 1946 | buffer_handle_t buffer_handle; |
| 1947 | if (useHalBufManager) { |
| 1948 | outputBuffers[k] = {halStream.id, 0, |
| 1949 | NativeHandle(), BufferStatus::OK, |
| 1950 | NativeHandle(), NativeHandle()}; |
| 1951 | } else { |
| 1952 | auto usage = android_convertGralloc1To0Usage( |
| 1953 | static_cast<uint64_t>(halStream.producerUsage), |
| 1954 | static_cast<uint64_t>(halStream.consumerUsage)); |
| 1955 | allocateGraphicBuffer(previewStream.width, previewStream.height, usage, |
| 1956 | halStream.overrideFormat, &buffer_handle); |
| 1957 | |
| 1958 | inflightReq->mOutstandingBufferIds[halStream.id][bufferId] = buffer_handle; |
| 1959 | graphicBuffers.push_back(buffer_handle); |
| 1960 | outputBuffers[k] = {halStream.id, bufferId, |
| 1961 | android::makeToAidl(buffer_handle), BufferStatus::OK, NativeHandle(), |
| 1962 | NativeHandle()}; |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 1963 | } |
| 1964 | k++; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1965 | } |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1966 | |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 1967 | request.inputBuffer = { |
| 1968 | -1, 0, NativeHandle(), BufferStatus::ERROR, NativeHandle(), NativeHandle()}; |
Emilian Peev | 470d138 | 2023-01-18 11:09:09 -0800 | [diff] [blame] | 1969 | request.frameNumber = bufferId; |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 1970 | request.fmqSettingsSize = 0; |
| 1971 | request.settings = settings; |
| 1972 | request.inputWidth = 0; |
| 1973 | request.inputHeight = 0; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1974 | |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 1975 | { |
| 1976 | std::unique_lock<std::mutex> l(mLock); |
Emilian Peev | 470d138 | 2023-01-18 11:09:09 -0800 | [diff] [blame] | 1977 | mInflightMap[bufferId] = inflightReq; |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | int32_t numRequestProcessed = 0; |
| 1983 | std::vector<BufferCache> cachesToRemove; |
| 1984 | ndk::ScopedAStatus returnStatus = |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 1985 | mSession->processCaptureRequest(requests, cachesToRemove, &numRequestProcessed); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1986 | ASSERT_TRUE(returnStatus.isOk()); |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 1987 | ASSERT_EQ(numRequestProcessed, requests.size()); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1988 | |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 1989 | returnStatus = mSession->repeatingRequestEnd(requests.size() - 1, |
| 1990 | std::vector<int32_t> {halStreams[0].id}); |
| 1991 | ASSERT_TRUE(returnStatus.isOk()); |
| 1992 | |
Emilian Peev | 470d138 | 2023-01-18 11:09:09 -0800 | [diff] [blame] | 1993 | // We are keeping frame numbers and buffer ids consistent. Buffer id value of 0 |
| 1994 | // is used to indicate a buffer that is not present/available so buffer ids as well |
| 1995 | // as frame numbers begin with 1. |
| 1996 | for (int32_t frameNumber = 1; frameNumber <= requests.size(); frameNumber++) { |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 1997 | const auto& inflightReq = mInflightMap[frameNumber]; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 1998 | std::unique_lock<std::mutex> l(mLock); |
| 1999 | while (!inflightReq->errorCodeValid && |
| 2000 | ((0 < inflightReq->numBuffersLeft) || (!inflightReq->haveResultMetadata))) { |
| 2001 | auto timeout = std::chrono::system_clock::now() + |
| 2002 | std::chrono::seconds(kStreamBufferTimeoutSec); |
| 2003 | ASSERT_NE(std::cv_status::timeout, mResultCondition.wait_until(l, timeout)); |
| 2004 | } |
| 2005 | |
Shuzhen Wang | 0f56c56 | 2023-04-03 16:58:59 -0700 | [diff] [blame] | 2006 | waitForReleaseFence(inflightReq->resultOutputBuffers); |
| 2007 | |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 2008 | ASSERT_FALSE(inflightReq->errorCodeValid); |
| 2009 | ASSERT_NE(inflightReq->resultOutputBuffers.size(), 0u); |
| 2010 | verify10BitMetadata(mHandleImporter, *inflightReq, profile); |
| 2011 | } |
Emilian Peev | dda1eb7 | 2022-07-28 16:37:40 -0700 | [diff] [blame] | 2012 | |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 2013 | if (useHalBufManager) { |
| 2014 | std::vector<int32_t> streamIds(halStreams.size()); |
| 2015 | for (size_t i = 0; i < streamIds.size(); i++) { |
| 2016 | streamIds[i] = halStreams[i].id; |
| 2017 | } |
| 2018 | mSession->signalStreamFlush(streamIds, /*streamConfigCounter*/ 0); |
| 2019 | cb->waitForBuffersReturned(); |
| 2020 | } |
| 2021 | |
| 2022 | ret = mSession->close(); |
| 2023 | mSession = nullptr; |
| 2024 | ASSERT_TRUE(ret.isOk()); |
| 2025 | } |
| 2026 | } |
| 2027 | } |
| 2028 | |
| 2029 | // Generate and verify a burst containing alternating sensor sensitivity values |
| 2030 | TEST_P(CameraAidlTest, processCaptureRequestBurstISO) { |
| 2031 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 2032 | AvailableStream previewThreshold = {kMaxPreviewWidth, kMaxPreviewHeight, |
| 2033 | static_cast<int32_t>(PixelFormat::IMPLEMENTATION_DEFINED)}; |
| 2034 | int64_t bufferId = 1; |
| 2035 | int32_t frameNumber = 1; |
| 2036 | float isoTol = .03f; |
| 2037 | CameraMetadata settings; |
| 2038 | |
| 2039 | for (const auto& name : cameraDeviceNames) { |
| 2040 | CameraMetadata meta; |
| 2041 | settings.metadata.clear(); |
| 2042 | std::shared_ptr<ICameraDevice> unusedDevice; |
| 2043 | openEmptyDeviceSession(name, mProvider, &mSession /*out*/, &meta /*out*/, |
| 2044 | &unusedDevice /*out*/); |
| 2045 | camera_metadata_t* staticMetaBuffer = |
| 2046 | clone_camera_metadata(reinterpret_cast<camera_metadata_t*>(meta.metadata.data())); |
| 2047 | ::android::hardware::camera::common::V1_0::helper::CameraMetadata staticMeta( |
| 2048 | staticMetaBuffer); |
| 2049 | |
| 2050 | camera_metadata_entry_t hwLevel = staticMeta.find(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL); |
| 2051 | ASSERT_TRUE(0 < hwLevel.count); |
| 2052 | if (ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED == hwLevel.data.u8[0] || |
| 2053 | ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL == hwLevel.data.u8[0]) { |
| 2054 | // Limited/External devices can skip this test |
| 2055 | ndk::ScopedAStatus ret = mSession->close(); |
| 2056 | mSession = nullptr; |
| 2057 | ASSERT_TRUE(ret.isOk()); |
| 2058 | continue; |
| 2059 | } |
| 2060 | |
| 2061 | camera_metadata_entry_t isoRange = staticMeta.find(ANDROID_SENSOR_INFO_SENSITIVITY_RANGE); |
| 2062 | ASSERT_EQ(isoRange.count, 2u); |
| 2063 | |
| 2064 | ndk::ScopedAStatus ret = mSession->close(); |
| 2065 | mSession = nullptr; |
| 2066 | ASSERT_TRUE(ret.isOk()); |
| 2067 | |
| 2068 | bool supportsPartialResults = false; |
| 2069 | bool useHalBufManager = false; |
| 2070 | int32_t partialResultCount = 0; |
| 2071 | Stream previewStream; |
| 2072 | std::vector<HalStream> halStreams; |
| 2073 | std::shared_ptr<DeviceCb> cb; |
| 2074 | configurePreviewStream(name, mProvider, &previewThreshold, &mSession /*out*/, |
| 2075 | &previewStream /*out*/, &halStreams /*out*/, |
| 2076 | &supportsPartialResults /*out*/, &partialResultCount /*out*/, |
| 2077 | &useHalBufManager /*out*/, &cb /*out*/); |
| 2078 | |
| 2079 | ::aidl::android::hardware::common::fmq::MQDescriptor< |
| 2080 | int8_t, aidl::android::hardware::common::fmq::SynchronizedReadWrite> |
| 2081 | descriptor; |
| 2082 | auto resultQueueRet = mSession->getCaptureResultMetadataQueue(&descriptor); |
| 2083 | std::shared_ptr<ResultMetadataQueue> resultQueue = |
| 2084 | std::make_shared<ResultMetadataQueue>(descriptor); |
| 2085 | ASSERT_TRUE(resultQueueRet.isOk()); |
| 2086 | if (!resultQueue->isValid() || resultQueue->availableToWrite() <= 0) { |
| 2087 | ALOGE("%s: HAL returns empty result metadata fmq, not use it", __func__); |
| 2088 | resultQueue = nullptr; |
| 2089 | // Don't use the queue onwards. |
| 2090 | } |
| 2091 | |
| 2092 | ret = mSession->constructDefaultRequestSettings(RequestTemplate::PREVIEW, &settings); |
| 2093 | ASSERT_TRUE(ret.isOk()); |
| 2094 | |
| 2095 | ::android::hardware::camera::common::V1_0::helper::CameraMetadata requestMeta; |
| 2096 | std::vector<CaptureRequest> requests(kBurstFrameCount); |
| 2097 | std::vector<buffer_handle_t> buffers(kBurstFrameCount); |
| 2098 | std::vector<std::shared_ptr<InFlightRequest>> inflightReqs(kBurstFrameCount); |
| 2099 | std::vector<int32_t> isoValues(kBurstFrameCount); |
| 2100 | std::vector<CameraMetadata> requestSettings(kBurstFrameCount); |
| 2101 | |
| 2102 | for (int32_t i = 0; i < kBurstFrameCount; i++) { |
| 2103 | std::unique_lock<std::mutex> l(mLock); |
| 2104 | CaptureRequest& request = requests[i]; |
| 2105 | std::vector<StreamBuffer>& outputBuffers = request.outputBuffers; |
| 2106 | outputBuffers.resize(1); |
| 2107 | StreamBuffer& outputBuffer = outputBuffers[0]; |
| 2108 | |
| 2109 | isoValues[i] = ((i % 2) == 0) ? isoRange.data.i32[0] : isoRange.data.i32[1]; |
| 2110 | if (useHalBufManager) { |
| 2111 | outputBuffer = {halStreams[0].id, 0, |
| 2112 | NativeHandle(), BufferStatus::OK, |
| 2113 | NativeHandle(), NativeHandle()}; |
| 2114 | } else { |
| 2115 | allocateGraphicBuffer(previewStream.width, previewStream.height, |
| 2116 | android_convertGralloc1To0Usage( |
| 2117 | static_cast<uint64_t>(halStreams[0].producerUsage), |
| 2118 | static_cast<uint64_t>(halStreams[0].consumerUsage)), |
| 2119 | halStreams[0].overrideFormat, &buffers[i]); |
| 2120 | outputBuffer = {halStreams[0].id, bufferId + i, ::android::makeToAidl(buffers[i]), |
| 2121 | BufferStatus::OK, NativeHandle(), NativeHandle()}; |
| 2122 | } |
| 2123 | |
| 2124 | requestMeta.append(reinterpret_cast<camera_metadata_t*>(settings.metadata.data())); |
| 2125 | |
| 2126 | // Disable all 3A routines |
| 2127 | uint8_t mode = static_cast<uint8_t>(ANDROID_CONTROL_MODE_OFF); |
| 2128 | ASSERT_EQ(::android::OK, requestMeta.update(ANDROID_CONTROL_MODE, &mode, 1)); |
| 2129 | ASSERT_EQ(::android::OK, |
| 2130 | requestMeta.update(ANDROID_SENSOR_SENSITIVITY, &isoValues[i], 1)); |
| 2131 | camera_metadata_t* metaBuffer = requestMeta.release(); |
| 2132 | uint8_t* rawMetaBuffer = reinterpret_cast<uint8_t*>(metaBuffer); |
| 2133 | requestSettings[i].metadata = std::vector( |
| 2134 | rawMetaBuffer, rawMetaBuffer + get_camera_metadata_size(metaBuffer)); |
| 2135 | overrideRotateAndCrop(&(requestSettings[i])); |
| 2136 | |
| 2137 | request.frameNumber = frameNumber + i; |
| 2138 | request.fmqSettingsSize = 0; |
| 2139 | request.settings = requestSettings[i]; |
| 2140 | request.inputBuffer = { |
| 2141 | -1, 0, NativeHandle(), BufferStatus::ERROR, NativeHandle(), NativeHandle()}; |
| 2142 | |
| 2143 | inflightReqs[i] = std::make_shared<InFlightRequest>(1, false, supportsPartialResults, |
| 2144 | partialResultCount, resultQueue); |
| 2145 | mInflightMap[frameNumber + i] = inflightReqs[i]; |
| 2146 | } |
| 2147 | |
| 2148 | int32_t numRequestProcessed = 0; |
| 2149 | std::vector<BufferCache> cachesToRemove; |
| 2150 | |
| 2151 | ndk::ScopedAStatus returnStatus = |
| 2152 | mSession->processCaptureRequest(requests, cachesToRemove, &numRequestProcessed); |
| 2153 | ASSERT_TRUE(returnStatus.isOk()); |
| 2154 | ASSERT_EQ(numRequestProcessed, kBurstFrameCount); |
| 2155 | |
| 2156 | for (size_t i = 0; i < kBurstFrameCount; i++) { |
| 2157 | std::unique_lock<std::mutex> l(mLock); |
| 2158 | while (!inflightReqs[i]->errorCodeValid && ((0 < inflightReqs[i]->numBuffersLeft) || |
| 2159 | (!inflightReqs[i]->haveResultMetadata))) { |
| 2160 | auto timeout = std::chrono::system_clock::now() + |
| 2161 | std::chrono::seconds(kStreamBufferTimeoutSec); |
| 2162 | ASSERT_NE(std::cv_status::timeout, mResultCondition.wait_until(l, timeout)); |
| 2163 | } |
| 2164 | |
| 2165 | ASSERT_FALSE(inflightReqs[i]->errorCodeValid); |
| 2166 | ASSERT_NE(inflightReqs[i]->resultOutputBuffers.size(), 0u); |
| 2167 | ASSERT_EQ(previewStream.id, inflightReqs[i]->resultOutputBuffers[0].buffer.streamId); |
| 2168 | ASSERT_FALSE(inflightReqs[i]->collectedResult.isEmpty()); |
| 2169 | ASSERT_TRUE(inflightReqs[i]->collectedResult.exists(ANDROID_SENSOR_SENSITIVITY)); |
| 2170 | camera_metadata_entry_t isoResult = |
| 2171 | inflightReqs[i]->collectedResult.find(ANDROID_SENSOR_SENSITIVITY); |
| 2172 | ASSERT_TRUE(std::abs(isoResult.data.i32[0] - isoValues[i]) <= |
| 2173 | std::round(isoValues[i] * isoTol)); |
| 2174 | } |
| 2175 | |
| 2176 | if (useHalBufManager) { |
| 2177 | verifyBuffersReturned(mSession, previewStream.id, cb); |
| 2178 | } |
| 2179 | ret = mSession->close(); |
| 2180 | mSession = nullptr; |
| 2181 | ASSERT_TRUE(ret.isOk()); |
| 2182 | } |
| 2183 | } |
| 2184 | |
| 2185 | // Test whether an incorrect capture request with missing settings will |
| 2186 | // be reported correctly. |
| 2187 | TEST_P(CameraAidlTest, processCaptureRequestInvalidSinglePreview) { |
| 2188 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 2189 | std::vector<AvailableStream> outputPreviewStreams; |
| 2190 | AvailableStream previewThreshold = {kMaxPreviewWidth, kMaxPreviewHeight, |
| 2191 | static_cast<int32_t>(PixelFormat::IMPLEMENTATION_DEFINED)}; |
| 2192 | int64_t bufferId = 1; |
| 2193 | int32_t frameNumber = 1; |
| 2194 | CameraMetadata settings; |
| 2195 | |
| 2196 | for (const auto& name : cameraDeviceNames) { |
| 2197 | Stream previewStream; |
| 2198 | std::vector<HalStream> halStreams; |
| 2199 | std::shared_ptr<DeviceCb> cb; |
| 2200 | bool supportsPartialResults = false; |
| 2201 | bool useHalBufManager = false; |
| 2202 | int32_t partialResultCount = 0; |
| 2203 | configurePreviewStream(name, mProvider, &previewThreshold, &mSession /*out*/, |
| 2204 | &previewStream /*out*/, &halStreams /*out*/, |
| 2205 | &supportsPartialResults /*out*/, &partialResultCount /*out*/, |
| 2206 | &useHalBufManager /*out*/, &cb /*out*/); |
| 2207 | ASSERT_NE(mSession, nullptr); |
| 2208 | ASSERT_FALSE(halStreams.empty()); |
| 2209 | |
| 2210 | buffer_handle_t buffer_handle = nullptr; |
| 2211 | |
| 2212 | if (useHalBufManager) { |
| 2213 | bufferId = 0; |
| 2214 | } else { |
| 2215 | allocateGraphicBuffer(previewStream.width, previewStream.height, |
| 2216 | android_convertGralloc1To0Usage( |
| 2217 | static_cast<uint64_t>(halStreams[0].producerUsage), |
| 2218 | static_cast<uint64_t>(halStreams[0].consumerUsage)), |
| 2219 | halStreams[0].overrideFormat, &buffer_handle); |
| 2220 | } |
| 2221 | |
| 2222 | std::vector<CaptureRequest> requests(1); |
| 2223 | CaptureRequest& request = requests[0]; |
| 2224 | std::vector<StreamBuffer>& outputBuffers = request.outputBuffers; |
| 2225 | outputBuffers.resize(1); |
| 2226 | StreamBuffer& outputBuffer = outputBuffers[0]; |
| 2227 | |
| 2228 | outputBuffer = { |
| 2229 | halStreams[0].id, |
| 2230 | bufferId, |
| 2231 | buffer_handle == nullptr ? NativeHandle() : ::android::makeToAidl(buffer_handle), |
| 2232 | BufferStatus::OK, |
| 2233 | NativeHandle(), |
| 2234 | NativeHandle()}; |
| 2235 | |
| 2236 | request.inputBuffer = { |
| 2237 | -1, 0, NativeHandle(), BufferStatus::ERROR, NativeHandle(), NativeHandle()}; |
| 2238 | request.frameNumber = frameNumber; |
| 2239 | request.fmqSettingsSize = 0; |
| 2240 | request.settings = settings; |
| 2241 | |
| 2242 | // Settings were not correctly initialized, we should fail here |
| 2243 | int32_t numRequestProcessed = 0; |
| 2244 | std::vector<BufferCache> cachesToRemove; |
| 2245 | ndk::ScopedAStatus ret = |
| 2246 | mSession->processCaptureRequest(requests, cachesToRemove, &numRequestProcessed); |
| 2247 | ASSERT_EQ(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT), ret.getServiceSpecificError()); |
| 2248 | ASSERT_EQ(numRequestProcessed, 0u); |
| 2249 | |
| 2250 | ret = mSession->close(); |
| 2251 | mSession = nullptr; |
| 2252 | ASSERT_TRUE(ret.isOk()); |
| 2253 | } |
| 2254 | } |
| 2255 | |
| 2256 | // Verify camera offline session behavior |
| 2257 | TEST_P(CameraAidlTest, switchToOffline) { |
| 2258 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 2259 | AvailableStream threshold = {kMaxStillWidth, kMaxStillHeight, |
| 2260 | static_cast<int32_t>(PixelFormat::BLOB)}; |
| 2261 | int64_t bufferId = 1; |
| 2262 | int32_t frameNumber = 1; |
| 2263 | CameraMetadata settings; |
| 2264 | |
| 2265 | for (const auto& name : cameraDeviceNames) { |
| 2266 | CameraMetadata meta; |
| 2267 | { |
| 2268 | std::shared_ptr<ICameraDevice> unusedDevice; |
| 2269 | openEmptyDeviceSession(name, mProvider, &mSession /*out*/, &meta /*out*/, |
| 2270 | &unusedDevice); |
| 2271 | camera_metadata_t* staticMetaBuffer = clone_camera_metadata( |
| 2272 | reinterpret_cast<camera_metadata_t*>(meta.metadata.data())); |
| 2273 | ::android::hardware::camera::common::V1_0::helper::CameraMetadata staticMeta( |
| 2274 | staticMetaBuffer); |
| 2275 | |
| 2276 | if (isOfflineSessionSupported(staticMetaBuffer) != Status::OK) { |
| 2277 | ndk::ScopedAStatus ret = mSession->close(); |
| 2278 | mSession = nullptr; |
| 2279 | ASSERT_TRUE(ret.isOk()); |
| 2280 | continue; |
| 2281 | } |
| 2282 | ndk::ScopedAStatus ret = mSession->close(); |
| 2283 | mSession = nullptr; |
| 2284 | ASSERT_TRUE(ret.isOk()); |
| 2285 | } |
| 2286 | |
| 2287 | bool supportsPartialResults = false; |
| 2288 | int32_t partialResultCount = 0; |
| 2289 | Stream stream; |
| 2290 | std::vector<HalStream> halStreams; |
| 2291 | std::shared_ptr<DeviceCb> cb; |
| 2292 | int32_t jpegBufferSize; |
| 2293 | bool useHalBufManager; |
| 2294 | configureOfflineStillStream(name, mProvider, &threshold, &mSession /*out*/, &stream /*out*/, |
| 2295 | &halStreams /*out*/, &supportsPartialResults /*out*/, |
| 2296 | &partialResultCount /*out*/, &cb /*out*/, |
| 2297 | &jpegBufferSize /*out*/, &useHalBufManager /*out*/); |
| 2298 | |
| 2299 | auto ret = mSession->constructDefaultRequestSettings(RequestTemplate::STILL_CAPTURE, |
| 2300 | &settings); |
| 2301 | ASSERT_TRUE(ret.isOk()); |
| 2302 | |
| 2303 | ::aidl::android::hardware::common::fmq::MQDescriptor< |
| 2304 | int8_t, aidl::android::hardware::common::fmq::SynchronizedReadWrite> |
| 2305 | descriptor; |
| 2306 | |
| 2307 | ndk::ScopedAStatus resultQueueRet = mSession->getCaptureResultMetadataQueue(&descriptor); |
| 2308 | ASSERT_TRUE(resultQueueRet.isOk()); |
| 2309 | std::shared_ptr<ResultMetadataQueue> resultQueue = |
| 2310 | std::make_shared<ResultMetadataQueue>(descriptor); |
| 2311 | if (!resultQueue->isValid() || resultQueue->availableToWrite() <= 0) { |
| 2312 | ALOGE("%s: HAL returns empty result metadata fmq, not use it", __func__); |
| 2313 | resultQueue = nullptr; |
| 2314 | // Don't use the queue onwards. |
| 2315 | } |
| 2316 | |
| 2317 | ::android::hardware::camera::common::V1_0::helper::CameraMetadata requestMeta; |
| 2318 | |
| 2319 | std::vector<buffer_handle_t> buffers(kBurstFrameCount); |
| 2320 | std::vector<std::shared_ptr<InFlightRequest>> inflightReqs(kBurstFrameCount); |
| 2321 | std::vector<CameraMetadata> requestSettings(kBurstFrameCount); |
| 2322 | |
| 2323 | std::vector<CaptureRequest> requests(kBurstFrameCount); |
| 2324 | |
| 2325 | HalStream halStream = halStreams[0]; |
| 2326 | for (uint32_t i = 0; i < kBurstFrameCount; i++) { |
| 2327 | CaptureRequest& request = requests[i]; |
| 2328 | std::vector<StreamBuffer>& outputBuffers = request.outputBuffers; |
| 2329 | outputBuffers.resize(1); |
| 2330 | StreamBuffer& outputBuffer = outputBuffers[0]; |
| 2331 | |
| 2332 | std::unique_lock<std::mutex> l(mLock); |
| 2333 | if (useHalBufManager) { |
| 2334 | outputBuffer = {halStream.id, 0, NativeHandle(), BufferStatus::OK, NativeHandle(), |
| 2335 | NativeHandle()}; |
| 2336 | } else { |
| 2337 | // jpeg buffer (w,h) = (blobLen, 1) |
| 2338 | allocateGraphicBuffer(jpegBufferSize, /*height*/ 1, |
| 2339 | android_convertGralloc1To0Usage( |
| 2340 | static_cast<uint64_t>(halStream.producerUsage), |
| 2341 | static_cast<uint64_t>(halStream.consumerUsage)), |
| 2342 | halStream.overrideFormat, &buffers[i]); |
| 2343 | outputBuffer = {halStream.id, bufferId + i, ::android::makeToAidl(buffers[i]), |
| 2344 | BufferStatus::OK, NativeHandle(), NativeHandle()}; |
| 2345 | } |
| 2346 | |
| 2347 | requestMeta.clear(); |
| 2348 | requestMeta.append(reinterpret_cast<camera_metadata_t*>(settings.metadata.data())); |
| 2349 | |
| 2350 | camera_metadata_t* metaBuffer = requestMeta.release(); |
| 2351 | uint8_t* rawMetaBuffer = reinterpret_cast<uint8_t*>(metaBuffer); |
| 2352 | requestSettings[i].metadata = std::vector( |
| 2353 | rawMetaBuffer, rawMetaBuffer + get_camera_metadata_size(metaBuffer)); |
| 2354 | overrideRotateAndCrop(&requestSettings[i]); |
| 2355 | |
| 2356 | request.frameNumber = frameNumber + i; |
| 2357 | request.fmqSettingsSize = 0; |
| 2358 | request.settings = requestSettings[i]; |
| 2359 | request.inputBuffer = {/*streamId*/ -1, |
| 2360 | /*bufferId*/ 0, NativeHandle(), |
| 2361 | BufferStatus::ERROR, NativeHandle(), |
| 2362 | NativeHandle()}; |
| 2363 | |
| 2364 | inflightReqs[i] = std::make_shared<InFlightRequest>(1, false, supportsPartialResults, |
| 2365 | partialResultCount, resultQueue); |
| 2366 | mInflightMap[frameNumber + i] = inflightReqs[i]; |
| 2367 | } |
| 2368 | |
| 2369 | int32_t numRequestProcessed = 0; |
| 2370 | std::vector<BufferCache> cachesToRemove; |
| 2371 | |
| 2372 | ndk::ScopedAStatus returnStatus = |
| 2373 | mSession->processCaptureRequest(requests, cachesToRemove, &numRequestProcessed); |
| 2374 | ASSERT_TRUE(returnStatus.isOk()); |
| 2375 | ASSERT_EQ(numRequestProcessed, kBurstFrameCount); |
| 2376 | |
| 2377 | std::vector<int32_t> offlineStreamIds = {halStream.id}; |
| 2378 | CameraOfflineSessionInfo offlineSessionInfo; |
| 2379 | std::shared_ptr<ICameraOfflineSession> offlineSession; |
| 2380 | returnStatus = |
| 2381 | mSession->switchToOffline(offlineStreamIds, &offlineSessionInfo, &offlineSession); |
| 2382 | |
| 2383 | if (!halStreams[0].supportOffline) { |
| 2384 | ASSERT_EQ(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT), |
| 2385 | returnStatus.getServiceSpecificError()); |
| 2386 | ret = mSession->close(); |
| 2387 | mSession = nullptr; |
| 2388 | ASSERT_TRUE(ret.isOk()); |
| 2389 | continue; |
| 2390 | } |
| 2391 | |
| 2392 | ASSERT_TRUE(returnStatus.isOk()); |
| 2393 | // Hal might be unable to find any requests qualified for offline mode. |
| 2394 | if (offlineSession == nullptr) { |
| 2395 | ret = mSession->close(); |
| 2396 | mSession = nullptr; |
| 2397 | ASSERT_TRUE(ret.isOk()); |
| 2398 | continue; |
| 2399 | } |
| 2400 | |
| 2401 | ASSERT_EQ(offlineSessionInfo.offlineStreams.size(), 1u); |
| 2402 | ASSERT_EQ(offlineSessionInfo.offlineStreams[0].id, halStream.id); |
| 2403 | ASSERT_NE(offlineSessionInfo.offlineRequests.size(), 0u); |
| 2404 | |
| 2405 | // close device session to make sure offline session does not rely on it |
| 2406 | ret = mSession->close(); |
| 2407 | mSession = nullptr; |
| 2408 | ASSERT_TRUE(ret.isOk()); |
| 2409 | |
| 2410 | ::aidl::android::hardware::common::fmq::MQDescriptor< |
| 2411 | int8_t, aidl::android::hardware::common::fmq::SynchronizedReadWrite> |
| 2412 | offlineResultDescriptor; |
| 2413 | |
| 2414 | auto offlineResultQueueRet = |
| 2415 | offlineSession->getCaptureResultMetadataQueue(&offlineResultDescriptor); |
| 2416 | std::shared_ptr<ResultMetadataQueue> offlineResultQueue = |
| 2417 | std::make_shared<ResultMetadataQueue>(descriptor); |
| 2418 | if (!offlineResultQueue->isValid() || offlineResultQueue->availableToWrite() <= 0) { |
| 2419 | ALOGE("%s: offline session returns empty result metadata fmq, not use it", __func__); |
| 2420 | offlineResultQueue = nullptr; |
| 2421 | // Don't use the queue onwards. |
| 2422 | } |
| 2423 | ASSERT_TRUE(offlineResultQueueRet.isOk()); |
| 2424 | |
| 2425 | updateInflightResultQueue(offlineResultQueue); |
| 2426 | |
| 2427 | ret = offlineSession->setCallback(cb); |
| 2428 | ASSERT_TRUE(ret.isOk()); |
| 2429 | |
| 2430 | for (size_t i = 0; i < kBurstFrameCount; i++) { |
| 2431 | std::unique_lock<std::mutex> l(mLock); |
| 2432 | while (!inflightReqs[i]->errorCodeValid && ((0 < inflightReqs[i]->numBuffersLeft) || |
| 2433 | (!inflightReqs[i]->haveResultMetadata))) { |
| 2434 | auto timeout = std::chrono::system_clock::now() + |
| 2435 | std::chrono::seconds(kStreamBufferTimeoutSec); |
| 2436 | ASSERT_NE(std::cv_status::timeout, mResultCondition.wait_until(l, timeout)); |
| 2437 | } |
| 2438 | |
| 2439 | ASSERT_FALSE(inflightReqs[i]->errorCodeValid); |
| 2440 | ASSERT_NE(inflightReqs[i]->resultOutputBuffers.size(), 0u); |
| 2441 | ASSERT_EQ(stream.id, inflightReqs[i]->resultOutputBuffers[0].buffer.streamId); |
| 2442 | ASSERT_FALSE(inflightReqs[i]->collectedResult.isEmpty()); |
| 2443 | } |
| 2444 | |
| 2445 | ret = offlineSession->close(); |
| 2446 | ASSERT_TRUE(ret.isOk()); |
| 2447 | } |
| 2448 | } |
| 2449 | |
| 2450 | // Check whether an invalid capture request with missing output buffers |
| 2451 | // will be reported correctly. |
| 2452 | TEST_P(CameraAidlTest, processCaptureRequestInvalidBuffer) { |
| 2453 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 2454 | std::vector<AvailableStream> outputBlobStreams; |
| 2455 | AvailableStream previewThreshold = {kMaxPreviewWidth, kMaxPreviewHeight, |
| 2456 | static_cast<int32_t>(PixelFormat::IMPLEMENTATION_DEFINED)}; |
| 2457 | int32_t frameNumber = 1; |
| 2458 | CameraMetadata settings; |
| 2459 | |
| 2460 | for (const auto& name : cameraDeviceNames) { |
| 2461 | Stream previewStream; |
| 2462 | std::vector<HalStream> halStreams; |
| 2463 | std::shared_ptr<DeviceCb> cb; |
| 2464 | bool supportsPartialResults = false; |
| 2465 | bool useHalBufManager = false; |
| 2466 | int32_t partialResultCount = 0; |
| 2467 | configurePreviewStream(name, mProvider, &previewThreshold, &mSession /*out*/, |
| 2468 | &previewStream /*out*/, &halStreams /*out*/, |
| 2469 | &supportsPartialResults /*out*/, &partialResultCount /*out*/, |
| 2470 | &useHalBufManager /*out*/, &cb /*out*/); |
| 2471 | |
| 2472 | RequestTemplate reqTemplate = RequestTemplate::PREVIEW; |
| 2473 | ndk::ScopedAStatus ret = mSession->constructDefaultRequestSettings(reqTemplate, &settings); |
| 2474 | ASSERT_TRUE(ret.isOk()); |
| 2475 | overrideRotateAndCrop(&settings); |
| 2476 | |
| 2477 | std::vector<CaptureRequest> requests(1); |
| 2478 | CaptureRequest& request = requests[0]; |
| 2479 | std::vector<StreamBuffer>& outputBuffers = request.outputBuffers; |
| 2480 | outputBuffers.resize(1); |
| 2481 | // Empty output buffer |
| 2482 | outputBuffers[0] = { |
| 2483 | -1, 0, NativeHandle(), BufferStatus::ERROR, NativeHandle(), NativeHandle()}; |
| 2484 | |
| 2485 | request.inputBuffer = { |
| 2486 | -1, 0, NativeHandle(), BufferStatus::ERROR, NativeHandle(), NativeHandle()}; |
| 2487 | request.frameNumber = frameNumber; |
| 2488 | request.fmqSettingsSize = 0; |
| 2489 | request.settings = settings; |
| 2490 | |
| 2491 | // Output buffers are missing, we should fail here |
| 2492 | int32_t numRequestProcessed = 0; |
| 2493 | std::vector<BufferCache> cachesToRemove; |
| 2494 | ret = mSession->processCaptureRequest(requests, cachesToRemove, &numRequestProcessed); |
| 2495 | ASSERT_EQ(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT), ret.getServiceSpecificError()); |
| 2496 | ASSERT_EQ(numRequestProcessed, 0u); |
| 2497 | |
| 2498 | ret = mSession->close(); |
| 2499 | mSession = nullptr; |
| 2500 | ASSERT_TRUE(ret.isOk()); |
| 2501 | } |
| 2502 | } |
| 2503 | |
| 2504 | // Generate, trigger and flush a preview request |
| 2505 | TEST_P(CameraAidlTest, flushPreviewRequest) { |
| 2506 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 2507 | std::vector<AvailableStream> outputPreviewStreams; |
| 2508 | AvailableStream previewThreshold = {kMaxPreviewWidth, kMaxPreviewHeight, |
| 2509 | static_cast<int32_t>(PixelFormat::IMPLEMENTATION_DEFINED)}; |
| 2510 | int64_t bufferId = 1; |
| 2511 | int32_t frameNumber = 1; |
| 2512 | CameraMetadata settings; |
| 2513 | |
| 2514 | for (const auto& name : cameraDeviceNames) { |
| 2515 | Stream previewStream; |
| 2516 | std::vector<HalStream> halStreams; |
| 2517 | std::shared_ptr<DeviceCb> cb; |
| 2518 | bool supportsPartialResults = false; |
| 2519 | bool useHalBufManager = false; |
| 2520 | int32_t partialResultCount = 0; |
| 2521 | |
| 2522 | configurePreviewStream(name, mProvider, &previewThreshold, &mSession /*out*/, |
| 2523 | &previewStream /*out*/, &halStreams /*out*/, |
| 2524 | &supportsPartialResults /*out*/, &partialResultCount /*out*/, |
| 2525 | &useHalBufManager /*out*/, &cb /*out*/); |
| 2526 | |
| 2527 | ASSERT_NE(mSession, nullptr); |
| 2528 | ASSERT_NE(cb, nullptr); |
| 2529 | ASSERT_FALSE(halStreams.empty()); |
| 2530 | |
| 2531 | ::aidl::android::hardware::common::fmq::MQDescriptor< |
| 2532 | int8_t, aidl::android::hardware::common::fmq::SynchronizedReadWrite> |
| 2533 | descriptor; |
| 2534 | |
| 2535 | auto resultQueueRet = mSession->getCaptureResultMetadataQueue(&descriptor); |
| 2536 | std::shared_ptr<ResultMetadataQueue> resultQueue = |
| 2537 | std::make_shared<ResultMetadataQueue>(descriptor); |
| 2538 | ASSERT_TRUE(resultQueueRet.isOk()); |
| 2539 | if (!resultQueue->isValid() || resultQueue->availableToWrite() <= 0) { |
| 2540 | ALOGE("%s: HAL returns empty result metadata fmq, not use it", __func__); |
| 2541 | resultQueue = nullptr; |
| 2542 | // Don't use the queue onwards. |
| 2543 | } |
| 2544 | |
| 2545 | std::shared_ptr<InFlightRequest> inflightReq = std::make_shared<InFlightRequest>( |
| 2546 | 1, false, supportsPartialResults, partialResultCount, resultQueue); |
| 2547 | RequestTemplate reqTemplate = RequestTemplate::PREVIEW; |
| 2548 | |
| 2549 | ndk::ScopedAStatus ret = mSession->constructDefaultRequestSettings(reqTemplate, &settings); |
| 2550 | ASSERT_TRUE(ret.isOk()); |
| 2551 | overrideRotateAndCrop(&settings); |
| 2552 | |
| 2553 | buffer_handle_t buffer_handle; |
| 2554 | std::vector<CaptureRequest> requests(1); |
| 2555 | CaptureRequest& request = requests[0]; |
| 2556 | std::vector<StreamBuffer>& outputBuffers = request.outputBuffers; |
| 2557 | outputBuffers.resize(1); |
| 2558 | StreamBuffer& outputBuffer = outputBuffers[0]; |
| 2559 | if (useHalBufManager) { |
| 2560 | bufferId = 0; |
| 2561 | outputBuffer = {halStreams[0].id, bufferId, NativeHandle(), |
| 2562 | BufferStatus::OK, NativeHandle(), NativeHandle()}; |
| 2563 | } else { |
| 2564 | allocateGraphicBuffer(previewStream.width, previewStream.height, |
| 2565 | android_convertGralloc1To0Usage( |
| 2566 | static_cast<uint64_t>(halStreams[0].producerUsage), |
| 2567 | static_cast<uint64_t>(halStreams[0].consumerUsage)), |
| 2568 | halStreams[0].overrideFormat, &buffer_handle); |
| 2569 | outputBuffer = {halStreams[0].id, bufferId, ::android::makeToAidl(buffer_handle), |
| 2570 | BufferStatus::OK, NativeHandle(), NativeHandle()}; |
| 2571 | } |
| 2572 | |
| 2573 | request.frameNumber = frameNumber; |
| 2574 | request.fmqSettingsSize = 0; |
| 2575 | request.settings = settings; |
| 2576 | request.inputBuffer = { |
| 2577 | -1, 0, NativeHandle(), BufferStatus::ERROR, NativeHandle(), NativeHandle()}; |
| 2578 | |
| 2579 | { |
| 2580 | std::unique_lock<std::mutex> l(mLock); |
| 2581 | mInflightMap.clear(); |
| 2582 | mInflightMap[frameNumber] = inflightReq; |
| 2583 | } |
| 2584 | |
| 2585 | int32_t numRequestProcessed = 0; |
| 2586 | std::vector<BufferCache> cachesToRemove; |
| 2587 | ret = mSession->processCaptureRequest(requests, cachesToRemove, &numRequestProcessed); |
| 2588 | ASSERT_TRUE(ret.isOk()); |
| 2589 | ASSERT_EQ(numRequestProcessed, 1u); |
| 2590 | |
| 2591 | // Flush before waiting for request to complete. |
| 2592 | ndk::ScopedAStatus returnStatus = mSession->flush(); |
| 2593 | ASSERT_TRUE(returnStatus.isOk()); |
| 2594 | |
| 2595 | { |
| 2596 | std::unique_lock<std::mutex> l(mLock); |
| 2597 | while (!inflightReq->errorCodeValid && |
| 2598 | ((0 < inflightReq->numBuffersLeft) || (!inflightReq->haveResultMetadata))) { |
| 2599 | auto timeout = std::chrono::system_clock::now() + |
| 2600 | std::chrono::seconds(kStreamBufferTimeoutSec); |
| 2601 | ASSERT_NE(std::cv_status::timeout, mResultCondition.wait_until(l, timeout)); |
| 2602 | } |
| 2603 | |
| 2604 | if (!inflightReq->errorCodeValid) { |
| 2605 | ASSERT_NE(inflightReq->resultOutputBuffers.size(), 0u); |
| 2606 | ASSERT_EQ(previewStream.id, inflightReq->resultOutputBuffers[0].buffer.streamId); |
| 2607 | } else { |
| 2608 | switch (inflightReq->errorCode) { |
| 2609 | case ErrorCode::ERROR_REQUEST: |
| 2610 | case ErrorCode::ERROR_RESULT: |
| 2611 | case ErrorCode::ERROR_BUFFER: |
| 2612 | // Expected |
| 2613 | break; |
| 2614 | case ErrorCode::ERROR_DEVICE: |
| 2615 | default: |
| 2616 | FAIL() << "Unexpected error:" |
| 2617 | << static_cast<uint32_t>(inflightReq->errorCode); |
| 2618 | } |
| 2619 | } |
| 2620 | } |
| 2621 | |
| 2622 | if (useHalBufManager) { |
| 2623 | verifyBuffersReturned(mSession, previewStream.id, cb); |
| 2624 | } |
| 2625 | |
| 2626 | ret = mSession->close(); |
| 2627 | mSession = nullptr; |
| 2628 | ASSERT_TRUE(ret.isOk()); |
| 2629 | } |
| 2630 | } |
| 2631 | |
| 2632 | // Verify that camera flushes correctly without any pending requests. |
| 2633 | TEST_P(CameraAidlTest, flushEmpty) { |
| 2634 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 2635 | std::vector<AvailableStream> outputPreviewStreams; |
| 2636 | AvailableStream previewThreshold = {kMaxPreviewWidth, kMaxPreviewHeight, |
| 2637 | static_cast<int32_t>(PixelFormat::IMPLEMENTATION_DEFINED)}; |
| 2638 | |
| 2639 | for (const auto& name : cameraDeviceNames) { |
| 2640 | Stream previewStream; |
| 2641 | std::vector<HalStream> halStreams; |
| 2642 | std::shared_ptr<DeviceCb> cb; |
| 2643 | bool supportsPartialResults = false; |
| 2644 | bool useHalBufManager = false; |
| 2645 | |
| 2646 | int32_t partialResultCount = 0; |
| 2647 | configurePreviewStream(name, mProvider, &previewThreshold, &mSession /*out*/, |
| 2648 | &previewStream /*out*/, &halStreams /*out*/, |
| 2649 | &supportsPartialResults /*out*/, &partialResultCount /*out*/, |
| 2650 | &useHalBufManager /*out*/, &cb /*out*/); |
| 2651 | |
| 2652 | ndk::ScopedAStatus returnStatus = mSession->flush(); |
| 2653 | ASSERT_TRUE(returnStatus.isOk()); |
| 2654 | |
| 2655 | { |
| 2656 | std::unique_lock<std::mutex> l(mLock); |
| 2657 | auto timeout = std::chrono::system_clock::now() + |
| 2658 | std::chrono::milliseconds(kEmptyFlushTimeoutMSec); |
| 2659 | ASSERT_EQ(std::cv_status::timeout, mResultCondition.wait_until(l, timeout)); |
| 2660 | } |
| 2661 | |
| 2662 | ndk::ScopedAStatus ret = mSession->close(); |
| 2663 | mSession = nullptr; |
| 2664 | ASSERT_TRUE(ret.isOk()); |
| 2665 | } |
| 2666 | } |
| 2667 | |
| 2668 | // Test camera provider notify method |
| 2669 | TEST_P(CameraAidlTest, providerDeviceStateNotification) { |
| 2670 | notifyDeviceState(ICameraProvider::DEVICE_STATE_BACK_COVERED); |
| 2671 | notifyDeviceState(ICameraProvider::DEVICE_STATE_NORMAL); |
| 2672 | } |
| 2673 | |
| 2674 | // Verify that all supported stream formats and sizes can be configured |
| 2675 | // successfully for injection camera. |
| 2676 | TEST_P(CameraAidlTest, configureInjectionStreamsAvailableOutputs) { |
| 2677 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 2678 | std::vector<AvailableStream> outputStreams; |
| 2679 | |
| 2680 | for (const auto& name : cameraDeviceNames) { |
| 2681 | CameraMetadata metadata; |
| 2682 | |
| 2683 | std::shared_ptr<ICameraInjectionSession> injectionSession; |
| 2684 | std::shared_ptr<ICameraDevice> unusedDevice; |
| 2685 | openEmptyInjectionSession(name, mProvider, &injectionSession /*out*/, &metadata /*out*/, |
| 2686 | &unusedDevice /*out*/); |
| 2687 | if (injectionSession == nullptr) { |
| 2688 | continue; |
| 2689 | } |
| 2690 | |
| 2691 | camera_metadata_t* staticMetaBuffer = |
| 2692 | reinterpret_cast<camera_metadata_t*>(metadata.metadata.data()); |
| 2693 | CameraMetadata chars; |
| 2694 | chars.metadata = metadata.metadata; |
| 2695 | |
| 2696 | outputStreams.clear(); |
| 2697 | ASSERT_EQ(Status::OK, getAvailableOutputStreams(staticMetaBuffer, outputStreams)); |
| 2698 | ASSERT_NE(0u, outputStreams.size()); |
| 2699 | |
| 2700 | int32_t jpegBufferSize = 0; |
| 2701 | ASSERT_EQ(Status::OK, getJpegBufferSize(staticMetaBuffer, &jpegBufferSize)); |
| 2702 | ASSERT_NE(0u, jpegBufferSize); |
| 2703 | |
| 2704 | int32_t streamId = 0; |
| 2705 | int32_t streamConfigCounter = 0; |
| 2706 | for (auto& it : outputStreams) { |
| 2707 | Dataspace dataspace = getDataspace(static_cast<PixelFormat>(it.format)); |
| 2708 | Stream stream = {streamId, |
| 2709 | StreamType::OUTPUT, |
| 2710 | it.width, |
| 2711 | it.height, |
| 2712 | static_cast<PixelFormat>(it.format), |
| 2713 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 2714 | GRALLOC1_CONSUMER_USAGE_HWCOMPOSER), |
| 2715 | dataspace, |
| 2716 | StreamRotation::ROTATION_0, |
| 2717 | std::string(), |
| 2718 | jpegBufferSize, |
| 2719 | 0, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 2720 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 2721 | RequestAvailableDynamicRangeProfilesMap:: |
| 2722 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 2723 | |
| 2724 | std::vector<Stream> streams = {stream}; |
| 2725 | StreamConfiguration config; |
| 2726 | createStreamConfiguration(streams, StreamConfigurationMode::NORMAL_MODE, &config, |
| 2727 | jpegBufferSize); |
| 2728 | |
| 2729 | config.streamConfigCounter = streamConfigCounter++; |
| 2730 | ndk::ScopedAStatus s = injectionSession->configureInjectionStreams(config, chars); |
| 2731 | ASSERT_TRUE(s.isOk()); |
| 2732 | streamId++; |
| 2733 | } |
| 2734 | |
| 2735 | std::shared_ptr<ICameraDeviceSession> session; |
| 2736 | ndk::ScopedAStatus ret = injectionSession->getCameraDeviceSession(&session); |
| 2737 | ASSERT_TRUE(ret.isOk()); |
| 2738 | ASSERT_NE(session, nullptr); |
| 2739 | ret = session->close(); |
| 2740 | ASSERT_TRUE(ret.isOk()); |
| 2741 | } |
| 2742 | } |
| 2743 | |
| 2744 | // Check for correct handling of invalid/incorrect configuration parameters for injection camera. |
| 2745 | TEST_P(CameraAidlTest, configureInjectionStreamsInvalidOutputs) { |
| 2746 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 2747 | std::vector<AvailableStream> outputStreams; |
| 2748 | |
| 2749 | for (const auto& name : cameraDeviceNames) { |
| 2750 | CameraMetadata metadata; |
| 2751 | std::shared_ptr<ICameraInjectionSession> injectionSession; |
| 2752 | std::shared_ptr<ICameraDevice> unusedDevice; |
| 2753 | openEmptyInjectionSession(name, mProvider, &injectionSession /*out*/, &metadata /*out*/, |
| 2754 | &unusedDevice); |
| 2755 | if (injectionSession == nullptr) { |
| 2756 | continue; |
| 2757 | } |
| 2758 | |
| 2759 | camera_metadata_t* staticMetaBuffer = |
| 2760 | reinterpret_cast<camera_metadata_t*>(metadata.metadata.data()); |
| 2761 | std::shared_ptr<ICameraDeviceSession> session; |
| 2762 | ndk::ScopedAStatus ret = injectionSession->getCameraDeviceSession(&session); |
| 2763 | ASSERT_TRUE(ret.isOk()); |
| 2764 | ASSERT_NE(session, nullptr); |
| 2765 | |
| 2766 | CameraMetadata chars; |
| 2767 | chars.metadata = metadata.metadata; |
| 2768 | |
| 2769 | outputStreams.clear(); |
| 2770 | ASSERT_EQ(Status::OK, getAvailableOutputStreams(staticMetaBuffer, outputStreams)); |
| 2771 | ASSERT_NE(0u, outputStreams.size()); |
| 2772 | |
| 2773 | int32_t jpegBufferSize = 0; |
| 2774 | ASSERT_EQ(Status::OK, getJpegBufferSize(staticMetaBuffer, &jpegBufferSize)); |
| 2775 | ASSERT_NE(0u, jpegBufferSize); |
| 2776 | |
| 2777 | int32_t streamId = 0; |
| 2778 | Stream stream = {streamId++, |
| 2779 | StreamType::OUTPUT, |
| 2780 | 0, |
| 2781 | 0, |
| 2782 | static_cast<PixelFormat>(outputStreams[0].format), |
| 2783 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 2784 | GRALLOC1_CONSUMER_USAGE_HWCOMPOSER), |
| 2785 | Dataspace::UNKNOWN, |
| 2786 | StreamRotation::ROTATION_0, |
| 2787 | std::string(), |
| 2788 | jpegBufferSize, |
| 2789 | 0, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 2790 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 2791 | RequestAvailableDynamicRangeProfilesMap:: |
| 2792 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 2793 | |
| 2794 | int32_t streamConfigCounter = 0; |
| 2795 | std::vector<Stream> streams = {stream}; |
| 2796 | StreamConfiguration config; |
| 2797 | createStreamConfiguration(streams, StreamConfigurationMode::NORMAL_MODE, &config, |
| 2798 | jpegBufferSize); |
| 2799 | |
| 2800 | config.streamConfigCounter = streamConfigCounter++; |
| 2801 | ndk::ScopedAStatus s = injectionSession->configureInjectionStreams(config, chars); |
| 2802 | ASSERT_TRUE( |
| 2803 | (static_cast<int32_t>(Status::ILLEGAL_ARGUMENT) == s.getServiceSpecificError()) || |
| 2804 | (static_cast<int32_t>(Status::INTERNAL_ERROR) == s.getServiceSpecificError())); |
| 2805 | |
| 2806 | stream = {streamId++, |
| 2807 | StreamType::OUTPUT, |
| 2808 | INT32_MAX, |
| 2809 | INT32_MAX, |
| 2810 | static_cast<PixelFormat>(outputStreams[0].format), |
| 2811 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 2812 | GRALLOC1_CONSUMER_USAGE_HWCOMPOSER), |
| 2813 | Dataspace::UNKNOWN, |
| 2814 | StreamRotation::ROTATION_0, |
| 2815 | std::string(), |
| 2816 | jpegBufferSize, |
| 2817 | 0, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 2818 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 2819 | RequestAvailableDynamicRangeProfilesMap:: |
| 2820 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
| 2821 | |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 2822 | streams[0] = stream; |
| 2823 | createStreamConfiguration(streams, StreamConfigurationMode::NORMAL_MODE, &config, |
| 2824 | jpegBufferSize); |
| 2825 | config.streamConfigCounter = streamConfigCounter++; |
| 2826 | s = injectionSession->configureInjectionStreams(config, chars); |
| 2827 | ASSERT_EQ(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT), s.getServiceSpecificError()); |
| 2828 | |
| 2829 | for (auto& it : outputStreams) { |
| 2830 | stream = {streamId++, |
| 2831 | StreamType::OUTPUT, |
| 2832 | it.width, |
| 2833 | it.height, |
| 2834 | static_cast<PixelFormat>(INT32_MAX), |
| 2835 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 2836 | GRALLOC1_CONSUMER_USAGE_HWCOMPOSER), |
| 2837 | Dataspace::UNKNOWN, |
| 2838 | StreamRotation::ROTATION_0, |
| 2839 | std::string(), |
| 2840 | jpegBufferSize, |
| 2841 | 0, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 2842 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 2843 | RequestAvailableDynamicRangeProfilesMap:: |
| 2844 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 2845 | streams[0] = stream; |
| 2846 | createStreamConfiguration(streams, StreamConfigurationMode::NORMAL_MODE, &config, |
| 2847 | jpegBufferSize); |
| 2848 | config.streamConfigCounter = streamConfigCounter++; |
| 2849 | s = injectionSession->configureInjectionStreams(config, chars); |
| 2850 | ASSERT_EQ(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT), s.getServiceSpecificError()); |
| 2851 | |
| 2852 | stream = {streamId++, |
| 2853 | StreamType::OUTPUT, |
| 2854 | it.width, |
| 2855 | it.height, |
| 2856 | static_cast<PixelFormat>(it.format), |
| 2857 | static_cast<aidl::android::hardware::graphics::common::BufferUsage>( |
| 2858 | GRALLOC1_CONSUMER_USAGE_HWCOMPOSER), |
| 2859 | Dataspace::UNKNOWN, |
| 2860 | static_cast<StreamRotation>(INT32_MAX), |
| 2861 | std::string(), |
| 2862 | jpegBufferSize, |
| 2863 | 0, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 2864 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 2865 | RequestAvailableDynamicRangeProfilesMap:: |
| 2866 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 2867 | streams[0] = stream; |
| 2868 | createStreamConfiguration(streams, StreamConfigurationMode::NORMAL_MODE, &config, |
| 2869 | jpegBufferSize); |
| 2870 | config.streamConfigCounter = streamConfigCounter++; |
| 2871 | s = injectionSession->configureInjectionStreams(config, chars); |
| 2872 | ASSERT_EQ(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT), s.getServiceSpecificError()); |
| 2873 | } |
| 2874 | |
| 2875 | ret = session->close(); |
| 2876 | ASSERT_TRUE(ret.isOk()); |
| 2877 | } |
| 2878 | } |
| 2879 | |
| 2880 | // Check whether session parameters are supported for injection camera. If Hal support for them |
| 2881 | // exist, then try to configure a preview stream using them. |
| 2882 | TEST_P(CameraAidlTest, configureInjectionStreamsWithSessionParameters) { |
| 2883 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 2884 | std::vector<AvailableStream> outputPreviewStreams; |
| 2885 | AvailableStream previewThreshold = {kMaxPreviewWidth, kMaxPreviewHeight, |
| 2886 | static_cast<int32_t>(PixelFormat::IMPLEMENTATION_DEFINED)}; |
| 2887 | |
| 2888 | for (const auto& name : cameraDeviceNames) { |
| 2889 | CameraMetadata metadata; |
| 2890 | std::shared_ptr<ICameraInjectionSession> injectionSession; |
| 2891 | std::shared_ptr<ICameraDevice> unusedDevice; |
| 2892 | openEmptyInjectionSession(name, mProvider, &injectionSession /*out*/, &metadata /*out*/, |
| 2893 | &unusedDevice /*out*/); |
| 2894 | if (injectionSession == nullptr) { |
| 2895 | continue; |
| 2896 | } |
| 2897 | |
| 2898 | std::shared_ptr<ICameraDeviceSession> session; |
| 2899 | ndk::ScopedAStatus ret = injectionSession->getCameraDeviceSession(&session); |
| 2900 | ASSERT_TRUE(ret.isOk()); |
| 2901 | ASSERT_NE(session, nullptr); |
| 2902 | |
| 2903 | camera_metadata_t* staticMetaBuffer = |
| 2904 | reinterpret_cast<camera_metadata_t*>(metadata.metadata.data()); |
| 2905 | CameraMetadata chars; |
| 2906 | chars.metadata = metadata.metadata; |
| 2907 | |
| 2908 | std::unordered_set<int32_t> availableSessionKeys; |
| 2909 | Status rc = getSupportedKeys(staticMetaBuffer, ANDROID_REQUEST_AVAILABLE_SESSION_KEYS, |
| 2910 | &availableSessionKeys); |
| 2911 | ASSERT_EQ(Status::OK, rc); |
| 2912 | if (availableSessionKeys.empty()) { |
| 2913 | ret = session->close(); |
| 2914 | ASSERT_TRUE(ret.isOk()); |
| 2915 | continue; |
| 2916 | } |
| 2917 | |
| 2918 | android::hardware::camera::common::V1_0::helper::CameraMetadata previewRequestSettings; |
| 2919 | android::hardware::camera::common::V1_0::helper::CameraMetadata sessionParams, |
| 2920 | modifiedSessionParams; |
| 2921 | constructFilteredSettings(session, availableSessionKeys, RequestTemplate::PREVIEW, |
| 2922 | &previewRequestSettings, &sessionParams); |
| 2923 | if (sessionParams.isEmpty()) { |
| 2924 | ret = session->close(); |
| 2925 | ASSERT_TRUE(ret.isOk()); |
| 2926 | continue; |
| 2927 | } |
| 2928 | |
| 2929 | outputPreviewStreams.clear(); |
| 2930 | |
| 2931 | ASSERT_EQ(Status::OK, getAvailableOutputStreams(staticMetaBuffer, outputPreviewStreams, |
| 2932 | &previewThreshold)); |
| 2933 | ASSERT_NE(0u, outputPreviewStreams.size()); |
| 2934 | |
| 2935 | Stream previewStream = { |
| 2936 | 0, |
| 2937 | StreamType::OUTPUT, |
| 2938 | outputPreviewStreams[0].width, |
| 2939 | outputPreviewStreams[0].height, |
| 2940 | static_cast<PixelFormat>(outputPreviewStreams[0].format), |
| 2941 | static_cast<::aidl::android::hardware::graphics::common::BufferUsage>( |
| 2942 | GRALLOC1_CONSUMER_USAGE_HWCOMPOSER), |
| 2943 | Dataspace::UNKNOWN, |
| 2944 | StreamRotation::ROTATION_0, |
| 2945 | std::string(), |
| 2946 | 0, |
| 2947 | -1, |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 2948 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 2949 | RequestAvailableDynamicRangeProfilesMap:: |
| 2950 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 2951 | std::vector<Stream> streams = {previewStream}; |
| 2952 | StreamConfiguration config; |
| 2953 | config.streams = streams; |
| 2954 | config.operationMode = StreamConfigurationMode::NORMAL_MODE; |
| 2955 | |
| 2956 | modifiedSessionParams = sessionParams; |
| 2957 | camera_metadata_t* sessionParamsBuffer = sessionParams.release(); |
| 2958 | uint8_t* rawSessionParamsBuffer = reinterpret_cast<uint8_t*>(sessionParamsBuffer); |
| 2959 | config.sessionParams.metadata = |
| 2960 | std::vector(rawSessionParamsBuffer, |
| 2961 | rawSessionParamsBuffer + get_camera_metadata_size(sessionParamsBuffer)); |
| 2962 | |
| 2963 | config.streamConfigCounter = 0; |
| 2964 | config.streamConfigCounter = 0; |
| 2965 | config.multiResolutionInputImage = false; |
| 2966 | |
| 2967 | ndk::ScopedAStatus s = injectionSession->configureInjectionStreams(config, chars); |
| 2968 | ASSERT_TRUE(s.isOk()); |
| 2969 | |
| 2970 | sessionParams.acquire(sessionParamsBuffer); |
| 2971 | free_camera_metadata(staticMetaBuffer); |
| 2972 | ret = session->close(); |
| 2973 | ASSERT_TRUE(ret.isOk()); |
| 2974 | } |
| 2975 | } |
| 2976 | |
| 2977 | // Verify that valid stream use cases can be configured successfully, and invalid use cases |
| 2978 | // fail stream configuration. |
| 2979 | TEST_P(CameraAidlTest, configureStreamsUseCases) { |
| 2980 | std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); |
| 2981 | |
| 2982 | for (const auto& name : cameraDeviceNames) { |
| 2983 | CameraMetadata meta; |
| 2984 | std::shared_ptr<ICameraDevice> cameraDevice; |
| 2985 | |
| 2986 | openEmptyDeviceSession(name, mProvider, &mSession /*out*/, &meta /*out*/, |
| 2987 | &cameraDevice /*out*/); |
| 2988 | |
| 2989 | camera_metadata_t* staticMeta = reinterpret_cast<camera_metadata_t*>(meta.metadata.data()); |
| 2990 | // Check if camera support depth only |
| 2991 | if (isDepthOnly(staticMeta)) { |
| 2992 | ndk::ScopedAStatus ret = mSession->close(); |
| 2993 | mSession = nullptr; |
| 2994 | ASSERT_TRUE(ret.isOk()); |
| 2995 | continue; |
| 2996 | } |
| 2997 | |
| 2998 | std::vector<AvailableStream> outputPreviewStreams; |
| 2999 | AvailableStream previewThreshold = {kMaxPreviewWidth, kMaxPreviewHeight, |
| 3000 | static_cast<int32_t>(PixelFormat::YCBCR_420_888)}; |
| 3001 | ASSERT_EQ(Status::OK, |
| 3002 | getAvailableOutputStreams(staticMeta, outputPreviewStreams, &previewThreshold)); |
| 3003 | ASSERT_NE(0u, outputPreviewStreams.size()); |
| 3004 | |
| 3005 | // Combine valid and invalid stream use cases |
Shuzhen Wang | 36efa71 | 2022-03-08 10:10:44 -0800 | [diff] [blame] | 3006 | std::vector<int64_t> useCases(kMandatoryUseCases); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 3007 | useCases.push_back(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_VIDEO_CALL + 1); |
| 3008 | |
Shuzhen Wang | 36efa71 | 2022-03-08 10:10:44 -0800 | [diff] [blame] | 3009 | std::vector<int64_t> supportedUseCases; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 3010 | camera_metadata_ro_entry entry; |
| 3011 | auto retcode = find_camera_metadata_ro_entry( |
| 3012 | staticMeta, ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES, &entry); |
| 3013 | if ((0 == retcode) && (entry.count > 0)) { |
Avichal Rakesh | e1685a7 | 2022-03-22 13:52:36 -0700 | [diff] [blame] | 3014 | supportedUseCases.insert(supportedUseCases.end(), entry.data.i64, |
| 3015 | entry.data.i64 + entry.count); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 3016 | } else { |
| 3017 | supportedUseCases.push_back(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT); |
| 3018 | } |
| 3019 | |
| 3020 | std::vector<Stream> streams(1); |
Avichal Rakesh | d3503a3 | 2022-02-25 06:23:14 +0000 | [diff] [blame] | 3021 | streams[0] = {0, |
| 3022 | StreamType::OUTPUT, |
| 3023 | outputPreviewStreams[0].width, |
| 3024 | outputPreviewStreams[0].height, |
| 3025 | static_cast<PixelFormat>(outputPreviewStreams[0].format), |
| 3026 | static_cast<::aidl::android::hardware::graphics::common::BufferUsage>( |
| 3027 | GRALLOC1_CONSUMER_USAGE_CPU_READ), |
| 3028 | Dataspace::UNKNOWN, |
| 3029 | StreamRotation::ROTATION_0, |
| 3030 | std::string(), |
| 3031 | 0, |
| 3032 | -1, |
| 3033 | {SensorPixelMode::ANDROID_SENSOR_PIXEL_MODE_DEFAULT}, |
| 3034 | RequestAvailableDynamicRangeProfilesMap:: |
| 3035 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD}; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 3036 | |
| 3037 | int32_t streamConfigCounter = 0; |
| 3038 | CameraMetadata req; |
| 3039 | StreamConfiguration config; |
| 3040 | RequestTemplate reqTemplate = RequestTemplate::STILL_CAPTURE; |
| 3041 | ndk::ScopedAStatus ret = mSession->constructDefaultRequestSettings(reqTemplate, &req); |
| 3042 | ASSERT_TRUE(ret.isOk()); |
| 3043 | config.sessionParams = req; |
| 3044 | |
Shuzhen Wang | 36efa71 | 2022-03-08 10:10:44 -0800 | [diff] [blame] | 3045 | for (int64_t useCase : useCases) { |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 3046 | bool useCaseSupported = std::find(supportedUseCases.begin(), supportedUseCases.end(), |
| 3047 | useCase) != supportedUseCases.end(); |
| 3048 | |
| 3049 | streams[0].useCase = static_cast< |
| 3050 | aidl::android::hardware::camera::metadata::ScalerAvailableStreamUseCases>( |
| 3051 | useCase); |
| 3052 | config.streams = streams; |
| 3053 | config.operationMode = StreamConfigurationMode::NORMAL_MODE; |
| 3054 | config.streamConfigCounter = streamConfigCounter; |
| 3055 | config.multiResolutionInputImage = false; |
| 3056 | |
| 3057 | bool combSupported; |
| 3058 | ret = cameraDevice->isStreamCombinationSupported(config, &combSupported); |
Avichal Rakesh | e1685a7 | 2022-03-22 13:52:36 -0700 | [diff] [blame] | 3059 | if (static_cast<int32_t>(Status::OPERATION_NOT_SUPPORTED) == |
| 3060 | ret.getServiceSpecificError()) { |
| 3061 | continue; |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 3062 | } |
Avichal Rakesh | e1685a7 | 2022-03-22 13:52:36 -0700 | [diff] [blame] | 3063 | |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 3064 | ASSERT_TRUE(ret.isOk()); |
Avichal Rakesh | e1685a7 | 2022-03-22 13:52:36 -0700 | [diff] [blame] | 3065 | ASSERT_EQ(combSupported, useCaseSupported); |
Avichal Rakesh | 362242f | 2022-02-08 12:40:53 -0800 | [diff] [blame] | 3066 | |
| 3067 | std::vector<HalStream> halStreams; |
| 3068 | ret = mSession->configureStreams(config, &halStreams); |
| 3069 | ALOGI("configureStreams returns status: %d", ret.getServiceSpecificError()); |
| 3070 | if (useCaseSupported) { |
| 3071 | ASSERT_TRUE(ret.isOk()); |
| 3072 | ASSERT_EQ(1u, halStreams.size()); |
| 3073 | } else { |
| 3074 | ASSERT_EQ(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT), |
| 3075 | ret.getServiceSpecificError()); |
| 3076 | } |
| 3077 | } |
| 3078 | ret = mSession->close(); |
| 3079 | mSession = nullptr; |
| 3080 | ASSERT_TRUE(ret.isOk()); |
| 3081 | } |
| 3082 | } |
| 3083 | |
| 3084 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CameraAidlTest); |
| 3085 | INSTANTIATE_TEST_SUITE_P( |
| 3086 | PerInstance, CameraAidlTest, |
| 3087 | testing::ValuesIn(android::getAidlHalInstanceNames(ICameraProvider::descriptor)), |
| 3088 | android::hardware::PrintInstanceNameToString); |