• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
83     if (Test_->rc == Camera::NO_ERROR) {
84         std::cout << "==========[test log]check Capture: UpdateSettings success, for 10s." << std::endl;
85     } else {
86         std::cout << "==========[test log]check Capture: UpdateSettings fail, rc = " << Test_->rc << std::endl;
87     }
88     // Capture video stream
89     Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
90     sleep(3); // sleep for 3 seconds
91     // Post-processing
92     Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
93     Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
94     Test_->StopStream(Test_->captureIds, Test_->streamIds);
95     Test_->StopConsumer(Test_->intents);
96 }
97 
98 /**
99   * @tc.name: Video
100   * @tc.desc: Preview + video, commit together, then close device, and preview + video again.
101   * @tc.size: MediumTest
102   * @tc.type: Function
103   */
104 HWTEST_F(VideoTest, Camera_Video_0003, TestSize.Level1)
105 {
106     std::cout << "==========[test log]Check video: Preview + video, ";
107     std::cout << "commit together, then close device, and preview + video again." << std::endl;
108     // Configure two stream information
109     Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
110     Test_->StartStream(Test_->intents);
111     // Capture preview stream
112     Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
113     // Capture video stream
114     Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
115     // Post-processing
116     Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
117     Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
118     Test_->StopStream(Test_->captureIds, Test_->streamIds);
119     Test_->consumerMap_.clear();
120     std::cout << "==========[test log]Check video: The 2nd time." << std::endl;
121     // second Configure two stream information
122     // Configure two stream information
123     Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
124     Test_->StartStream(Test_->intents);
125     // Capture preview stream
126     Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
127     // Capture video stream
128     Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
129     // Post-processing
130     Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
131     Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
132     Test_->StopStream(Test_->captureIds, Test_->streamIds);
133     Test_->StopConsumer(Test_->intents);
134 }
135 
136 /**
137   * @tc.name: Video
138   * @tc.desc: Preview + video, commit together, then close device, and preview + capture.
139   * @tc.size: MediumTest
140   * @tc.type: Function
141   */
142 HWTEST_F(VideoTest, Camera_Video_0004, TestSize.Level1)
143 {
144     std::cout << "==========[test log]Check video: Preview + video, ";
145     std::cout << "commit together, then close device, and preview + capture." << std::endl;
146     // Configure two stream information
147     Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
148     Test_->StartStream(Test_->intents);
149     // Capture preview stream
150     Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
151     // Capture video stream
152     Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
153     // Post-processing
154     Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
155     Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
156     Test_->StopStream(Test_->captureIds, Test_->streamIds);
157     Test_->consumerMap_.clear();
158 
159     std::cout << "==========[test log]Check video: The 2nd time." << std::endl;
160     // Configure two stream information
161     Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
162     Test_->StartStream(Test_->intents);
163     // Capture preview stream
164     Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
165     // Capture camera stream, continuous capture
166     Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
167     // Post-processing
168     Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
169     Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture};
170     Test_->StopStream(Test_->captureIds, Test_->streamIds);
171     Test_->StopConsumer(Test_->intents);
172 }
173 
174 /**
175   * @tc.name: Video
176   * @tc.desc: Preview + video, commit together, success.
177   * @tc.size: MediumTest
178   * @tc.type: Function
179   */
180 HWTEST_F(VideoTest, Camera_Video_0005, TestSize.Level0)
181 {
182     std::cout << "==========[test log]Check video: Preview + video, commit together, success." << std::endl;
183     // Configure two stream information
184     Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
185     Test_->StartStream(Test_->intents);
186     // Capture preview stream
187     Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
188     // Capture video stream
189     Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
190     // Post-processing
191     Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
192     Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
193     Test_->StopStream(Test_->captureIds, Test_->streamIds);
194     Test_->StopConsumer(Test_->intents);
195 }
196 
197 /**
198   * @tc.name: Video
199   * @tc.desc: Dynamic Video mode, preview, success.
200   * @tc.size: MediumTest
201   * @tc.type: Function
202   */
203 HWTEST_F(VideoTest, Camera_Video_0020, TestSize.Level1)
204 {
205     std::cout << "==========[test log]Check video: Video mode, preview, success." << std::endl;
206     // Start preview stream
207     Test_->intents = {Camera::PREVIEW};
208     Test_->StartStream(Test_->intents);
209     // Get preview
210     Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
211     // Start stream
212     Test_->intents = {Camera::VIDEO};
213     Test_->StartStream(Test_->intents);
214     // Start capture
215     Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
216     Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
217     // Release stream
218     Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
219     Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
220     Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
221     Test_->StopStream(Test_->captureIds, Test_->streamIds);
222     Test_->StopConsumer(Test_->intents);
223 }
224 
225 /**
226   * @tc.name: Video
227   * @tc.desc: Video mode, preview, set 3A, success.
228   * @tc.size: MediumTest
229   * @tc.type: Function
230   */
231 HWTEST_F(VideoTest, Camera_Video_0021, TestSize.Level1)
232 {
233     std::cout << "==========[test log]Check video: Video mode, preview, set 3A, success." << std::endl;
234     // Configure two stream information
235     Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
236     Test_->StartStream(Test_->intents);
237     // Capture preview stream
238     Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
239     // Issue 3A parameters to increase exposure
240     std::shared_ptr<Camera::CameraSetting> meta = std::make_shared<Camera::CameraSetting>(100, 2000);
241     int32_t expo = 0xc0;
242     meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1);
243     Test_->rc = Test_->cameraDevice->UpdateSettings(meta);
244     EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
245     if (Test_->rc == Camera::NO_ERROR) {
246         std::cout << "==========[test log]check Capture: UpdateSettings success, for 10s." << std::endl;
247     } else {
248         std::cout << "==========[test log]check Capture: UpdateSettings fail, rc = " << Test_->rc << std::endl;
249     }
250     // Capture preview stream
251     Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
252     sleep(3); // sleep for 3 seconds
253     // Post-processing
254     Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
255     Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
256     Test_->StopStream(Test_->captureIds, Test_->streamIds);
257     Test_->StopConsumer(Test_->intents);
258 }
259 
260 /**
261   * @tc.name: Video
262   * @tc.desc: Preview and video streams + 3A, Commit 2 streams together, video in order.
263   * @tc.size: MediumTest
264   * @tc.type: Function
265   */
266 HWTEST_F(VideoTest, Camera_Video_0022, TestSize.Level2)
267 {
268     std::cout << "==========[test log]Check video: Preview and video streams + 3A, ";
269     std::cout << "Commit 2 streams together, capture in order." << std::endl;
270     // Configure two stream information
271     Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
272     Test_->StartStream(Test_->intents);
273     Test_->StopConsumer({Camera::VIDEO});
274     // Capture preview stream
275     Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
276     // Issue 3A parameters to increase exposure
277     std::shared_ptr<Camera::CameraSetting> meta = std::make_shared<Camera::CameraSetting>(100, 2000);
278     int32_t expo = 0xb0;
279     meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1);
280     Test_->rc = Test_->cameraDevice->UpdateSettings(meta);
281     EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
282     if (Test_->rc == Camera::NO_ERROR) {
283         std::cout << "==========[test log]check Capture: UpdateSettings success, for 10s." << std::endl;
284     } else {
285         std::cout << "==========[test log]check Capture: UpdateSettings fail, rc = " << Test_->rc << std::endl;
286     }
287     // Capture video stream
288     Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
289     sleep(3); // sleep for 3 seconds
290     // Post-processing
291     Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
292     Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
293     Test_->StopStream(Test_->captureIds, Test_->streamIds);
294 }