1 /*
2 * Copyright (c) 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 "camera_capture_test.h"
16
17 using namespace testing::ext;
18
SetUpTestCase(void)19 void CameraCaptureTest::SetUpTestCase(void)
20 {}
TearDownTestCase(void)21 void CameraCaptureTest::TearDownTestCase(void)
22 {}
SetUp(void)23 void CameraCaptureTest::SetUp(void)
24 {
25 if (display_ == nullptr)
26 display_ = std::make_shared<TestDisplay>();
27 display_->Init();
28 }
TearDown(void)29 void CameraCaptureTest::TearDown(void)
30 {
31 display_->Close();
32 }
33
34 /**
35 * @tc.name: preview and capture
36 * @tc.desc: Commit 2 streams together, Preview and still_capture streams, isStreaming is true.
37 * @tc.level: Level1
38 * @tc.size: MediumTest
39 * @tc.type: Function
40 */
41 HWTEST_F(CameraCaptureTest, SUB_DriverSystem_CameraHdi_0150, TestSize.Level1)
42 {
43 // Get the stream manager
44 display_->AchieveStreamOperator();
45 // start stream
46 display_->intents = {PREVIEW, STILL_CAPTURE};
47 display_->StartStream(display_->intents);
48 // Get preview
49 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
50 display_->StartCapture(display_->STREAM_ID_CAPTURE, display_->CAPTURE_ID_CAPTURE, false, true);
51 // release stream
52 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_CAPTURE};
53 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_CAPTURE};
54 display_->StopStream(display_->captureIds, display_->streamIds);
55 }
56
57 /**
58 * @tc.name: preview and capture
59 * @tc.desc: Preview + capture, then close camera, and preview + capture again.
60 * @tc.level: Level1
61 * @tc.size: MediumTest
62 * @tc.type: Function
63 */
64 HWTEST_F(CameraCaptureTest, SUB_DriverSystem_CameraHdi_0160, TestSize.Level1)
65 {
66 std::cout << "==========[test log] Preview + capture, then cloase camera,";
67 std::cout << "and preview + capture again." << std::endl;
68 // Get the stream manager
69 display_->AchieveStreamOperator();
70 // start stream
71 display_->intents = {PREVIEW, STILL_CAPTURE};
72 display_->StartStream(display_->intents);
73 // Get preview
74 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
75 display_->StartCapture(display_->STREAM_ID_CAPTURE, display_->CAPTURE_ID_CAPTURE, false, true);
76 // release stream
77 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_CAPTURE};
78 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_CAPTURE};
79 display_->StopStream(display_->captureIds, display_->streamIds);
80
81 // the 2nd time
82 // Configure two streams of information
83 // Get the stream manager
84 display_->AchieveStreamOperator();
85 // start stream
86 display_->intents = {PREVIEW, STILL_CAPTURE};
87 display_->StartStream(display_->intents);
88 // Get preview
89 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
90 display_->StartCapture(display_->STREAM_ID_CAPTURE, display_->CAPTURE_ID_CAPTURE, false, true);
91 // release stream
92 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_CAPTURE};
93 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_CAPTURE};
94 display_->StopStream(display_->captureIds, display_->streamIds);
95 }
96
97 /**
98 * @tc.name: preview and capture
99 * @tc.desc: Preview + capture with 3A, success.
100 * @tc.level: Level1
101 * @tc.size: MediumTest
102 * @tc.type: Function
103 */
104 HWTEST_F(CameraCaptureTest, SUB_DriverSystem_CameraHdi_0170, TestSize.Level1)
105 {
106 std::cout << "==========[test log] Capture with 3A, success." << std::endl;
107 // Get the stream manager
108 display_->AchieveStreamOperator();
109 // start stream
110 display_->intents = {PREVIEW, STILL_CAPTURE};
111 display_->StartStream(display_->intents);
112 // Get preview
113 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
114 display_->StartCapture(display_->STREAM_ID_CAPTURE, display_->CAPTURE_ID_CAPTURE, false, true);
115 // Issue 3A parameters to increase exposure
116 std::shared_ptr<CameraSetting> meta = std::make_shared<CameraSetting>(100, 2000);
117 int32_t expo = 0xa0;
118 meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1);
119 const int32_t deviceStreamId = display_->STREAM_ID_CAPTURE;
120 meta->addEntry(OHOS_CAMERA_STREAM_ID, &deviceStreamId, 1);
121 std::vector<uint8_t> setting;
122 MetadataUtils::ConvertMetadataToVec(meta, setting);
123 display_->rc = (CamRetCode)display_->cameraDevice->UpdateSettings(setting);
124 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
125 std::cout << "==========[test log] UpdateSettings success, for 10s." << std::endl;
126 } else {
127 std::cout << "==========[test log] UpdateSettings fail, rc = " << display_->rc << std::endl;
128 }
129 // release stream
130 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_CAPTURE};
131 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_CAPTURE};
132 display_->StopStream(display_->captureIds, display_->streamIds);
133 }
134
135 /**
136 * @tc.name: preview and capture
137 * @tc.desc: Preview + capture, then switch to preview + video.
138 * @tc.level: Level1
139 * @tc.size: MediumTest
140 * @tc.type: Function
141 */
142 HWTEST_F(CameraCaptureTest, SUB_DriverSystem_CameraHdi_0180, TestSize.Level1)
143 {
144 std::cout << "==========[test log] Preview + capture, then switch to preview + video." << std::endl;
145 std::cout << "==========[test log] First, create preview + capture." << std::endl;
146 // Get the stream manager
147 display_->AchieveStreamOperator();
148 // start stream
149 display_->intents = {PREVIEW, STILL_CAPTURE};
150 display_->StartStream(display_->intents);
151 // Get preview
152 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
153 display_->StartCapture(display_->STREAM_ID_CAPTURE, display_->CAPTURE_ID_CAPTURE, false, true);
154 // release stream
155 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_CAPTURE};
156 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_CAPTURE};
157 display_->StopStream(display_->captureIds, display_->streamIds);
158 sleep(3);
159
160 std::cout << "==========[test log] Next, switch to preview + video." << display_->rc << std::endl;
161 // Get the stream manager
162 display_->AchieveStreamOperator();
163 // start stream
164 display_->intents = {PREVIEW, VIDEO};
165 display_->StartStream(display_->intents);
166 // Get preview
167 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
168 display_->StartCapture(display_->STREAM_ID_VIDEO, display_->CAPTURE_ID_VIDEO, false, true);
169 // release stream
170 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_VIDEO};
171 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_VIDEO};
172 display_->StopStream(display_->captureIds, display_->streamIds);
173 }
174
175 /**
176 * @tc.name: preview and capture
177 * @tc.desc: Commit 2 streams together, Preview and still_capture streams, isStreaming is false.
178 * @tc.level: Level1
179 * @tc.size: MediumTest
180 * @tc.type: Function
181 */
182 HWTEST_F(CameraCaptureTest, SUB_DriverSystem_CameraHdi_0200, TestSize.Level1)
183 {
184 // Get the stream manager
185 display_->AchieveStreamOperator();
186 // start stream
187 display_->intents = {PREVIEW, STILL_CAPTURE};
188 display_->StartStream(display_->intents);
189 // Get preview
190 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
191 display_->StartCapture(display_->STREAM_ID_CAPTURE, display_->CAPTURE_ID_CAPTURE, false, false);
192
193 sleep(3);
194 CAMERA_LOGD("frame off.");
195 display_->streamCustomerPreview_->ReceiveFrameOff();
196 display_->streamCustomerCapture_->ReceiveFrameOff();
197
198 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(
199 {display_->STREAM_ID_CAPTURE});
200 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
201 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
202 std::cout << "==========[test log] ReleaseStreams success." << std::endl;
203 } else {
204 std::cout << "==========[test log] ReleaseStreams fail, rc = ." << display_->rc << std::endl;
205 }
206 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(
207 {display_->STREAM_ID_PREVIEW});
208 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
209 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
210 std::cout << "==========[test log] ReleaseStreams success." << std::endl;
211 } else {
212 std::cout << "==========[test log] ReleaseStreams fail, rc = ." << display_->rc << std::endl;
213 }
214 }
215
216 /**
217 * @tc.name: preview and capture
218 * @tc.desc: Commit 2 streams in order, Preview and still_capture streams.
219 * @tc.level: Level1
220 * @tc.size: MediumTest
221 * @tc.type: Function
222 */
223 HWTEST_F(CameraCaptureTest, SUB_DriverSystem_CameraHdi_0210, TestSize.Level1)
224 {
225 std::cout << "==========[test log] Preview and still_capture streams." << std::endl;
226 // Configure two streams of information
227 EXPECT_EQ(true, display_->cameraDevice != nullptr);
228 display_->AchieveStreamOperator();
229 // Create video stream
230 display_->intents = {PREVIEW, STILL_CAPTURE};
231 display_->StartStream(display_->intents);
232 // Start capture recording
233 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
234 display_->StartCapture(display_->STREAM_ID_CAPTURE, display_->CAPTURE_ID_CAPTURE, false, true);
235 sleep(2);
236
237 // post-processing
238 display_->streamCustomerPreview_->ReceiveFrameOff();
239 display_->streamCustomerCapture_->ReceiveFrameOff();
240 display_->rc = (CamRetCode)display_->streamOperator->CancelCapture(display_->CAPTURE_ID_CAPTURE);
241 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
242 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
243 std::cout << "==========[test log] CancelCapture success." << std::endl;
244 } else {
245 std::cout << "==========[test log] CancelCapture fail, rc = ." << display_->rc << std::endl;
246 }
247 display_->rc = (CamRetCode)display_->streamOperator->CancelCapture(display_->CAPTURE_ID_PREVIEW);
248 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
249 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
250 std::cout << "==========[test log] CancelCapture success." << std::endl;
251 } else {
252 std::cout << "==========[test log] CancelCapture fail, rc = ." << display_->rc << std::endl;
253 }
254 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(
255 {display_->STREAM_ID_CAPTURE});
256 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
257 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
258 std::cout << "==========[test log] ReleaseStreams success." << std::endl;
259 } else {
260 std::cout << "==========[test log] ReleaseStreams fail, rc = ." << display_->rc << std::endl;
261 }
262 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(
263 {display_->STREAM_ID_PREVIEW});
264 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
265 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
266 std::cout << "==========[test log] ReleaseStreams success." << std::endl;
267 } else {
268 std::cout << "==========[test log] ReleaseStreams fail, rc = ." << display_->rc << std::endl;
269 }
270 }
271
272 /**
273 * @tc.name: Only Still_capture stream
274 * @tc.desc: Only Still_capture stream, capture->isStreaming = false.
275 * @tc.level: Level1
276 * @tc.size: MediumTest
277 * @tc.type: Function
278 */
279 HWTEST_F(CameraCaptureTest, camera_capture_020, TestSize.Level1)
280 {
281 std::cout << "==========[test log] No preview, only still_capture." << std::endl;
282 // start stream
283 display_->AchieveStreamOperator();
284 std::shared_ptr<StreamCustomer> streamCustomer = std::make_shared<StreamCustomer>();
285 OHOS::sptr<OHOS::IBufferProducer> producer = streamCustomer->CreateProducer();
286 producer->SetQueueSize(8); // buffer queue size
287 if (producer->GetQueueSize() != 8) { // buffer queue size
288 std::cout << "~~~~~~~" << std::endl;
289 }
__anon713166060102(const unsigned char *addr, const uint32_t size) 290 streamCustomer->ReceiveFrameOn([this](const unsigned char *addr, const uint32_t size) {
291 display_->StoreImage(addr, size);
292 });
293 std::vector<StreamInfo> streamInfos;
294 display_->streamInfo.streamId_ = 1001;
295 display_->streamInfo.width_ = 1280; // picture width
296 display_->streamInfo.height_ = 960; // picture height
297 display_->streamInfo.format_ = PIXEL_FMT_RGBA_8888;
298 display_->streamInfo.dataspace_ = 8; // picture dataspace
299 display_->streamInfo.intent_ = STILL_CAPTURE;
300 display_->streamInfo.tunneledMode_ = 5; // tunnel mode
301 display_->streamInfo.encodeType_ = ENCODE_TYPE_JPEG;
302 display_->streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
303 ASSERT_NE(display_->streamInfo.bufferQueue_, nullptr);
304 streamInfos.push_back(display_->streamInfo);
305 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
306 CAMERA_LOGE("CreateStreams! rc:0x%x\n", display_->rc);
307
308 display_->rc = (CamRetCode)display_->streamOperator->CommitStreams(NORMAL, display_->ability_);
309 CAMERA_LOGE("CommitStreams! rc:0x%x\n", display_->rc);
310 int captureId = 2001;
311 CaptureInfo captureInfo = {};
312 captureInfo.streamIds_ = {1001};
313 captureInfo.captureSetting_ = display_->ability_;
314 captureInfo.enableShutterCallback_ = false;
315
316 display_->rc = (CamRetCode)display_->streamOperator->Capture(captureId, captureInfo, false);
317 CAMERA_LOGE("Capture! rc:0x%x\n", display_->rc);
318 sleep(3);
319 streamCustomer->ReceiveFrameOff();
320 display_->rc = (CamRetCode)display_->streamOperator->CancelCapture(captureId);
321 CAMERA_LOGE("CancelCapture! rc:0x%x\n", display_->rc);
322 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(captureInfo.streamIds_);
323 CAMERA_LOGE("ReleaseStreams! rc:0x%x\n", display_->rc);
324 }
325
326 /**
327 * @tc.name: Only Still_capture stream
328 * @tc.desc: Only Still_capture stream, capture->isStreaming = true.
329 * @tc.level: Level1
330 * @tc.size: MediumTest
331 * @tc.type: Function
332 */
333 HWTEST_F(CameraCaptureTest, camera_capture_021, TestSize.Level1)
334 {
335 std::cout << "==========[test log] Still_capture stream, capture->isStreaming = true." << std::endl;
336 // start stream
337 display_->AchieveStreamOperator();
338 std::shared_ptr<StreamCustomer> streamCustomer = std::make_shared<StreamCustomer>();
339 OHOS::sptr<OHOS::IBufferProducer> producer = streamCustomer->CreateProducer();
340 producer->SetQueueSize(8); // 8:set bufferqueue size
341 if (producer->GetQueueSize() != 8) { // 8:get bufferqueue size
342 std::cout << "~~~~~~~" << std::endl;
343 }
__anon713166060202(const unsigned char *addr, const uint32_t size) 344 streamCustomer->ReceiveFrameOn([this](const unsigned char *addr, const uint32_t size) {
345 display_->StoreImage(addr, size);
346 });
347 std::vector<StreamInfo> streamInfos;
348 display_->streamInfo.streamId_ = 1001;
349 display_->streamInfo.width_ = 1280; // 640:picture width
350 display_->streamInfo.height_ = 960; // 640:picture height
351 display_->streamInfo.format_ = PIXEL_FMT_RGBA_8888;
352 display_->streamInfo.dataspace_ = 8; // 8:picture dataspace
353 display_->streamInfo.intent_ = STILL_CAPTURE;
354 display_->streamInfo.tunneledMode_ = 5; // 5:tunnel mode
355 display_->streamInfo.encodeType_ = ENCODE_TYPE_JPEG;
356 display_->streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
357 ASSERT_NE(display_->streamInfo.bufferQueue_, nullptr);
358 streamInfos.push_back(display_->streamInfo);
359 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
360 CAMERA_LOGE("CreateStreams! rc:0x%x\n", display_->rc);
361
362 display_->rc = (CamRetCode)display_->streamOperator->CommitStreams(NORMAL, display_->ability_);
363 CAMERA_LOGE("CommitStreams! rc:0x%x\n", display_->rc);
364 int captureId = 2001;
365 CaptureInfo captureInfo = {};
366 captureInfo.streamIds_ = {1001};
367 captureInfo.captureSetting_ = display_->ability_;
368 captureInfo.enableShutterCallback_ = false;
369
370 display_->rc = (CamRetCode)display_->streamOperator->Capture(captureId, captureInfo, true);
371 CAMERA_LOGE("Capture! rc:0x%x\n", display_->rc);
372 sleep(3);
373 streamCustomer->ReceiveFrameOff();
374 display_->rc = (CamRetCode)display_->streamOperator->CancelCapture(captureId);
375 CAMERA_LOGE("CancelCapture! rc:0x%x\n", display_->rc);
376 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(captureInfo.streamIds_);
377 CAMERA_LOGE("ReleaseStreams! rc:0x%x\n", display_->rc);
378 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
379 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
380 std::cout << "==========[test log] ReleaseStreams success." << std::endl;
381 } else {
382 std::cout << "==========[test log] ReleaseStreams fail, rc = ." << display_->rc << std::endl;
383 }
384 }
385
386 /**
387 * @tc.name: RE_CONFIGURED_REQUIRED
388 * @tc.desc: RE_CONFIGURED_REQUIRED
389 * @tc.size: MediumTest
390 * @tc.type: Function
391 */
392 HWTEST_F(CameraCaptureTest, Camera_Capture_022, TestSize.Level1)
393 {
394 std::cout << "==========[test log]check Capture: Preview + video, then capture a photo." << std::endl;
395 std::cout << "==========[test log]check Capture: First, create Preview + video." << std::endl;
396 // Configure two streams of information
397 display_->AchieveStreamOperator();
398 display_->intents = {PREVIEW, VIDEO};
399 display_->StartStream(display_->intents);
400 // Capture preview stream
401 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
402 // Capture video stream
403 display_->StartCapture(display_->STREAM_ID_VIDEO, display_->CAPTURE_ID_VIDEO, false, true);
404
405 // Start the capture stream
406 std::shared_ptr<HDI::Camera::V1_0::StreamInfo> streamInfo_capture =
407 std::make_shared<HDI::Camera::V1_0::StreamInfo>();
408 streamInfo_capture->streamId_ = display_->STREAM_ID_CAPTURE;
409 streamInfo_capture->width_ = 640;
410 streamInfo_capture->height_ = 480;
411 streamInfo_capture->format_ = PIXEL_FMT_YCRCB_420_SP;
412 streamInfo_capture->dataspace_ = 8;
413 streamInfo_capture->intent_ = HDI::Camera::V1_0::STILL_CAPTURE;
414 streamInfo_capture->tunneledMode_ = 5;
415
416 // Query whether the IsStreamsSupported interface supports
417 HDI::Camera::V1_0::StreamSupportType pType;
418 std::vector<HDI::Camera::V1_0::StreamInfo> stre;
419 stre.push_back(*streamInfo_capture);
420 display_->rc = (CamRetCode)display_->streamOperator->IsStreamsSupported(HDI::Camera::V1_0::NORMAL,
421 display_->ability_, stre, pType);
422 EXPECT_EQ(display_->rc, HDI::Camera::V1_0::NO_ERROR);
423 std::cout << "ptype = " << pType << std::endl;
424 EXPECT_EQ(true, pType == HDI::Camera::V1_0::RE_CONFIGURED_REQUIRED);
425 // post-processing
426 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_VIDEO};
427 display_->streamIds.push_back(display_->STREAM_ID_PREVIEW);
428 display_->streamIds.push_back(display_->STREAM_ID_VIDEO);
429 display_->StopStream(display_->captureIds, display_->streamIds);
430 }