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
16 #include "video_test.h"
17
18 using namespace OHOS;
19 using namespace std;
20 using namespace testing::ext;
21 using namespace OHOS::Camera;
22
SetUpTestCase(void)23 void VideoTest::SetUpTestCase(void) {}
TearDownTestCase(void)24 void VideoTest::TearDownTestCase(void) {}
SetUp(void)25 void VideoTest::SetUp(void)
26 {
27 Test_ = std::make_shared<OHOS::Camera::Test>();
28 Test_->Init();
29 Test_->Open();
30 }
TearDown(void)31 void VideoTest::TearDown(void)
32 {
33 Test_->Close();
34 }
35
36 /**
37 * @tc.name: Video
38 * @tc.desc: Preview and video streams, Commit 2 streams together, capture in order.
39 * @tc.size: MediumTest
40 * @tc.type: Function
41 */
42 HWTEST_F(VideoTest, Camera_Video_0001, TestSize.Level0)
43 {
44 std::cout << "==========[test log]Check video: Preview and video streams, ";
45 std::cout << "Commit 2 streams together, capture in order." << std::endl;
46 // Configure two stream information
47 Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
48 Test_->StartStream(Test_->intents);
49 // Capture preview stream
50 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
51 // Capture video stream
52 Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
53 // Post-processing
54 sleep(3); // sleep for 3 seconds
55 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
56 Test_->streamIds.push_back(Test_->streamId_preview);
57 Test_->streamIds.push_back(Test_->streamId_video);
58 Test_->StopStream(Test_->captureIds, Test_->streamIds);
59 Test_->StopConsumer(Test_->intents);
60 }
61
62 /**
63 * @tc.name: Video
64 * @tc.desc: Preview and video streams + 3A, Commit 2 streams together, capture in order.
65 * @tc.size: MediumTest
66 * @tc.type: Function
67 */
68 HWTEST_F(VideoTest, Camera_Video_0002, TestSize.Level1)
69 {
70 std::cout << "==========[test log]Check video: Preview and video streams + 3A, ";
71 std::cout << "Commit 2 streams together, capture in order." << std::endl;
72 // Configure two stream information
73 Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
74 Test_->StartStream(Test_->intents);
75 // Capture preview stream
76 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
77 // Issue 3A parameters to increase exposure
78 std::shared_ptr<Camera::CameraSetting> meta = std::make_shared<Camera::CameraSetting>(100, 2000);
79 int32_t expo = 0xb0;
80 meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1);
81 Test_->rc = Test_->cameraDevice->UpdateSettings(meta);
82 if (Test_->rc == Camera::NO_ERROR) {
83 std::cout << "==========[test log]check Capture: UpdateSettings success, for 10s." << std::endl;
84 } else {
85 std::cout << "==========[test log]check Capture: UpdateSettings fail, rc = " << Test_->rc << std::endl;
86 }
87 // Capture video stream
88 Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
89 sleep(3); // sleep for 3 seconds
90 // Post-processing
91 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
92 Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
93 Test_->StopStream(Test_->captureIds, Test_->streamIds);
94 Test_->StopConsumer(Test_->intents);
95 }
96
97 /**
98 * @tc.name: Video
99 * @tc.desc: Preview + video, commit together, then close device, and preview + video again.
100 * @tc.size: MediumTest
101 * @tc.type: Function
102 */
103 HWTEST_F(VideoTest, Camera_Video_0003, TestSize.Level1)
104 {
105 std::cout << "==========[test log]Check video: Preview + video, ";
106 std::cout << "commit together, then close device, and preview + video again." << std::endl;
107 // Configure two stream information
108 Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
109 Test_->StartStream(Test_->intents);
110 // Capture preview stream
111 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
112 // Capture video stream
113 Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
114 // Post-processing
115 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
116 Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
117 Test_->StopStream(Test_->captureIds, Test_->streamIds);
118 Test_->consumerMap_.clear();
119 std::cout << "==========[test log]Check video: The 2nd time." << std::endl;
120 // second Configure two stream information
121 // Configure two stream information
122 Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
123 Test_->StartStream(Test_->intents);
124 // Capture preview stream
125 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
126 // Capture video stream
127 Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
128 // Post-processing
129 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
130 Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
131 Test_->StopStream(Test_->captureIds, Test_->streamIds);
132 Test_->StopConsumer(Test_->intents);
133 }
134
135 /**
136 * @tc.name: Video
137 * @tc.desc: Preview + video, commit together, then close device, and preview + capture.
138 * @tc.size: MediumTest
139 * @tc.type: Function
140 */
141 HWTEST_F(VideoTest, Camera_Video_0004, TestSize.Level1)
142 {
143 std::cout << "==========[test log]Check video: Preview + video, ";
144 std::cout << "commit together, then close device, and preview + capture." << std::endl;
145 // Configure two stream information
146 Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
147 Test_->StartStream(Test_->intents);
148 // Capture preview stream
149 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
150 // Capture video stream
151 Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
152 // Post-processing
153 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
154 Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
155 Test_->StopStream(Test_->captureIds, Test_->streamIds);
156 Test_->consumerMap_.clear();
157
158 std::cout << "==========[test log]Check video: The 2nd time." << std::endl;
159 // Configure two stream information
160 Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
161 Test_->StartStream(Test_->intents);
162 // Capture preview stream
163 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
164 // Capture camera stream, continuous capture
165 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
166 // Post-processing
167 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
168 Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture};
169 Test_->StopStream(Test_->captureIds, Test_->streamIds);
170 Test_->StopConsumer(Test_->intents);
171 }
172
173 /**
174 * @tc.name: Video
175 * @tc.desc: Preview + video, commit together, success.
176 * @tc.size: MediumTest
177 * @tc.type: Function
178 */
179 HWTEST_F(VideoTest, Camera_Video_0005, TestSize.Level0)
180 {
181 std::cout << "==========[test log]Check video: Preview + video, commit together, success." << std::endl;
182 // Configure two stream information
183 Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
184 Test_->StartStream(Test_->intents);
185 // Capture preview stream
186 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
187 // Capture video stream
188 Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
189 // Post-processing
190 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
191 Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
192 Test_->StopStream(Test_->captureIds, Test_->streamIds);
193 Test_->StopConsumer(Test_->intents);
194 }
195
196 /**
197 * @tc.name: Video
198 * @tc.desc: Dynamic Video mode, preview, success.
199 * @tc.size: MediumTest
200 * @tc.type: Function
201 */
202 HWTEST_F(VideoTest, Camera_Video_0020, TestSize.Level1)
203 {
204 std::cout << "==========[test log]Check video: Video mode, preview, success." << std::endl;
205 // Start preview stream
206 Test_->intents = {Camera::PREVIEW};
207 Test_->StartStream(Test_->intents);
208 // Get preview
209 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
210 // Start stream
211 Test_->intents = {Camera::VIDEO};
212 Test_->StartStream(Test_->intents);
213 // Start capture
214 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
215 Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
216 // Release stream
217 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
218 Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
219 Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
220 Test_->StopStream(Test_->captureIds, Test_->streamIds);
221 Test_->StopConsumer(Test_->intents);
222 }
223
224 /**
225 * @tc.name: Video
226 * @tc.desc: Video mode, preview, set 3A, success.
227 * @tc.size: MediumTest
228 * @tc.type: Function
229 */
230 HWTEST_F(VideoTest, Camera_Video_0021, TestSize.Level1)
231 {
232 std::cout << "==========[test log]Check video: Video mode, preview, set 3A, success." << std::endl;
233 // Configure two stream information
234 Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
235 Test_->StartStream(Test_->intents);
236 // Capture preview stream
237 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
238 // Issue 3A parameters to increase exposure
239 std::shared_ptr<Camera::CameraSetting> meta = std::make_shared<Camera::CameraSetting>(100, 2000);
240 int32_t expo = 0xc0;
241 meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1);
242 Test_->rc = Test_->cameraDevice->UpdateSettings(meta);
243 if (Test_->rc == Camera::NO_ERROR) {
244 std::cout << "==========[test log]check Capture: UpdateSettings success, for 10s." << std::endl;
245 } else {
246 std::cout << "==========[test log]check Capture: UpdateSettings fail, rc = " << Test_->rc << std::endl;
247 }
248 // Capture preview stream
249 Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
250 sleep(3); // sleep for 3 seconds
251 // Post-processing
252 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
253 Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
254 Test_->StopStream(Test_->captureIds, Test_->streamIds);
255 Test_->StopConsumer(Test_->intents);
256 }
257
258 /**
259 * @tc.name: Video
260 * @tc.desc: Preview and video streams + 3A, Commit 2 streams together, video in order.
261 * @tc.size: MediumTest
262 * @tc.type: Function
263 */
264 HWTEST_F(VideoTest, Camera_Video_0022, TestSize.Level2)
265 {
266 std::cout << "==========[test log]Check video: Preview and video streams + 3A, ";
267 std::cout << "Commit 2 streams together, capture in order." << std::endl;
268 // Configure two stream information
269 Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
270 Test_->StartStream(Test_->intents);
271 Test_->StopConsumer({Camera::VIDEO});
272 // Capture preview stream
273 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
274 // Issue 3A parameters to increase exposure
275 std::shared_ptr<Camera::CameraSetting> meta = std::make_shared<Camera::CameraSetting>(100, 2000);
276 int32_t expo = 0xb0;
277 meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1);
278 Test_->rc = Test_->cameraDevice->UpdateSettings(meta);
279 if (Test_->rc == Camera::NO_ERROR) {
280 std::cout << "==========[test log]check Capture: UpdateSettings success, for 10s." << std::endl;
281 } else {
282 std::cout << "==========[test log]check Capture: UpdateSettings fail, rc = " << Test_->rc << std::endl;
283 }
284 // Capture video stream
285 Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
286 sleep(3); // sleep for 3 seconds
287 // Post-processing
288 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
289 Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
290 Test_->StopStream(Test_->captureIds, Test_->streamIds);
291 }