New use cases

Signed-off-by: qwx1028698 <quannini@huawei.com>
Change-Id: I846517574a08d6eb2301ff541050e5385d942238
This commit is contained in:
qwx1028698 2024-02-21 16:53:32 +08:00
parent a25aa149d6
commit 9001938eb6
8 changed files with 1037 additions and 4 deletions

View File

@ -1,4 +1,4 @@
# Copyright (c) 2022 - 2023 Huawei Device Co., Ltd.
# Copyright (c) 2022 - 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@ -17,6 +17,7 @@ import("//test/xts/tools/build/suite.gni")
import("//build/ohos.gni")
import("//build/test.gni")
import("//drivers/peripheral/camera/camera.gni")
import("//drivers/peripheral/display/display_config.gni")
if (defined(ohos_lite)) {
import("//device/board/hisilicon/hispark_taurus/device.gni")
@ -32,6 +33,8 @@ config("cameraTest_config") {
ohos_moduletest_suite("HatsHdfCameraTest") {
testonly = true
defines = []
defines += display_defines
module_out_path = module_output_path
sources = [
"./src/camera_ability_test.cpp",
@ -39,6 +42,7 @@ ohos_moduletest_suite("HatsHdfCameraTest") {
"./src/camera_fps_test.cpp",
"./src/camera_preview_test.cpp",
"./src/camera_stabili_test.cpp",
"./src/camera_vendor_tag_test.cpp",
"./src/camera_video_test.cpp",
"./src/double_preview_test.cpp",
"./src/hdfcamera_facedetect.cpp",
@ -46,6 +50,7 @@ ohos_moduletest_suite("HatsHdfCameraTest") {
"./src/stream_customer.cpp",
"./src/test_display.cpp",
"./src/usb_camera_test.cpp",
"./src/usb_camera_test_mult.cpp",
]
include_dirs = [
@ -77,6 +82,9 @@ ohos_moduletest_suite("HatsHdfCameraTest") {
"$camera_path/pipeline_core/pipeline_impl/src/parser",
"$camera_path/pipeline_core/pipeline_impl/src/strategy",
"$camera_path/pipeline_core/ipp/include",
# metadata manager includes
"$camera_path/metadata_manager/include",
]
deps = [

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CAMERA_VENDOR_TAG_TEST_H
#define CAMERA_VENDOR_TAG_TEST_H
#include "test_display.h"
class UtestCameraVendorTagTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp(void);
void TearDown(void);
std::shared_ptr<TestDisplay> cameraBase_ = nullptr;
std::shared_ptr<CameraAbility> ability_ = nullptr;
bool usbCameraExit_ = false;
};
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -158,6 +158,7 @@ public:
void UsbInit();
std::shared_ptr<CameraAbility> GetCameraAbility();
void OpenUsbCamera();
CamRetCode SelectOpenCamera(std::string cameraId);
void Close();
void OpenCamera();
void AchieveStreamOperator();

View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef USB_CAMERA_TEST_MULT_H
#define USB_CAMERA_TEST_MULT_H
#include "test_display.h"
enum {
STREAM_ID_PREVIEW_DOUBLE = 1100, // 1100:double preview streamID
STREAM_ID_CAPTURE_DOUBLE,
STREAM_ID_VIDEO_DOUBLE,
CAPTURE_ID_PREVIEW_DOUBLE = 2100, // 2100:double preview captureId
CAPTURE_ID_CAPTURE_DOUBLE,
CAPTURE_ID_VIDEO_DOUBLE
};
class UtestUSBCameraTestMult : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp(void);
void TearDown(void);
CamRetCode SelectOpenCamera(std::string cameraId);
void AchieveStreamOperator();
uint32_t ConvertPixfmtHal2V4l2(uint32_t ohosfmt);
void DefaultInfosPreview();
void DefaultInfosVideo();
void DefaultInfosCapture();
void StartStream(std::vector<StreamIntent> intents);
void StoreImage(const unsigned char *bufStart, const uint32_t size);
void StoreVideo(const unsigned char *bufStart, const uint32_t size);
void OpenVideoFile();
void CloseFd();
void StartCapture(int streamId, int captureId, bool shutterCallback, bool isStreaming);
void StopStream(std::vector<int>& captureIds, std::vector<int>& streamIds);
std::shared_ptr<TestDisplay> cameraBase_ = nullptr;
bool usbCameraExit_ = false;
std::vector<uint8_t> vecAbility_ = {};
std::shared_ptr<CameraAbility> ability_ = nullptr;
OHOS::sptr<ICameraDevice> cameraDevice_ = nullptr;
OHOS::sptr<IStreamOperator> streamOperator_ = nullptr;
std::shared_ptr<StreamCustomer> streamCustomerPreview_ = nullptr;
std::shared_ptr<StreamCustomer> streamCustomerCapture_ = nullptr;
std::shared_ptr<StreamCustomer> streamCustomerVideo_ = nullptr;
std::vector<StreamInfo> streamInfos_ = {};
StreamInfo streamInfoPre_ = {};
StreamInfo streamInfoVideo_ = {};
StreamInfo streamInfoCapture_ = {};
CaptureInfo captureInfo_ = {};
uint32_t videoFormat_;
int videoFd_ = -1;
};
#endif

View File

@ -0,0 +1,239 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "camera_vendor_tag_test.h"
#include <dlfcn.h>
#include "camera_example_vendor_tags.h"
const char* g_exampleVendorTagLib = "libcamera_example_vendor_tag_impl.z.so";
void UtestCameraVendorTagTest::SetUpTestCase(void)
{}
void UtestCameraVendorTagTest::TearDownTestCase(void)
{}
void UtestCameraVendorTagTest::SetUp(void)
{
if (cameraBase_ == nullptr)
cameraBase_ = std::make_shared<TestDisplay>();
cameraBase_->UsbInit();
}
void UtestCameraVendorTagTest::TearDown(void)
{
cameraBase_->Close();
}
#ifdef DISPLAY_COMMUNITY
TEST_F(UtestCameraVendorTagTest, SUB_Driver_Camera_MetaDataTag_0100)
{
constexpr int itemCapacitySize = 30;
constexpr int dataCapacitySize = 2000;
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraMetadata>(itemCapacitySize, dataCapacitySize);
const uint8_t sensorMode = 5;
int ohosTag = EXAMPLE_VENDOR_SENSOR_MODE;
if (!meta->addEntry(ohosTag, &sensorMode, 1)) {
CAMERA_LOGE("%{public}s(%{public}d) add failed", GetCameraMetadataItemName(ohosTag), ohosTag);
return;
}
CAMERA_LOGD("%{public}s(%{public}ld) add success", GetCameraMetadataItemName(ohosTag), ohosTag);
common_metadata_header_t *data = meta->get();
camera_metadata_item_t entry;
int ret = FindCameraMetadataItem(data, EXAMPLE_VENDOR_SENSOR_MODE, &entry);
EXPECT_EQ(ret, CAM_META_SUCCESS);
EXPECT_EQ(entry.data.u8[0], sensorMode);
}
TEST_F(UtestCameraVendorTagTest, SUB_Driver_Camera_MetaDataTag_0200)
{
if (!usbCameraExit_) {
std::cout << "No usb camera plugged in" << std::endl;
} else if (usbCameraExit_) {
ability_ = cameraBase_->GetCameraAbility();
EXPECT_NE(ability_, nullptr);
constexpr int itemCapacitySize = 30;
constexpr int dataCapacitySize = 2000;
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraMetadata>(itemCapacitySize, dataCapacitySize);
const uint8_t sensorMode = 1;
int ohosTag = EXAMPLE_VENDOR_SENSOR_MODE;
if (!meta->addEntry(ohosTag, &sensorMode, 1)) {
CAMERA_LOGE("%{public}s(%{public}d) add failed", GetCameraMetadataItemName(ohosTag), ohosTag);
return;
}
CAMERA_LOGD("%{public}s(%{public}ld) add success", GetCameraMetadataItemName(ohosTag), ohosTag);
const uint8_t newSensorMode = 5;
std::vector<uint8_t> sensorModeVector;
sensorModeVector.push_back(newSensorMode);
if (!meta->updateEntry(EXAMPLE_VENDOR_SENSOR_MODE, sensorModeVector.data(), sensorModeVector.size())) {
CAMERA_LOGE("update %{public}s failed", GetCameraMetadataItemName(ohosTag));
}
common_metadata_header_t *data = meta->get();
camera_metadata_item_t entry;
int ret = FindCameraMetadataItem(data, EXAMPLE_VENDOR_SENSOR_MODE, &entry);
EXPECT_EQ(ret, CAM_META_SUCCESS);
EXPECT_EQ(entry.data.u8[0], newSensorMode);
}
}
TEST_F(UtestCameraVendorTagTest, SUB_Driver_Camera_MetaDataTag_0300)
{
constexpr int itemCapacitySize = 30;
constexpr int dataCapacitySize = 2000;
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraMetadata>(itemCapacitySize, dataCapacitySize);
int ohosTag = EXAMPLE_VENDOR_SENSOR_MODE;
auto ret = meta->addEntry(ohosTag, nullptr, 1);
EXPECT_EQ(ret, false);
}
TEST_F(UtestCameraVendorTagTest, camera_usb_vendor_tag_004)
{
constexpr int itemCapacitySize = 30;
constexpr int dataCapacitySize = 2000;
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraMetadata>(itemCapacitySize, dataCapacitySize);
const int64_t sensorExposure = 34;
int ohosTag = EXAMPLE_VENDOR_SENSOR_EXPOSURE;
if (!meta->addEntry(ohosTag, &sensorExposure, 1)) {
CAMERA_LOGE("%{public}s(%{public}d) add failed", GetCameraMetadataItemName(ohosTag), ohosTag);
return;
}
CAMERA_LOGD("%{public}s(%{public}ld) add success", GetCameraMetadataItemName(ohosTag), ohosTag);
const int64_t newSensorExposure = 5;
std::vector<int64_t> sensorExposureVector;
sensorExposureVector.push_back(newSensorExposure);
if (!meta->updateEntry(EXAMPLE_VENDOR_SENSOR_EXPOSURE, sensorExposureVector.data(), sensorExposureVector.size())) {
CAMERA_LOGE("update %{public}s failed", GetCameraMetadataItemName(ohosTag));
}
common_metadata_header_t *data = meta->get();
camera_metadata_item_t entry;
int ret = FindCameraMetadataItem(data, EXAMPLE_VENDOR_SENSOR_EXPOSURE, &entry);
EXPECT_EQ(ret, CAM_META_SUCCESS);
EXPECT_EQ(entry.data.i64[0], newSensorExposure);
}
TEST_F(UtestCameraVendorTagTest, SUB_Driver_Camera_MetaDataTag_0500)
{
constexpr int itemCapacitySize = 30;
constexpr int dataCapacitySize = 2000;
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraMetadata>(itemCapacitySize, dataCapacitySize);
const int64_t sensorExposure = 34;
int ohosTag = EXAMPLE_VENDOR_SENSOR_EXPOSURE;
if (!meta->addEntry(ohosTag, &sensorExposure, 1)) {
CAMERA_LOGE("%{public}s(%{public}d) add failed", GetCameraMetadataItemName(ohosTag), ohosTag);
return;
}
CAMERA_LOGD("%{public}s(%{public}ld) add success", GetCameraMetadataItemName(ohosTag), ohosTag);
common_metadata_header_t *data = meta->get();
camera_metadata_item_t entry;
int ret = FindCameraMetadataItem(data, EXAMPLE_VENDOR_SENSOR_EXPOSURE, &entry);
EXPECT_EQ(ret, CAM_META_SUCCESS);
EXPECT_EQ(entry.data.i64[0], sensorExposure);
}
TEST_F(UtestCameraVendorTagTest, SUB_Driver_Camera_MetaDataTag_0600)
{
constexpr int itemCapacitySize = 30;
constexpr int dataCapacitySize = 2000;
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraMetadata>(itemCapacitySize, dataCapacitySize);
int ohosTag = EXAMPLE_VENDOR_SENSOR_EXPOSURE;
auto ret = meta->addEntry(ohosTag, nullptr, 1);
EXPECT_EQ(ret, false);
}
#else
TEST_F(UtestCameraVendorTagTest, SUB_Driver_Camera_MetaDataTag_0700)
{
if (!usbCameraExit_) {
std::cout << "No usb camera plugged in" << std::endl;
} else if (usbCameraExit_) {
void* libHandle = dlopen(g_exampleVendorTagLib, RTLD_LAZY);
if (libHandle == nullptr) {
GTEST_SKIP() << "please push " << g_exampleVendorTagLib << " to the device." << std::endl;
} else {
dlclose(libHandle);
}
// Get the device manager
cameraBase_->OpenUsbCamera();
ability_ = cameraBase_->GetCameraAbility();
EXPECT_NE(ability_, nullptr);
// Get the stream manager
cameraBase_->AchieveStreamOperator();
// start stream
cameraBase_->intents = {PREVIEW, STILL_CAPTURE};
cameraBase_->StartStream(cameraBase_->intents);
// updateSettings
const uint32_t itemCapacity = 100;
const uint32_t dataCapacity = 2000;
std::shared_ptr<CameraSetting> meta = std::make_shared<CameraSetting>(
itemCapacity, dataCapacity);
const int64_t sensorExposure = 8888;
int ohosTag = EXAMPLE_VENDOR_SENSOR_EXPOSURE;
if (!meta->addEntry(ohosTag, &sensorExposure, 1)) {
std::cout << "addEntry failed" << std::endl;
return;
}
std::cout << GetCameraMetadataItemName(ohosTag) << "(" << ohosTag << ")" << "add success" << std::endl;
const int32_t deviceStreamId = 0;
meta->addEntry(OHOS_CAMERA_STREAM_ID, &deviceStreamId, 1);
std::vector<uint8_t> setting;
MetadataUtils::ConvertMetadataToVec(meta, setting);
cameraBase_->rc = (CamRetCode)cameraBase_->cameraDevice->UpdateSettings(setting);
EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
// Get preview
cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
cameraBase_->StartCapture(cameraBase_->STREAM_ID_CAPTURE, cameraBase_->CAPTURE_ID_CAPTURE, false, true);
// release stream
cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_CAPTURE};
cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_CAPTURE};
cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
}
}
TEST_F(UtestCameraVendorTagTest, SUB_Driver_Camera_MetaDataTag_0800)
{
if (!usbCameraExit_) {
std::cout << "No usb camera plugged in" << std::endl;
} else if (usbCameraExit_) {
void* libHandle = dlopen(g_exampleVendorTagLib, RTLD_LAZY);
if (libHandle == nullptr) {
GTEST_SKIP() << "please push " << g_exampleVendorTagLib << " to the device." << std::endl;
} else {
dlclose(libHandle);
}
std::vector<vendorTag_t> tagVec {};
auto ret = GetAllVendorTags(tagVec);
for (auto tag : tagVec) {
std::cout << "tagId = " << tag.tagId << ", tagName = " << tag.tagName << "\n";
}
EXPECT_EQ(ret, CAM_META_SUCCESS);
}
}
#endif // DISPLAY_COMMUNITY

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -485,6 +485,20 @@ void TestDisplay::OpenUsbCamera()
}
}
CamRetCode TestDisplay::SelectOpenCamera(std::string cameraId)
{
cameraHost->GetCameraAbility(cameraId, ability_);
MetadataUtils::ConvertVecToMetadata(ability_, ability);
const OHOS::sptr<DemoCameraDeviceCallback> callback = new DemoCameraDeviceCallback();
rc = (CamRetCode)cameraHost->OpenCamera(cameraId, callback, cameraDevice);
if (rc != HDI::Camera::V1_0::NO_ERROR || cameraDevice == nullptr) {
std::cout << "OpenCamera failed, rc = " << rc << std::endl;
return rc;
}
std::cout << "OpenCamera success." << std::endl;
return rc;
}
void TestDisplay::Close()
{
CAMERA_LOGD("cameraDevice->Close().");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -1163,3 +1163,71 @@ HWTEST_F(USBCameraTest, SUB_Driver_Camera_UsbAbility_1700, TestSize.Level3)
}
}
/**
* @tc.name: USB Camera
* @tc.desc: Commit 2 streams together, width = 1280, height = 720, expected success.
* @tc.level: Level0
* @tc.size: MediumTest
* @tc.type: Function
*/
HWTEST_F(USBCameraTest, SUB_Driver_Camera_Pipeline_0100, TestSize.Level3)
{
if (!usbCameraExit_) {
std::cout << "No usb camera plugged in" << std::endl;
} else if (usbCameraExit_) {
std::vector<std::string> usbCameraIds;
display_->cameraHost->GetCameraIds(usbCameraIds);
if (usbCameraIds.size() > 1) { // 2:usb camera quantity
usbCameraExit_ = true;
} else {
usbCameraExit_ = false;
}
display_->OpenUsbCamera();
if (!usbCameraExit_) {
GTEST_SKIP() << "No usb camera plugged in" << std::endl;
}
display_->AchieveStreamOperator();
if (display_->streamCustomerPreview_ == nullptr) {
display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
}
std::vector<StreamInfo> streamInfos;
StreamInfo streamInfo = {};
streamInfo.streamId_ = display_->STREAM_ID_PREVIEW;
streamInfo.width_ = 1280; // 1280:picture width
streamInfo.height_ = 960; // 720:picture height
streamInfo.format_ = PIXEL_FMT_RGBA_8888;
streamInfo.dataspace_ = 8; // 8:picture dataspace
streamInfo.intent_ = PREVIEW;
streamInfo.tunneledMode_ = 5; // 5:tunnel mode
streamInfo.bufferQueue_ = new BufferProducerSequenceable(display_->streamCustomerPreview_->CreateProducer());
ASSERT_NE(streamInfo.bufferQueue_, nullptr);
streamInfo.bufferQueue_->producer_->SetQueueSize(8); // 8:set bufferQueue size
streamInfos.push_back(streamInfo);
if (display_->streamCustomerCapture_ == nullptr) {
display_->streamCustomerCapture_ = std::make_shared<StreamCustomer>();
}
StreamInfo streamInfoCapture = {};
streamInfoCapture.streamId_ = display_->STREAM_ID_CAPTURE;
streamInfoCapture.width_ = 640; // 1280:picture width
streamInfoCapture.height_ = 480; // 960:picture height
streamInfoCapture.format_ = PIXEL_FMT_RGBA_8888;
streamInfoCapture.dataspace_ = 8; // 8:picture dataspace
streamInfoCapture.intent_ = STILL_CAPTURE;
streamInfoCapture.encodeType_ = ENCODE_TYPE_JPEG;
streamInfoCapture.tunneledMode_ = 5; // 5:tunnel mode
streamInfoCapture.bufferQueue_ = new BufferProducerSequenceable(
display_->streamCustomerCapture_->CreateProducer());
ASSERT_NE(streamInfoCapture.bufferQueue_, nullptr);
streamInfoCapture.bufferQueue_->producer_->SetQueueSize(8); // 8:set bufferQueue size
streamInfos.push_back(streamInfoCapture);
display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
display_->rc = (CamRetCode)display_->streamOperator->CommitStreams(NORMAL, display_->ability_);
EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
display_->StartCapture(display_->STREAM_ID_CAPTURE, display_->CAPTURE_ID_CAPTURE, false, true);
display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_CAPTURE};
display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_CAPTURE};
display_->StopStream(display_->captureIds, display_->streamIds);
}
}

