Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +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 | 3b478c4 | 2023-11-23 13:15:56 +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 | |
Jan Sebechlebsky | 8ae2359 | 2024-02-02 16:08:18 +0100 | [diff] [blame] | 17 | #include <algorithm> |
| 18 | #include <iterator> |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 19 | #include <memory> |
| 20 | |
| 21 | #include "VirtualCameraDevice.h" |
| 22 | #include "aidl/android/companion/virtualcamera/Format.h" |
| 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 | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 25 | #include "aidl/android/hardware/camera/device/CameraMetadata.h" |
| 26 | #include "aidl/android/hardware/camera/device/StreamConfiguration.h" |
Jan Sebechlebsky | 8ae2359 | 2024-02-02 16:08:18 +0100 | [diff] [blame] | 27 | #include "aidl/android/hardware/graphics/common/PixelFormat.h" |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 28 | #include "android/binder_interface_utils.h" |
| 29 | #include "gmock/gmock.h" |
| 30 | #include "gtest/gtest.h" |
| 31 | #include "log/log_main.h" |
| 32 | #include "system/camera_metadata.h" |
Jan Sebechlebsky | 4ce3208 | 2024-02-14 16:02:11 +0100 | [diff] [blame] | 33 | #include "util/MetadataUtil.h" |
| 34 | #include "util/Util.h" |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 35 | #include "utils/Errors.h" |
| 36 | |
| 37 | namespace android { |
| 38 | namespace companion { |
| 39 | namespace virtualcamera { |
| 40 | namespace { |
| 41 | |
| 42 | using ::aidl::android::companion::virtualcamera::Format; |
Biswarup Pal | 112458f | 2023-12-28 19:50:17 +0000 | [diff] [blame] | 43 | using ::aidl::android::companion::virtualcamera::LensFacing; |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 44 | using ::aidl::android::companion::virtualcamera::SensorOrientation; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 45 | using ::aidl::android::companion::virtualcamera::SupportedStreamConfiguration; |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 46 | using ::aidl::android::companion::virtualcamera::VirtualCameraConfiguration; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 47 | using ::aidl::android::hardware::camera::device::CameraMetadata; |
| 48 | using ::aidl::android::hardware::camera::device::Stream; |
| 49 | using ::aidl::android::hardware::camera::device::StreamConfiguration; |
| 50 | using ::aidl::android::hardware::camera::device::StreamType; |
| 51 | using ::aidl::android::hardware::graphics::common::PixelFormat; |
Jan Sebechlebsky | 4ce3208 | 2024-02-14 16:02:11 +0100 | [diff] [blame] | 52 | using ::testing::ElementsAre; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 53 | using ::testing::UnorderedElementsAreArray; |
| 54 | using metadata_stream_t = |
| 55 | camera_metadata_enum_android_scaler_available_stream_configurations_t; |
| 56 | |
| 57 | constexpr int kCameraId = 42; |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame^] | 58 | constexpr int kQvgaWidth = 320; |
| 59 | constexpr int kQvgaHeight = 240; |
| 60 | constexpr int k360pWidth = 640; |
| 61 | constexpr int k360pHeight = 360; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 62 | constexpr int kVgaWidth = 640; |
| 63 | constexpr int kVgaHeight = 480; |
| 64 | constexpr int kHdWidth = 1280; |
| 65 | constexpr int kHdHeight = 720; |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 66 | constexpr int kMaxFps = 30; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 67 | |
Jan Sebechlebsky | 8ae2359 | 2024-02-02 16:08:18 +0100 | [diff] [blame] | 68 | const Stream kVgaYUV420Stream = Stream{ |
| 69 | .streamType = StreamType::OUTPUT, |
| 70 | .width = kVgaWidth, |
| 71 | .height = kVgaHeight, |
| 72 | .format = PixelFormat::YCBCR_420_888, |
| 73 | }; |
| 74 | |
| 75 | const Stream kVgaJpegStream = Stream{ |
| 76 | .streamType = StreamType::OUTPUT, |
| 77 | .width = kVgaWidth, |
| 78 | .height = kVgaHeight, |
| 79 | .format = PixelFormat::BLOB, |
| 80 | }; |
| 81 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 82 | struct AvailableStreamConfiguration { |
| 83 | const int width; |
| 84 | const int height; |
| 85 | const int pixelFormat; |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame^] | 86 | const metadata_stream_t streamConfiguration = |
| 87 | ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | bool operator==(const AvailableStreamConfiguration& a, |
| 91 | const AvailableStreamConfiguration& b) { |
| 92 | return a.width == b.width && a.height == b.height && |
| 93 | a.pixelFormat == b.pixelFormat && |
| 94 | a.streamConfiguration == b.streamConfiguration; |
| 95 | } |
| 96 | |
| 97 | std::ostream& operator<<(std::ostream& os, |
| 98 | const AvailableStreamConfiguration& config) { |
| 99 | os << config.width << "x" << config.height << " (pixfmt " |
| 100 | << config.pixelFormat << ", streamConfiguration " |
| 101 | << config.streamConfiguration << ")"; |
| 102 | return os; |
| 103 | } |
| 104 | |
| 105 | std::vector<AvailableStreamConfiguration> getAvailableStreamConfigurations( |
| 106 | const CameraMetadata& metadata) { |
| 107 | const camera_metadata_t* const raw = |
| 108 | reinterpret_cast<const camera_metadata_t*>(metadata.metadata.data()); |
| 109 | camera_metadata_ro_entry_t entry; |
| 110 | if (find_camera_metadata_ro_entry( |
| 111 | raw, ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, &entry) != |
| 112 | NO_ERROR) { |
| 113 | return {}; |
| 114 | } |
| 115 | |
| 116 | std::vector<AvailableStreamConfiguration> res; |
| 117 | for (int i = 0; i < entry.count; i += 4) { |
| 118 | res.push_back(AvailableStreamConfiguration{ |
| 119 | .width = entry.data.i32[i + 1], |
| 120 | .height = entry.data.i32[i + 2], |
| 121 | .pixelFormat = entry.data.i32[i], |
| 122 | .streamConfiguration = |
| 123 | static_cast<metadata_stream_t>(entry.data.i32[i + 3])}); |
| 124 | } |
| 125 | return res; |
| 126 | } |
| 127 | |
| 128 | struct VirtualCameraConfigTestParam { |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 129 | VirtualCameraConfiguration inputConfig; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 130 | std::vector<AvailableStreamConfiguration> expectedAvailableStreamConfigs; |
| 131 | }; |
| 132 | |
Jan Sebechlebsky | 8ae2359 | 2024-02-02 16:08:18 +0100 | [diff] [blame] | 133 | class VirtualCameraDeviceCharacterisicsTest |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 134 | : public testing::TestWithParam<VirtualCameraConfigTestParam> {}; |
| 135 | |
Jan Sebechlebsky | 8ae2359 | 2024-02-02 16:08:18 +0100 | [diff] [blame] | 136 | TEST_P(VirtualCameraDeviceCharacterisicsTest, |
| 137 | cameraCharacteristicsForInputFormat) { |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 138 | const VirtualCameraConfigTestParam& param = GetParam(); |
| 139 | std::shared_ptr<VirtualCameraDevice> camera = |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 140 | ndk::SharedRefBase::make<VirtualCameraDevice>(kCameraId, |
| 141 | param.inputConfig); |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 142 | |
| 143 | CameraMetadata metadata; |
| 144 | ASSERT_TRUE(camera->getCameraCharacteristics(&metadata).isOk()); |
| 145 | EXPECT_THAT(getAvailableStreamConfigurations(metadata), |
| 146 | UnorderedElementsAreArray(param.expectedAvailableStreamConfigs)); |
| 147 | |
| 148 | // Configuration needs to succeed for every available stream configuration |
| 149 | for (const AvailableStreamConfiguration& config : |
| 150 | param.expectedAvailableStreamConfigs) { |
| 151 | StreamConfiguration configuration{ |
| 152 | .streams = std::vector<Stream>{Stream{ |
| 153 | .streamType = StreamType::OUTPUT, |
| 154 | .width = config.width, |
| 155 | .height = config.height, |
| 156 | .format = static_cast<PixelFormat>(config.pixelFormat), |
| 157 | }}}; |
| 158 | bool aidl_ret; |
| 159 | ASSERT_TRUE( |
| 160 | camera->isStreamCombinationSupported(configuration, &aidl_ret).isOk()); |
| 161 | EXPECT_TRUE(aidl_ret); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | INSTANTIATE_TEST_SUITE_P( |
Jan Sebechlebsky | 8ae2359 | 2024-02-02 16:08:18 +0100 | [diff] [blame] | 166 | cameraCharacteristicsForInputFormat, VirtualCameraDeviceCharacterisicsTest, |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 167 | testing::Values( |
| 168 | VirtualCameraConfigTestParam{ |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 169 | .inputConfig = |
| 170 | VirtualCameraConfiguration{ |
| 171 | .supportedStreamConfigs = {SupportedStreamConfiguration{ |
| 172 | .width = kVgaWidth, |
| 173 | .height = kVgaHeight, |
| 174 | .pixelFormat = Format::YUV_420_888, |
| 175 | .maxFps = kMaxFps}}, |
| 176 | .virtualCameraCallback = nullptr, |
Biswarup Pal | 112458f | 2023-12-28 19:50:17 +0000 | [diff] [blame] | 177 | .sensorOrientation = SensorOrientation::ORIENTATION_0, |
| 178 | .lensFacing = LensFacing::FRONT}, |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 179 | .expectedAvailableStreamConfigs = |
| 180 | {AvailableStreamConfiguration{ |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame^] | 181 | .width = kQvgaWidth, |
| 182 | .height = kQvgaHeight, |
| 183 | .pixelFormat = |
| 184 | ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888}, |
| 185 | AvailableStreamConfiguration{ |
| 186 | .width = kQvgaWidth, |
| 187 | .height = kQvgaHeight, |
| 188 | .pixelFormat = |
| 189 | ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED}, |
| 190 | AvailableStreamConfiguration{ |
| 191 | .width = kQvgaWidth, |
| 192 | .height = kQvgaHeight, |
| 193 | .pixelFormat = ANDROID_SCALER_AVAILABLE_FORMATS_BLOB}, |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 194 | AvailableStreamConfiguration{ |
| 195 | .width = kVgaWidth, |
| 196 | .height = kVgaHeight, |
| 197 | .pixelFormat = |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame^] | 198 | ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888}, |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 199 | AvailableStreamConfiguration{ |
| 200 | .width = kVgaWidth, |
| 201 | .height = kVgaHeight, |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame^] | 202 | .pixelFormat = |
| 203 | ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED}, |
| 204 | AvailableStreamConfiguration{ |
| 205 | .width = kVgaWidth, |
| 206 | .height = kVgaHeight, |
| 207 | .pixelFormat = ANDROID_SCALER_AVAILABLE_FORMATS_BLOB}}}, |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 208 | VirtualCameraConfigTestParam{ |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 209 | .inputConfig = |
| 210 | VirtualCameraConfiguration{ |
| 211 | .supportedStreamConfigs = |
| 212 | {SupportedStreamConfiguration{ |
| 213 | .width = kVgaWidth, |
| 214 | .height = kVgaHeight, |
| 215 | .pixelFormat = Format::YUV_420_888, |
| 216 | .maxFps = kMaxFps}, |
| 217 | SupportedStreamConfiguration{ |
| 218 | .width = kHdWidth, |
| 219 | .height = kHdHeight, |
| 220 | .pixelFormat = Format::YUV_420_888, |
| 221 | .maxFps = kMaxFps}}, |
| 222 | .virtualCameraCallback = nullptr, |
Biswarup Pal | 112458f | 2023-12-28 19:50:17 +0000 | [diff] [blame] | 223 | .sensorOrientation = SensorOrientation::ORIENTATION_0, |
| 224 | .lensFacing = LensFacing::BACK}, |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 225 | .expectedAvailableStreamConfigs = { |
| 226 | AvailableStreamConfiguration{ |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame^] | 227 | .width = kQvgaWidth, |
| 228 | .height = kQvgaHeight, |
| 229 | .pixelFormat = ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888}, |
| 230 | AvailableStreamConfiguration{ |
| 231 | .width = kQvgaWidth, |
| 232 | .height = kQvgaHeight, |
| 233 | .pixelFormat = |
| 234 | ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED}, |
| 235 | AvailableStreamConfiguration{ |
| 236 | .width = kQvgaWidth, |
| 237 | .height = kQvgaHeight, |
| 238 | .pixelFormat = ANDROID_SCALER_AVAILABLE_FORMATS_BLOB}, |
| 239 | AvailableStreamConfiguration{ |
| 240 | .width = 640, |
| 241 | .height = 360, |
| 242 | .pixelFormat = ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888}, |
| 243 | AvailableStreamConfiguration{ |
| 244 | .width = 640, |
| 245 | .height = 360, |
| 246 | .pixelFormat = |
| 247 | ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED}, |
| 248 | AvailableStreamConfiguration{ |
| 249 | .width = 640, |
| 250 | .height = 360, |
| 251 | .pixelFormat = ANDROID_SCALER_AVAILABLE_FORMATS_BLOB}, |
| 252 | AvailableStreamConfiguration{ |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 253 | .width = kVgaWidth, |
| 254 | .height = kVgaHeight, |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame^] | 255 | .pixelFormat = ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888}, |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 256 | AvailableStreamConfiguration{ |
| 257 | .width = kVgaWidth, |
| 258 | .height = kVgaHeight, |
| 259 | .pixelFormat = |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame^] | 260 | ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED}, |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 261 | AvailableStreamConfiguration{ |
| 262 | .width = kVgaWidth, |
| 263 | .height = kVgaHeight, |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame^] | 264 | .pixelFormat = ANDROID_SCALER_AVAILABLE_FORMATS_BLOB}, |
| 265 | AvailableStreamConfiguration{ |
| 266 | .width = 1024, |
| 267 | .height = 576, |
| 268 | .pixelFormat = ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888}, |
| 269 | AvailableStreamConfiguration{ |
| 270 | .width = 1024, |
| 271 | .height = 576, |
| 272 | .pixelFormat = |
| 273 | ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED}, |
| 274 | AvailableStreamConfiguration{ |
| 275 | .width = 1024, |
| 276 | .height = 576, |
| 277 | .pixelFormat = ANDROID_SCALER_AVAILABLE_FORMATS_BLOB}, |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 278 | AvailableStreamConfiguration{ |
| 279 | .width = kHdWidth, |
| 280 | .height = kHdHeight, |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame^] | 281 | .pixelFormat = ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888}, |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 282 | AvailableStreamConfiguration{ |
| 283 | .width = kHdWidth, |
| 284 | .height = kHdHeight, |
| 285 | .pixelFormat = |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame^] | 286 | ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED}, |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 287 | AvailableStreamConfiguration{ |
| 288 | .width = kHdWidth, |
| 289 | .height = kHdHeight, |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame^] | 290 | .pixelFormat = ANDROID_SCALER_AVAILABLE_FORMATS_BLOB}}})); |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 291 | |
Jan Sebechlebsky | 8ae2359 | 2024-02-02 16:08:18 +0100 | [diff] [blame] | 292 | class VirtualCameraDeviceTest : public ::testing::Test { |
| 293 | public: |
| 294 | void SetUp() override { |
| 295 | mCamera = ndk::SharedRefBase::make<VirtualCameraDevice>( |
| 296 | kCameraId, VirtualCameraConfiguration{ |
| 297 | .supportedStreamConfigs = {SupportedStreamConfiguration{ |
| 298 | .width = kVgaWidth, |
| 299 | .height = kVgaHeight, |
| 300 | .pixelFormat = Format::YUV_420_888, |
| 301 | .maxFps = kMaxFps}}, |
| 302 | .virtualCameraCallback = nullptr, |
| 303 | .sensorOrientation = SensorOrientation::ORIENTATION_0, |
| 304 | .lensFacing = LensFacing::FRONT}); |
| 305 | } |
| 306 | |
| 307 | protected: |
| 308 | std::shared_ptr<VirtualCameraDevice> mCamera; |
| 309 | }; |
| 310 | |
| 311 | TEST_F(VirtualCameraDeviceTest, configureMaximalNumberOfNonStallStreamsSuceeds) { |
| 312 | StreamConfiguration config; |
| 313 | std::fill_n(std::back_insert_iterator(config.streams), |
| 314 | VirtualCameraDevice::kMaxNumberOfProcessedStreams, |
| 315 | kVgaYUV420Stream); |
| 316 | |
| 317 | bool aidl_ret; |
| 318 | ASSERT_TRUE(mCamera->isStreamCombinationSupported(config, &aidl_ret).isOk()); |
| 319 | EXPECT_TRUE(aidl_ret); |
| 320 | } |
| 321 | |
| 322 | TEST_F(VirtualCameraDeviceTest, configureTooManyNonStallStreamsFails) { |
| 323 | StreamConfiguration config; |
| 324 | std::fill_n(std::back_insert_iterator(config.streams), |
| 325 | VirtualCameraDevice::kMaxNumberOfProcessedStreams + 1, |
| 326 | kVgaYUV420Stream); |
| 327 | |
| 328 | bool aidl_ret; |
| 329 | ASSERT_TRUE(mCamera->isStreamCombinationSupported(config, &aidl_ret).isOk()); |
| 330 | EXPECT_FALSE(aidl_ret); |
| 331 | } |
| 332 | |
| 333 | TEST_F(VirtualCameraDeviceTest, configureMaximalNumberOfStallStreamsSuceeds) { |
| 334 | StreamConfiguration config; |
| 335 | std::fill_n(std::back_insert_iterator(config.streams), |
| 336 | VirtualCameraDevice::kMaxNumberOfStallStreams, kVgaJpegStream); |
| 337 | |
| 338 | bool aidl_ret; |
| 339 | ASSERT_TRUE(mCamera->isStreamCombinationSupported(config, &aidl_ret).isOk()); |
| 340 | EXPECT_TRUE(aidl_ret); |
| 341 | } |
| 342 | |
| 343 | TEST_F(VirtualCameraDeviceTest, configureTooManyStallStreamsFails) { |
| 344 | StreamConfiguration config; |
| 345 | std::fill_n(std::back_insert_iterator(config.streams), |
| 346 | VirtualCameraDevice::kMaxNumberOfStallStreams + 1, kVgaJpegStream); |
| 347 | |
| 348 | bool aidl_ret; |
| 349 | ASSERT_TRUE(mCamera->isStreamCombinationSupported(config, &aidl_ret).isOk()); |
| 350 | EXPECT_FALSE(aidl_ret); |
| 351 | } |
| 352 | |
Jan Sebechlebsky | 4ce3208 | 2024-02-14 16:02:11 +0100 | [diff] [blame] | 353 | TEST_F(VirtualCameraDeviceTest, thumbnailSizeWithCompatibleAspectRatio) { |
| 354 | CameraMetadata metadata; |
| 355 | ASSERT_TRUE(mCamera->getCameraCharacteristics(&metadata).isOk()); |
| 356 | |
| 357 | // Camera is configured with VGA input, we expect 240 x 180 thumbnail size in |
| 358 | // characteristics, since it has same aspect ratio. |
| 359 | EXPECT_THAT(getJpegAvailableThumbnailSizes(metadata), |
| 360 | ElementsAre(Resolution(0, 0), Resolution(240, 180))); |
| 361 | } |
| 362 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 363 | } // namespace |
| 364 | } // namespace virtualcamera |
| 365 | } // namespace companion |
| 366 | } // namespace android |