Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 1 | /* |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 2 | * Copyright 2023 The Android Open Source Project |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <cstdint> |
| 18 | #include <memory> |
| 19 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 20 | #include "VirtualCameraDevice.h" |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 21 | #include "VirtualCameraSession.h" |
| 22 | #include "aidl/android/companion/virtualcamera/BnVirtualCameraCallback.h" |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 23 | #include "aidl/android/companion/virtualcamera/SupportedStreamConfiguration.h" |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 24 | #include "aidl/android/companion/virtualcamera/VirtualCameraConfiguration.h" |
Jan Sebechlebsky | 0bb5e09 | 2023-12-08 16:17:54 +0100 | [diff] [blame] | 25 | #include "aidl/android/hardware/camera/common/Status.h" |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 26 | #include "aidl/android/hardware/camera/device/BnCameraDeviceCallback.h" |
| 27 | #include "aidl/android/hardware/camera/device/StreamConfiguration.h" |
| 28 | #include "aidl/android/hardware/graphics/common/PixelFormat.h" |
| 29 | #include "android/binder_auto_utils.h" |
| 30 | #include "android/binder_interface_utils.h" |
| 31 | #include "gmock/gmock.h" |
| 32 | #include "gtest/gtest.h" |
Jan Sebechlebsky | 4ce3208 | 2024-02-14 16:02:11 +0100 | [diff] [blame] | 33 | #include "util/MetadataUtil.h" |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 34 | |
| 35 | namespace android { |
| 36 | namespace companion { |
| 37 | namespace virtualcamera { |
| 38 | namespace { |
| 39 | |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame^] | 40 | constexpr int kQvgaWidth = 320; |
| 41 | constexpr int kQvgaHeight = 240; |
Jan Sebechlebsky | 39129f8 | 2024-01-19 16:42:11 +0100 | [diff] [blame] | 42 | constexpr int kVgaWidth = 640; |
| 43 | constexpr int kVgaHeight = 480; |
| 44 | constexpr int kSvgaWidth = 800; |
| 45 | constexpr int kSvgaHeight = 600; |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 46 | constexpr int kMaxFps = 30; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 47 | constexpr int kStreamId = 0; |
Jan Sebechlebsky | 39129f8 | 2024-01-19 16:42:11 +0100 | [diff] [blame] | 48 | constexpr int kSecondStreamId = 1; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 49 | constexpr int kCameraId = 42; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 50 | |
| 51 | using ::aidl::android::companion::virtualcamera::BnVirtualCameraCallback; |
| 52 | using ::aidl::android::companion::virtualcamera::Format; |
Biswarup Pal | 112458f | 2023-12-28 19:50:17 +0000 | [diff] [blame] | 53 | using ::aidl::android::companion::virtualcamera::LensFacing; |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 54 | using ::aidl::android::companion::virtualcamera::SensorOrientation; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 55 | using ::aidl::android::companion::virtualcamera::SupportedStreamConfiguration; |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 56 | using ::aidl::android::companion::virtualcamera::VirtualCameraConfiguration; |
Jan Sebechlebsky | 0bb5e09 | 2023-12-08 16:17:54 +0100 | [diff] [blame] | 57 | using ::aidl::android::hardware::camera::common::Status; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 58 | using ::aidl::android::hardware::camera::device::BnCameraDeviceCallback; |
| 59 | using ::aidl::android::hardware::camera::device::BufferRequest; |
| 60 | using ::aidl::android::hardware::camera::device::BufferRequestStatus; |
| 61 | using ::aidl::android::hardware::camera::device::CaptureRequest; |
| 62 | using ::aidl::android::hardware::camera::device::CaptureResult; |
| 63 | using ::aidl::android::hardware::camera::device::HalStream; |
| 64 | using ::aidl::android::hardware::camera::device::NotifyMsg; |
| 65 | using ::aidl::android::hardware::camera::device::Stream; |
| 66 | using ::aidl::android::hardware::camera::device::StreamBuffer; |
| 67 | using ::aidl::android::hardware::camera::device::StreamBufferRet; |
| 68 | using ::aidl::android::hardware::camera::device::StreamConfiguration; |
| 69 | using ::aidl::android::hardware::graphics::common::PixelFormat; |
| 70 | using ::aidl::android::view::Surface; |
| 71 | using ::testing::_; |
| 72 | using ::testing::ElementsAre; |
| 73 | using ::testing::Eq; |
| 74 | using ::testing::Return; |
| 75 | using ::testing::SizeIs; |
| 76 | |
| 77 | Stream createStream(int streamId, int width, int height, PixelFormat format) { |
| 78 | Stream s; |
| 79 | s.id = streamId; |
| 80 | s.width = width; |
| 81 | s.height = height; |
| 82 | s.format = format; |
| 83 | return s; |
| 84 | } |
| 85 | |
| 86 | class MockCameraDeviceCallback : public BnCameraDeviceCallback { |
| 87 | public: |
| 88 | MOCK_METHOD(ndk::ScopedAStatus, notify, (const std::vector<NotifyMsg>&), |
| 89 | (override)); |
| 90 | MOCK_METHOD(ndk::ScopedAStatus, processCaptureResult, |
| 91 | (const std::vector<CaptureResult>&), (override)); |
| 92 | MOCK_METHOD(ndk::ScopedAStatus, requestStreamBuffers, |
| 93 | (const std::vector<BufferRequest>&, std::vector<StreamBufferRet>*, |
| 94 | BufferRequestStatus*), |
| 95 | (override)); |
| 96 | MOCK_METHOD(ndk::ScopedAStatus, returnStreamBuffers, |
| 97 | (const std::vector<StreamBuffer>&), (override)); |
| 98 | }; |
| 99 | |
| 100 | class MockVirtualCameraCallback : public BnVirtualCameraCallback { |
| 101 | public: |
| 102 | MOCK_METHOD(ndk::ScopedAStatus, onStreamConfigured, |
| 103 | (int, const Surface&, int32_t, int32_t, Format), (override)); |
| 104 | MOCK_METHOD(ndk::ScopedAStatus, onProcessCaptureRequest, (int, int), |
| 105 | (override)); |
| 106 | MOCK_METHOD(ndk::ScopedAStatus, onStreamClosed, (int), (override)); |
| 107 | }; |
| 108 | |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame^] | 109 | class VirtualCameraSessionTestBase : public ::testing::Test { |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 110 | public: |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame^] | 111 | virtual void SetUp() override { |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 112 | mMockCameraDeviceCallback = |
| 113 | ndk::SharedRefBase::make<MockCameraDeviceCallback>(); |
| 114 | mMockVirtualCameraClientCallback = |
| 115 | ndk::SharedRefBase::make<MockVirtualCameraCallback>(); |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 116 | |
Jan Sebechlebsky | 85a2aef | 2023-11-29 10:35:55 +0100 | [diff] [blame] | 117 | // Explicitly defining default actions below to prevent gmock from |
| 118 | // default-constructing ndk::ScopedAStatus, because default-constructed |
| 119 | // status wraps nullptr AStatus and causes crash when attempting to print |
| 120 | // it in gtest report. |
| 121 | ON_CALL(*mMockCameraDeviceCallback, notify) |
| 122 | .WillByDefault(ndk::ScopedAStatus::ok); |
| 123 | ON_CALL(*mMockCameraDeviceCallback, processCaptureResult) |
| 124 | .WillByDefault(ndk::ScopedAStatus::ok); |
| 125 | ON_CALL(*mMockCameraDeviceCallback, requestStreamBuffers) |
| 126 | .WillByDefault(ndk::ScopedAStatus::ok); |
| 127 | ON_CALL(*mMockCameraDeviceCallback, returnStreamBuffers) |
| 128 | .WillByDefault(ndk::ScopedAStatus::ok); |
| 129 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 130 | ON_CALL(*mMockVirtualCameraClientCallback, onStreamConfigured) |
| 131 | .WillByDefault(ndk::ScopedAStatus::ok); |
| 132 | ON_CALL(*mMockVirtualCameraClientCallback, onProcessCaptureRequest) |
| 133 | .WillByDefault(ndk::ScopedAStatus::ok); |
Jan Sebechlebsky | 85a2aef | 2023-11-29 10:35:55 +0100 | [diff] [blame] | 134 | ON_CALL(*mMockVirtualCameraClientCallback, onStreamClosed) |
| 135 | .WillByDefault(ndk::ScopedAStatus::ok); |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | protected: |
| 139 | std::shared_ptr<MockCameraDeviceCallback> mMockCameraDeviceCallback; |
| 140 | std::shared_ptr<MockVirtualCameraCallback> mMockVirtualCameraClientCallback; |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame^] | 141 | }; |
| 142 | |
| 143 | class VirtualCameraSessionTest : public VirtualCameraSessionTestBase { |
| 144 | public: |
| 145 | void SetUp() override { |
| 146 | VirtualCameraSessionTestBase::SetUp(); |
| 147 | |
| 148 | mVirtualCameraDevice = ndk::SharedRefBase::make<VirtualCameraDevice>( |
| 149 | kCameraId, |
| 150 | VirtualCameraConfiguration{ |
| 151 | .supportedStreamConfigs = {SupportedStreamConfiguration{ |
| 152 | .width = kVgaWidth, |
| 153 | .height = kVgaHeight, |
| 154 | .pixelFormat = Format::YUV_420_888, |
| 155 | .maxFps = kMaxFps}, |
| 156 | SupportedStreamConfiguration{ |
| 157 | .width = kSvgaWidth, |
| 158 | .height = kSvgaHeight, |
| 159 | .pixelFormat = Format::YUV_420_888, |
| 160 | .maxFps = kMaxFps}}, |
| 161 | .virtualCameraCallback = mMockVirtualCameraClientCallback, |
| 162 | .sensorOrientation = SensorOrientation::ORIENTATION_0, |
| 163 | .lensFacing = LensFacing::FRONT}); |
| 164 | mVirtualCameraSession = ndk::SharedRefBase::make<VirtualCameraSession>( |
| 165 | mVirtualCameraDevice, mMockCameraDeviceCallback, |
| 166 | mMockVirtualCameraClientCallback); |
| 167 | } |
| 168 | |
| 169 | protected: |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 170 | std::shared_ptr<VirtualCameraDevice> mVirtualCameraDevice; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 171 | std::shared_ptr<VirtualCameraSession> mVirtualCameraSession; |
| 172 | }; |
| 173 | |
| 174 | TEST_F(VirtualCameraSessionTest, ConfigureTriggersClientConfigureCallback) { |
| 175 | PixelFormat format = PixelFormat::YCBCR_420_888; |
| 176 | StreamConfiguration streamConfiguration; |
| 177 | streamConfiguration.streams = { |
Jan Sebechlebsky | 39129f8 | 2024-01-19 16:42:11 +0100 | [diff] [blame] | 178 | createStream(kStreamId, kVgaWidth, kVgaHeight, format), |
| 179 | createStream(kSecondStreamId, kSvgaWidth, kSvgaHeight, format)}; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 180 | std::vector<HalStream> halStreams; |
Jan Sebechlebsky | 39129f8 | 2024-01-19 16:42:11 +0100 | [diff] [blame] | 181 | |
| 182 | // Expect highest resolution to be picked for the client input. |
| 183 | EXPECT_CALL(*mMockVirtualCameraClientCallback, |
| 184 | onStreamConfigured(kStreamId, _, kSvgaWidth, kSvgaHeight, |
| 185 | Format::YUV_420_888)); |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 186 | |
| 187 | ASSERT_TRUE( |
| 188 | mVirtualCameraSession->configureStreams(streamConfiguration, &halStreams) |
| 189 | .isOk()); |
| 190 | |
| 191 | EXPECT_THAT(halStreams, SizeIs(streamConfiguration.streams.size())); |
Jan Sebechlebsky | 39129f8 | 2024-01-19 16:42:11 +0100 | [diff] [blame] | 192 | EXPECT_THAT(mVirtualCameraSession->getStreamIds(), |
| 193 | ElementsAre(kStreamId, kSecondStreamId)); |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | TEST_F(VirtualCameraSessionTest, SecondConfigureDropsUnreferencedStreams) { |
| 197 | PixelFormat format = PixelFormat::YCBCR_420_888; |
| 198 | StreamConfiguration streamConfiguration; |
| 199 | std::vector<HalStream> halStreams; |
| 200 | |
Jan Sebechlebsky | 39129f8 | 2024-01-19 16:42:11 +0100 | [diff] [blame] | 201 | streamConfiguration.streams = {createStream(0, kVgaWidth, kVgaHeight, format), |
| 202 | createStream(1, kVgaWidth, kVgaHeight, format), |
| 203 | createStream(2, kVgaWidth, kVgaHeight, format)}; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 204 | ASSERT_TRUE( |
| 205 | mVirtualCameraSession->configureStreams(streamConfiguration, &halStreams) |
| 206 | .isOk()); |
| 207 | |
| 208 | EXPECT_THAT(mVirtualCameraSession->getStreamIds(), ElementsAre(0, 1, 2)); |
| 209 | |
Jan Sebechlebsky | 39129f8 | 2024-01-19 16:42:11 +0100 | [diff] [blame] | 210 | streamConfiguration.streams = {createStream(0, kVgaWidth, kVgaHeight, format), |
| 211 | createStream(2, kVgaWidth, kVgaHeight, format), |
| 212 | createStream(3, kVgaWidth, kVgaHeight, format)}; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 213 | ASSERT_TRUE( |
| 214 | mVirtualCameraSession->configureStreams(streamConfiguration, &halStreams) |
| 215 | .isOk()); |
| 216 | |
| 217 | EXPECT_THAT(mVirtualCameraSession->getStreamIds(), ElementsAre(0, 2, 3)); |
| 218 | } |
| 219 | |
| 220 | TEST_F(VirtualCameraSessionTest, CloseTriggersClientTerminateCallback) { |
| 221 | EXPECT_CALL(*mMockVirtualCameraClientCallback, onStreamClosed(kStreamId)) |
| 222 | .WillOnce(Return(ndk::ScopedAStatus::ok())); |
| 223 | |
| 224 | ASSERT_TRUE(mVirtualCameraSession->close().isOk()); |
| 225 | } |
| 226 | |
Jan Sebechlebsky | b0d8cab | 2023-11-28 10:55:04 +0100 | [diff] [blame] | 227 | TEST_F(VirtualCameraSessionTest, FlushBeforeConfigure) { |
| 228 | // Flush request coming before the configure request finished |
| 229 | // (so potentially the thread is not yet running) should be |
| 230 | // gracefully handled. |
| 231 | |
| 232 | EXPECT_TRUE(mVirtualCameraSession->flush().isOk()); |
| 233 | } |
| 234 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 235 | TEST_F(VirtualCameraSessionTest, onProcessCaptureRequestTriggersClientCallback) { |
| 236 | StreamConfiguration streamConfiguration; |
Jan Sebechlebsky | 39129f8 | 2024-01-19 16:42:11 +0100 | [diff] [blame] | 237 | streamConfiguration.streams = {createStream(kStreamId, kVgaWidth, kVgaHeight, |
| 238 | PixelFormat::YCBCR_420_888)}; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 239 | std::vector<CaptureRequest> requests(1); |
| 240 | requests[0].frameNumber = 42; |
| 241 | requests[0].settings = *( |
| 242 | MetadataBuilder().setControlAfMode(ANDROID_CONTROL_AF_MODE_AUTO).build()); |
| 243 | |
| 244 | std::vector<HalStream> halStreams; |
| 245 | ASSERT_TRUE( |
| 246 | mVirtualCameraSession->configureStreams(streamConfiguration, &halStreams) |
| 247 | .isOk()); |
| 248 | |
| 249 | EXPECT_CALL(*mMockVirtualCameraClientCallback, |
| 250 | onProcessCaptureRequest(kStreamId, requests[0].frameNumber)) |
| 251 | .WillOnce(Return(ndk::ScopedAStatus::ok())); |
| 252 | int32_t aidlReturn = 0; |
| 253 | ASSERT_TRUE(mVirtualCameraSession |
| 254 | ->processCaptureRequest(requests, /*in_cachesToRemove=*/{}, |
| 255 | &aidlReturn) |
| 256 | .isOk()); |
| 257 | EXPECT_THAT(aidlReturn, Eq(requests.size())); |
| 258 | } |
| 259 | |
Jan Sebechlebsky | 0bb5e09 | 2023-12-08 16:17:54 +0100 | [diff] [blame] | 260 | TEST_F(VirtualCameraSessionTest, configureAfterCameraRelease) { |
| 261 | StreamConfiguration streamConfiguration; |
Jan Sebechlebsky | 39129f8 | 2024-01-19 16:42:11 +0100 | [diff] [blame] | 262 | streamConfiguration.streams = {createStream(kStreamId, kVgaWidth, kVgaHeight, |
| 263 | PixelFormat::YCBCR_420_888)}; |
Jan Sebechlebsky | 0bb5e09 | 2023-12-08 16:17:54 +0100 | [diff] [blame] | 264 | std::vector<HalStream> halStreams; |
| 265 | |
| 266 | // Release virtual camera. |
| 267 | mVirtualCameraDevice.reset(); |
| 268 | |
| 269 | // Expect configuration attempt returns CAMERA_DISCONNECTED service specific code. |
| 270 | EXPECT_THAT( |
| 271 | mVirtualCameraSession->configureStreams(streamConfiguration, &halStreams) |
| 272 | .getServiceSpecificError(), |
| 273 | Eq(static_cast<int32_t>(Status::CAMERA_DISCONNECTED))); |
| 274 | } |
| 275 | |
Jan Sebechlebsky | 39129f8 | 2024-01-19 16:42:11 +0100 | [diff] [blame] | 276 | TEST_F(VirtualCameraSessionTest, ConfigureWithEmptyStreams) { |
| 277 | StreamConfiguration streamConfiguration; |
| 278 | std::vector<HalStream> halStreams; |
| 279 | |
| 280 | // Expect configuration attempt returns CAMERA_DISCONNECTED service specific code. |
| 281 | EXPECT_THAT( |
| 282 | mVirtualCameraSession->configureStreams(streamConfiguration, &halStreams) |
| 283 | .getServiceSpecificError(), |
| 284 | Eq(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT))); |
| 285 | } |
| 286 | |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame^] | 287 | TEST_F(VirtualCameraSessionTest, ConfigureWithDifferentAspectRatioFails) { |
| 288 | StreamConfiguration streamConfiguration; |
| 289 | streamConfiguration.streams = { |
| 290 | createStream(kStreamId, kVgaWidth, kVgaHeight, PixelFormat::YCBCR_420_888), |
| 291 | createStream(kSecondStreamId, kVgaHeight, kVgaWidth, |
| 292 | PixelFormat::YCBCR_420_888)}; |
| 293 | |
| 294 | std::vector<HalStream> halStreams; |
| 295 | |
| 296 | // Expect configuration attempt returns CAMERA_DISCONNECTED service specific code. |
| 297 | EXPECT_THAT( |
| 298 | mVirtualCameraSession->configureStreams(streamConfiguration, &halStreams) |
| 299 | .getServiceSpecificError(), |
| 300 | Eq(static_cast<int32_t>(Status::ILLEGAL_ARGUMENT))); |
| 301 | } |
| 302 | |
| 303 | class VirtualCameraSessionInputChoiceTest : public VirtualCameraSessionTestBase { |
| 304 | public: |
| 305 | std::shared_ptr<VirtualCameraSession> createSession( |
| 306 | const std::vector<SupportedStreamConfiguration>& supportedInputConfigs) { |
| 307 | mVirtualCameraDevice = ndk::SharedRefBase::make<VirtualCameraDevice>( |
| 308 | kCameraId, VirtualCameraConfiguration{ |
| 309 | .supportedStreamConfigs = supportedInputConfigs, |
| 310 | .virtualCameraCallback = mMockVirtualCameraClientCallback, |
| 311 | .sensorOrientation = SensorOrientation::ORIENTATION_0, |
| 312 | .lensFacing = LensFacing::FRONT}); |
| 313 | return ndk::SharedRefBase::make<VirtualCameraSession>( |
| 314 | mVirtualCameraDevice, mMockCameraDeviceCallback, |
| 315 | mMockVirtualCameraClientCallback); |
| 316 | } |
| 317 | |
| 318 | protected: |
| 319 | std::shared_ptr<VirtualCameraDevice> mVirtualCameraDevice; |
| 320 | }; |
| 321 | |
| 322 | TEST_F(VirtualCameraSessionInputChoiceTest, |
| 323 | configureChoosesCorrectInputStreamForDownsampledOutput) { |
| 324 | // Create camera configured to support SVGA YUV input and RGB QVGA input. |
| 325 | auto virtualCameraSession = createSession( |
| 326 | {SupportedStreamConfiguration{.width = kSvgaWidth, |
| 327 | .height = kSvgaHeight, |
| 328 | .pixelFormat = Format::YUV_420_888, |
| 329 | .maxFps = kMaxFps}, |
| 330 | SupportedStreamConfiguration{.width = kQvgaWidth, |
| 331 | .height = kQvgaHeight, |
| 332 | .pixelFormat = Format::RGBA_8888, |
| 333 | .maxFps = kMaxFps}}); |
| 334 | |
| 335 | // Configure VGA stream. Expect SVGA input to be chosen to downscale from. |
| 336 | StreamConfiguration streamConfiguration; |
| 337 | streamConfiguration.streams = {createStream( |
| 338 | kStreamId, kVgaWidth, kVgaHeight, PixelFormat::IMPLEMENTATION_DEFINED)}; |
| 339 | std::vector<HalStream> halStreams; |
| 340 | |
| 341 | // Expect configuration attempt returns CAMERA_DISCONNECTED service specific code. |
| 342 | EXPECT_CALL(*mMockVirtualCameraClientCallback, |
| 343 | onStreamConfigured(kStreamId, _, kSvgaWidth, kSvgaHeight, |
| 344 | Format::YUV_420_888)); |
| 345 | EXPECT_TRUE( |
| 346 | virtualCameraSession->configureStreams(streamConfiguration, &halStreams) |
| 347 | .isOk()); |
| 348 | } |
| 349 | |
| 350 | TEST_F(VirtualCameraSessionInputChoiceTest, |
| 351 | configureChoosesCorrectInputStreamForMatchingResolution) { |
| 352 | // Create camera configured to support SVGA YUV input and RGB QVGA input. |
| 353 | auto virtualCameraSession = createSession( |
| 354 | {SupportedStreamConfiguration{.width = kSvgaWidth, |
| 355 | .height = kSvgaHeight, |
| 356 | .pixelFormat = Format::YUV_420_888, |
| 357 | .maxFps = kMaxFps}, |
| 358 | SupportedStreamConfiguration{.width = kQvgaWidth, |
| 359 | .height = kQvgaHeight, |
| 360 | .pixelFormat = Format::RGBA_8888, |
| 361 | .maxFps = kMaxFps}}); |
| 362 | |
| 363 | // Configure VGA stream. Expect SVGA input to be chosen to downscale from. |
| 364 | StreamConfiguration streamConfiguration; |
| 365 | streamConfiguration.streams = {createStream( |
| 366 | kStreamId, kQvgaWidth, kQvgaHeight, PixelFormat::IMPLEMENTATION_DEFINED)}; |
| 367 | std::vector<HalStream> halStreams; |
| 368 | |
| 369 | // Expect configuration attempt returns CAMERA_DISCONNECTED service specific code. |
| 370 | EXPECT_CALL(*mMockVirtualCameraClientCallback, |
| 371 | onStreamConfigured(kStreamId, _, kQvgaWidth, kQvgaHeight, |
| 372 | Format::RGBA_8888)); |
| 373 | EXPECT_TRUE( |
| 374 | virtualCameraSession->configureStreams(streamConfiguration, &halStreams) |
| 375 | .isOk()); |
| 376 | } |
| 377 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 378 | } // namespace |
| 379 | } // namespace virtualcamera |
| 380 | } // namespace companion |
| 381 | } // namespace android |