1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file expected in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15#include "capture_test.h" 16 17using namespace OHOS; 18using namespace std; 19using namespace testing::ext; 20using namespace OHOS::Camera; 21 22void CaptureTest::SetUpTestCase(void) {} 23void CaptureTest::TearDownTestCase(void) {} 24void CaptureTest::SetUp(void) 25{ 26 Test_ = std::make_shared<OHOS::Camera::Test>(); 27 Test_->Init(); 28 Test_->Open(); 29} 30void CaptureTest::TearDown(void) 31{ 32 Test_->Close(); 33} 34 35/** 36 * @tc.name: preview and capture 37 * @tc.desc: Preview and still_capture streams, Commit 2 streams together, capture in order, isStreaming is true. 38 * @tc.size: MediumTest 39 * @tc.type: Function 40 */ 41HWTEST_F(CaptureTest, Camera_Capture_0001, TestSize.Level0) 42{ 43 std::cout << "==========[test log]check Capture: Preview and still_capture streams."; 44 std::cout << " Commit 2 streams together, capture in order, isStreaming is true." << std::endl; 45 // Configure two streams of information 46 Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE}; 47 Test_->StartStream(Test_->intents); 48 // Capture preview stream 49 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 50 // Capture the photo stream, continuous capture 51 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true); 52 // post-processing 53 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture}; 54 Test_->streamIds.push_back(Test_->streamId_preview); 55 Test_->streamIds.push_back(Test_->streamId_capture); 56 Test_->StopStream(Test_->captureIds, Test_->streamIds); 57} 58 59/** 60 * @tc.name: preview and capture 61 * @tc.desc: Preview + capture, then cloase camera, and preview + capture again. 62 * @tc.size: MediumTest 63 * @tc.type: Function 64 */ 65HWTEST_F(CaptureTest, Camera_Capture_0002, TestSize.Level2) 66{ 67 std::cout << "==========[test log]Preview + capture, cloase camera, and preview + capture." << std::endl; 68 // Configure two streams of information 69 Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE}; 70 Test_->StartStream(Test_->intents); 71 // Capture preview stream 72 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 73 // Capture the photo stream, continuous capture 74 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true); 75 // post-processing 76 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture}; 77 Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture}; 78 Test_->StopStream(Test_->captureIds, Test_->streamIds); 79 Test_->consumerMap_.clear(); 80 // the 2nd time configures two streams of information 81 Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE}; 82 Test_->StartStream(Test_->intents); 83 // Capture preview stream 84 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 85 // Capture the photo stream, continuous capture 86 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true); 87 // post-processing 88 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture}; 89 Test_->streamIds.push_back(Test_->streamId_preview); 90 Test_->streamIds.push_back(Test_->streamId_capture); 91 Test_->StopStream(Test_->captureIds, Test_->streamIds); 92} 93 94/** 95 * @tc.name: preview and capture 96 * @tc.desc: Preview and still_capture streams + 3A, Commit 2 streams together, capture in order, isStreaming is true. 97 * @tc.size: MediumTest 98 * @tc.type: Function 99 */ 100HWTEST_F(CaptureTest, Camera_Capture_0003, TestSize.Level1) 101{ 102 std::cout << "==========[test log]check Capture: Preview and still_capture streams + 3A,"; 103 std::cout << "Commit 2 streams together, capture in order, isStreaming is true." << std::endl; 104 // Configure two streams of information 105 Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE}; 106 Test_->StartStream(Test_->intents); 107 // Capture preview stream 108 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 109 // Issue 3A parameters to increase exposure 110 int32_t expo = 0xa0; 111 std::shared_ptr<Camera::CameraSetting> meta = std::make_shared<Camera::CameraSetting>(100, 2000); 112 meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1); 113 Test_->rc = Test_->cameraDevice->UpdateSettings(meta); 114 if (Test_->rc == Camera::NO_ERROR) { 115 std::cout << "==========[test log]check Capture: UpdateSettings success, for 10s." << std::endl; 116 } else { 117 std::cout << "==========[test log]check Capture: UpdateSettings fail, rc = " << Test_->rc << std::endl; 118 } 119 sleep(3); // sleep for 3 seconds 120 // Capture the photo stream, continuous capture 121 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true); 122 // post-processing 123 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture}; 124 Test_->streamIds.push_back(Test_->streamId_preview); 125 Test_->streamIds.push_back(Test_->streamId_capture); 126 Test_->StopStream(Test_->captureIds, Test_->streamIds); 127} 128 129/** 130 * @tc.name: preview and capture 131 * @tc.desc: Preview + capture, then switch to preview + video. 132 * @tc.size: MediumTest 133 * @tc.type: Function 134 */ 135HWTEST_F(CaptureTest, Camera_Capture_0004, TestSize.Level1) 136{ 137 std::cout << "==========[test log]check Capture: Preview + capture, then switch to preview + video." << std::endl; 138 std::cout << "==========[test log]check Capture: First, create preview + capture." << std::endl; 139 // Configure two streams of information 140 Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE}; 141 Test_->StartStream(Test_->intents); 142 // Capture preview stream 143 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 144 // Capture the photo stream, continuous capture 145 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true); 146 // post-processing 147 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture}; 148 Test_->streamIds.push_back(Test_->streamId_preview); 149 Test_->streamIds.push_back(Test_->streamId_capture); 150 Test_->StopStream(Test_->captureIds, Test_->streamIds); 151 Test_->consumerMap_.clear(); 152 std::cout << "==========[test log]check Capture: Next, switch to preview + video." << Test_->rc << std::endl; 153 // Configure two streams of information 154 Test_->intents = {Camera::PREVIEW, Camera::VIDEO}; 155 Test_->StartStream(Test_->intents); 156 // Capture preview stream 157 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 158 // Capture video stream 159 Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true); 160 // post-processing 161 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video}; 162 Test_->streamIds.push_back(Test_->streamId_preview); 163 Test_->streamIds.push_back(Test_->streamId_video); 164 Test_->StopStream(Test_->captureIds, Test_->streamIds); 165} 166 167/** 168 * @tc.name: video cannot capture 169 * @tc.desc: Preview + video, then capture a photo, expected not support. 170 * @tc.size: MediumTest 171 * @tc.type: Function 172 */ 173HWTEST_F(CaptureTest, Camera_Capture_0005, TestSize.Level2) 174{ 175 std::cout << "==========[test log]check Capture: Preview + video, then capture a photo." << std::endl; 176 std::cout << "==========[test log]check Capture: First, create Preview + video." << std::endl; 177 // Configure two streams of information 178 Test_->intents = {Camera::PREVIEW, Camera::VIDEO}; 179 Test_->StartStream(Test_->intents); 180 // Capture preview stream 181 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 182 // Capture video stream 183 Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true); 184 185 // Start the capture stream 186 std::shared_ptr<Camera::StreamInfo> streamInfo_capture = std::make_shared<Camera::StreamInfo>(); 187 streamInfo_capture->streamId_ = Test_->streamId_capture; 188 streamInfo_capture->width_ = 640; 189 streamInfo_capture->height_ = 480; 190#ifdef CAMERA_BUILT_ON_OHOS_LITE 191 streamInfo_capture->format_ = IMAGE_PIXEL_FORMAT_NV21; 192#else 193 streamInfo_capture->format_ = PIXEL_FMT_YCRCB_420_SP; 194#endif 195 streamInfo_capture->dataspace_ = 8; 196 streamInfo_capture->intent_ = Camera::STILL_CAPTURE; 197 streamInfo_capture->tunneledMode_ = 5; 198 std::shared_ptr<OHOS::Camera::Test::StreamConsumer> capture_consumer = 199 std::make_shared<OHOS::Camera::Test::StreamConsumer>(); 200#ifdef CAMERA_BUILT_ON_OHOS_LITE 201 streamInfo_capture->bufferQueue_ = capture_consumer->CreateProducer([this](OHOS::SurfaceBuffer* buffer) { 202 Test_->SaveYUV("capture", buffer->GetVirAddr(), buffer->GetSize()); 203 }); 204#else 205 streamInfo_capture->bufferQueue_ = capture_consumer->CreateProducer([this](void* addr, uint32_t size) { 206 Test_->SaveYUV("capture", addr, size); 207 }); 208#endif 209 streamInfo_capture->bufferQueue_->SetQueueSize(8); 210 Test_->consumerMap_[Camera::STILL_CAPTURE] = capture_consumer; 211 // Query whether the IsStreamsSupported interface supports 212 Camera::StreamSupportType pType; 213 std::shared_ptr<CameraMetadata> modeSetting = 214 std::make_shared<CameraMetadata>(2, 128); 215 int64_t expoTime = 0; 216 modeSetting->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1); 217 int64_t colorGains[4] = {0}; 218 modeSetting->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4); 219 std::vector<std::shared_ptr<Camera::StreamInfo>> stre; 220 stre.push_back(streamInfo_capture); 221 Test_->rc = Test_->streamOperator->IsStreamsSupported(Camera::NORMAL, modeSetting, stre, pType); 222 EXPECT_EQ(Test_->rc, Camera::NO_ERROR); 223 std::cout << "ptype = " << pType << std::endl; 224 EXPECT_EQ(true, pType == Camera::RE_CONFIGURED_REQUIRED); 225 // post-processing 226 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video}; 227 Test_->streamIds.push_back(Test_->streamId_preview); 228 Test_->streamIds.push_back(Test_->streamId_video); 229 Test_->StopStream(Test_->captureIds, Test_->streamIds); 230} 231 232/** 233 * @tc.name: preview and capture 234 * @tc.desc: Commit 2 streams together, Preview and still_capture streams, isStreaming is false. 235 * @tc.size: MediumTest 236 * @tc.type: Function 237 */ 238HWTEST_F(CaptureTest, Camera_Capture_0006, TestSize.Level0) 239{ 240 std::cout << "==========[test log]check Capture: Commit 2 streams together,"; 241 std::cout << "Preview and still_capture streams, isStreaming is false." << std::endl; 242 // Configure two streams of information 243 Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE}; 244 Test_->StartStream(Test_->intents); 245 // Capture preview stream 246 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 247 // Capture the photo stream, single capture 248 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, false); 249 // post-processing 250 Test_->captureIds = {Test_->captureId_preview}; 251 Test_->streamIds.push_back(Test_->streamId_preview); 252 Test_->streamIds.push_back(Test_->streamId_capture); 253 Test_->StopStream(Test_->captureIds, Test_->streamIds); 254} 255 256/** 257 * @tc.name: preview and capture 258 * @tc.desc: Commit 2 streams together, Preview and still_capture streams, isStreaming is false, 259 * Do not stop the stream, multiple single capture 260 * @tc.size: MediumTest 261 * @tc.type: Function 262 */ 263HWTEST_F(CaptureTest, Camera_Capture_0007, TestSize.Level0) 264{ 265 std::cout << "==========[test log]check Capture: Commit 2 streams together,"; 266 std::cout << "Preview and still_capture streams, isStreaming is false, multiple single capture" << std::endl; 267 // Configure two streams of information 268 Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE}; 269 Test_->StartStream(Test_->intents); 270 // Capture preview stream 271 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 272 // Capture the photo stream, multiple single capture 273 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, false); 274 sleep(1); 275 Test_->StartCapture(Test_->streamId_capture, (Test_->captureId_capture) + 1, false, false); 276 sleep(1); 277 Test_->StartCapture(Test_->streamId_capture, (Test_->captureId_capture) + 2, false, false); 278 // post-processing 279 Test_->captureIds = {Test_->captureId_preview}; 280 Test_->streamIds.push_back(Test_->streamId_preview); 281 Test_->streamIds.push_back(Test_->streamId_capture); 282 Test_->StopStream(Test_->captureIds, Test_->streamIds); 283} 284 285/** 286 * @tc.name: preview and capture 287 * @tc.desc: Commit 2 streams in order, Preview and still_capture streams. 288 * @tc.size: MediumTest 289 * @tc.type: Function 290 */ 291HWTEST_F(CaptureTest, Camera_Capture_0010, TestSize.Level1) 292{ 293 std::cout << "==========[test log]Commit 2 streams in order, Preview and still_capture." << std::endl; 294 // start preview stream 295 Test_->intents = {Camera::PREVIEW}; 296 Test_->StartStream(Test_->intents); 297 // Get preview 298 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 299 // start stream 300 Test_->intents = {Camera::STILL_CAPTURE}; 301 Test_->StartStream(Test_->intents); 302 // Start capture 303 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 304 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true); 305 // release stream 306 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture}; 307 Test_->streamIds.push_back(Test_->streamId_preview); 308 Test_->streamIds.push_back(Test_->streamId_capture); 309 Test_->StopStream(Test_->captureIds, Test_->streamIds); 310} 311 312/** 313 * @tc.name: preview and capture 314 * @tc.desc: Preview and still_capture streams, Commit 2 streams together, capture together, isStreaming is true. 315 * @tc.size: MediumTest 316 * @tc.type: Function 317 */ 318HWTEST_F(CaptureTest, Camera_Capture_0030, TestSize.Level2) 319{ 320 std::cout << "==========[test log]check Capture: Preview and still_capture streams,"; 321 std::cout << " Commit 2 streams together, capture together, isStreaming is true." << std::endl; 322 // Configure two streams of information 323 Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE}; 324 Test_->StartStream(Test_->intents); 325 // Capture preview stream 326 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 327 // Capture the photo stream, continuous capture 328 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true); 329 // post-processing 330 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture}; 331 Test_->streamIds.push_back(Test_->streamId_preview); 332 Test_->streamIds.push_back(Test_->streamId_capture); 333 Test_->StopStream(Test_->captureIds, Test_->streamIds); 334} 335 336/** 337 * @tc.name: preview and capture 338 * @tc.desc: Preview and still_capture streams + 3A, Commit 2 streams together, capture together, isStreaming is true. 339 * @tc.size: MediumTest 340 * @tc.type: Function 341 */ 342HWTEST_F(CaptureTest, Camera_Capture_0040, TestSize.Level2) 343{ 344 std::cout << "==========[test log]check Capture: Preview and still_capture streams + 3A,"; 345 std::cout << " Commit 2 streams together, capture together, isStreaming is true." << std::endl; 346 // Configure two streams of information 347 Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE}; 348 Test_->StartStream(Test_->intents); 349 // Capture preview stream 350 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 351 // Issue 3A parameters to increase exposure 352 std::shared_ptr<Camera::CameraSetting> meta = std::make_shared<Camera::CameraSetting>(100, 2000); 353 int32_t expo = 0xa0; 354 meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1); 355 Test_->rc = Test_->cameraDevice->UpdateSettings(meta); 356 if (Test_->rc == Camera::NO_ERROR) { 357 std::cout << "==========[test log]check Capture: UpdateSettings success, for 10s." << std::endl; 358 } else { 359 std::cout << "==========[test log]check Capture: UpdateSettings fail, rc = " << Test_->rc << std::endl; 360 } 361 sleep(3); // sleep for 3 seconds 362 // Capture the photo stream, continuous capture 363 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true); 364 // post-processing 365 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture}; 366 Test_->streamIds.push_back(Test_->streamId_preview); 367 Test_->streamIds.push_back(Test_->streamId_capture); 368 Test_->StopStream(Test_->captureIds, Test_->streamIds); 369}