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