View File

@ -0,0 +1,605 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "usb_camera_test_mult.h"
bool g_usbCameraExit = false;
void UtestUSBCameraTestMult::SetUpTestCase(void)
{}
void UtestUSBCameraTestMult::TearDownTestCase(void)
{}
void UtestUSBCameraTestMult::SetUp(void)
{
if (cameraBase_ == nullptr)
cameraBase_ = std::make_shared<TestDisplay>();
cameraBase_->UsbInit();
}
void UtestUSBCameraTestMult::TearDown(void)
{
cameraBase_->Close();
}
CamRetCode UtestUSBCameraTestMult::SelectOpenCamera(std::string cameraId)
{
cameraBase_->cameraHost->GetCameraAbility(cameraId, vecAbility_);
MetadataUtils::ConvertVecToMetadata(vecAbility_, ability_);
const OHOS::sptr<DemoCameraDeviceCallback> callback = new DemoCameraDeviceCallback();
cameraBase_->rc = (CamRetCode)cameraBase_->cameraHost->OpenCamera(cameraId, callback, cameraDevice_);
if (cameraBase_->rc != HDI::Camera::V1_0::NO_ERROR || cameraDevice_ == nullptr) {
std::cout << "OpenCamera2 failed, rc = " << cameraBase_->rc << std::endl;
return cameraBase_->rc;
}
std::cout << "OpenCamera2 success." << std::endl;
return cameraBase_->rc;
}
void UtestUSBCameraTestMult::AchieveStreamOperator()
{
OHOS::sptr<DemoStreamOperatorCallback> streamOperatorCallback = new DemoStreamOperatorCallback();
cameraBase_->rc = (CamRetCode)cameraDevice_->GetStreamOperator(streamOperatorCallback, streamOperator_);
EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
std::cout << "AchieveStreamOperator2 success." << std::endl;
} else {
std::cout << "AchieveStreamOperator2 fail, rc = " << cameraBase_->rc << std::endl;
}
}
void UtestUSBCameraTestMult::DefaultInfosPreview()
{
if (streamCustomerPreview_ == nullptr) {
streamCustomerPreview_ = std::make_shared<StreamCustomer>();
}
streamInfoPre_.streamId_ = STREAM_ID_PREVIEW_DOUBLE;
streamInfoPre_.width_ = PREVIEW_WIDTH; // 640:picture width
streamInfoPre_.height_ = PREVIEW_HEIGHT; // 480:picture height
streamInfoPre_.format_ = PIXEL_FMT_RGBA_8888;
streamInfoPre_.dataspace_ = 8; // 8:picture dataspace
streamInfoPre_.intent_ = PREVIEW;
streamInfoPre_.tunneledMode_ = 5; // 5:tunnel mode
streamInfoPre_.bufferQueue_ = new BufferProducerSequenceable(streamCustomerPreview_->CreateProducer());
ASSERT_NE(streamInfoPre_.bufferQueue_, nullptr);
streamInfoPre_.bufferQueue_->producer_->SetQueueSize(8); // 8:set bufferQueue size
std::cout << "preview success1." << std::endl;
std::vector<StreamInfo>().swap(streamInfos_);
streamInfos_.push_back(streamInfoPre_);
}
void UtestUSBCameraTestMult::DefaultInfosVideo()
{
if (streamCustomerVideo_ == nullptr) {
streamCustomerVideo_ = std::make_shared<StreamCustomer>();
}
streamInfoVideo_.streamId_ = STREAM_ID_VIDEO_DOUBLE;
streamInfoVideo_.width_ = VIDEO_WIDTH; // 1280:picture width
streamInfoVideo_.height_ = VIDEO_HEIGHT; // 960:picture height
streamInfoVideo_.format_ = videoFormat_;
streamInfoVideo_.dataspace_ = 8; // 8:picture dataspace
streamInfoVideo_.intent_ = VIDEO;
streamInfoVideo_.encodeType_ = ENCODE_TYPE_H264;
streamInfoVideo_.tunneledMode_ = 5; // 5:tunnel mode
streamInfoVideo_.bufferQueue_ = new BufferProducerSequenceable(streamCustomerVideo_->CreateProducer());
ASSERT_NE(streamInfoVideo_.bufferQueue_, nullptr);
streamInfoVideo_.bufferQueue_->producer_->SetQueueSize(8); // 8:set bufferQueue size
std::cout << "video success1." << std::endl;
std::vector<StreamInfo>().swap(streamInfos_);
streamInfos_.push_back(streamInfoVideo_);
}
void UtestUSBCameraTestMult::DefaultInfosCapture()
{
if (streamCustomerCapture_ == nullptr) {
streamCustomerCapture_ = std::make_shared<StreamCustomer>();
}
streamInfoCapture_.streamId_ = STREAM_ID_CAPTURE_DOUBLE;
streamInfoCapture_.width_ = CAPTURE_WIDTH; // 1280:picture width
streamInfoCapture_.height_ = CAPTURE_HEIGHT; // 960:picture height
streamInfoCapture_.format_ = PIXEL_FMT_RGBA_8888;
streamInfoCapture_.dataspace_ = 8; // 8:picture dataspace
streamInfoCapture_.intent_ = STILL_CAPTURE;
streamInfoCapture_.encodeType_ = ENCODE_TYPE_JPEG;
streamInfoCapture_.tunneledMode_ = 5; // 5:tunnel mode
streamInfoCapture_.bufferQueue_ = new BufferProducerSequenceable(streamCustomerCapture_->CreateProducer());
ASSERT_NE(streamInfoCapture_.bufferQueue_, nullptr);
streamInfoCapture_.bufferQueue_->producer_->SetQueueSize(8); // 8:set bufferQueue size
std::cout << "capture success1." << std::endl;
std::vector<StreamInfo>().swap(streamInfos_);
streamInfos_.push_back(streamInfoCapture_);
}
void UtestUSBCameraTestMult::StartStream(std::vector<StreamIntent> intents)
{
for (auto& intent : intents) {
if (intent == PREVIEW) {
DefaultInfosPreview();
} else if (intent == VIDEO) {
DefaultInfosVideo();
} else if (intent == STILL_CAPTURE) {
DefaultInfosCapture();
}
cameraBase_->rc = (CamRetCode)streamOperator_->CreateStreams(streamInfos_);
EXPECT_EQ(false, cameraBase_->rc != HDI::Camera::V1_0::NO_ERROR);
if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
std::cout << "CreateStreams2 success." << std::endl;
} else {
std::cout << "CreateStreams2 fail, rc = " << cameraBase_->rc << std::endl;
}
cameraBase_->rc = (CamRetCode)streamOperator_->CommitStreams(NORMAL, vecAbility_);
EXPECT_EQ(false, cameraBase_->rc != HDI::Camera::V1_0::NO_ERROR);
if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
std::cout << "CommitStreams2 success." << std::endl;
} else {
std::cout << "CommitStreams2 fail, rc = " << cameraBase_->rc << std::endl;
}
}
}
void UtestUSBCameraTestMult::StoreImage(const unsigned char *bufStart, const uint32_t size)
{
constexpr uint32_t pathLen = 64;
char path[pathLen] = {0};
#ifdef CAMERA_BUILT_ON_OHOS_LITE
char prefix[] = "/userdata/photo/";
#else
char prefix[] = "/data/";
#endif
int imgFD = 0;
int ret = 0;
struct timeval start = {};
gettimeofday(&start, nullptr);
if (sprintf_s(path, sizeof(path), "%spicture222_%ld.jpeg", prefix, start.tv_usec) < 0) {
CAMERA_LOGE("sprintf_s error .....\n");
return;
}
imgFD = open(path, O_RDWR | O_CREAT, 00766); // 00766:file operate permission
if (imgFD == -1) {
CAMERA_LOGE("demo test:open image file error %{public}s.....\n", strerror(errno));
return;
}
CAMERA_LOGD("demo test:StoreImage2 %{public}s size == %{public}d\n", path, size);
ret = write(imgFD, bufStart, size);
if (ret == -1) {
CAMERA_LOGE("demo test:write image file error %{public}s.....\n", strerror(errno));
}
close(imgFD);
}
void UtestUSBCameraTestMult::StoreVideo(const unsigned char *bufStart, const uint32_t size)
{
int ret = 0;
ret = write(videoFd_, bufStart, size);
if (ret == -1) {
CAMERA_LOGE("demo test:write video file error %{public}s.....\n", strerror(errno));
}
CAMERA_LOGD("demo test:StoreVideo size == %{public}d\n", size);
}
void UtestUSBCameraTestMult::OpenVideoFile()
{
constexpr uint32_t pathLen = 64;
char path[pathLen] = {0};
#ifdef CAMERA_BUILT_ON_OHOS_LITE
char prefix[] = "/userdata/video/";
#else
char prefix[] = "/data/";
#endif
auto seconds = time(nullptr);
if (sprintf_s(path, sizeof(path), "%svideo222%ld.h264", prefix, seconds) < 0) {
CAMERA_LOGE("%{public}s: sprintf failed", __func__);
return;
}
videoFd_ = open(path, O_RDWR | O_CREAT, 00766); // 00766:file operate permission
if (videoFd_ < 0) {
CAMERA_LOGE("demo test: StartVideo open %s %{public}s failed", path, strerror(errno));
}
}
void UtestUSBCameraTestMult::CloseFd()
{
close(videoFd_);
videoFd_ = -1;
}
void UtestUSBCameraTestMult::StartCapture(int streamId, int captureId, bool shutterCallback, bool isStreaming)
{
// Get preview
captureInfo_.streamIds_ = {streamId};
captureInfo_.captureSetting_ = vecAbility_;
captureInfo_.enableShutterCallback_ = shutterCallback;
cameraBase_->rc = (CamRetCode)streamOperator_->Capture(captureId, captureInfo_, isStreaming);
EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
std::cout << "check Capture: Capture2 success, captureId = " << captureId << std::endl;
} else {
std::cout << "check Capture: Capture2 fail, rc = " << cameraBase_->rc
<< ", captureId = " << captureId<< std::endl;
}
if (captureId == CAPTURE_ID_PREVIEW_DOUBLE) {
streamCustomerPreview_->ReceiveFrameOn(nullptr);
} else if (captureId == CAPTURE_ID_CAPTURE_DOUBLE) {
streamCustomerCapture_->ReceiveFrameOn([this](const unsigned char *addr, const uint32_t size) {
StoreImage(addr, size);
});
} else if (captureId == CAPTURE_ID_VIDEO_DOUBLE) {
OpenVideoFile();
streamCustomerVideo_->ReceiveFrameOn([this](const unsigned char *addr, const uint32_t size) {
StoreVideo(addr, size);
});
}
sleep(2); // 2:sleep two second
}
void UtestUSBCameraTestMult::StopStream(std::vector<int>& captureIds, std::vector<int>& streamIds)
{
constexpr uint32_t TIME_FOR_WAIT_CANCEL_CAPTURE = 2;
sleep(TIME_FOR_WAIT_CANCEL_CAPTURE);
if (sizeof(captureIds) > 0) {
for (auto &captureId : captureIds) {
if (captureId == CAPTURE_ID_PREVIEW_DOUBLE) {
streamCustomerPreview_->ReceiveFrameOff();
} else if (captureId == CAPTURE_ID_CAPTURE_DOUBLE) {
streamCustomerCapture_->ReceiveFrameOff();
} else if (captureId == CAPTURE_ID_VIDEO_DOUBLE) {
streamCustomerVideo_->ReceiveFrameOff();
sleep(1);
CloseFd();
}
}
for (const auto &captureId : captureIds) {
std::cout << "check Capture: CancelCapture success, captureId = " << captureId << std::endl;
cameraBase_->rc = (CamRetCode)streamOperator_->CancelCapture(captureId);
sleep(TIME_FOR_WAIT_CANCEL_CAPTURE);
EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
std::cout << "check Capture: CancelCapture success, captureId = " << captureId << std::endl;
} else {
std::cout << "check Capture: CancelCapture fail, rc = "
<< cameraBase_->rc <<", captureId = " << captureId << std::endl;
}
}
}
sleep(1); // 1:sleep two second
if (sizeof(streamIds) > 0) {
// release stream
cameraBase_->rc = (CamRetCode)streamOperator_->ReleaseStreams(streamIds);
EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
std::cout << "check Capture: ReleaseStreams success." << std::endl;
} else {
std::cout << "check Capture: ReleaseStreams fail, rc = "
<< cameraBase_->rc << ", streamIds = " << streamIds.front() << std::endl;
}
}
}
const std::map<uint32_t, uint32_t> g_mapOhosFmtToPixFmt = {
{ OHOS_CAMERA_FORMAT_RGBA_8888, PIXEL_FMT_RGBA_8888 },
{ OHOS_CAMERA_FORMAT_YCRCB_420_SP, PIXEL_FMT_YCRCB_420_SP },
};
uint32_t UtestUSBCameraTestMult::ConvertPixfmtHal2V4l2(uint32_t ohosfmt)
{
auto it = g_mapOhosFmtToPixFmt.find(ohosfmt);
if (it == g_mapOhosFmtToPixFmt.end()) {
CAMERA_LOGI("The ohosfmt is not find in g_mapOhosFmtToPixFmt");
return PIXEL_FMT_RGBA_8888; // default value
}
return it->second;
}
/**
* @tc.name: USB Camera
* @tc.desc: USB Camera, getCameraID success.
* @tc.level: Level0
* @tc.size: MediumTest
* @tc.type: Function
*/
TEST_F(UtestUSBCameraTestMult, SUB_Driver_Camera_MultipleUsb_0600)
{
if (!usbCameraExit_) {
std::cout << "No usb camera plugged in" << std::endl;
} else if (usbCameraExit_) {
std::vector<std::string> usbCameraIds;
cameraBase_->cameraHost->GetCameraIds(usbCameraIds);
if (usbCameraIds.size() > 1) { // 1:number of cameras connect
usbCameraExit_ = true;
} else {
usbCameraExit_ = false;
}
if (!usbCameraExit_) {
GTEST_SKIP() << "No usb camera plugged in" << std::endl;
}
cameraBase_->rc = cameraBase_->SelectOpenCamera(usbCameraIds[0]); // 0:first camera id
ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
cameraBase_->rc = SelectOpenCamera(usbCameraIds[1]); // 1:second camera id
ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
cameraBase_->AchieveStreamOperator();
AchieveStreamOperator();
ability_ = cameraBase_->GetCameraAbility();
EXPECT_NE(ability_, nullptr);
common_metadata_header_t *data = ability_->get();
EXPECT_NE(data, nullptr);
camera_metadata_item_t entry;
int ret = FindCameraMetadataItem(data, OHOS_ABILITY_STREAM_AVAILABLE_EXTEND_CONFIGURATIONS, &entry);
uint32_t format = 0;
if (ret == 0 && entry.data.i32 != nullptr && entry.count > 0) {
format = entry.data.i32[entry.count - 6]; // 6:The sixth digit from the bottom is the format of video
}
videoFormat_ = ConvertPixfmtHal2V4l2(format);
for (int i = 0; i < usbCameraIds.size(); i++) {
cameraBase_->rc = cameraBase_->SelectOpenCamera(usbCameraIds[i]);
ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
// Get the stream manager
cameraBase_->AchieveStreamOperator();
// start stream
cameraBase_->intents = {PREVIEW, STILL_CAPTURE, VIDEO};
cameraBase_->StartStream(cameraBase_->intents);
// Get preview
cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
cameraBase_->StartCapture(cameraBase_->STREAM_ID_CAPTURE, cameraBase_->CAPTURE_ID_CAPTURE, false, true);
cameraBase_->StartCapture(cameraBase_->STREAM_ID_VIDEO, cameraBase_->CAPTURE_ID_VIDEO, false, true);
// release stream
cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_CAPTURE,
cameraBase_->CAPTURE_ID_VIDEO};
cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_CAPTURE,
cameraBase_->STREAM_ID_VIDEO};
cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
}
}
}
/**
* @tc.name: USB Camera
* @tc.desc: Commit 2 streams together, Preview and still_capture streams, isStreaming is true.
* @tc.level: Level0
* @tc.size: MediumTest
* @tc.type: Function
*/
TEST_F(UtestUSBCameraTestMult, SUB_Driver_Camera_MultipleUsb_0100)
{
if (!usbCameraExit_) {
std::cout << "No usb camera plugged in" << std::endl;
} else if (usbCameraExit_) {
// Get the device manager
std::vector<std::string> usbCameraIds;
cameraBase_->cameraHost->GetCameraIds(usbCameraIds);
if (usbCameraIds.size() > 1) {
g_usbCameraExit = true;
} else {
g_usbCameraExit = false;
}
for (int i = 0; i < usbCameraIds.size(); i++) {
if (!g_usbCameraExit) {
GTEST_SKIP() << "No usb camera plugged in" << std::endl;
}
cameraBase_->rc = cameraBase_->SelectOpenCamera(usbCameraIds[i]);
ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
// Get the stream manager
cameraBase_->AchieveStreamOperator();
// start stream
cameraBase_->intents = {PREVIEW, STILL_CAPTURE};
cameraBase_->StartStream(cameraBase_->intents);
// Get preview
cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
cameraBase_->StartCapture(cameraBase_->STREAM_ID_CAPTURE, cameraBase_->CAPTURE_ID_CAPTURE, false, true);
// release stream
cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_CAPTURE};
cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_CAPTURE};
cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
}
}
}
/**
* @tc.name: USB Camera
* @tc.desc: Open the capture stream for both cameras at the same time.
* @tc.level: Level0
* @tc.size: MediumTest
* @tc.type: Function
*/
TEST_F(UtestUSBCameraTestMult, SUB_Driver_Camera_MultipleUsb_0200)
{
if (!usbCameraExit_) {
std::cout << "No usb camera plugged in" << std::endl;
} else if (usbCameraExit_) {
// Get the device manager
std::vector<std::string> usbCameraIds;
cameraBase_->cameraHost->GetCameraIds(usbCameraIds);
if (usbCameraIds.size() > 1) {
g_usbCameraExit = true;
} else {
g_usbCameraExit = false;
}
for (int i = 0; i < usbCameraIds.size(); i++) {
if (!g_usbCameraExit) {
GTEST_SKIP() << "No usb camera plugged in" << std::endl;
}
cameraBase_->rc = cameraBase_->SelectOpenCamera(usbCameraIds[i]);
ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
// Get the stream manager
cameraBase_->AchieveStreamOperator();
// start stream
cameraBase_->intents = {PREVIEW, STILL_CAPTURE, VIDEO};
cameraBase_->StartStream(cameraBase_->intents);
// Get preview
cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
cameraBase_->StartCapture(cameraBase_->STREAM_ID_CAPTURE, cameraBase_->CAPTURE_ID_CAPTURE, false, true);
cameraBase_->StartCapture(cameraBase_->STREAM_ID_VIDEO, cameraBase_->CAPTURE_ID_VIDEO, false, true);
// release stream
cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_CAPTURE,
cameraBase_->CAPTURE_ID_VIDEO};
cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_CAPTURE,
cameraBase_->STREAM_ID_VIDEO};
cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
}
}
}
/**
* @tc.name: USB Camera
* @tc.desc: One camera starts capturing and the other camera starts recording.
* @tc.level: Level0
* @tc.size: MediumTest
* @tc.type: Function
*/
TEST_F(UtestUSBCameraTestMult, SUB_Driver_Camera_MultipleUsb_0300)
{
if (!usbCameraExit_) {
std::cout << "No usb camera plugged in" << std::endl;
} else if (usbCameraExit_) {
// Get the device manager
std::vector<std::string> usbCameraIds;
cameraBase_->cameraHost->GetCameraIds(usbCameraIds);
if (usbCameraIds.size() > 1) {
g_usbCameraExit = true;
} else {
g_usbCameraExit = false;
}
if (!g_usbCameraExit) {
GTEST_SKIP() << "No usb camera plugged in" << std::endl;
}
cameraBase_->rc = cameraBase_->SelectOpenCamera(usbCameraIds[0]);
ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
// Get the stream manager
cameraBase_->AchieveStreamOperator();
// start stream
cameraBase_->intents = {PREVIEW, STILL_CAPTURE};
cameraBase_->StartStream(cameraBase_->intents);
// Get preview
cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
cameraBase_->StartCapture(cameraBase_->STREAM_ID_CAPTURE, cameraBase_->CAPTURE_ID_CAPTURE, false, true);
// release stream
cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_CAPTURE};
cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_CAPTURE};
cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
cameraBase_->rc = cameraBase_->SelectOpenCamera(usbCameraIds[1]);
ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
// Get the stream manager
cameraBase_->AchieveStreamOperator();
// start stream
cameraBase_->intents = {PREVIEW, STILL_CAPTURE, VIDEO};
cameraBase_->StartStream(cameraBase_->intents);
// Get preview
cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
cameraBase_->StartCapture(cameraBase_->STREAM_ID_CAPTURE, cameraBase_->CAPTURE_ID_CAPTURE, false, true);
cameraBase_->StartCapture(cameraBase_->STREAM_ID_VIDEO, cameraBase_->CAPTURE_ID_VIDEO, false, true);
// release stream
cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_CAPTURE,
cameraBase_->CAPTURE_ID_VIDEO};
cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_CAPTURE,
cameraBase_->STREAM_ID_VIDEO};
cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
}
}
/**
* @tc.name: USB Camera
* @tc.desc: USB Camera, getCameraID success.
* @tc.level: Level0
* @tc.size: MediumTest
* @tc.type: Function
*/
TEST_F(UtestUSBCameraTestMult, SUB_Driver_Camera_MultipleUsb_0400)
{
if (!usbCameraExit_) {
std::cout << "No usb camera plugged in" << std::endl;
} else if (usbCameraExit_) {
std::vector<std::string> usbCameraIds;
cameraBase_->cameraHost->GetCameraIds(usbCameraIds);
if (usbCameraIds.size() > 1) { // 1:number of cameras connect
usbCameraExit_ = true;
} else {
usbCameraExit_ = false;
}
if (!usbCameraExit_) {
GTEST_SKIP() << "No usb camera plugged in" << std::endl;
}
cameraBase_->rc = cameraBase_->SelectOpenCamera(usbCameraIds[0]); // 0:first camera id
ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
cameraBase_->rc = SelectOpenCamera(usbCameraIds[1]); // 1:second camera id
ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
cameraBase_->AchieveStreamOperator();
AchieveStreamOperator();
cameraBase_->intents = {PREVIEW};
cameraBase_->StartStream(cameraBase_->intents);
StartStream(cameraBase_->intents);
cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
StartCapture(STREAM_ID_PREVIEW_DOUBLE, CAPTURE_ID_PREVIEW_DOUBLE, false, true);
cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW};
cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW};
cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
cameraBase_->captureIds = {CAPTURE_ID_PREVIEW_DOUBLE};
cameraBase_->streamIds = {STREAM_ID_PREVIEW_DOUBLE};
StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
}
}
/**
* @tc.name: USB Camera
* @tc.desc: USB Camera, getCameraID success.
* @tc.level: Level0
* @tc.size: MediumTest
* @tc.type: Function
*/
TEST_F(UtestUSBCameraTestMult, SUB_Driver_Camera_MultipleUsb_0500)
{
if (!usbCameraExit_) {
std::cout << "No usb camera plugged in" << std::endl;
} else if (usbCameraExit_) {
std::vector<std::string> usbCameraIds;
cameraBase_->cameraHost->GetCameraIds(usbCameraIds);
if (usbCameraIds.size() > 1) { // 1:number of cameras connect
usbCameraExit_ = true;
} else {
usbCameraExit_ = false;
}
if (!usbCameraExit_) {
GTEST_SKIP() << "No usb camera plugged in" << std::endl;
}
cameraBase_->rc = cameraBase_->SelectOpenCamera(usbCameraIds[0]); // 0:first camera id
ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
cameraBase_->rc = SelectOpenCamera(usbCameraIds[1]); // 1:second camera id
ASSERT_EQ(cameraBase_->rc, HDI::Camera::V1_0::NO_ERROR);
cameraBase_->AchieveStreamOperator();
AchieveStreamOperator();
cameraBase_->intents = {PREVIEW, STILL_CAPTURE};
cameraBase_->StartStream(cameraBase_->intents);
StartStream(cameraBase_->intents);
cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
cameraBase_->StartCapture(cameraBase_->STREAM_ID_CAPTURE, cameraBase_->CAPTURE_ID_CAPTURE, false, true);
StartCapture(STREAM_ID_PREVIEW_DOUBLE, CAPTURE_ID_PREVIEW_DOUBLE, false, true);
StartCapture(STREAM_ID_CAPTURE_DOUBLE, CAPTURE_ID_CAPTURE_DOUBLE, false, true);
cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_CAPTURE};
cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_CAPTURE};
cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
cameraBase_->captureIds = {CAPTURE_ID_PREVIEW_DOUBLE, CAPTURE_ID_CAPTURE_DOUBLE};
cameraBase_->streamIds = {STREAM_ID_PREVIEW_DOUBLE, STREAM_ID_CAPTURE_DOUBLE};
StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
}
}