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