Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | #define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "CameraBinderTests" |
| 19 | |
| 20 | #include <binder/IInterface.h> |
| 21 | #include <binder/IServiceManager.h> |
| 22 | #include <binder/Parcel.h> |
| 23 | #include <binder/ProcessState.h> |
| 24 | #include <utils/Errors.h> |
| 25 | #include <utils/Log.h> |
| 26 | #include <utils/List.h> |
| 27 | #include <utils/String8.h> |
| 28 | #include <utils/String16.h> |
| 29 | #include <utils/Condition.h> |
| 30 | #include <utils/Mutex.h> |
| 31 | #include <system/graphics.h> |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 32 | #include <hardware/camera3.h> |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 33 | #include <hardware/gralloc.h> |
| 34 | |
| 35 | #include <camera/CameraMetadata.h> |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 36 | #include <android/hardware/ICameraService.h> |
| 37 | #include <android/hardware/ICameraServiceListener.h> |
| 38 | #include <android/hardware/BnCameraServiceListener.h> |
| 39 | #include <android/hardware/camera2/ICameraDeviceUser.h> |
| 40 | #include <android/hardware/camera2/ICameraDeviceCallbacks.h> |
| 41 | #include <android/hardware/camera2/BnCameraDeviceCallbacks.h> |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 42 | #include <camera/camera2/CaptureRequest.h> |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 43 | #include <camera/camera2/OutputConfiguration.h> |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 44 | #include <camera/camera2/SessionConfiguration.h> |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 45 | #include <camera/camera2/SubmitInfo.h> |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 46 | |
| 47 | #include <gui/BufferItemConsumer.h> |
| 48 | #include <gui/IGraphicBufferProducer.h> |
| 49 | #include <gui/Surface.h> |
| 50 | |
| 51 | #include <gtest/gtest.h> |
| 52 | #include <unistd.h> |
| 53 | #include <stdint.h> |
| 54 | #include <utility> |
| 55 | #include <vector> |
| 56 | #include <map> |
| 57 | #include <algorithm> |
| 58 | |
| 59 | using namespace android; |
Jiyong Park | 5a095ea | 2019-07-09 15:43:57 +0900 | [diff] [blame] | 60 | using ::android::hardware::ICameraService; |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 61 | using ::android::hardware::camera2::ICameraDeviceUser; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 62 | |
| 63 | #define ASSERT_NOT_NULL(x) \ |
| 64 | ASSERT_TRUE((x) != nullptr) |
| 65 | |
| 66 | #define SETUP_TIMEOUT 2000000000 // ns |
| 67 | #define IDLE_TIMEOUT 2000000000 // ns |
| 68 | |
| 69 | // Stub listener implementation |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 70 | class TestCameraServiceListener : public hardware::BnCameraServiceListener { |
| 71 | std::map<String16, int32_t> mCameraTorchStatuses; |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 72 | std::map<String16, int32_t> mCameraStatuses; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 73 | mutable Mutex mLock; |
| 74 | mutable Condition mCondition; |
| 75 | mutable Condition mTorchCondition; |
| 76 | public: |
| 77 | virtual ~TestCameraServiceListener() {}; |
| 78 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 79 | virtual binder::Status onStatusChanged(int32_t status, const String16& cameraId) { |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 80 | Mutex::Autolock l(mLock); |
| 81 | mCameraStatuses[cameraId] = status; |
| 82 | mCondition.broadcast(); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 83 | return binder::Status::ok(); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 86 | virtual binder::Status onPhysicalCameraStatusChanged(int32_t /*status*/, |
| 87 | const String16& /*cameraId*/, const String16& /*physicalCameraId*/) { |
| 88 | // No op |
| 89 | return binder::Status::ok(); |
| 90 | }; |
| 91 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 92 | virtual binder::Status onTorchStatusChanged(int32_t status, const String16& cameraId) { |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 93 | Mutex::Autolock l(mLock); |
| 94 | mCameraTorchStatuses[cameraId] = status; |
| 95 | mTorchCondition.broadcast(); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 96 | return binder::Status::ok(); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
Rucha Katakwar | 3828452 | 2021-11-10 11:25:21 -0800 | [diff] [blame] | 99 | virtual binder::Status onTorchStrengthLevelChanged(const String16& /*cameraId*/, |
| 100 | int32_t /*torchStrength*/) { |
| 101 | // No op |
| 102 | return binder::Status::ok(); |
| 103 | } |
| 104 | |
Emilian Peev | 53722fa | 2019-02-22 17:47:20 -0800 | [diff] [blame] | 105 | virtual binder::Status onCameraAccessPrioritiesChanged() { |
| 106 | // No op |
| 107 | return binder::Status::ok(); |
| 108 | } |
| 109 | |
Shuzhen Wang | 695044d | 2020-03-06 09:02:23 -0800 | [diff] [blame] | 110 | virtual binder::Status onCameraOpened(const String16& /*cameraId*/, |
| 111 | const String16& /*clientPackageName*/) { |
| 112 | // No op |
| 113 | return binder::Status::ok(); |
| 114 | } |
| 115 | |
| 116 | virtual binder::Status onCameraClosed(const String16& /*cameraId*/) { |
| 117 | // No op |
| 118 | return binder::Status::ok(); |
| 119 | } |
| 120 | |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 121 | bool waitForNumCameras(size_t num) const { |
| 122 | Mutex::Autolock l(mLock); |
| 123 | |
| 124 | if (mCameraStatuses.size() == num) { |
| 125 | return true; |
| 126 | } |
| 127 | |
| 128 | while (mCameraStatuses.size() < num) { |
| 129 | if (mCondition.waitRelative(mLock, SETUP_TIMEOUT) != OK) { |
| 130 | return false; |
| 131 | } |
| 132 | } |
| 133 | return true; |
| 134 | }; |
| 135 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 136 | bool waitForTorchState(int32_t status, int32_t cameraId) const { |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 137 | Mutex::Autolock l(mLock); |
| 138 | |
| 139 | const auto& iter = mCameraTorchStatuses.find(String16(String8::format("%d", cameraId))); |
| 140 | if (iter != mCameraTorchStatuses.end() && iter->second == status) { |
| 141 | return true; |
| 142 | } |
| 143 | |
| 144 | bool foundStatus = false; |
| 145 | while (!foundStatus) { |
| 146 | if (mTorchCondition.waitRelative(mLock, SETUP_TIMEOUT) != OK) { |
| 147 | return false; |
| 148 | } |
| 149 | const auto& iter = |
| 150 | mCameraTorchStatuses.find(String16(String8::format("%d", cameraId))); |
| 151 | foundStatus = (iter != mCameraTorchStatuses.end() && iter->second == status); |
| 152 | } |
| 153 | return true; |
| 154 | }; |
| 155 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 156 | int32_t getTorchStatus(int32_t cameraId) const { |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 157 | Mutex::Autolock l(mLock); |
| 158 | const auto& iter = mCameraTorchStatuses.find(String16(String8::format("%d", cameraId))); |
| 159 | if (iter == mCameraTorchStatuses.end()) { |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 160 | return hardware::ICameraServiceListener::TORCH_STATUS_UNKNOWN; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 161 | } |
| 162 | return iter->second; |
| 163 | }; |
| 164 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 165 | int32_t getStatus(const String16& cameraId) const { |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 166 | Mutex::Autolock l(mLock); |
| 167 | const auto& iter = mCameraStatuses.find(cameraId); |
| 168 | if (iter == mCameraStatuses.end()) { |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 169 | return hardware::ICameraServiceListener::STATUS_UNKNOWN; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 170 | } |
| 171 | return iter->second; |
| 172 | }; |
| 173 | }; |
| 174 | |
| 175 | // Callback implementation |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 176 | class TestCameraDeviceCallbacks : public hardware::camera2::BnCameraDeviceCallbacks { |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 177 | public: |
| 178 | enum Status { |
| 179 | IDLE, |
| 180 | ERROR, |
| 181 | PREPARED, |
| 182 | RUNNING, |
| 183 | SENT_RESULT, |
Chien-Yu Chen | e8c535e | 2016-04-14 12:18:26 -0700 | [diff] [blame] | 184 | UNINITIALIZED, |
| 185 | REPEATING_REQUEST_ERROR, |
Shuzhen Wang | 9d06601 | 2016-09-30 11:30:20 -0700 | [diff] [blame] | 186 | REQUEST_QUEUE_EMPTY, |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | protected: |
| 190 | bool mError; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 191 | int32_t mLastStatus; |
| 192 | mutable std::vector<int32_t> mStatusesHit; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 193 | mutable Mutex mLock; |
| 194 | mutable Condition mStatusCondition; |
| 195 | public: |
| 196 | TestCameraDeviceCallbacks() : mError(false), mLastStatus(UNINITIALIZED) {} |
| 197 | |
| 198 | virtual ~TestCameraDeviceCallbacks() {} |
| 199 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 200 | virtual binder::Status onDeviceError(int errorCode, |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 201 | const CaptureResultExtras& resultExtras) { |
Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 202 | (void) resultExtras; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 203 | ALOGE("%s: onDeviceError occurred with: %d", __FUNCTION__, static_cast<int>(errorCode)); |
| 204 | Mutex::Autolock l(mLock); |
| 205 | mError = true; |
| 206 | mLastStatus = ERROR; |
| 207 | mStatusesHit.push_back(mLastStatus); |
| 208 | mStatusCondition.broadcast(); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 209 | return binder::Status::ok(); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 212 | virtual binder::Status onDeviceIdle() { |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 213 | Mutex::Autolock l(mLock); |
| 214 | mLastStatus = IDLE; |
| 215 | mStatusesHit.push_back(mLastStatus); |
| 216 | mStatusCondition.broadcast(); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 217 | return binder::Status::ok(); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 220 | virtual binder::Status onCaptureStarted(const CaptureResultExtras& resultExtras, |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 221 | int64_t timestamp) { |
Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 222 | (void) resultExtras; |
| 223 | (void) timestamp; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 224 | Mutex::Autolock l(mLock); |
| 225 | mLastStatus = RUNNING; |
| 226 | mStatusesHit.push_back(mLastStatus); |
| 227 | mStatusCondition.broadcast(); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 228 | return binder::Status::ok(); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 232 | virtual binder::Status onResultReceived(const CameraMetadata& metadata, |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 233 | const CaptureResultExtras& resultExtras, |
| 234 | const std::vector<PhysicalCaptureResultInfo>& physicalResultInfos) { |
Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 235 | (void) metadata; |
| 236 | (void) resultExtras; |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 237 | (void) physicalResultInfos; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 238 | Mutex::Autolock l(mLock); |
| 239 | mLastStatus = SENT_RESULT; |
| 240 | mStatusesHit.push_back(mLastStatus); |
| 241 | mStatusCondition.broadcast(); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 242 | return binder::Status::ok(); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 245 | virtual binder::Status onPrepared(int streamId) { |
Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 246 | (void) streamId; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 247 | Mutex::Autolock l(mLock); |
| 248 | mLastStatus = PREPARED; |
| 249 | mStatusesHit.push_back(mLastStatus); |
| 250 | mStatusCondition.broadcast(); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 251 | return binder::Status::ok(); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Yin-Chia Yeh | 8ca23dc | 2017-09-05 18:15:56 -0700 | [diff] [blame] | 254 | virtual binder::Status onRepeatingRequestError( |
| 255 | int64_t lastFrameNumber, int32_t stoppedSequenceId) { |
Chien-Yu Chen | e8c535e | 2016-04-14 12:18:26 -0700 | [diff] [blame] | 256 | (void) lastFrameNumber; |
Yin-Chia Yeh | 8ca23dc | 2017-09-05 18:15:56 -0700 | [diff] [blame] | 257 | (void) stoppedSequenceId; |
Chien-Yu Chen | e8c535e | 2016-04-14 12:18:26 -0700 | [diff] [blame] | 258 | Mutex::Autolock l(mLock); |
| 259 | mLastStatus = REPEATING_REQUEST_ERROR; |
| 260 | mStatusesHit.push_back(mLastStatus); |
| 261 | mStatusCondition.broadcast(); |
| 262 | return binder::Status::ok(); |
| 263 | } |
| 264 | |
Shuzhen Wang | 9d06601 | 2016-09-30 11:30:20 -0700 | [diff] [blame] | 265 | virtual binder::Status onRequestQueueEmpty() { |
| 266 | Mutex::Autolock l(mLock); |
| 267 | mLastStatus = REQUEST_QUEUE_EMPTY; |
| 268 | mStatusesHit.push_back(mLastStatus); |
| 269 | mStatusCondition.broadcast(); |
| 270 | return binder::Status::ok(); |
| 271 | } |
| 272 | |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 273 | // Test helper functions: |
| 274 | |
| 275 | bool hadError() const { |
| 276 | Mutex::Autolock l(mLock); |
| 277 | return mError; |
| 278 | } |
| 279 | |
| 280 | bool waitForStatus(Status status) const { |
| 281 | Mutex::Autolock l(mLock); |
| 282 | if (mLastStatus == status) { |
| 283 | return true; |
| 284 | } |
| 285 | |
| 286 | while (std::find(mStatusesHit.begin(), mStatusesHit.end(), status) |
| 287 | == mStatusesHit.end()) { |
| 288 | |
| 289 | if (mStatusCondition.waitRelative(mLock, IDLE_TIMEOUT) != OK) { |
| 290 | mStatusesHit.clear(); |
| 291 | return false; |
| 292 | } |
| 293 | } |
| 294 | mStatusesHit.clear(); |
| 295 | |
| 296 | return true; |
| 297 | |
| 298 | } |
| 299 | |
| 300 | void clearStatus() const { |
| 301 | Mutex::Autolock l(mLock); |
| 302 | mStatusesHit.clear(); |
| 303 | } |
| 304 | |
| 305 | bool waitForIdle() const { |
| 306 | return waitForStatus(IDLE); |
| 307 | } |
| 308 | |
| 309 | }; |
| 310 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 311 | namespace { |
| 312 | Mutex gLock; |
| 313 | class DeathNotifier : public IBinder::DeathRecipient |
| 314 | { |
| 315 | public: |
| 316 | DeathNotifier() {} |
| 317 | |
| 318 | virtual void binderDied(const wp<IBinder>& /*who*/) { |
| 319 | ALOGV("binderDied"); |
| 320 | Mutex::Autolock _l(gLock); |
| 321 | ALOGW("Camera service died!"); |
| 322 | } |
| 323 | }; |
| 324 | sp<DeathNotifier> gDeathNotifier; |
| 325 | }; // anonymous namespace |
| 326 | |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 327 | // Exercise basic binder calls for the camera service |
| 328 | TEST(CameraServiceBinderTest, CheckBinderCameraService) { |
| 329 | ProcessState::self()->startThreadPool(); |
| 330 | sp<IServiceManager> sm = defaultServiceManager(); |
| 331 | sp<IBinder> binder = sm->getService(String16("media.camera")); |
| 332 | ASSERT_NOT_NULL(binder); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 333 | if (gDeathNotifier == NULL) { |
| 334 | gDeathNotifier = new DeathNotifier(); |
| 335 | } |
| 336 | binder->linkToDeath(gDeathNotifier); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 337 | sp<hardware::ICameraService> service = |
| 338 | interface_cast<hardware::ICameraService>(binder); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 339 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 340 | binder::Status res; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 341 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 342 | int32_t numCameras = 0; |
| 343 | res = service->getNumberOfCameras(hardware::ICameraService::CAMERA_TYPE_ALL, &numCameras); |
| 344 | EXPECT_TRUE(res.isOk()) << res; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 345 | EXPECT_LE(0, numCameras); |
| 346 | |
| 347 | // Check listener binder calls |
| 348 | sp<TestCameraServiceListener> listener(new TestCameraServiceListener()); |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 349 | std::vector<hardware::CameraStatus> statuses; |
| 350 | res = service->addListener(listener, &statuses); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 351 | EXPECT_TRUE(res.isOk()) << res; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 352 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 353 | EXPECT_EQ(numCameras, static_cast<const int>(statuses.size())); |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 354 | for (const auto &it : statuses) { |
| 355 | listener->onStatusChanged(it.status, String16(it.cameraId)); |
| 356 | } |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 357 | |
| 358 | for (int32_t i = 0; i < numCameras; i++) { |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 359 | String16 cameraId = String16(String8::format("%d", i)); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 360 | bool isSupported = false; |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 361 | res = service->supportsCameraApi(cameraId, |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 362 | hardware::ICameraService::API_VERSION_2, &isSupported); |
| 363 | EXPECT_TRUE(res.isOk()) << res; |
| 364 | |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 365 | // We only care about binder calls for the Camera2 API. Camera1 is deprecated. |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 366 | if (!isSupported) { |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 367 | continue; |
| 368 | } |
| 369 | |
| 370 | // Check metadata binder call |
| 371 | CameraMetadata metadata; |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 372 | res = service->getCameraCharacteristics(cameraId, |
Austin Borger | 18b30a7 | 2022-10-27 12:20:29 -0700 | [diff] [blame] | 373 | /*targetSdkVersion*/__ANDROID_API_FUTURE__, /*overrideToPortrait*/false, &metadata); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 374 | EXPECT_TRUE(res.isOk()) << res; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 375 | EXPECT_FALSE(metadata.isEmpty()); |
| 376 | |
| 377 | // Make sure we're available, or skip device tests otherwise |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 378 | int32_t s = listener->getStatus(cameraId); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 379 | EXPECT_EQ(::android::hardware::ICameraServiceListener::STATUS_PRESENT, s); |
| 380 | if (s != ::android::hardware::ICameraServiceListener::STATUS_PRESENT) { |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 381 | continue; |
| 382 | } |
| 383 | |
| 384 | // Check connect binder calls |
| 385 | sp<TestCameraDeviceCallbacks> callbacks(new TestCameraDeviceCallbacks()); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 386 | sp<hardware::camera2::ICameraDeviceUser> device; |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 387 | res = service->connectDevice(callbacks, cameraId, String16("meeeeeeeee!"), |
Jayant Chowdhary | 8eb8d91 | 2021-05-18 17:41:56 +0000 | [diff] [blame] | 388 | {}, hardware::ICameraService::USE_CALLING_UID, /*oomScoreOffset*/ 0, |
Austin Borger | 18b30a7 | 2022-10-27 12:20:29 -0700 | [diff] [blame] | 389 | /*targetSdkVersion*/__ANDROID_API_FUTURE__, |
| 390 | /*overrideToPortrait*/false, /*out*/&device); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 391 | EXPECT_TRUE(res.isOk()) << res; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 392 | ASSERT_NE(nullptr, device.get()); |
| 393 | device->disconnect(); |
| 394 | EXPECT_FALSE(callbacks->hadError()); |
| 395 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 396 | int32_t torchStatus = listener->getTorchStatus(i); |
| 397 | if (torchStatus == hardware::ICameraServiceListener::TORCH_STATUS_AVAILABLE_OFF) { |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 398 | // Check torch calls |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 399 | res = service->setTorchMode(cameraId, |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 400 | /*enabled*/true, callbacks); |
| 401 | EXPECT_TRUE(res.isOk()) << res; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 402 | EXPECT_TRUE(listener->waitForTorchState( |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 403 | hardware::ICameraServiceListener::TORCH_STATUS_AVAILABLE_ON, i)); |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 404 | res = service->setTorchMode(cameraId, |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 405 | /*enabled*/false, callbacks); |
| 406 | EXPECT_TRUE(res.isOk()) << res; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 407 | EXPECT_TRUE(listener->waitForTorchState( |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 408 | hardware::ICameraServiceListener::TORCH_STATUS_AVAILABLE_OFF, i)); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 412 | res = service->removeListener(listener); |
| 413 | EXPECT_TRUE(res.isOk()) << res; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | // Test fixture for client focused binder tests |
| 417 | class CameraClientBinderTest : public testing::Test { |
| 418 | protected: |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 419 | sp<hardware::ICameraService> service; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 420 | int32_t numCameras; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 421 | std::vector<std::pair<sp<TestCameraDeviceCallbacks>, sp<hardware::camera2::ICameraDeviceUser>>> |
| 422 | openDeviceList; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 423 | sp<TestCameraServiceListener> serviceListener; |
| 424 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 425 | std::pair<sp<TestCameraDeviceCallbacks>, sp<hardware::camera2::ICameraDeviceUser>> |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 426 | openNewDevice(const String16& deviceId) { |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 427 | sp<TestCameraDeviceCallbacks> callbacks(new TestCameraDeviceCallbacks()); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 428 | sp<hardware::camera2::ICameraDeviceUser> device; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 429 | { |
| 430 | SCOPED_TRACE("openNewDevice"); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 431 | binder::Status res = service->connectDevice(callbacks, deviceId, String16("meeeeeeeee!"), |
Jayant Chowdhary | 8eb8d91 | 2021-05-18 17:41:56 +0000 | [diff] [blame] | 432 | {}, hardware::ICameraService::USE_CALLING_UID, /*oomScoreOffset*/ 0, |
Austin Borger | 18b30a7 | 2022-10-27 12:20:29 -0700 | [diff] [blame] | 433 | /*targetSdkVersion*/__ANDROID_API_FUTURE__, |
| 434 | /*overrideToPortrait*/false, /*out*/&device); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 435 | EXPECT_TRUE(res.isOk()) << res; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 436 | } |
| 437 | auto p = std::make_pair(callbacks, device); |
| 438 | openDeviceList.push_back(p); |
| 439 | return p; |
| 440 | } |
| 441 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 442 | void closeDevice(std::pair<sp<TestCameraDeviceCallbacks>, |
| 443 | sp<hardware::camera2::ICameraDeviceUser>>& p) { |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 444 | if (p.second.get() != nullptr) { |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 445 | binder::Status res = p.second->disconnect(); |
| 446 | EXPECT_TRUE(res.isOk()) << res; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 447 | { |
| 448 | SCOPED_TRACE("closeDevice"); |
| 449 | EXPECT_FALSE(p.first->hadError()); |
| 450 | } |
| 451 | } |
| 452 | auto iter = std::find(openDeviceList.begin(), openDeviceList.end(), p); |
| 453 | if (iter != openDeviceList.end()) { |
| 454 | openDeviceList.erase(iter); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | virtual void SetUp() { |
| 459 | ProcessState::self()->startThreadPool(); |
| 460 | sp<IServiceManager> sm = defaultServiceManager(); |
| 461 | sp<IBinder> binder = sm->getService(String16("media.camera")); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 462 | service = interface_cast<hardware::ICameraService>(binder); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 463 | serviceListener = new TestCameraServiceListener(); |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 464 | std::vector<hardware::CameraStatus> statuses; |
| 465 | service->addListener(serviceListener, &statuses); |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 466 | for (const auto &it : statuses) { |
| 467 | serviceListener->onStatusChanged(it.status, String16(it.cameraId)); |
| 468 | } |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 469 | service->getNumberOfCameras(hardware::ICameraService::CAMERA_TYPE_BACKWARD_COMPATIBLE, |
| 470 | &numCameras); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | virtual void TearDown() { |
| 474 | service = nullptr; |
| 475 | numCameras = 0; |
| 476 | for (auto& p : openDeviceList) { |
| 477 | closeDevice(p); |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | }; |
| 482 | |
| 483 | TEST_F(CameraClientBinderTest, CheckBinderCameraDeviceUser) { |
| 484 | ASSERT_NOT_NULL(service); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 485 | EXPECT_TRUE(serviceListener->waitForNumCameras(numCameras)); |
| 486 | for (int32_t i = 0; i < numCameras; i++) { |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 487 | String8 cameraId8 = String8::format("%d", i); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 488 | // Make sure we're available, or skip device tests otherwise |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 489 | String16 cameraId(cameraId8); |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 490 | int32_t s = serviceListener->getStatus(cameraId); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 491 | EXPECT_EQ(hardware::ICameraServiceListener::STATUS_PRESENT, s); |
| 492 | if (s != hardware::ICameraServiceListener::STATUS_PRESENT) { |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 493 | continue; |
| 494 | } |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 495 | binder::Status res; |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 496 | auto p = openNewDevice(cameraId); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 497 | sp<TestCameraDeviceCallbacks> callbacks = p.first; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 498 | sp<hardware::camera2::ICameraDeviceUser> device = p.second; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 499 | |
| 500 | // Setup a buffer queue; I'm just using the vendor opaque format here as that is |
| 501 | // guaranteed to be present |
| 502 | sp<IGraphicBufferProducer> gbProducer; |
| 503 | sp<IGraphicBufferConsumer> gbConsumer; |
| 504 | BufferQueue::createBufferQueue(&gbProducer, &gbConsumer); |
| 505 | sp<BufferItemConsumer> opaqueConsumer = new BufferItemConsumer(gbConsumer, |
| 506 | GRALLOC_USAGE_SW_READ_NEVER, /*maxImages*/2, /*controlledByApp*/true); |
| 507 | EXPECT_TRUE(opaqueConsumer.get() != nullptr); |
| 508 | opaqueConsumer->setName(String8("nom nom nom")); |
| 509 | |
| 510 | // Set to VGA dimens for default, as that is guaranteed to be present |
| 511 | EXPECT_EQ(OK, gbConsumer->setDefaultBufferSize(640, 480)); |
| 512 | EXPECT_EQ(OK, gbConsumer->setDefaultBufferFormat(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED)); |
| 513 | |
| 514 | sp<Surface> surface(new Surface(gbProducer, /*controlledByApp*/false)); |
| 515 | |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 516 | String16 noPhysicalId; |
| 517 | OutputConfiguration output(gbProducer, /*rotation*/0, noPhysicalId); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 518 | |
| 519 | // Can we configure? |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 520 | res = device->beginConfigure(); |
| 521 | EXPECT_TRUE(res.isOk()) << res; |
| 522 | status_t streamId; |
| 523 | res = device->createStream(output, &streamId); |
| 524 | EXPECT_TRUE(res.isOk()) << res; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 525 | EXPECT_LE(0, streamId); |
Emilian Peev | 5fbe0ba | 2017-10-20 15:45:45 +0100 | [diff] [blame] | 526 | CameraMetadata sessionParams; |
Emilian Peev | cc0b795 | 2020-01-07 13:54:47 -0800 | [diff] [blame] | 527 | std::vector<int> offlineStreamIds; |
| 528 | res = device->endConfigure(/*isConstrainedHighSpeed*/ false, sessionParams, |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 529 | ns2ms(systemTime()), &offlineStreamIds); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 530 | EXPECT_TRUE(res.isOk()) << res; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 531 | EXPECT_FALSE(callbacks->hadError()); |
| 532 | |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 533 | // Session configuration must also be supported in this case |
| 534 | SessionConfiguration sessionConfiguration = { /*inputWidth*/ 0, /*inputHeight*/0, |
| 535 | /*inputFormat*/ -1, CAMERA3_STREAM_CONFIGURATION_NORMAL_MODE}; |
| 536 | sessionConfiguration.addOutputConfiguration(output); |
| 537 | bool queryStatus; |
| 538 | res = device->isSessionConfigurationSupported(sessionConfiguration, &queryStatus); |
| 539 | EXPECT_TRUE(res.isOk() || |
Jiyong Park | 5a095ea | 2019-07-09 15:43:57 +0900 | [diff] [blame] | 540 | (res.serviceSpecificErrorCode() == ICameraService::ERROR_INVALID_OPERATION)) |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 541 | << res; |
| 542 | if (res.isOk()) { |
| 543 | EXPECT_TRUE(queryStatus); |
| 544 | } |
| 545 | |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 546 | // Can we make requests? |
| 547 | CameraMetadata requestTemplate; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 548 | res = device->createDefaultRequest(/*preview template*/1, |
| 549 | /*out*/&requestTemplate); |
| 550 | EXPECT_TRUE(res.isOk()) << res; |
| 551 | |
| 552 | hardware::camera2::CaptureRequest request; |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 553 | request.mPhysicalCameraSettings.push_back({cameraId8.string(), requestTemplate}); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 554 | request.mSurfaceList.add(surface); |
| 555 | request.mIsReprocess = false; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 556 | int64_t lastFrameNumber = 0; |
| 557 | int64_t lastFrameNumberPrev = 0; |
| 558 | callbacks->clearStatus(); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 559 | |
| 560 | hardware::camera2::utils::SubmitInfo info; |
| 561 | res = device->submitRequest(request, /*streaming*/true, /*out*/&info); |
| 562 | EXPECT_TRUE(res.isOk()) << res; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 563 | EXPECT_TRUE(callbacks->waitForStatus(TestCameraDeviceCallbacks::SENT_RESULT)); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 564 | EXPECT_LE(0, info.mRequestId); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 565 | |
| 566 | // Can we stop requests? |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 567 | res = device->cancelRequest(info.mRequestId, /*out*/&lastFrameNumber); |
| 568 | EXPECT_TRUE(res.isOk()) << res; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 569 | EXPECT_TRUE(callbacks->waitForIdle()); |
| 570 | EXPECT_FALSE(callbacks->hadError()); |
| 571 | |
| 572 | // Can we do it again? |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 573 | lastFrameNumberPrev = info.mLastFrameNumber; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 574 | lastFrameNumber = 0; |
| 575 | requestTemplate.clear(); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 576 | res = device->createDefaultRequest(hardware::camera2::ICameraDeviceUser::TEMPLATE_PREVIEW, |
| 577 | /*out*/&requestTemplate); |
| 578 | EXPECT_TRUE(res.isOk()) << res; |
| 579 | hardware::camera2::CaptureRequest request2; |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 580 | request2.mPhysicalCameraSettings.push_back({cameraId8.string(), requestTemplate}); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 581 | request2.mSurfaceList.add(surface); |
| 582 | request2.mIsReprocess = false; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 583 | callbacks->clearStatus(); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 584 | hardware::camera2::utils::SubmitInfo info2; |
| 585 | res = device->submitRequest(request2, /*streaming*/true, |
| 586 | /*out*/&info2); |
| 587 | EXPECT_TRUE(res.isOk()) << res; |
| 588 | EXPECT_EQ(hardware::camera2::ICameraDeviceUser::NO_IN_FLIGHT_REPEATING_FRAMES, |
| 589 | info2.mLastFrameNumber); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 590 | lastFrameNumber = 0; |
| 591 | EXPECT_TRUE(callbacks->waitForStatus(TestCameraDeviceCallbacks::SENT_RESULT)); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 592 | EXPECT_LE(0, info2.mRequestId); |
| 593 | res = device->cancelRequest(info2.mRequestId, /*out*/&lastFrameNumber); |
| 594 | EXPECT_TRUE(res.isOk()) << res; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 595 | EXPECT_TRUE(callbacks->waitForIdle()); |
| 596 | EXPECT_LE(lastFrameNumberPrev, lastFrameNumber); |
| 597 | sleep(/*second*/1); // allow some time for errors to show up, if any |
| 598 | EXPECT_FALSE(callbacks->hadError()); |
| 599 | |
| 600 | // Can we do it with a request list? |
| 601 | lastFrameNumberPrev = lastFrameNumber; |
| 602 | lastFrameNumber = 0; |
| 603 | requestTemplate.clear(); |
| 604 | CameraMetadata requestTemplate2; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 605 | res = device->createDefaultRequest(hardware::camera2::ICameraDeviceUser::TEMPLATE_PREVIEW, |
| 606 | /*out*/&requestTemplate); |
| 607 | EXPECT_TRUE(res.isOk()) << res; |
| 608 | res = device->createDefaultRequest(hardware::camera2::ICameraDeviceUser::TEMPLATE_PREVIEW, |
| 609 | /*out*/&requestTemplate2); |
| 610 | EXPECT_TRUE(res.isOk()) << res; |
| 611 | android::hardware::camera2::CaptureRequest request3; |
| 612 | android::hardware::camera2::CaptureRequest request4; |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 613 | request3.mPhysicalCameraSettings.push_back({cameraId8.string(), requestTemplate}); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 614 | request3.mSurfaceList.add(surface); |
| 615 | request3.mIsReprocess = false; |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 616 | request4.mPhysicalCameraSettings.push_back({cameraId8.string(), requestTemplate2}); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 617 | request4.mSurfaceList.add(surface); |
| 618 | request4.mIsReprocess = false; |
| 619 | std::vector<hardware::camera2::CaptureRequest> requestList; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 620 | requestList.push_back(request3); |
| 621 | requestList.push_back(request4); |
| 622 | |
| 623 | callbacks->clearStatus(); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 624 | hardware::camera2::utils::SubmitInfo info3; |
| 625 | res = device->submitRequestList(requestList, /*streaming*/false, |
| 626 | /*out*/&info3); |
| 627 | EXPECT_TRUE(res.isOk()) << res; |
| 628 | EXPECT_LE(0, info3.mRequestId); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 629 | EXPECT_TRUE(callbacks->waitForStatus(TestCameraDeviceCallbacks::SENT_RESULT)); |
| 630 | EXPECT_TRUE(callbacks->waitForIdle()); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 631 | EXPECT_LE(lastFrameNumberPrev, info3.mLastFrameNumber); |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 632 | sleep(/*second*/1); // allow some time for errors to show up, if any |
| 633 | EXPECT_FALSE(callbacks->hadError()); |
| 634 | |
| 635 | // Can we unconfigure? |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 636 | res = device->beginConfigure(); |
| 637 | EXPECT_TRUE(res.isOk()) << res; |
| 638 | res = device->deleteStream(streamId); |
| 639 | EXPECT_TRUE(res.isOk()) << res; |
Emilian Peev | cc0b795 | 2020-01-07 13:54:47 -0800 | [diff] [blame] | 640 | res = device->endConfigure(/*isConstrainedHighSpeed*/ false, sessionParams, |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 641 | ns2ms(systemTime()), &offlineStreamIds); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 642 | EXPECT_TRUE(res.isOk()) << res; |
| 643 | |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 644 | sleep(/*second*/1); // allow some time for errors to show up, if any |
| 645 | EXPECT_FALSE(callbacks->hadError()); |
| 646 | |
| 647 | closeDevice(p); |
| 648 | } |
| 649 | |
| 650 | }; |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 651 | |
| 652 | TEST_F(CameraClientBinderTest, CheckBinderCaptureRequest) { |
| 653 | sp<CaptureRequest> requestOriginal, requestParceled; |
| 654 | sp<IGraphicBufferProducer> gbProducer; |
| 655 | sp<IGraphicBufferConsumer> gbConsumer; |
| 656 | BufferQueue::createBufferQueue(&gbProducer, &gbConsumer); |
| 657 | sp<Surface> surface(new Surface(gbProducer, /*controlledByApp*/false)); |
| 658 | Vector<sp<Surface>> surfaceList; |
| 659 | surfaceList.push_back(surface); |
| 660 | std::string physicalDeviceId1 = "0"; |
| 661 | std::string physicalDeviceId2 = "1"; |
| 662 | CameraMetadata physicalDeviceSettings1, physicalDeviceSettings2; |
| 663 | uint8_t intent1 = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW; |
| 664 | uint8_t intent2 = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD; |
| 665 | EXPECT_EQ(OK, physicalDeviceSettings1.update(ANDROID_CONTROL_CAPTURE_INTENT, &intent1, 1)); |
| 666 | EXPECT_EQ(OK, physicalDeviceSettings2.update(ANDROID_CONTROL_CAPTURE_INTENT, &intent2, 1)); |
| 667 | |
| 668 | requestParceled = new CaptureRequest(); |
| 669 | Parcel p; |
| 670 | EXPECT_TRUE(requestParceled->readFromParcel(&p) != OK); |
| 671 | p.writeInt32(0); |
| 672 | p.setDataPosition(0); |
| 673 | EXPECT_TRUE(requestParceled->readFromParcel(&p) != OK); |
| 674 | p.freeData(); |
| 675 | p.writeInt32(-1); |
| 676 | p.setDataPosition(0); |
| 677 | EXPECT_TRUE(requestParceled->readFromParcel(&p) != OK); |
| 678 | p.freeData(); |
| 679 | p.writeInt32(1); |
| 680 | p.setDataPosition(0); |
| 681 | EXPECT_TRUE(requestParceled->readFromParcel(&p) != OK); |
| 682 | |
| 683 | requestOriginal = new CaptureRequest(); |
| 684 | requestOriginal->mPhysicalCameraSettings.push_back({physicalDeviceId1, |
| 685 | physicalDeviceSettings1}); |
| 686 | requestOriginal->mPhysicalCameraSettings.push_back({physicalDeviceId2, |
| 687 | physicalDeviceSettings2}); |
| 688 | requestOriginal->mSurfaceList.push_back(surface); |
| 689 | requestOriginal->mIsReprocess = false; |
| 690 | requestOriginal->mSurfaceConverted = false; |
| 691 | |
| 692 | p.freeData(); |
| 693 | EXPECT_TRUE(requestOriginal->writeToParcel(&p) == OK); |
| 694 | p.setDataPosition(0); |
| 695 | EXPECT_TRUE(requestParceled->readFromParcel(&p) == OK); |
| 696 | EXPECT_EQ(requestParceled->mIsReprocess, false); |
| 697 | EXPECT_FALSE(requestParceled->mSurfaceList.empty()); |
| 698 | EXPECT_EQ(2u, requestParceled->mPhysicalCameraSettings.size()); |
| 699 | auto it = requestParceled->mPhysicalCameraSettings.begin(); |
| 700 | EXPECT_EQ(physicalDeviceId1, it->id); |
| 701 | EXPECT_TRUE(it->settings.exists(ANDROID_CONTROL_CAPTURE_INTENT)); |
| 702 | auto entry = it->settings.find(ANDROID_CONTROL_CAPTURE_INTENT); |
| 703 | EXPECT_EQ(entry.data.u8[0], intent1); |
| 704 | it++; |
| 705 | EXPECT_EQ(physicalDeviceId2, it->id); |
| 706 | EXPECT_TRUE(it->settings.exists(ANDROID_CONTROL_CAPTURE_INTENT)); |
| 707 | entry = it->settings.find(ANDROID_CONTROL_CAPTURE_INTENT); |
| 708 | EXPECT_EQ(entry.data.u8[0], intent2); |
| 709 | }; |