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 "video_test.h"
16
SetUpTestCase(void)17 void UtestVideoTest::SetUpTestCase(void)
18 {}
TearDownTestCase(void)19 void UtestVideoTest::TearDownTestCase(void)
20 {}
SetUp(void)21 void UtestVideoTest::SetUp(void)
22 {
23 if (display_ == nullptr)
24 display_ = std::make_shared<TestDisplay>();
25 display_->FBInit();
26 display_->Init();
27 }
TearDown(void)28 void UtestVideoTest::TearDown(void)
29 {
30 display_->Close();
31 }
32
33 /**
34 * @tc.name: Video
35 * @tc.desc: Preview + video, commit together, success.
36 * @tc.level: Level0
37 * @tc.size: MediumTest
38 * @tc.type: Function
39 */
TEST_F(UtestVideoTest,camera_video_0001)40 TEST_F(UtestVideoTest, camera_video_0001)
41 {
42 std::cout << "==========[test log] 1 Preview + video, commit together, success." << std::endl;
43 // 创建并获取streamOperator信息
44 display_->AchieveStreamOperator();
45 // 启流
46 display_->intents = {Camera::PREVIEW, Camera::VIDEO};
47 display_->StartStream(display_->intents);
48 // 获取预览图
49 display_->StartCapture(display_->streamId_preview, display_->captureId_preview, false, true);
50 display_->StartCapture(display_->streamId_video, display_->captureId_preview, false, true);
51 // 释放流
52 display_->captureIds = {display_->captureId_preview};
53 display_->streamIds = {display_->streamId_preview, display_->streamId_video};
54 display_->StopStream(display_->captureIds, display_->streamIds);
55 }
56
57 /**
58 * @tc.name: Video
59 * @tc.desc: Preview + video, commit together, set 3A, success.
60 * @tc.level: Level1
61 * @tc.size: MediumTest
62 * @tc.type: Function
63 */
TEST_F(UtestVideoTest,camera_video_0002)64 TEST_F(UtestVideoTest, camera_video_0002)
65 {
66 std::cout << "==========[test log] Preview + video, commit together, set 3A, success." << std::endl;
67 // 创建并获取streamOperator信息
68 display_->AchieveStreamOperator();
69
70 // 启流
71 display_->intents = {Camera::PREVIEW, Camera::VIDEO};
72 display_->StartStream(display_->intents);
73 // 下发3A参数,增加曝光度
74 std::shared_ptr<OHOS::Camera::CameraSetting> meta = std::make_shared<OHOS::Camera::CameraSetting>(100, 2000);
75 int32_t expo = 0xa0;
76 meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1);
77 display_->rc = display_->cameraDevice->UpdateSettings(meta);
78 if (display_->rc == Camera::NO_ERROR) {
79 std::cout << "==========[test log] UpdateSettings success, for 5s." << std::endl;
80 } else {
81 std::cout << "==========[test log] UpdateSettings fail, rc = " << display_->rc << std::endl;
82 }
83 sleep(3);
84
85 // 获取预览图
86 display_->StartCapture(display_->streamId_preview, display_->captureId_video, false, true);
87 display_->StartCapture(display_->streamId_video, display_->captureId_video, false, true);
88 // 释放流
89 display_->captureIds = {display_->captureId_video};
90 display_->streamIds = {display_->streamId_preview, display_->streamId_video};
91 display_->StopStream(display_->captureIds, display_->streamIds);
92 }
93
94 /**
95 * @tc.name: Video
96 * @tc.desc: Preview + video, commit together, then close device, and preview + video again.
97 * @tc.level: Level1
98 * @tc.size: MediumTest
99 * @tc.type: Function
100 */
TEST_F(UtestVideoTest,camera_video_0003)101 TEST_F(UtestVideoTest, camera_video_0003)
102 {
103 std::cout << "==========[test log] Preview + video, commit together, then close device,";
104 std::cout << "and preview + video again." << std::endl;
105 // 创建并获取streamOperator信息
106 display_->AchieveStreamOperator();
107 // 启流
108 display_->intents = {Camera::PREVIEW, Camera::VIDEO};
109 display_->StartStream(display_->intents);
110 // 获取预览图
111 display_->StartCapture(display_->streamId_preview, display_->captureId_preview, false, true);
112 display_->StartCapture(display_->streamId_video, display_->captureId_preview, false, true);
113 // 释放流
114 display_->captureIds = {display_->captureId_preview};
115 display_->streamIds = {display_->streamId_preview, display_->streamId_video};
116 display_->StopStream(display_->captureIds, display_->streamIds);
117
118 // 关闭设备
119 display_->Close();
120 // 打开设备
121 display_->Init();
122 std::cout << "==========[test log] The 2nd time." << std::endl;
123
124 // 创建并获取streamOperator信息
125 display_->AchieveStreamOperator();
126 // 启流
127 display_->intents = {Camera::PREVIEW, Camera::VIDEO};
128 display_->StartStream(display_->intents);
129 // 获取预览图
130 display_->StartCapture(display_->streamId_preview, display_->captureId_preview, false, true);
131 display_->StartCapture(display_->streamId_video, display_->captureId_preview, false, true);
132 // 释放流
133 display_->captureIds = {display_->captureId_preview};
134 display_->streamIds = {display_->streamId_preview, display_->streamId_video};
135 display_->StopStream(display_->captureIds, display_->streamIds);
136 }
137
138 /**
139 * @tc.name: Video
140 * @tc.desc: Preview + video, commit together, then close device, and preview + capture.
141 * @tc.level: Level1
142 * @tc.size: MediumTest
143 * @tc.type: Function
144 */
TEST_F(UtestVideoTest,camera_video_0004)145 TEST_F(UtestVideoTest, camera_video_0004)
146 {
147 std::cout << "==========[test log] Preview + video, commit together, then close device,";
148 std::cout << "and preview + capture." << std::endl;
149 // 创建并获取streamOperator信息
150 display_->AchieveStreamOperator();
151 // 启流
152 display_->intents = {Camera::PREVIEW, Camera::VIDEO};
153 display_->StartStream(display_->intents);
154 // 获取预览图
155 display_->StartCapture(display_->streamId_preview, display_->captureId_preview, false, true);
156 display_->StartCapture(display_->streamId_video, display_->captureId_preview, false, true);
157 // 释放流
158 display_->captureIds = {display_->captureId_preview};
159 display_->streamIds = {display_->streamId_preview, display_->streamId_video};
160 display_->StopStream(display_->captureIds, display_->streamIds);
161
162 // 关闭设备
163 display_->Close();
164 std::cout << "==========[test log] cameraDevice->Close" << std::endl;
165 // 打开设备
166 display_->Init();
167
168 // 创建并获取streamOperator信息
169 display_->AchieveStreamOperator();
170 // 启流
171 display_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
172 display_->StartStream(display_->intents);
173 // 获取预览图
174 display_->StartCapture(display_->streamId_preview, display_->captureId_preview, false, true);
175 display_->StartCapture(display_->streamId_capture, display_->captureId_preview, false, true);
176 // 释放流
177 display_->captureIds = {display_->captureId_preview};
178 display_->streamIds = {display_->streamId_preview, display_->streamId_capture};
179 display_->StopStream(display_->captureIds, display_->streamIds);
180 }
181
182 /**
183 * @tc.name: Video
184 * @tc.desc: Preview + video, commit together, success.
185 * @tc.level: Level1
186 * @tc.size: MediumTest
187 * @tc.type: Function
188 */
TEST_F(UtestVideoTest,camera_video_0005)189 TEST_F(UtestVideoTest, camera_video_0005)
190 {
191 std::cout << "==========[test log] 1 Preview + video, commit together, success." << std::endl;
192 // 创建并获取streamOperator信息
193 display_->AchieveStreamOperator();
194 // 启流
195 display_->intents = {Camera::PREVIEW, Camera::VIDEO};
196 display_->StartStream(display_->intents);
197 // 获取预览图
198 display_->StartCapture(display_->streamId_preview, display_->captureId_preview, false, true);
199 display_->StartCapture(display_->streamId_video, display_->captureId_preview, false, true);
200 // 释放流
201 display_->captureIds = {display_->captureId_preview};
202 display_->streamIds = {display_->streamId_preview, display_->streamId_video};
203 display_->StopStream(display_->captureIds, display_->streamIds);
204 }
205
206 /**
207 * @tc.name: Video
208 * @tc.desc: Video start&stop, for 5 times, success.
209 * @tc.level: Level2
210 * @tc.size: MediumTest
211 * @tc.type: Function
212 */
TEST_F(UtestVideoTest,camera_video_0010)213 TEST_F(UtestVideoTest, camera_video_0010)
214 {
215 std::cout << "==========[test log] Video start&stop, for 5 times, success." << std::endl;
216 // 创建并获取streamOperator信息
217 display_->AchieveStreamOperator();
218 for (int i = 0; i < 5; i++) {
219 // 启流
220 display_->intents = {Camera::PREVIEW, Camera::VIDEO};
221 display_->StartStream(display_->intents);
222 // 获取预览图
223 display_->StartCapture(display_->streamId_preview, display_->captureId_preview, false, true);
224 display_->StartCapture(display_->streamId_video, display_->captureId_preview, false, true);
225 // 释放流
226 display_->captureIds = {display_->captureId_preview};
227 display_->streamIds = {display_->streamId_preview, display_->streamId_video};
228 display_->StopStream(display_->captureIds, display_->streamIds);
229 }
230 }
231
232 /**
233 * @tc.name: Video
234 * @tc.desc: Video start&stop, for 5 times, success.
235 * @tc.level: Level2
236 * @tc.size: MediumTest
237 * @tc.type: Function
238 */
TEST_F(UtestVideoTest,camera_video_0011)239 TEST_F(UtestVideoTest, camera_video_0011)
240 {
241 std::cout << "==========[test log] Video start&stop, for 5 times, success." << std::endl;
242 // 创建并获取streamOperator信息
243 display_->AchieveStreamOperator();
244 for (int i = 0; i < 5; i++) {
245 // 启流
246 display_->intents = {Camera::PREVIEW, Camera::VIDEO};
247 display_->StartStream(display_->intents);
248
249 // 抓拍预览
250 display_->StartCapture(display_->streamId_preview, display_->captureId_preview, false, true);
251 // 抓拍录制
252 display_->StartCapture(display_->streamId_video, display_->captureId_video, false, true);
253
254 // 后处理
255 display_->captureIds = {display_->captureId_preview, display_->captureId_video};
256 display_->streamIds = {display_->streamId_preview, display_->streamId_video};
257 display_->StopStream(display_->captureIds, display_->streamIds);
258 }
259 }
260
261 /**
262 * @tc.name: Video
263 * @tc.desc: Dynamic Video mode, preview, success.
264 * @tc.level: Level2
265 * @tc.size: MediumTest
266 * @tc.type: Function
267 */
TEST_F(UtestVideoTest,camera_video_0020)268 TEST_F(UtestVideoTest, camera_video_0020)
269 {
270 std::cout << "==========[test log] Video mode, preview, success." << std::endl;
271 // 创建并获取streamOperator信息
272 display_->AchieveStreamOperator();
273 // 创建数据流
274 display_->intents = {Camera::PREVIEW};
275 display_->StartStream(display_->intents);
276 // 捕获
277 display_->StartCapture(display_->streamId_preview, display_->captureId_preview, false, true);
278 // 创建录像流
279 display_->intents = {Camera::VIDEO};
280 display_->StartStream(display_->intents);
281 // 抓拍预览
282 display_->StartCapture(display_->streamId_preview, display_->captureId_preview, false, true);
283 // 抓拍录制
284 display_->StartCapture(display_->streamId_video, display_->captureId_video, false, true);
285
286 // 后处理
287 display_->rc = display_->streamOperator->CancelCapture(display_->captureId_video);
288 EXPECT_EQ(true, display_->rc == Camera::NO_ERROR);
289 if (display_->rc == Camera::NO_ERROR) {
290 std::cout << "==========[test log] CancelCapture success, captureId = ";
291 std::cout << display_->captureId_video << std::endl;
292 } else {
293 std::cout << "==========[test log] CancelCapture fail, rc = " << display_->rc << std::endl;
294 }
295 display_->rc = display_->streamOperator->CancelCapture(display_->captureId_preview);
296 EXPECT_EQ(true, display_->rc == Camera::NO_ERROR);
297 if (display_->rc == Camera::NO_ERROR) {
298 std::cout << "==========[test log] CancelCapture success, captureId = ";
299 std::cout << display_->captureId_preview << std::endl;
300 } else {
301 std::cout << "==========[test log] CancelCapture fail, rc = " << display_->rc << std::endl;
302 }
303 display_->rc = display_->streamOperator->ReleaseStreams({display_->streamId_video});
304 EXPECT_EQ(true, display_->rc == Camera::NO_ERROR);
305 if (display_->rc == Camera::NO_ERROR) {
306 std::cout << "==========[test log] ReleaseStreams success." << std::endl;
307 } else {
308 std::cout << "==========[test log] ReleaseStreams fail, rc = " << display_->rc << std::endl;
309 }
310 display_->rc = display_->streamOperator->ReleaseStreams({display_->streamId_preview});
311 EXPECT_EQ(true, display_->rc == Camera::NO_ERROR);
312 if (display_->rc == Camera::NO_ERROR) {
313 std::cout << "==========[test log] ReleaseStreams success." << std::endl;
314 } else {
315 std::cout << "==========[test log] ReleaseStreams fail, rc = " << display_->rc << std::endl;
316 }
317 }
318
319 /**
320 * @tc.name: Video
321 * @tc.desc: Video mode, preview, set 3A, success.
322 * @tc.level: Level1
323 * @tc.size: MediumTest
324 * @tc.type: Function
325 */
TEST_F(UtestVideoTest,camera_video_0021)326 TEST_F(UtestVideoTest, camera_video_0021)
327 {
328 std::cout << "==========[test log] Video mode, preview, set 3A, success." << std::endl;
329 EXPECT_EQ(true, display_->cameraDevice != nullptr);
330 display_->AchieveStreamOperator();
331 // 启流
332 display_->intents = {Camera::PREVIEW, Camera::VIDEO};
333 display_->StartStream(display_->intents);
334 // 捕获
335 display_->StartCapture(display_->streamId_preview, display_->captureId_video, false, true);
336 display_->StartCapture(display_->streamId_video, display_->captureId_video, false, true);
337 // 下发3A参数,增加曝光度
338 std::shared_ptr<OHOS::Camera::CameraSetting> meta = std::make_shared<OHOS::Camera::CameraSetting>(100, 2000);
339 int32_t expo = 0xa0;
340 meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1);
341 display_->rc = display_->cameraDevice->UpdateSettings(meta);
342 if (display_->rc == Camera::NO_ERROR) {
343 std::cout << "==========[test log] UpdateSettings success, for 5s." << std::endl;
344 } else {
345 std::cout << "==========[test log] UpdateSettings fail, rc = " << display_->rc << std::endl;
346 }
347 sleep(3);
348
349 // 后处理
350 display_->captureIds = {display_->captureId_video};
351 display_->streamIds = {display_->streamId_preview, display_->streamId_video};
352 display_->StopStream(display_->captureIds, display_->streamIds);
353 }
354
355 /**
356 * @tc.name: Video
357 * @tc.desc: Video mode without preview, system not support, expected return fail.
358 * @tc.level: Level2
359 * @tc.size: MediumTest
360 * @tc.type: Function
361 */
TEST_F(UtestVideoTest,camera_video_0030)362 TEST_F(UtestVideoTest, camera_video_0030)
363 {
364 std::cout << "==========[test log] Video mode without preview, system not support,";
365 std::cout << "expected return fail." << std::endl;
366
367 EXPECT_EQ(true, display_->cameraDevice != nullptr);
368 display_->AchieveStreamOperator();
369 // 创建视频流
370 std::vector<std::shared_ptr<StreamInfo>> streamInfos;
371 std::shared_ptr<IBufferProducer> producer = IBufferProducer::CreateBufferQueue();
372 producer->SetQueueSize(8); // 8:set bufferQueue size
373 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
374 std::cout << "~~~~~~~" << std::endl;
375 }
376 auto callbackVideo = [this](std::shared_ptr<SurfaceBuffer> b) {
377 display_->BufferCallback(b, display_->video_mode);
378 return;
379 };
380 producer->SetCallback(callbackVideo);
381 display_->streamInfo = std::make_shared<OHOS::Camera::StreamInfo>();
382 display_->streamInfo->streamId_ = display_->streamId_video;
383 display_->streamInfo->width_ = 640; // 640:picture width
384 display_->streamInfo->height_ = 480; // 480:picture height
385 display_->streamInfo->format_ = CAMERA_FORMAT_YUYV_422_PKG;
386 display_->streamInfo->datasapce_ = 10;
387 display_->streamInfo->intent_ = Camera::VIDEO;
388 display_->streamInfo->tunneledMode_ = 5; // 5:tunnel mode
389 display_->streamInfo->bufferQueue_ = producer;
390 std::vector<std::shared_ptr<OHOS::Camera::StreamInfo>>().swap(streamInfos);
391 streamInfos.push_back(display_->streamInfo);
392 display_->rc = display_->streamOperator->CreateStreams(streamInfos);
393 EXPECT_EQ(false, display_->rc == Camera::METHOD_NOT_SUPPORTED);
394 if (display_->rc == Camera::METHOD_NOT_SUPPORTED) {
395 std::cout << "==========[test log] CreateStreams METHOD_NOT_SUPPORTED, streamId = ";
396 std::cout << display_->streamId_video <<", intent = Camera::VIDEO" << std::endl;
397 } else {
398 std::cout << "==========[test log] CreateStreams fail, rc = " << display_->rc << std::endl;
399 }
400
401 display_->rc = display_->streamOperator->CommitStreams(Camera::NORMAL, nullptr);
402 EXPECT_EQ(false, display_->rc == Camera::NO_ERROR);
403 if (display_->rc == Camera::NO_ERROR) {
404 std::cout << "==========[test log] CommitStreams success." << std::endl;
405 } else {
406 std::cout << "==========[test log] CommitStreams fail, rc = ." << display_->rc << std::endl;
407 }
408 }