1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except 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
17 using namespace OHOS;
18 using namespace std;
19 using namespace testing::ext;
20 using namespace OHOS::Camera;
21
SetUpTestCase(void)22 void CaptureTest::SetUpTestCase(void) {}
TearDownTestCase(void)23 void CaptureTest::TearDownTestCase(void) {}
SetUp(void)24 void CaptureTest::SetUp(void)
25 {
26 Test_ = std::make_shared<OHOS::Camera::Test>();
27 Test_->Init();
28 Test_->Open();
29 }
TearDown(void)30 void 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 */
41 HWTEST_F(CaptureTest, Camera_Capture_0001, Function | MediumTest | Level1)
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 close camera, and preview + capture again.
62 * @tc.size: MediumTest
63 * @tc.type: Function
64 */
65 HWTEST_F(CaptureTest, Camera_Capture_0002, Function | MediumTest | 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 */
100 HWTEST_F(CaptureTest, Camera_Capture_0003, Function | MediumTest | 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(5);
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 */
135 HWTEST_F(CaptureTest, Camera_Capture_0004, Function | MediumTest | 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 supported.
170 * @tc.size: MediumTest
171 * @tc.type: Function
172 */
173 HWTEST_F(CaptureTest, Camera_Capture_0005, Function | MediumTest | 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->datasapce_ = 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
__anona9a0fa1b0102(OHOS::SurfaceBuffer* buffer) 201 streamInfo_capture->bufferQueue_ = capture_consumer->CreateProducer([this](OHOS::SurfaceBuffer* buffer) {
202 Test_->SaveYUV("capture", buffer->GetVirAddr(), buffer->GetSize());
203 });
204 #else
__anona9a0fa1b0202(void* addr, uint32_t size) 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 is supported
212 Camera::StreamSupportType pType;
213 std::shared_ptr<Camera::CameraMetadata> modeSetting =
214 std::make_shared<Camera::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 */
238 HWTEST_F(CaptureTest, Camera_Capture_0006, Function | MediumTest | Level1)
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 * @tc.size: MediumTest
260 * @tc.type: Function
261 */
262 HWTEST_F(CaptureTest, Camera_Capture_0007, Function | MediumTest | Level1)
263 {
264 std::cout << "==========[test log]check Capture: Commit 2 streams together,";
265 std::cout << "Preview and still_capture streams, isStreaming is false, multiple single capture" << std::endl;
266 // Configure two streams of information
267 Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
268 Test_->StartStream(Test_->intents);
269 // Capture preview stream
270 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
271 // Capture the photo stream, multiple single capture
272 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, false);
273 sleep(1);
274 Test_->StartCapture(Test_->streamId_capture, (Test_->captureId_capture) + 1, false, false);
275 sleep(1);
276 Test_->StartCapture(Test_->streamId_capture, (Test_->captureId_capture) + 2, false, false);
277 // post-processing
278 Test_->captureIds = {Test_->captureId_preview};
279 Test_->streamIds.push_back(Test_->streamId_preview);
280 Test_->streamIds.push_back(Test_->streamId_capture);
281 Test_->StopStream(Test_->captureIds, Test_->streamIds);
282 }
283
284 /**
285 * @tc.name: preview and capture
286 * @tc.desc: Commit 2 streams in order, Preview and still_capture streams.
287 * @tc.size: MediumTest
288 * @tc.type: Function
289 */
290 HWTEST_F(CaptureTest, Camera_Capture_0010, Function | MediumTest | Level1)
291 {
292 std::cout << "==========[test log]Commit 2 streams in order, Preview and still_capture." << std::endl;
293 // start preview stream
294 Test_->intents = {Camera::PREVIEW};
295 Test_->StartStream(Test_->intents);
296 // Get preview
297 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
298 // start stream
299 Test_->intents = {Camera::STILL_CAPTURE};
300 Test_->StartStream(Test_->intents);
301 // Start capture
302 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
303 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
304 // release stream
305 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
306 Test_->streamIds.push_back(Test_->streamId_preview);
307 Test_->streamIds.push_back(Test_->streamId_capture);
308 Test_->StopStream(Test_->captureIds, Test_->streamIds);
309 }
310
311 /**
312 * @tc.name: preview and capture
313 * @tc.desc: Preview and still_capture streams, Commit 2 streams together, capture together, isStreaming is true.
314 * @tc.size: MediumTest
315 * @tc.type: Function
316 */
317 HWTEST_F(CaptureTest, Camera_Capture_0030, Function | MediumTest | Level2)
318 {
319 std::cout << "==========[test log]check Capture: Preview and still_capture streams,";
320 std::cout << " Commit 2 streams together, capture together, isStreaming is true." << std::endl;
321 // Configure two streams of information
322 Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
323 Test_->StartStream(Test_->intents);
324 // Capture preview stream
325 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
326 // Capture the photo stream, continuous capture
327 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
328 // post-processing
329 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
330 Test_->streamIds.push_back(Test_->streamId_preview);
331 Test_->streamIds.push_back(Test_->streamId_capture);
332 Test_->StopStream(Test_->captureIds, Test_->streamIds);
333 }
334
335 /**
336 * @tc.name: preview and capture
337 * @tc.desc: Preview and still_capture streams + 3A, Commit 2 streams together, capture together, isStreaming is true.
338 * @tc.size: MediumTest
339 * @tc.type: Function
340 */
341 HWTEST_F(CaptureTest, Camera_Capture_0040, Function | MediumTest | Level2)
342 {
343 std::cout << "==========[test log]check Capture: Preview and still_capture streams + 3A,";
344 std::cout << " Commit 2 streams together, capture together, isStreaming is true." << std::endl;
345 // Configure two streams of information
346 Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
347 Test_->StartStream(Test_->intents);
348 // Capture preview stream
349 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
350 // Issue 3A parameters to increase exposure
351 std::shared_ptr<Camera::CameraSetting> meta = std::make_shared<Camera::CameraSetting>(100, 2000);
352 int32_t expo = 0xa0;
353 meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1);
354 Test_->rc = Test_->cameraDevice->UpdateSettings(meta);
355 if (Test_->rc == Camera::NO_ERROR) {
356 std::cout << "==========[test log]check Capture: UpdateSettings success, for 10s." << std::endl;
357 } else {
358 std::cout << "==========[test log]check Capture: UpdateSettings fail, rc = " << Test_->rc << std::endl;
359 }
360 sleep(5);
361 // Capture the photo stream, continuous capture
362 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
363 // post-processing
364 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
365 Test_->streamIds.push_back(Test_->streamId_preview);
366 Test_->streamIds.push_back(Test_->streamId_capture);
367 Test_->StopStream(Test_->captureIds, Test_->streamIds);
368 }