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_video_test.h"
16
17 using namespace testing::ext;
18
SetUpTestCase(void)19 void CameraVideoTest::SetUpTestCase(void)
20 {}
TearDownTestCase(void)21 void CameraVideoTest::TearDownTestCase(void)
22 {}
SetUp(void)23 void CameraVideoTest::SetUp(void)
24 {
25 if (display_ == nullptr)
26 display_ = std::make_shared<TestDisplay>();
27 display_->Init();
28 }
TearDown(void)29 void CameraVideoTest::TearDown(void)
30 {
31 display_->Close();
32 }
33
SetStreamInfo(StreamInfo & streamInfo,const std::shared_ptr<StreamCustomer> & streamCustomer,const int streamId,const StreamIntent intent)34 void CameraVideoTest::SetStreamInfo(StreamInfo &streamInfo, const std::shared_ptr<StreamCustomer> &streamCustomer,
35 const int streamId, const StreamIntent intent)
36 {
37 sptr<OHOS::IBufferProducer> producer;
38 constexpr uint32_t DATA_SPACE = 8;
39 constexpr uint32_t TUNNEL_MODE = 5;
40 constexpr uint32_t BUFFER_QUEUE_SIZE = 8;
41 constexpr uint32_t WIDTH = 1280;
42 constexpr uint32_t HEIGHT = 960;
43 if (intent == PREVIEW) {
44 streamInfo.width_ = PREVIEW_WIDTH;
45 streamInfo.height_ = PREVIEW_HEIGHT;
46 } else if (intent == STILL_CAPTURE) {
47 streamInfo.width_ = WIDTH;
48 streamInfo.height_ = HEIGHT;
49 streamInfo.encodeType_ = ENCODE_TYPE_JPEG;
50 } else if (intent == VIDEO) {
51 streamInfo.width_ = WIDTH;
52 streamInfo.height_ = HEIGHT;
53 streamInfo.encodeType_ = ENCODE_TYPE_H264;
54 }
55 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
56 streamInfo.streamId_ = streamId;
57 streamInfo.dataspace_ = DATA_SPACE;
58 streamInfo.intent_ = intent;
59 streamInfo.tunneledMode_ = TUNNEL_MODE;
60 producer = streamCustomer->CreateProducer();
61 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
62 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
63 streamInfo.bufferQueue_->producer_->SetQueueSize(BUFFER_QUEUE_SIZE);
64 }
65
CreateStream(int streamId,StreamIntent intent)66 void CameraVideoTest::CreateStream(int streamId, StreamIntent intent)
67 {
68 StreamInfo streamInfo = {};
69 if (intent == PREVIEW) {
70 if (streamId == display_->STREAM_ID_PREVIEW) {
71 if (streamCustomerPreview_ == nullptr) {
72 streamCustomerPreview_ = std::make_shared<StreamCustomer>();
73 SetStreamInfo(streamInfo, streamCustomerPreview_, streamId, intent);
74 }
75 }
76 } else if (intent == STILL_CAPTURE) {
77 if (streamCustomerSnapshot_ == nullptr) {
78 streamCustomerSnapshot_ = std::make_shared<StreamCustomer>();
79 SetStreamInfo(streamInfo, streamCustomerSnapshot_, streamId, intent);
80 }
81 } else if (intent == VIDEO) {
82 if (streamCustomerVideo_ == nullptr) {
83 streamCustomerVideo_ = std::make_shared<StreamCustomer>();
84 SetStreamInfo(streamInfo, streamCustomerVideo_, streamId, intent);
85 }
86 }
87 std::vector<StreamInfo>().swap(streamInfos_);
88 streamInfos_.push_back(streamInfo);
89 CamRetCode result = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos_);
90 EXPECT_EQ(false, result != HDI::Camera::V1_0::NO_ERROR);
91 if (result == HDI::Camera::V1_0::NO_ERROR) {
92 CAMERA_LOGI("CreateStreams success.");
93 } else {
94 CAMERA_LOGE("CreateStreams fail, result = %{public}d", result);
95 }
96 }
97
CommitStream()98 void CameraVideoTest::CommitStream()
99 {
100 CamRetCode result = (CamRetCode)display_->streamOperator->CommitStreams(NORMAL, display_->ability_);
101 EXPECT_EQ(false, result != HDI::Camera::V1_0::NO_ERROR);
102 if (result == HDI::Camera::V1_0::NO_ERROR) {
103 CAMERA_LOGI("CommitStreams success.");
104 } else {
105 CAMERA_LOGE("CommitStreams fail, result = %{public}d", result);
106 }
107 }
StartCapture(int streamId,int captureId,bool shutterCallback,bool isStreaming,const CaptureInfo captureInfo)108 void CameraVideoTest::StartCapture(
109 int streamId, int captureId, bool shutterCallback, bool isStreaming, const CaptureInfo captureInfo)
110 {
111 captureInfo_.streamIds_ = {streamId};
112 captureInfo_.captureSetting_ = display_->ability_;
113 captureInfo_.enableShutterCallback_ = shutterCallback;
114 CamRetCode result;
115 if (captureInfo.captureSetting_.size() != 0) {
116 result = (CamRetCode)display_->streamOperator->Capture(captureId, captureInfo, isStreaming);
117 } else {
118 result = (CamRetCode)display_->streamOperator->Capture(captureId, captureInfo_, isStreaming);
119 }
120
121 EXPECT_EQ(true, result == HDI::Camera::V1_0::NO_ERROR);
122 if (result == HDI::Camera::V1_0::NO_ERROR) {
123 CAMERA_LOGI("check Capture: Capture success, captureId = %{public}d", captureId);
124 } else {
125 CAMERA_LOGE("check Capture: Capture fail, captureId = %{public}d, result = %{public}d", captureId, result);
126 }
127
128 if (captureId == display_->CAPTURE_ID_PREVIEW) {
129 streamCustomerPreview_->ReceiveFrameOn([this](const unsigned char *addr, const uint32_t size) {
130 CAMERA_LOGI("preview size = %{public}u", size);
131 });
132 } else if (captureId == display_->CAPTURE_ID_CAPTURE) {
133 streamCustomerSnapshot_->ReceiveFrameOn([this](const unsigned char *addr, const uint32_t size) {
134 CAMERA_LOGI("snapshot size = %{public}u", size);
135 });
136 } else if (captureId == display_->CAPTURE_ID_VIDEO) {
137 streamCustomerVideo_->ReceiveFrameOn([this](const unsigned char *addr, const uint32_t size) {
138 CAMERA_LOGI("video size = %{public}u", size);
139 });
140 } else {
141 CAMERA_LOGE("StartCapture ignore command");
142 }
143 }
144
StopStream(std::vector<int> & captureIds,std::vector<int> & streamIds)145 void CameraVideoTest::StopStream(std::vector<int> &captureIds, std::vector<int> &streamIds)
146 {
147 constexpr uint32_t TIME_FOR_RECEIVE_FRAME_OFF = 1;
148 constexpr uint32_t TIME_FOR_WAIT_IMAGE_PREVIEW = 2;
149 sleep(TIME_FOR_WAIT_IMAGE_PREVIEW);
150 if (sizeof(captureIds) > 0) {
151 for (const auto &captureId : captureIds) {
152 if (captureId == display_->CAPTURE_ID_PREVIEW) {
153 streamCustomerPreview_->ReceiveFrameOff();
154 } else if (captureId == display_->CAPTURE_ID_CAPTURE) {
155 streamCustomerSnapshot_->ReceiveFrameOff();
156 } else if (captureId == display_->CAPTURE_ID_VIDEO) {
157 streamCustomerVideo_->ReceiveFrameOff();
158 sleep(TIME_FOR_RECEIVE_FRAME_OFF);
159 } else {
160 CAMERA_LOGE("StopStream ignore command.");
161 }
162 }
163
164 for (auto &captureId : captureIds) {
165 CamRetCode result = (CamRetCode)display_->streamOperator->CancelCapture(captureId);
166 sleep(TIME_FOR_WAIT_IMAGE_PREVIEW);
167 EXPECT_EQ(true, result == HDI::Camera::V1_0::NO_ERROR);
168 if (result == HDI::Camera::V1_0::NO_ERROR) {
169 CAMERA_LOGI("check Capture: CancelCapture success, captureId = %{public}d", captureId);
170 } else {
171 CAMERA_LOGE("check Capture: CancelCapture fail, captureId = %{public}d, result = %{public}d",
172 captureId, result);
173 }
174 }
175 }
176 sleep(TIME_FOR_RECEIVE_FRAME_OFF);
177 }
178 /**
179 * @tc.name: Video
180 * @tc.desc: Preview + video, commit together, success.
181 * @tc.level: Level1
182 * @tc.size: MediumTest
183 * @tc.type: Function
184 */
185 HWTEST_F(CameraVideoTest, SUB_DriverSystem_CameraHdi_0250, TestSize.Level1)
186 {
187 CAMERA_LOGD("Preview + video, commit together, success.");
188 // Create and get streamOperator information
189 display_->AchieveStreamOperator();
190 // start stream
191 display_->intents = {PREVIEW, VIDEO};
192 display_->StartStream(display_->intents);
193 // Get preview
194 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
195 display_->StartCapture(display_->STREAM_ID_VIDEO, display_->CAPTURE_ID_VIDEO, false, true);
196
197 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_VIDEO};
198 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_VIDEO};
199 display_->StopStream(display_->captureIds, display_->streamIds);
200 }
201
202 /**
203 * @tc.name: Video
204 * @tc.desc: Preview + video, commit together, set 3A, success.
205 * @tc.level: Level1
206 * @tc.size: MediumTest
207 * @tc.type: Function
208 */
209 HWTEST_F(CameraVideoTest, SUB_DriverSystem_CameraHdi_0260, TestSize.Level1)
210 {
211 CAMERA_LOGD("Preview + video, commit together, set 3A, success.");
212 // Create and get streamOperator information
213 display_->AchieveStreamOperator();
214
215 std::vector<int32_t> resultsList;
216 resultsList.push_back(OHOS_CAMERA_STREAM_ID);
217 resultsList.push_back(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION);
218 display_->cameraDevice->EnableResult(resultsList);
219
220 // start stream
221 display_->intents = {PREVIEW, VIDEO};
222 display_->StartStream(display_->intents);
223 // Get preview
224 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
225 display_->StartCapture(display_->STREAM_ID_VIDEO, display_->CAPTURE_ID_VIDEO, false, true);
226 // Issue 3A parameters to increase exposure
227 std::shared_ptr<CameraSetting> meta = std::make_shared<CameraSetting>(100, 2000);
228 int32_t expo = 0xa0;
229 meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1);
230 const int32_t deviceStreamId = 0;
231 meta->addEntry(OHOS_CAMERA_STREAM_ID, &deviceStreamId, 1);
232 std::vector<uint8_t> setting;
233 MetadataUtils::ConvertMetadataToVec(meta, setting);
234 display_->rc = (CamRetCode)display_->cameraDevice->UpdateSettings(setting);
235 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
236 CAMERA_LOGI("UpdateSettings success, for 5s.");
237 } else {
238 CAMERA_LOGE("UpdateSettings fail, rc = %{public}d", display_->rc);
239 }
240 sleep(3);
241
242 // release stream
243 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_VIDEO};
244 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_VIDEO};
245 display_->StopStream(display_->captureIds, display_->streamIds);
246 }
247
248 /**
249 * @tc.name: Video
250 * @tc.desc: Preview + video, commit together, then close device, and preview + video again.
251 * @tc.level: Level1
252 * @tc.size: MediumTest
253 * @tc.type: Function
254 */
255 HWTEST_F(CameraVideoTest, SUB_DriverSystem_CameraHdi_0270, TestSize.Level1)
256 {
257 CAMERA_LOGD("Preview + video, commit together, then close device, and preview + video again.");
258 // Create and get streamOperator information
259 display_->AchieveStreamOperator();
260 // start stream
261 display_->intents = {PREVIEW, VIDEO};
262 display_->StartStream(display_->intents);
263 // Get preview
264 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
265 display_->StartCapture(display_->STREAM_ID_VIDEO, display_->CAPTURE_ID_VIDEO, false, true);
266 // release stream
267 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_VIDEO};
268 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_VIDEO};
269 display_->StopStream(display_->captureIds, display_->streamIds);
270
271 // Turn off the device
272 display_->Close();
273 // Turn on the device
274 display_->Init();
275 CAMERA_LOGD("The 2nd time.");
276
277 // Create and get streamOperator information
278 display_->AchieveStreamOperator();
279 // start stream
280 display_->intents = {PREVIEW, VIDEO};
281 display_->StartStream(display_->intents);
282 // Get preview
283 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
284 display_->StartCapture(display_->STREAM_ID_VIDEO, display_->CAPTURE_ID_VIDEO, false, true);
285 // release stream
286 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_VIDEO};
287 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_VIDEO};
288 display_->StopStream(display_->captureIds, display_->streamIds);
289 }
290
291 /**
292 * @tc.name: Video
293 * @tc.desc: Preview + video, commit together, then close device, and preview + capture.
294 * @tc.level: Level1
295 * @tc.size: MediumTest
296 * @tc.type: Function
297 */
298 HWTEST_F(CameraVideoTest, SUB_DriverSystem_CameraHdi_0280, TestSize.Level1)
299 {
300 CAMERA_LOGD("Preview + video, commit together, then close device, and preview + capture.");
301 std::cout << "and preview + capture." << std::endl;
302 // Create and get streamOperator information
303 display_->AchieveStreamOperator();
304 // start stream
305 display_->intents = {PREVIEW, VIDEO};
306 display_->StartStream(display_->intents);
307 // Get preview
308 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
309 display_->StartCapture(display_->STREAM_ID_VIDEO, display_->CAPTURE_ID_VIDEO, false, true);
310 // release stream
311 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_VIDEO};
312 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_VIDEO};
313 display_->StopStream(display_->captureIds, display_->streamIds);
314
315 // Turn off the device
316 display_->Close();
317 CAMERA_LOGD("cameraDevice->Close");
318 // Turn on the device
319 display_->Init();
320
321 // Create and get streamOperator information
322 display_->AchieveStreamOperator();
323 // start stream
324 display_->intents = {PREVIEW, STILL_CAPTURE};
325 display_->StartStream(display_->intents);
326 // Get preview
327 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
328 display_->StartCapture(display_->STREAM_ID_CAPTURE, display_->CAPTURE_ID_CAPTURE, false, true);
329 // release stream
330 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_CAPTURE};
331 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_CAPTURE};
332 display_->StopStream(display_->captureIds, display_->streamIds);
333 }
334
335 /**
336 * @tc.name: Video
337 * @tc.desc: Preview + video, commit together, success.
338 * @tc.level: Level1
339 * @tc.size: MediumTest
340 * @tc.type: Function
341 */
342 HWTEST_F(CameraVideoTest, camera_video_005, TestSize.Level1)
343 {
344 CAMERA_LOGD("Preview + video, commit together, success.");
345 // Create and get streamOperator information
346 display_->AchieveStreamOperator();
347 // start stream
348 display_->intents = {PREVIEW, VIDEO};
349 display_->StartStream(display_->intents);
350 // Get preview
351 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
352 display_->StartCapture(display_->STREAM_ID_VIDEO, display_->CAPTURE_ID_VIDEO, false, true);
353 // release stream
354 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_VIDEO};
355 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_VIDEO};
356 display_->StopStream(display_->captureIds, display_->streamIds);
357 }
358
359 /**
360 * @tc.name: Video
361 * @tc.desc: Video start&stop, for 5 times, success.
362 * @tc.level: Level2
363 * @tc.size: MediumTest
364 * @tc.type: Function
365 */
366 HWTEST_F(CameraVideoTest, camera_video_010, TestSize.Level2)
367 {
368 CAMERA_LOGD("Video start&stop, for 5 times, success.");
369 // Create and get streamOperator information
370 display_->AchieveStreamOperator();
371 for (int i = 0; i < 5; i++) {
372 // start stream
373 display_->intents = {PREVIEW, VIDEO};
374 display_->StartStream(display_->intents);
375 // Get preview
376 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
377 display_->StartCapture(display_->STREAM_ID_VIDEO, display_->CAPTURE_ID_VIDEO, false, true);
378 // release stream
379 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_VIDEO};
380 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_VIDEO};
381 display_->StopStream(display_->captureIds, display_->streamIds);
382 }
383 }
384
385 /**
386 * @tc.name: Video
387 * @tc.desc: Video start&stop, for 5 times, success.
388 * @tc.level: Level2
389 * @tc.size: MediumTest
390 * @tc.type: Function
391 */
392 HWTEST_F(CameraVideoTest, camera_video_011, TestSize.Level2)
393 {
394 CAMERA_LOGD("Video start&stop, for 5 times, success.");
395 // Create and get streamOperator information
396 display_->AchieveStreamOperator();
397 for (int i = 0; i < 5; i++) {
398 // start stream
399 display_->intents = {PREVIEW, VIDEO};
400 display_->StartStream(display_->intents);
401
402 // Start capture preview
403 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
404 // Start capture recording
405 display_->StartCapture(display_->STREAM_ID_VIDEO, display_->CAPTURE_ID_VIDEO, false, true);
406
407 // post-processing
408 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_VIDEO};
409 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_VIDEO};
410 display_->StopStream(display_->captureIds, display_->streamIds);
411 }
412 }
413
414 /**
415 * @tc.name: Video
416 * @tc.desc: Dynamic Video mode, preview, success.
417 * @tc.level: Level2
418 * @tc.size: MediumTest
419 * @tc.type: Function
420 */
421 HWTEST_F(CameraVideoTest, camera_video_020, TestSize.Level2)
422 {
423 CAMERA_LOGD("Video mode, preview, success.");
424 // Create and get streamOperator information
425 display_->AchieveStreamOperator();
426 // Create video stream
427 display_->intents = {PREVIEW, VIDEO};
428 display_->StartStream(display_->intents);
429 // Start capture recording
430 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
431 display_->StartCapture(display_->STREAM_ID_VIDEO, display_->CAPTURE_ID_VIDEO, false, true);
432
433 // post-processing
434 display_->streamCustomerPreview_->ReceiveFrameOff();
435 display_->streamCustomerVideo_->ReceiveFrameOff();
436 display_->rc = (CamRetCode)display_->streamOperator->CancelCapture(display_->CAPTURE_ID_VIDEO);
437 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
438 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
439 CAMERA_LOGI("CancelCapture success, captureId = %{public}d", display_->CAPTURE_ID_VIDEO);
440 } else {
441 CAMERA_LOGE("CancelCapture fail, rc = %{public}d", display_->rc);
442 }
443 display_->rc = (CamRetCode)display_->streamOperator->CancelCapture(display_->CAPTURE_ID_PREVIEW);
444 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
445 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
446 CAMERA_LOGI("CancelCapture success, captureId = %{public}d", display_->CAPTURE_ID_PREVIEW);
447 } else {
448 CAMERA_LOGE("CancelCapture fail, rc = %{public}d", display_->rc);
449 }
450 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(
451 {display_->STREAM_ID_VIDEO});
452 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
453 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
454 CAMERA_LOGI("ReleaseStreams success.");
455 } else {
456 CAMERA_LOGE("ReleaseStreams fail, rc = %{public}d", display_->rc);
457 }
458 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(
459 {display_->STREAM_ID_PREVIEW});
460 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
461 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
462 CAMERA_LOGI("ReleaseStreams success.");
463 } else {
464 CAMERA_LOGE("ReleaseStreams fail, rc = %{public}d", display_->rc);
465 }
466 }
467
468 /**
469 * @tc.name: Video
470 * @tc.desc: Video mode, preview, set 3A, success.
471 * @tc.level: Level1
472 * @tc.size: MediumTest
473 * @tc.type: Function
474 */
475 HWTEST_F(CameraVideoTest, camera_video_021, TestSize.Level1)
476 {
477 CAMERA_LOGD("Video mode, preview, set 3A, success.");
478 EXPECT_EQ(true, display_->cameraDevice != nullptr);
479 display_->AchieveStreamOperator();
480
481 std::vector<int32_t> resultsList;
482 resultsList.push_back(OHOS_CAMERA_STREAM_ID);
483 resultsList.push_back(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION);
484 display_->cameraDevice->EnableResult(resultsList);
485 // start stream
486 display_->intents = {PREVIEW, VIDEO};
487 display_->StartStream(display_->intents);
488 // capture
489 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
490 display_->StartCapture(display_->STREAM_ID_VIDEO, display_->CAPTURE_ID_VIDEO, false, true);
491 // Issue 3A parameters to increase exposure
492 std::shared_ptr<CameraSetting> meta = std::make_shared<CameraSetting>(100, 2000);
493 int32_t expo = 0xa0;
494 meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1);
495 const int32_t deviceStreamId = 0;
496 meta->addEntry(OHOS_CAMERA_STREAM_ID, &deviceStreamId, 1);
497 std::vector<uint8_t> setting;
498 MetadataUtils::ConvertMetadataToVec(meta, setting);
499 display_->rc = (CamRetCode)display_->cameraDevice->UpdateSettings(setting);
500 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
501 CAMERA_LOGI("UpdateSettings success, for 5s.");
502 } else {
503 CAMERA_LOGE("UpdateSettings fail, rc = %{public}d", display_->rc);
504 }
505 sleep(3);
506
507 // post-processing
508 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_VIDEO};
509 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_VIDEO};
510 display_->StopStream(display_->captureIds, display_->streamIds);
511 }
512
513 /**
514 * @tc.name: Video
515 * @tc.desc: Video mode without preview, system not support, expected return fail.
516 * @tc.level: Level2
517 * @tc.size: MediumTest
518 * @tc.type: Function
519 */
520 HWTEST_F(CameraVideoTest, camera_video_030, TestSize.Level2)
521 {
522 CAMERA_LOGD("Video mode without preview, system not support, expected return fail.");
523
524 EXPECT_EQ(true, display_->cameraDevice != nullptr);
525 display_->AchieveStreamOperator();
526 // Create video stream
527 std::shared_ptr<StreamCustomer> streamCustomer = std::make_shared<StreamCustomer>();
528 OHOS::sptr<OHOS::IBufferProducer> producer = streamCustomer->CreateProducer();
529 producer->SetQueueSize(8); // 8:set bufferQueue size
530 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
531 CAMERA_LOGE("~~~~~~~");
532 }
533
534 std::vector<StreamInfo> streamInfos;
535 display_->streamInfo.streamId_ = display_->STREAM_ID_VIDEO;
536 display_->streamInfo.width_ = 1280; // 1280:picture width
537 display_->streamInfo.height_ = 960; // 960:picture height
538 display_->streamInfo.format_ = PIXEL_FMT_RGBA_8888;
539 display_->streamInfo.dataspace_ = 10;
540 display_->streamInfo.intent_ = VIDEO;
541 display_->streamInfo.tunneledMode_ = 5; // 5:tunnel mode
542 display_->streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
543 ASSERT_NE(display_->streamInfo.bufferQueue_, nullptr);
544 streamInfos.push_back(display_->streamInfo);
545 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
546 EXPECT_EQ(false, display_->rc == OHOS::Camera::METHOD_NOT_SUPPORTED);
547 if (display_->rc == OHOS::Camera::METHOD_NOT_SUPPORTED) {
548 CAMERA_LOGI("CreateStreams METHOD_NOT_SUPPORTED, streamId = %{public}d", display_->STREAM_ID_VIDEO);
549 } else {
550 CAMERA_LOGE("CreateStreams fail, rc = %{public}d", display_->rc);
551 }
552 std::vector<uint8_t> modeSetting = {};
553 display_->rc = (CamRetCode)display_->streamOperator->CommitStreams(NORMAL, modeSetting);
554 EXPECT_EQ(false, display_->rc == HDI::Camera::V1_0::NO_ERROR);
555 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
556 CAMERA_LOGI("CommitStreams success.");
557 } else {
558 CAMERA_LOGE("CommitStreams fail, rc = %{public}d", display_->rc);
559 }
560 }