• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "usb_camera_test_mult.h"
16 
17 bool g_usbCameraExit = false;
SetUpTestCase(void)18 void UtestUSBCameraTestMult::SetUpTestCase(void)
19 {}
TearDownTestCase(void)20 void UtestUSBCameraTestMult::TearDownTestCase(void)
21 {}
SetUp(void)22 void UtestUSBCameraTestMult::SetUp(void)
23 {
24     if (cameraBase_ == nullptr)
25     cameraBase_ = std::make_shared<TestDisplay>();
26     cameraBase_->UsbInit();
27 }
TearDown(void)28 void UtestUSBCameraTestMult::TearDown(void)
29 {
30     cameraBase_->Close();
31 }
32 
SelectOpenCamera(std::string cameraId)33 CamRetCode UtestUSBCameraTestMult::SelectOpenCamera(std::string cameraId)
34 {
35     cameraBase_->cameraHost->GetCameraAbility(cameraId, vecAbility_);
36     MetadataUtils::ConvertVecToMetadata(vecAbility_, ability_);
37     const OHOS::sptr<DemoCameraDeviceCallback> callback = new DemoCameraDeviceCallback();
38     cameraBase_->rc = (CamRetCode)cameraBase_->cameraHost->OpenCamera(cameraId, callback, cameraDevice_);
39     if (cameraBase_->rc != HDI::Camera::V1_0::NO_ERROR || cameraDevice_ == nullptr) {
40         std::cout << "OpenCamera2 failed, rc = " << cameraBase_->rc << std::endl;
41         return cameraBase_->rc;
42     }
43     std::cout << "OpenCamera2 success." << std::endl;
44     return cameraBase_->rc;
45 }
46 
AchieveStreamOperator()47 void UtestUSBCameraTestMult::AchieveStreamOperator()
48 {
49     OHOS::sptr<DemoStreamOperatorCallback> streamOperatorCallback = new DemoStreamOperatorCallback();
50     cameraBase_->rc = (CamRetCode)cameraDevice_->GetStreamOperator(streamOperatorCallback, streamOperator_);
51     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
52     if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
53         std::cout << "AchieveStreamOperator2 success." << std::endl;
54     } else {
55         std::cout << "AchieveStreamOperator2 fail, rc = " << cameraBase_->rc << std::endl;
56     }
57 }
58 
DefaultInfosPreview()59 void UtestUSBCameraTestMult::DefaultInfosPreview()
60 {
61     if (streamCustomerPreview_ == nullptr) {
62         streamCustomerPreview_ = std::make_shared<StreamCustomer>();
63     }
64     streamInfoPre_.streamId_ = STREAM_ID_PREVIEW_DOUBLE;
65     streamInfoPre_.width_ = PREVIEW_WIDTH; // 640:picture width
66     streamInfoPre_.height_ = PREVIEW_HEIGHT; // 480:picture height
67     streamInfoPre_.format_ = PIXEL_FMT_RGBA_8888;
68     streamInfoPre_.dataspace_ = 8; // 8:picture dataspace
69     streamInfoPre_.intent_ = PREVIEW;
70     streamInfoPre_.tunneledMode_ = 5; // 5:tunnel mode
71     streamInfoPre_.bufferQueue_ = new BufferProducerSequenceable(streamCustomerPreview_->CreateProducer());
72     ASSERT_NE(streamInfoPre_.bufferQueue_, nullptr);
73     streamInfoPre_.bufferQueue_->producer_->SetQueueSize(8); // 8:set bufferQueue size
74     std::cout << "preview success1." << std::endl;
75     std::vector<StreamInfo>().swap(streamInfos_);
76     streamInfos_.push_back(streamInfoPre_);
77 }
78 
DefaultInfosVideo()79 void UtestUSBCameraTestMult::DefaultInfosVideo()
80 {
81     if (streamCustomerVideo_ == nullptr) {
82         streamCustomerVideo_ = std::make_shared<StreamCustomer>();
83     }
84     streamInfoVideo_.streamId_ = STREAM_ID_VIDEO_DOUBLE;
85     streamInfoVideo_.width_ = VIDEO_WIDTH; // 1280:picture width
86     streamInfoVideo_.height_ = VIDEO_HEIGHT; // 960:picture height
87     streamInfoVideo_.format_ = videoFormat_;
88     streamInfoVideo_.dataspace_ = 8; // 8:picture dataspace
89     streamInfoVideo_.intent_ = VIDEO;
90     streamInfoVideo_.encodeType_ = ENCODE_TYPE_H264;
91     streamInfoVideo_.tunneledMode_ = 5; // 5:tunnel mode
92     streamInfoVideo_.bufferQueue_ = new BufferProducerSequenceable(streamCustomerVideo_->CreateProducer());
93     ASSERT_NE(streamInfoVideo_.bufferQueue_, nullptr);
94     streamInfoVideo_.bufferQueue_->producer_->SetQueueSize(8); // 8:set bufferQueue size
95     std::cout << "video success1." << std::endl;
96     std::vector<StreamInfo>().swap(streamInfos_);
97     streamInfos_.push_back(streamInfoVideo_);
98 }
99 
DefaultInfosCapture()100 void UtestUSBCameraTestMult::DefaultInfosCapture()
101 {
102     if (streamCustomerCapture_ == nullptr) {
103         streamCustomerCapture_ = std::make_shared<StreamCustomer>();
104     }
105     streamInfoCapture_.streamId_ = STREAM_ID_CAPTURE_DOUBLE;
106     streamInfoCapture_.width_ = CAPTURE_WIDTH; // 1280:picture width
107     streamInfoCapture_.height_ = CAPTURE_HEIGHT; // 960:picture height
108     streamInfoCapture_.format_ = PIXEL_FMT_RGBA_8888;
109     streamInfoCapture_.dataspace_ = 8; // 8:picture dataspace
110     streamInfoCapture_.intent_ = STILL_CAPTURE;
111     streamInfoCapture_.encodeType_ = ENCODE_TYPE_JPEG;
112     streamInfoCapture_.tunneledMode_ = 5; // 5:tunnel mode
113     streamInfoCapture_.bufferQueue_ = new BufferProducerSequenceable(streamCustomerCapture_->CreateProducer());
114     ASSERT_NE(streamInfoCapture_.bufferQueue_, nullptr);
115     streamInfoCapture_.bufferQueue_->producer_->SetQueueSize(8); // 8:set bufferQueue size
116     std::cout << "capture success1." << std::endl;
117     std::vector<StreamInfo>().swap(streamInfos_);
118     streamInfos_.push_back(streamInfoCapture_);
119 }
120 
StartStream(std::vector<StreamIntent> intents)121 void UtestUSBCameraTestMult::StartStream(std::vector<StreamIntent> intents)
122 {
123     for (auto& intent : intents) {
124         if (intent == PREVIEW) {
125             DefaultInfosPreview();
126         } else if (intent == VIDEO) {
127             DefaultInfosVideo();
128         } else if (intent == STILL_CAPTURE) {
129             DefaultInfosCapture();
130         }
131         cameraBase_->rc = (CamRetCode)streamOperator_->CreateStreams(streamInfos_);
132         EXPECT_EQ(false, cameraBase_->rc != HDI::Camera::V1_0::NO_ERROR);
133         if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
134             std::cout << "CreateStreams2 success." << std::endl;
135         } else {
136             std::cout << "CreateStreams2 fail, rc = " << cameraBase_->rc << std::endl;
137         }
138 
139         cameraBase_->rc = (CamRetCode)streamOperator_->CommitStreams(NORMAL, vecAbility_);
140         EXPECT_EQ(false, cameraBase_->rc != HDI::Camera::V1_0::NO_ERROR);
141         if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
142             std::cout << "CommitStreams2 success." << std::endl;
143         } else {
144             std::cout << "CommitStreams2 fail, rc = " << cameraBase_->rc << std::endl;
145         }
146     }
147 }
148 
StoreImage(const unsigned char * bufStart,const uint32_t size)149 void UtestUSBCameraTestMult::StoreImage(const unsigned char *bufStart, const uint32_t size)
150 {
151     constexpr uint32_t pathLen = 64;
152     char path[pathLen] = {0};
153 #ifdef CAMERA_BUILT_ON_OHOS_LITE
154     char prefix[] = "/userdata/photo/";
155 #else
156     char prefix[] = "/data/";
157 #endif
158 
159     int imgFD = 0;
160     int ret = 0;
161 
162     struct timeval start = {};
163     gettimeofday(&start, nullptr);
164     if (sprintf_s(path, sizeof(path), "%spicture222_%ld.jpeg", prefix, start.tv_usec) < 0) {
165         CAMERA_LOGE("sprintf_s error .....\n");
166         return;
167     }
168 
169     imgFD = open(path, O_RDWR | O_CREAT, 00766); // 00766:file operate permission
170     if (imgFD == -1) {
171         CAMERA_LOGE("demo test:open image file error %{public}s.....\n", strerror(errno));
172         return;
173     }
174 
175     CAMERA_LOGD("demo test:StoreImage2 %{public}s size == %{public}d\n", path, size);
176 
177     ret = write(imgFD, bufStart, size);
178     if (ret == -1) {
179         CAMERA_LOGE("demo test:write image file error %{public}s.....\n", strerror(errno));
180     }
181 
182     close(imgFD);
183 }
184 
StoreVideo(const unsigned char * bufStart,const uint32_t size)185 void UtestUSBCameraTestMult::StoreVideo(const unsigned char *bufStart, const uint32_t size)
186 {
187     int ret = 0;
188 
189     ret = write(videoFd_, bufStart, size);
190     if (ret == -1) {
191         CAMERA_LOGE("demo test:write video file error %{public}s.....\n", strerror(errno));
192     }
193     CAMERA_LOGD("demo test:StoreVideo size == %{public}d\n", size);
194 }
195 
OpenVideoFile()196 void UtestUSBCameraTestMult::OpenVideoFile()
197 {
198     constexpr uint32_t pathLen = 64;
199     char path[pathLen] = {0};
200 #ifdef CAMERA_BUILT_ON_OHOS_LITE
201     char prefix[] = "/userdata/video/";
202 #else
203     char prefix[] = "/data/";
204 #endif
205     auto seconds = time(nullptr);
206     if (sprintf_s(path, sizeof(path), "%svideo222%ld.h264", prefix, seconds) < 0) {
207         CAMERA_LOGE("%{public}s: sprintf  failed", __func__);
208         return;
209     }
210     videoFd_ = open(path, O_RDWR | O_CREAT, 00766); // 00766:file operate permission
211     if (videoFd_ < 0) {
212         CAMERA_LOGE("demo test: StartVideo open %s %{public}s failed", path, strerror(errno));
213     }
214 }
215 
CloseFd()216 void UtestUSBCameraTestMult::CloseFd()
217 {
218     close(videoFd_);
219     videoFd_ = -1;
220 }
221 
StartCapture(int streamId,int captureId,bool shutterCallback,bool isStreaming)222 void UtestUSBCameraTestMult::StartCapture(int streamId, int captureId, bool shutterCallback, bool isStreaming)
223 {
224     // Get preview
225     captureInfo_.streamIds_ = {streamId};
226     captureInfo_.captureSetting_ = vecAbility_;
227     captureInfo_.enableShutterCallback_ = shutterCallback;
228     cameraBase_->rc = (CamRetCode)streamOperator_->Capture(captureId, captureInfo_, isStreaming);
229     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
230     if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
231         std::cout << "check Capture: Capture2 success, captureId = " << captureId << std::endl;
232     } else {
233         std::cout << "check Capture: Capture2 fail, rc = " << cameraBase_->rc
234                   << ", captureId = " << captureId<< std::endl;
235     }
236     if (captureId == CAPTURE_ID_PREVIEW_DOUBLE) {
237         streamCustomerPreview_->ReceiveFrameOn(nullptr);
238     } else if (captureId == CAPTURE_ID_CAPTURE_DOUBLE) {
239         streamCustomerCapture_->ReceiveFrameOn([this](const unsigned char *addr, const uint32_t size) {
240             StoreImage(addr, size);
241         });
242     } else if (captureId == CAPTURE_ID_VIDEO_DOUBLE) {
243         OpenVideoFile();
244         streamCustomerVideo_->ReceiveFrameOn([this](const unsigned char *addr, const uint32_t size) {
245             StoreVideo(addr, size);
246         });
247     }
248     sleep(2); // 2:sleep two second
249 }
250 
StopStream(std::vector<int> & captureIds,std::vector<int> & streamIds)251 void UtestUSBCameraTestMult::StopStream(std::vector<int>& captureIds, std::vector<int>& streamIds)
252 {
253     constexpr uint32_t TIME_FOR_WAIT_CANCEL_CAPTURE = 2;
254     sleep(TIME_FOR_WAIT_CANCEL_CAPTURE);
255     if (sizeof(captureIds) > 0) {
256         for (auto &captureId : captureIds) {
257             if (captureId == CAPTURE_ID_PREVIEW_DOUBLE) {
258                 streamCustomerPreview_->ReceiveFrameOff();
259             } else if (captureId == CAPTURE_ID_CAPTURE_DOUBLE) {
260                 streamCustomerCapture_->ReceiveFrameOff();
261             } else if (captureId == CAPTURE_ID_VIDEO_DOUBLE) {
262                 streamCustomerVideo_->ReceiveFrameOff();
263                 sleep(1);
264                 CloseFd();
265             }
266         }
267         for (const auto &captureId : captureIds) {
268             std::cout << "check Capture: CancelCapture success, captureId = " << captureId << std::endl;
269             cameraBase_->rc = (CamRetCode)streamOperator_->CancelCapture(captureId);
270             sleep(TIME_FOR_WAIT_CANCEL_CAPTURE);
271             EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
272             if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
273                 std::cout << "check Capture: CancelCapture success, captureId = " << captureId << std::endl;
274             } else {
275                 std::cout << "check Capture: CancelCapture fail, rc = "
276                           << cameraBase_->rc <<", captureId = " << captureId << std::endl;
277             }
278         }
279     }
280     sleep(1); // 1:sleep two second
281     if (sizeof(streamIds) > 0) {
282         // release stream
283         cameraBase_->rc = (CamRetCode)streamOperator_->ReleaseStreams(streamIds);
284         EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
285         if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
286             std::cout << "check Capture: ReleaseStreams success." << std::endl;
287         } else {
288             std::cout << "check Capture: ReleaseStreams fail, rc = "
289                       << cameraBase_->rc << ", streamIds = " << streamIds.front() << std::endl;
290         }
291     }
292 }
293 
294 const std::map<uint32_t, uint32_t> g_mapOhosFmtToPixFmt = {
295     { OHOS_CAMERA_FORMAT_RGBA_8888, PIXEL_FMT_RGBA_8888 },
296     { OHOS_CAMERA_FORMAT_YCRCB_420_SP, PIXEL_FMT_YCRCB_420_SP },
297 };
298 
ConvertPixfmtHal2V4l2(uint32_t ohosfmt)299 uint32_t UtestUSBCameraTestMult::ConvertPixfmtHal2V4l2(uint32_t ohosfmt)
300 {
301     auto it = g_mapOhosFmtToPixFmt.find(ohosfmt);
302     if (it == g_mapOhosFmtToPixFmt.end()) {
303         CAMERA_LOGI("The ohosfmt is not find in g_mapOhosFmtToPixFmt");
304         return PIXEL_FMT_RGBA_8888; // default value
305     }
306     return it->second;
307 }
308 
309 /**
310   * @tc.name: USB Camera
311   * @tc.desc: USB Camera, getCameraID success.
312   * @tc.level: Level0
313   * @tc.size: MediumTest
314   * @tc.type: Function
315   */
TEST_F(UtestUSBCameraTestMult,SUB_Driver_Camera_MultipleUsb_0600)316 TEST_F(UtestUSBCameraTestMult, SUB_Driver_Camera_MultipleUsb_0600)
317 {
318     if (!usbCameraExit_) {
319         std::cout << "No usb camera plugged in" << std::endl;
320     } else if (usbCameraExit_) {
321         std::vector<std::string> usbCameraIds;
322         cameraBase_->cameraHost->GetCameraIds(usbCameraIds);
323         if (usbCameraIds.size() > 1) { // 1:number of cameras connect
324             usbCameraExit_ = true;
325         } else {
326             usbCameraExit_ = false;
327         }
328         if (!usbCameraExit_) {
329             GTEST_SKIP() << "No usb camera plugged in" << std::endl;
330         }
331         cameraBase_->rc = cameraBase_->SelectOpenCamera(usbCameraIds[0]); // 0:first camera id
332         ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
333         cameraBase_->rc = SelectOpenCamera(usbCameraIds[1]);  // 1:second camera id
334         ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
335         cameraBase_->AchieveStreamOperator();
336         AchieveStreamOperator();
337 
338         ability_ = cameraBase_->GetCameraAbility();
339         EXPECT_NE(ability_, nullptr);
340         common_metadata_header_t *data = ability_->get();
341         EXPECT_NE(data, nullptr);
342         camera_metadata_item_t entry;
343         int ret = FindCameraMetadataItem(data, OHOS_ABILITY_STREAM_AVAILABLE_EXTEND_CONFIGURATIONS, &entry);
344 
345         uint32_t format = 0;
346         if (ret == 0 && entry.data.i32 != nullptr && entry.count > 0) {
347             format = entry.data.i32[entry.count - 6]; // 6:The sixth digit from the bottom is the format of video
348         }
349         videoFormat_ = ConvertPixfmtHal2V4l2(format);
350 
351         for (int i = 0; i < usbCameraIds.size(); i++) {
352             cameraBase_->rc = cameraBase_->SelectOpenCamera(usbCameraIds[i]);
353             ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
354             // Get the stream manager
355             cameraBase_->AchieveStreamOperator();
356             // start stream
357             cameraBase_->intents = {PREVIEW, STILL_CAPTURE, VIDEO};
358             cameraBase_->StartStream(cameraBase_->intents);
359             // Get preview
360             cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
361             cameraBase_->StartCapture(cameraBase_->STREAM_ID_CAPTURE, cameraBase_->CAPTURE_ID_CAPTURE, false, true);
362             cameraBase_->StartCapture(cameraBase_->STREAM_ID_VIDEO, cameraBase_->CAPTURE_ID_VIDEO, false, true);
363             // release stream
364             cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_CAPTURE,
365             cameraBase_->CAPTURE_ID_VIDEO};
366             cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_CAPTURE,
367             cameraBase_->STREAM_ID_VIDEO};
368             cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
369         }
370     }
371 }
372 
373 /**
374   * @tc.name: USB Camera
375   * @tc.desc: Commit 2 streams together, Preview and still_capture streams, isStreaming is true.
376   * @tc.level: Level0
377   * @tc.size: MediumTest
378   * @tc.type: Function
379   */
TEST_F(UtestUSBCameraTestMult,SUB_Driver_Camera_MultipleUsb_0100)380 TEST_F(UtestUSBCameraTestMult, SUB_Driver_Camera_MultipleUsb_0100)
381 {
382     if (!usbCameraExit_) {
383         std::cout << "No usb camera plugged in" << std::endl;
384     } else if (usbCameraExit_) {
385         // Get the device manager
386         std::vector<std::string> usbCameraIds;
387         cameraBase_->cameraHost->GetCameraIds(usbCameraIds);
388         if (usbCameraIds.size() > 1) {
389             g_usbCameraExit = true;
390         } else {
391             g_usbCameraExit = false;
392         }
393         for (int i = 0; i < usbCameraIds.size(); i++) {
394             if (!g_usbCameraExit) {
395                 GTEST_SKIP() << "No usb camera plugged in" << std::endl;
396             }
397             cameraBase_->rc = cameraBase_->SelectOpenCamera(usbCameraIds[i]);
398             ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
399             // Get the stream manager
400             cameraBase_->AchieveStreamOperator();
401             // start stream
402             cameraBase_->intents = {PREVIEW, STILL_CAPTURE};
403             cameraBase_->StartStream(cameraBase_->intents);
404             // Get preview
405             cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
406             cameraBase_->StartCapture(cameraBase_->STREAM_ID_CAPTURE, cameraBase_->CAPTURE_ID_CAPTURE, false, true);
407             // release stream
408             cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_CAPTURE};
409             cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_CAPTURE};
410             cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
411         }
412     }
413 }
414 
415 /**
416   * @tc.name: USB Camera
417   * @tc.desc: Open the capture stream for both cameras at the same time.
418   * @tc.level: Level0
419   * @tc.size: MediumTest
420   * @tc.type: Function
421   */
TEST_F(UtestUSBCameraTestMult,SUB_Driver_Camera_MultipleUsb_0200)422 TEST_F(UtestUSBCameraTestMult, SUB_Driver_Camera_MultipleUsb_0200)
423 {
424     if (!usbCameraExit_) {
425         std::cout << "No usb camera plugged in" << std::endl;
426     } else if (usbCameraExit_) {
427         // Get the device manager
428         std::vector<std::string> usbCameraIds;
429         cameraBase_->cameraHost->GetCameraIds(usbCameraIds);
430         if (usbCameraIds.size() > 1) {
431             g_usbCameraExit = true;
432         } else {
433             g_usbCameraExit = false;
434         }
435         for (int i = 0; i < usbCameraIds.size(); i++) {
436             if (!g_usbCameraExit) {
437                 GTEST_SKIP() << "No usb camera plugged in" << std::endl;
438             }
439             cameraBase_->rc = cameraBase_->SelectOpenCamera(usbCameraIds[i]);
440             ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
441             // Get the stream manager
442             cameraBase_->AchieveStreamOperator();
443             // start stream
444             cameraBase_->intents = {PREVIEW, STILL_CAPTURE, VIDEO};
445             cameraBase_->StartStream(cameraBase_->intents);
446             // Get preview
447             cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
448             cameraBase_->StartCapture(cameraBase_->STREAM_ID_CAPTURE, cameraBase_->CAPTURE_ID_CAPTURE, false, true);
449             cameraBase_->StartCapture(cameraBase_->STREAM_ID_VIDEO, cameraBase_->CAPTURE_ID_VIDEO, false, true);
450             // release stream
451             cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_CAPTURE,
452             cameraBase_->CAPTURE_ID_VIDEO};
453             cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_CAPTURE,
454             cameraBase_->STREAM_ID_VIDEO};
455             cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
456         }
457     }
458 }
459 
460 /**
461   * @tc.name: USB Camera
462   * @tc.desc: One camera starts capturing and the other camera starts recording.
463   * @tc.level: Level0
464   * @tc.size: MediumTest
465   * @tc.type: Function
466   */
TEST_F(UtestUSBCameraTestMult,SUB_Driver_Camera_MultipleUsb_0300)467 TEST_F(UtestUSBCameraTestMult, SUB_Driver_Camera_MultipleUsb_0300)
468 {
469     if (!usbCameraExit_) {
470         std::cout << "No usb camera plugged in" << std::endl;
471     } else if (usbCameraExit_) {
472         // Get the device manager
473         std::vector<std::string> usbCameraIds;
474         cameraBase_->cameraHost->GetCameraIds(usbCameraIds);
475         if (usbCameraIds.size() > 1) {
476             g_usbCameraExit = true;
477         } else {
478             g_usbCameraExit = false;
479         }
480 
481         if (!g_usbCameraExit) {
482                 GTEST_SKIP() << "No usb camera plugged in" << std::endl;
483         }
484         cameraBase_->rc = cameraBase_->SelectOpenCamera(usbCameraIds[0]);
485         ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
486         // Get the stream manager
487         cameraBase_->AchieveStreamOperator();
488         // start stream
489         cameraBase_->intents = {PREVIEW, STILL_CAPTURE};
490         cameraBase_->StartStream(cameraBase_->intents);
491         // Get preview
492         cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
493         cameraBase_->StartCapture(cameraBase_->STREAM_ID_CAPTURE, cameraBase_->CAPTURE_ID_CAPTURE, false, true);
494         // release stream
495         cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_CAPTURE};
496         cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_CAPTURE};
497         cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
498 
499         cameraBase_->rc = cameraBase_->SelectOpenCamera(usbCameraIds[1]);
500         ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
501         // Get the stream manager
502         cameraBase_->AchieveStreamOperator();
503         // start stream
504         cameraBase_->intents = {PREVIEW, STILL_CAPTURE, VIDEO};
505         cameraBase_->StartStream(cameraBase_->intents);
506         // Get preview
507         cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
508         cameraBase_->StartCapture(cameraBase_->STREAM_ID_CAPTURE, cameraBase_->CAPTURE_ID_CAPTURE, false, true);
509         cameraBase_->StartCapture(cameraBase_->STREAM_ID_VIDEO, cameraBase_->CAPTURE_ID_VIDEO, false, true);
510         // release stream
511         cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_CAPTURE,
512         cameraBase_->CAPTURE_ID_VIDEO};
513         cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_CAPTURE,
514         cameraBase_->STREAM_ID_VIDEO};
515         cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
516     }
517 }
518 
519 /**
520   * @tc.name: USB Camera
521   * @tc.desc: USB Camera, getCameraID success.
522   * @tc.level: Level0
523   * @tc.size: MediumTest
524   * @tc.type: Function
525   */
TEST_F(UtestUSBCameraTestMult,SUB_Driver_Camera_MultipleUsb_0400)526 TEST_F(UtestUSBCameraTestMult, SUB_Driver_Camera_MultipleUsb_0400)
527 {
528     if (!usbCameraExit_) {
529         std::cout << "No usb camera plugged in" << std::endl;
530     } else if (usbCameraExit_) {
531         std::vector<std::string> usbCameraIds;
532         cameraBase_->cameraHost->GetCameraIds(usbCameraIds);
533         if (usbCameraIds.size() > 1) { // 1:number of cameras connect
534             usbCameraExit_ = true;
535         } else {
536             usbCameraExit_ = false;
537         }
538         if (!usbCameraExit_) {
539             GTEST_SKIP() << "No usb camera plugged in" << std::endl;
540         }
541         cameraBase_->rc = cameraBase_->SelectOpenCamera(usbCameraIds[0]); // 0:first camera id
542         ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
543         cameraBase_->rc = SelectOpenCamera(usbCameraIds[1]);  // 1:second camera id
544         ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
545         cameraBase_->AchieveStreamOperator();
546         AchieveStreamOperator();
547 
548         cameraBase_->intents = {PREVIEW};
549         cameraBase_->StartStream(cameraBase_->intents);
550         StartStream(cameraBase_->intents);
551         cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
552         StartCapture(STREAM_ID_PREVIEW_DOUBLE, CAPTURE_ID_PREVIEW_DOUBLE, false, true);
553         cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW};
554         cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW};
555         cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
556         cameraBase_->captureIds = {CAPTURE_ID_PREVIEW_DOUBLE};
557         cameraBase_->streamIds = {STREAM_ID_PREVIEW_DOUBLE};
558         StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
559     }
560 }
561 
562 /**
563   * @tc.name: USB Camera
564   * @tc.desc: USB Camera, getCameraID success.
565   * @tc.level: Level0
566   * @tc.size: MediumTest
567   * @tc.type: Function
568   */
TEST_F(UtestUSBCameraTestMult,SUB_Driver_Camera_MultipleUsb_0500)569 TEST_F(UtestUSBCameraTestMult, SUB_Driver_Camera_MultipleUsb_0500)
570 {
571     if (!usbCameraExit_) {
572         std::cout << "No usb camera plugged in" << std::endl;
573     } else if (usbCameraExit_) {
574         std::vector<std::string> usbCameraIds;
575         cameraBase_->cameraHost->GetCameraIds(usbCameraIds);
576         if (usbCameraIds.size() > 1) { // 1:number of cameras connect
577             usbCameraExit_ = true;
578         } else {
579             usbCameraExit_ = false;
580         }
581         if (!usbCameraExit_) {
582             GTEST_SKIP() << "No usb camera plugged in" << std::endl;
583         }
584         cameraBase_->rc = cameraBase_->SelectOpenCamera(usbCameraIds[0]); // 0:first camera id
585         ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
586         cameraBase_->rc = SelectOpenCamera(usbCameraIds[1]);  // 1:second camera id
587         ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
588         cameraBase_->AchieveStreamOperator();
589         AchieveStreamOperator();
590 
591         cameraBase_->intents = {PREVIEW, STILL_CAPTURE};
592         cameraBase_->StartStream(cameraBase_->intents);
593         StartStream(cameraBase_->intents);
594         cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
595         cameraBase_->StartCapture(cameraBase_->STREAM_ID_CAPTURE, cameraBase_->CAPTURE_ID_CAPTURE, false, true);
596         StartCapture(STREAM_ID_PREVIEW_DOUBLE, CAPTURE_ID_PREVIEW_DOUBLE, false, true);
597         StartCapture(STREAM_ID_CAPTURE_DOUBLE, CAPTURE_ID_CAPTURE_DOUBLE, false, true);
598         cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_CAPTURE};
599         cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_CAPTURE};
600         cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
601         cameraBase_->captureIds = {CAPTURE_ID_PREVIEW_DOUBLE, CAPTURE_ID_CAPTURE_DOUBLE};
602         cameraBase_->streamIds = {STREAM_ID_PREVIEW_DOUBLE, STREAM_ID_CAPTURE_DOUBLE};
603         StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
604     }
605 }