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