diff --git a/bundle.json b/bundle.json index 1571a19ccc5fc6dc0affb9f70fec70f780f60399..8c7ca8d4882c84aa49f28bc744dec6280b40c888 100644 --- a/bundle.json +++ b/bundle.json @@ -78,7 +78,8 @@ "//foundation/distributedhardware/distributed_camera/services/channel/test/unittest:camera_channel_test", "//foundation/distributedhardware/distributed_camera/services/data_process/test/unittest:data_process_test", "//foundation/distributedhardware/distributed_camera/interfaces/inner_kits/native_cpp/test/fuzztest:fuzztest", - "//foundation/distributedhardware/distributed_camera/interfaces/inner_kits/native_cpp/test/unittest:dcamera_handler_test" + "//foundation/distributedhardware/distributed_camera/interfaces/inner_kits/native_cpp/test/unittest:dcamera_handler_test", + "//foundation/distributedhardware/distributed_camera/test:distributedcameradcts" ] } } diff --git a/test/BUILD.gn b/test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3569f2c6f3c53ac41df20563595435162cad13e3 --- /dev/null +++ b/test/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (C) 2023 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. + +import("//build/ohos_var.gni") + +group("distributedcameradcts") { + testonly = true + if (is_standard_system) { + deps = [ + "distributedcameraclienttest:SubDctsdisCameraClientTest", + "distributedcameratest:SubDctsdisCameraTest", + ] + } +} diff --git a/test/distributedcameraclienttest/BUILD.gn b/test/distributedcameraclienttest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4da4bec820ebf6a96961b111a31043e5232acd83 --- /dev/null +++ b/test/distributedcameraclienttest/BUILD.gn @@ -0,0 +1,102 @@ +# Copyright (c) 2023 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. + +base_root = "../../../../../" +import( + "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") +import("//test/xts/tools/build/suite.gni") + +module_output_path = "distributed_camera/dcts" + +config("module_private_config") { + include_dirs = [ + "$base_root/third_party/jsoncpp/include", + "$base_root/foundation/graphic/graphic_2d/frameworks/surface/include", + "$base_root/foundation/multimedia/camera_framework/interfaces/inner_api/native/camera/include", + "$base_root/foundation/multimedia/camera_framework/interfaces/inner_api/native/camera/include/input", + "$base_root/foundation/multimedia/camera_framework/interfaces/inner_api/native/camera/include/output", + "$base_root/foundation/multimedia/camera_framework/interfaces/inner_api/native/camera/include/session", + "$base_root/foundation/multimedia/camera_framework/services/camera_service/binder/base/include", + "$base_root/foundation/multimedia/camera_framework/services/camera_service/binder/client/include", + "$base_root/foundation/multimedia/camera_framework/services/camera_service/binder/server/include", + "$base_root/foundation/multimedia/camera_framework/services/camera_service/include", + "$base_root/foundation/distributedhardware/distributed_hardware_fwk/common/log/include", + "$base_root/foundation/distributedhardware/distributed_hardware_fwk/common/utils/include", + "$base_root/foundation/distributedhardware/distributed_hardware_fwk/utils/include/log", + "$base_root/foundation/distributedhardware/distributed_hardware_fwk/utils/include", + ] + + include_dirs += [ + "./include", + "$base_root/foundation/distributedhardware/distributed_camera/common/include/constants", + "$base_root/foundation/distributedhardware/distributed_camera/common/include/utils", + "$base_root/foundation/distributedhardware/distributed_camera/services/cameraservice/base/include", + "$base_root/foundation/distributedhardware/distributed_camera/services/cameraservice/cameraoperator/client/include", + "$base_root/foundation/distributedhardware/distributed_camera/services/cameraservice/cameraoperator/client/include/callback", + "$base_root/foundation/distributedhardware/distributed_camera/services/cameraservice/cameraoperator/client/include/listener", + ] +} + +ohos_moduletest_suite("SubDctsdisCameraClientTest") { + module_out_path = module_output_path + install_enable = true + sources = [ + "dcamera_client_automat_test.cpp", + "dcamera_client_demo.cpp", + ] + + configs = [ ":module_private_config" ] + + cflags = [ + "-fPIC", + "-Wall", + ] + + if (distributed_camera_common) { + cflags += [ "-DDCAMERA_COMMON" ] + } + + deps = [ + "$base_root/foundation/distributedhardware/distributed_camera/common:distributed_camera_utils", + "$base_root/foundation/distributedhardware/distributed_camera/services/cameraservice/cameraoperator/client:distributed_camera_client", + "$base_root/foundation/distributedhardware/distributed_camera/services/cameraservice/sinkservice:distributed_camera_sink", + "$base_root/foundation/distributedhardware/distributed_hardware_fwk/utils:distributedhardwareutils", + "$base_root/foundation/graphic/graphic_2d:libsurface", + "$base_root/foundation/multimedia/camera_framework/frameworks/native/camera:camera_framework", + "$base_root/third_party/jsoncpp:jsoncpp", + ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "access_token:libtoken_setproc", + "c_utils:utils", + "drivers_interface_camera:metadata", + "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0", + "hilog:libhilog", + "ipc:ipc_core", + "player_framework:media_client", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SubDctsdisCameraClientTest\"", + "LOG_DOMAIN=0xD004100", + ] + + cflags_cc = cflags + subsystem_name = "distributedhardware" + part_name = "distributed_camera" +} diff --git a/test/distributedcameraclienttest/Test.json b/test/distributedcameraclienttest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..360b06c93acf08168dfd12406acec0e815332c04 --- /dev/null +++ b/test/distributedcameraclienttest/Test.json @@ -0,0 +1,22 @@ +{ + "description": "Config for disCamera test cases", + "driver": { + "module-name": "SubDctsdisCameraTest", + "native-test-timeout": "120000", + "native-test-device-path": "/data/local/tmp", + "runtime-hint": "1s", + "type": "CppTest" + }, + "kits": [ + { + "post-push" : [ + "chmod -R 777 /data/local/tmp/*" + ], + "push": [ + "SubDctsdisCameraTest->/data/local/tmp/SubDctsdisCameraTest" + ], + "type": "PushKit" + } + ] +} + diff --git a/test/distributedcameraclienttest/dcamera_client_automat_test.cpp b/test/distributedcameraclienttest/dcamera_client_automat_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..07a2f9be2ba9a1e76c747ae7e188708df8f882ff --- /dev/null +++ b/test/distributedcameraclienttest/dcamera_client_automat_test.cpp @@ -0,0 +1,317 @@ +/* + * Copyright (c) 2023 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 +#include "dcamera_client_demo.h" +#include "distributed_hardware_log.h" + +#include "access_token.h" +#include "accesstoken_kit.h" +#include "hap_token_info.h" +#include "ipc_skeleton.h" +#include "nativetoken_kit.h" +#include "token_setproc.h" + +using namespace testing::ext; +using namespace OHOS::DistributedHardware; + +int32_t cameraOk = 0; +int32_t sleepOk = 2; +int32_t camoreError = -1; +int32_t SLEEP_FIVE_SECOND = 5; + +class DCameraClientAutomatTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + DCameraClientAutomatTest(); +}; + +void DCameraClientAutomatTest::SetUpTestCase(void) +{ + uint64_t tokenId; + const char *perms[2]; + perms[0] = "ohos.permission.DISTRIBUTED_DATASYNC"; + perms[1] = "ohos.permission.CAMERA"; + NativeTokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = 2, + .aclsNum = 0, + .dcaps = NULL, + .perms = perms, + .acls = NULL, + .processName = "dcamera_client_demo", + .aplStr = "system_basic", + }; + tokenId = GetAccessTokenId(&infoInstance); + SetSelfTokenID(tokenId); + OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); + sleep(sleepOk); +} + +void DCameraClientAutomatTest::TearDownTestCase(void) {} +void DCameraClientAutomatTest::SetUp(void) {} +void DCameraClientAutomatTest::TearDown(void) {} +DCameraClientAutomatTest::DCameraClientAutomatTest(void) {} + +/** + * @tc.number : DCameraTest_0100 + * @tc.name :InitCameraStandard() + * @tc.desc : 后置摄像头获取 + * @tc.desc : swicth distributed cmera + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraClientAutomatTest, DCameraTest_0100, TestSize.Level1) +{ + int32_t ret = InitCameraStandard(); + EXPECT_EQ(cameraOk, ret) << "InitCameraStandard fail"; + ReleaseResource(); + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_0200 + * @tc.name :InitCameraStandard() + * @tc.desc : 后置预览 + * @tc.desc : swicth distributed cmera + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraClientAutomatTest, DCameraTest_0200, TestSize.Level1) +{ + int32_t ret = InitCameraStandard(); + EXPECT_EQ(cameraOk, ret) << "InitCameraStandard fail"; + InitCaptureInfo(0, 0); + InitPhotoOutput(); + InitPreviewOutput(); + ConfigCaptureSession(); + sleep(SLEEP_FIVE_SECOND); + ReleaseResource(); + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_0300 + * @tc.name :InitCameraStandardBack() + * @tc.desc : 前置摄像头获取 + * @tc.desc : swicth distributed cmera + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraClientAutomatTest, DCameraTest_0300, TestSize.Level1) +{ + int32_t ret = InitCameraStandardBack(); + EXPECT_EQ(cameraOk, ret) << "InitCameraStandardBack fail"; + ReleaseResource(); + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_0400 + * @tc.name :InitCameraStandardBack() + * @tc.desc : 前置预览 + * @tc.desc : swicth distributed cmera + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraClientAutomatTest, DCameraTest_0400, TestSize.Level1) +{ + int32_t ret = InitCameraStandardBack(); + EXPECT_EQ(cameraOk, ret) << "InitCameraStandardBack fail"; + InitCaptureInfo(0, 0); + InitPhotoOutput(); + InitPreviewOutput(); + ConfigCaptureSession(); + sleep(SLEEP_FIVE_SECOND); + ReleaseResource(); + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_0500 + * @tc.name :InitCameraStandardBack() + * @tc.desc : 前后置切换预览 + * @tc.desc : swicth distributed cmera + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraClientAutomatTest, DCameraTest_0500, TestSize.Level1) +{ + int32_t ret = InitCameraStandard(); + EXPECT_EQ(cameraOk, ret) << "InitCameraStandard fail"; + InitCaptureInfo(0, 0); + InitPhotoOutput(); + InitPreviewOutput(); + ConfigCaptureSession(); + sleep(SLEEP_FIVE_SECOND); + ReleaseResource(); + sleep(sleepOk); + + ret = InitCameraStandardBack(); + EXPECT_EQ(cameraOk, ret) << "InitCameraStandardBack fail"; + InitCaptureInfo(0, 0); + InitPhotoOutput(); + InitPreviewOutput(); + ConfigCaptureSession(); + sleep(SLEEP_FIVE_SECOND); + ReleaseResource(); + sleep(sleepOk); + + ret = InitCameraStandard(); + EXPECT_EQ(cameraOk, ret) << "InitCameraStandard fail"; + InitCaptureInfo(0, 0); + InitPhotoOutput(); + InitPreviewOutput(); + ConfigCaptureSession(); + sleep(SLEEP_FIVE_SECOND); + ReleaseResource(); + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_0600 + * @tc.name :Capture() + * @tc.desc : 后置摄像头拍照 + * @tc.desc : swicth distributed cmera + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraClientAutomatTest, DCameraTest_0600, TestSize.Level1) +{ + int32_t ret = InitCameraStandard(); + EXPECT_EQ(cameraOk, ret) << "InitCameraStandard fail"; + InitCaptureInfo(0, 0); + InitPhotoOutput(); + InitPreviewOutput(); + ConfigCaptureSession(); + ret = Capture(); + EXPECT_EQ(cameraOk, ret) << "Capture fail"; + sleep(SLEEP_FIVE_SECOND); + ReleaseResource(); + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_0700 + * @tc.name :Capture() + * @tc.desc : 前置摄像头拍照 + * @tc.desc : swicth distributed cmera + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraClientAutomatTest, DCameraTest_0700, TestSize.Level1) +{ + int32_t ret = InitCameraStandardBack(); + EXPECT_EQ(cameraOk, ret) << "InitCameraStandardBack fail"; + InitCaptureInfo(0, 0); + InitPhotoOutput(); + InitPreviewOutput(); + ConfigCaptureSession(); + ret = Capture(); + EXPECT_EQ(cameraOk, ret) << "Capture fail"; + sleep(SLEEP_FIVE_SECOND); + ReleaseResource(); + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_0800 + * @tc.name :Capture() + * @tc.desc : 闪光灯拍照 + * @tc.desc : swicth distributed cmera + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraClientAutomatTest, DCameraTest_0800, TestSize.Level1) +{ + int32_t ret = InitCameraStandardBack(); + EXPECT_EQ(cameraOk, ret) << "InitCameraStandard fail"; + InitCaptureInfo(0, 0); + InitPhotoOutput(); + InitPreviewOutput(); + ConfigCaptureSession(); + ConfigFocusFlashAndExposure(false); + ret = Capture(); + EXPECT_EQ(cameraOk, ret) << "Capture fail"; + sleep(SLEEP_FIVE_SECOND); + ReleaseResource(); + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_0900 + * @tc.name :Capture() + * @tc.desc : 使用分辨率预览 + * @tc.desc : swicth distributed cmera + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraClientAutomatTest, DCameraTest_0900, TestSize.Level1) +{ + int32_t ret = InitCameraStandardBack(); + EXPECT_EQ(cameraOk, ret) << "InitCameraStandard fail"; + std::vector previewResolution = {}; + ret = GetPreviewProfiles(previewResolution); + EXPECT_EQ(cameraOk, ret) << "GetPreviewProfiles fail"; + CameraStandard::Size size = previewResolution.back(); + InitCaptureInfo(size.width, size.height); + InitPhotoOutput(); + InitPreviewOutput(); + ConfigCaptureSession(); + ConfigFocusFlashAndExposure(false); + ret = Capture(); + EXPECT_EQ(cameraOk, ret) << "Capture fail"; + sleep(SLEEP_FIVE_SECOND); + ReleaseResource(); + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_1000 + * @tc.name :Capture() + * @tc.desc : 前后置切换预览50次 + * @tc.desc : swicth distributed cmera + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraClientAutomatTest, DCameraTest_1000, TestSize.Level1) +{ + int32_t i = 50; + while (i > 0) { + int32_t ret = InitCameraStandard(); + EXPECT_EQ(cameraOk, ret) << "InitCameraStandard fail"; + InitCaptureInfo(0, 0); + InitPhotoOutput(); + InitPreviewOutput(); + ConfigCaptureSession(); + sleep(SLEEP_FIVE_SECOND); + ReleaseResource(); + sleep(sleepOk); + + ret = InitCameraStandardBack(); + EXPECT_EQ(cameraOk, ret) << "InitCameraStandardBack fail"; + InitCaptureInfo(0, 0); + InitPhotoOutput(); + InitPreviewOutput(); + ConfigCaptureSession(); + sleep(SLEEP_FIVE_SECOND); + ReleaseResource(); + sleep(sleepOk); + i--; + } +} diff --git a/test/distributedcameraclienttest/dcamera_client_demo.cpp b/test/distributedcameraclienttest/dcamera_client_demo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e5b78e01d5d1317458e2813c7284e6ec7c1595b2 --- /dev/null +++ b/test/distributedcameraclienttest/dcamera_client_demo.cpp @@ -0,0 +1,402 @@ +/* + * Copyright (c) 2023 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 "dcamera_client_demo.h" + +using namespace OHOS; +using namespace OHOS::Camera; +using namespace OHOS::CameraStandard; +using namespace OHOS::DistributedHardware; + +constexpr double LATITUDE = 22.306; +constexpr double LONGITUDE = 52.12; +constexpr double ALTITUDE = 2.365; +#ifdef DCAMERA_COMMON + constexpr int32_t PHOTO_WIDTH = 1280; + constexpr int32_t PHOTO_HEIGTH = 960; +#else + constexpr int32_t PHOTO_WIDTH = 1920; + constexpr int32_t PHOTO_HEIGTH = 1080; +#endif +constexpr int32_t PREVIEW_WIDTH = 640; +constexpr int32_t PREVIEW_HEIGTH = 480; +constexpr int32_t VIDEO_WIDTH = 640; +constexpr int32_t VIDEO_HEIGTH = 480; + +static sptr g_cameraInfo = nullptr; +static sptr g_cameraManager = nullptr; +static sptr g_cameraInput = nullptr; +static sptr g_photoOutput = nullptr; +static sptr g_previewOutput = nullptr; +static sptr g_videoOutput = nullptr; +static sptr g_captureSession = nullptr; +static std::shared_ptr g_photoInfo = nullptr; +static std::shared_ptr g_previewInfo = nullptr; +static std::shared_ptr g_videoInfo = nullptr; + +#ifdef DCAMERA_COMMON + constexpr int32_t PHOTO_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_JPEG; + constexpr int32_t PREVIEW_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_RGBA_8888; + constexpr int32_t VIDEO_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_RGBA_8888; +#else + constexpr int32_t PHOTO_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_JPEG; + constexpr int32_t PREVIEW_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_YCRCB_420_SP; + constexpr int32_t VIDEO_FORMAT = camera_format_t::OHOS_CAMERA_FORMAT_YCRCB_420_SP; +#endif + +int32_t InitCameraStandard() +{ + g_cameraManager = CameraManager::GetInstance(); + g_cameraManager->SetCallback(std::make_shared()); + + int rv = g_cameraManager->CreateCaptureSession(&g_captureSession); + if (rv != DCAMERA_OK) { + DHLOGE("InitCameraStandard create captureSession failed, rv: %d", rv); + return rv; + } + std::shared_ptr sessionCallback = std::make_shared(); + g_captureSession->SetCallback(sessionCallback); + g_captureSession->SetFocusCallback(sessionCallback); + + std::vector> cameraObjList = g_cameraManager->GetSupportedCameras(); + for (auto info : cameraObjList) { + DHLOGI("Camera: %s, position: %d, camera type: %d, connection type: %d", GetAnonyString(info->GetID()).c_str(), + info->GetPosition(), info->GetCameraType(), info->GetConnectionType()); + // OHOS_CAMERA_POSITION_FRONT or OHOS_CAMERA_POSITION_BACK + if ((info->GetPosition() == CameraPosition::CAMERA_POSITION_FRONT) && + (info->GetConnectionType() == ConnectionType::CAMERA_CONNECTION_REMOTE)) { + g_cameraInfo = info; + break; + } + } + + if (g_cameraInfo == nullptr) { + DHLOGE("Distributed Camera Demo: have no remote camera"); + return DCAMERA_BAD_VALUE; + } + + rv = g_cameraManager->CreateCameraInput(g_cameraInfo, &((sptr &)g_cameraInput)); + if (rv != DCAMERA_OK) { + DHLOGE("InitCameraStandard create cameraInput failed, rv: %d", rv); + return rv; + } + int32_t ret = ((sptr &)g_cameraInput)->Open(); + if (ret != DCAMERA_OK) { + DHLOGE("InitCameraStandard g_cameraInput Open failed, ret: %d", ret); + return ret; + } + std::shared_ptr inputCallback = std::make_shared(); + ((sptr &)g_cameraInput)->SetErrorCallback(inputCallback); + return DCAMERA_OK; +} + +int32_t InitCameraStandardBack() +{ + g_cameraManager = CameraManager::GetInstance(); + g_cameraManager->SetCallback(std::make_shared()); + + int rv = g_cameraManager->CreateCaptureSession(&g_captureSession); + if (rv != DCAMERA_OK) { + DHLOGE("InitCameraStandard create captureSession failed, rv: %d", rv); + return rv; + } + std::shared_ptr sessionCallback = std::make_shared(); + g_captureSession->SetCallback(sessionCallback); + g_captureSession->SetFocusCallback(sessionCallback); + + std::vector> cameraObjList = g_cameraManager->GetSupportedCameras(); + for (auto info : cameraObjList) { + DHLOGI("Camera: %s, position: %d, camera type: %d, connection type: %d", GetAnonyString(info->GetID()).c_str(), + info->GetPosition(), info->GetCameraType(), info->GetConnectionType()); + // OHOS_CAMERA_POSITION_FRONT or OHOS_CAMERA_POSITION_BACK + if ((info->GetPosition() == CameraPosition::CAMERA_POSITION_BACK) && + (info->GetConnectionType() == ConnectionType::CAMERA_CONNECTION_REMOTE)) { + g_cameraInfo = info; + break; + } + } + + if (g_cameraInfo == nullptr) { + DHLOGE("Distributed Camera Demo: have no remote camera"); + return DCAMERA_BAD_VALUE; + } + + rv = g_cameraManager->CreateCameraInput(g_cameraInfo, &((sptr &)g_cameraInput)); + if (rv != DCAMERA_OK) { + DHLOGE("InitCameraStandard create cameraInput failed, rv: %d", rv); + return rv; + } + int32_t ret = ((sptr &)g_cameraInput)->Open(); + if (ret != DCAMERA_OK) { + DHLOGE("InitCameraStandard g_cameraInput Open failed, ret: %d", ret); + return ret; + } + std::shared_ptr inputCallback = std::make_shared(); + ((sptr &)g_cameraInput)->SetErrorCallback(inputCallback); + return DCAMERA_OK; +} + +void InitCaptureInfo(int32_t width, int32_t height) +{ + g_photoInfo = std::make_shared(); + g_photoInfo->width_ = PHOTO_WIDTH; + g_photoInfo->height_ = PHOTO_HEIGTH; + g_photoInfo->format_ = PHOTO_FORMAT; + + g_previewInfo = std::make_shared(); + if (width == 0 && height == 0) { + g_previewInfo->width_ = PREVIEW_WIDTH; + g_previewInfo->height_ = PREVIEW_HEIGTH; + } else { + g_previewInfo->width_ = width; + g_previewInfo->height_ = height; + } + g_previewInfo->format_ = PREVIEW_FORMAT; + + g_videoInfo = std::make_shared(); + g_videoInfo->width_ = VIDEO_WIDTH; + g_videoInfo->height_ = VIDEO_HEIGTH; + g_videoInfo->format_ = VIDEO_FORMAT; +} + +CameraFormat ConvertToCameraFormat(int32_t format) +{ + CameraFormat ret = CameraFormat::CAMERA_FORMAT_INVALID; + DCameraFormat df = static_cast(format); + switch (df) { + case DCameraFormat::OHOS_CAMERA_FORMAT_RGBA_8888: + ret = CameraFormat::CAMERA_FORMAT_RGBA_8888; + break; + case DCameraFormat::OHOS_CAMERA_FORMAT_YCBCR_420_888: + ret = CameraFormat::CAMERA_FORMAT_YCBCR_420_888; + break; + case DCameraFormat::OHOS_CAMERA_FORMAT_YCRCB_420_SP: + ret = CameraFormat::CAMERA_FORMAT_YUV_420_SP; + break; + case DCameraFormat::OHOS_CAMERA_FORMAT_JPEG: + ret = CameraFormat::CAMERA_FORMAT_JPEG; + break; + default: + break; + } + return ret; +} + +void InitPhotoOutput() +{ + DHLOGI("Distributed Camera Demo: Create PhotoOutput, width = %d, height = %d, format = %d", + g_photoInfo->width_, g_photoInfo->height_, g_photoInfo->format_); + sptr photoSurface = IConsumerSurface::Create(); + sptr photoListener = new DemoDCameraPhotoSurfaceListener(photoSurface); + photoSurface->RegisterConsumerListener(photoListener); + CameraFormat photoFormat = ConvertToCameraFormat(g_photoInfo->format_); + Size photoSize = {g_photoInfo->width_, g_photoInfo->height_}; + Profile photoProfile(photoFormat, photoSize); + sptr photoProducer = photoSurface->GetProducer(); + int rv = g_cameraManager->CreatePhotoOutput(photoProfile, photoProducer, &((sptr &)g_photoOutput)); + if (rv != DCAMERA_OK) { + DHLOGE("InitPhotoOutput create photoOutput failed, rv: %d", rv); + return; + } + ((sptr &)g_photoOutput)->SetCallback(std::make_shared()); +} + +void InitPreviewOutput() +{ + DHLOGI("Distributed Camera Demo: Create PreviewOutput, width = %d, height = %d, format = %d", + g_previewInfo->width_, g_previewInfo->height_, g_previewInfo->format_); + sptr previewSurface = IConsumerSurface::Create(); + sptr previewListener = new DemoDCameraPreviewSurfaceListener(previewSurface); + previewSurface->RegisterConsumerListener(previewListener); + CameraFormat previewFormat = ConvertToCameraFormat(g_previewInfo->format_); + Size previewSize = {g_previewInfo->width_, g_previewInfo->height_}; + Profile previewProfile(previewFormat, previewSize); + sptr previewProducer = previewSurface->GetProducer(); + sptr previewProducerSurface = Surface::CreateSurfaceAsProducer(previewProducer); + int rv = g_cameraManager->CreatePreviewOutput( + previewProfile, previewProducerSurface, &((sptr &)g_previewOutput)); + if (rv != DCAMERA_OK) { + DHLOGE("InitPhotoOutput create previewOutput failed, rv: %d", rv); + return; + } + ((sptr &)g_previewOutput)->SetCallback(std::make_shared()); +} + +void InitVideoOutput() +{ + DHLOGI("Distributed Camera Demo: Create VideoOutput, width = %d, height = %d, format = %d", + g_videoInfo->width_, g_videoInfo->height_, g_videoInfo->format_); + sptr videoSurface = IConsumerSurface::Create(); + sptr videoListener = new DemoDCameraVideoSurfaceListener(videoSurface); + videoSurface->RegisterConsumerListener(videoListener); + CameraFormat videoFormat = ConvertToCameraFormat(g_videoInfo->format_); + Size videoSize = {g_videoInfo->width_, g_videoInfo->height_}; + std::vector framerates = {}; + VideoProfile videoSettings(videoFormat, videoSize, framerates); + sptr videoProducer = videoSurface->GetProducer(); + sptr pSurface = Surface::CreateSurfaceAsProducer(videoProducer); + int rv = g_cameraManager->CreateVideoOutput(videoSettings, pSurface, &((sptr &)g_videoOutput)); + if (rv != DCAMERA_OK) { + DHLOGE("InitPhotoOutput create videoOutput failed, rv: %d", rv); + return; + } + ((sptr &)g_videoOutput)->SetCallback(std::make_shared()); +} + +void ConfigCaptureSession() +{ + g_captureSession->BeginConfig(); + g_captureSession->AddInput(g_cameraInput); + g_captureSession->AddOutput(g_previewOutput); + g_captureSession->AddOutput(g_videoOutput); + g_captureSession->AddOutput(g_photoOutput); + g_captureSession->CommitConfig(); + + std::vector stabilizationModes; + int32_t rv = g_captureSession->GetSupportedStabilizationMode(stabilizationModes); + if (rv != DCAMERA_OK) { + DHLOGE("ConfigCaptureSession get supported stabilization mode failed, rv: %d", rv); + return; + } + if (!stabilizationModes.empty()) { + for (auto mode : stabilizationModes) { + DHLOGI("Distributed Camera Demo: video stabilization mode %d", mode); + } + g_captureSession->SetVideoStabilizationMode(stabilizationModes.back()); + } + g_captureSession->Start(); +} + +void ConfigFocusFlashAndExposure(bool video) +{ + g_captureSession->LockForControl(); + FocusMode focusMode = FOCUS_MODE_CONTINUOUS_AUTO; + ExposureMode exposureMode = EXPOSURE_MODE_AUTO; + float exposureValue = 0; + std::vector biasRange; + int32_t rv = g_captureSession->GetExposureBiasRange(biasRange); + if (rv != DCAMERA_OK) { + DHLOGE("ConfigFocusAndExposure get exposure bias range failed, rv: %d", rv); + return; + } + if (!biasRange.empty()) { + DHLOGI("Distributed Camera Demo: get %d exposure compensation range", biasRange.size()); + exposureValue = biasRange[0]; + } + FlashMode flash = FLASH_MODE_OPEN; + if (video) { + flash = FLASH_MODE_ALWAYS_OPEN; + } + g_captureSession->SetFlashMode(flash); + g_captureSession->SetFocusMode(focusMode); + g_captureSession->SetExposureMode(exposureMode); + g_captureSession->SetExposureBias(exposureValue); + g_captureSession->UnlockForControl(); +} + +std::shared_ptr ConfigPhotoCaptureSetting() +{ + std::shared_ptr photoCaptureSettings = std::make_shared(); + // Rotation + PhotoCaptureSetting::RotationConfig rotation = PhotoCaptureSetting::RotationConfig::Rotation_0; + photoCaptureSettings->SetRotation(rotation); + // QualityLevel + PhotoCaptureSetting::QualityLevel quality = PhotoCaptureSetting::QualityLevel::QUALITY_LEVEL_HIGH; + photoCaptureSettings->SetQuality(quality); + // Location + std::unique_ptr location = std::make_unique(); + location->latitude = LATITUDE; + location->longitude = LONGITUDE; + location->altitude = ALTITUDE; + photoCaptureSettings->SetLocation(location); + return photoCaptureSettings; +} + +void ReleaseResource() +{ + if (g_previewOutput != nullptr) { + ((sptr &)g_previewOutput)->Stop(); + g_previewOutput->Release(); + g_previewOutput = nullptr; + } + if (g_photoOutput != nullptr) { + g_photoOutput->Release(); + g_photoOutput = nullptr; + } + if (g_videoOutput != nullptr) { + g_videoOutput->Release(); + g_videoOutput = nullptr; + } + if (g_cameraInput != nullptr) { + g_cameraInput->Close(); + g_cameraInput->Release(); + g_cameraInput = nullptr; + } + if (g_captureSession != nullptr) { + g_captureSession->Stop(); + g_captureSession->Release(); + g_captureSession = nullptr; + } + if (g_cameraManager != nullptr) { + g_cameraManager->SetCallback(nullptr); + } + g_cameraInfo = nullptr; + g_cameraManager = nullptr; +} + +int32_t Capture() +{ + int32_t ret = ((sptr &)g_photoOutput)->Capture(ConfigPhotoCaptureSetting()); + if (ret != DCAMERA_OK) { + DHLOGE("main g_photoOutput Capture failed, ret: %d", ret); + return ret; + } + return DCAMERA_OK; +} + +int32_t Video() +{ + int32_t ret = ((sptr &)g_videoOutput)->Start(); + if (ret != DCAMERA_OK) { + DHLOGE("main VideoOutput Start failed, ret: %d", ret); + return ret; + } + return DCAMERA_OK; +} + +int32_t GetPreviewProfiles(std::vector &previewResolution) +{ + sptr capability = g_cameraManager->GetSupportedOutputCapability(g_cameraInfo); + if (capability == nullptr) { + DHLOGI("get supported capability is null"); + return DCAMERA_BAD_VALUE; + } + std::vector previewProfiles = capability->GetPreviewProfiles(); + DHLOGI("size: %d", previewProfiles.size()); + for (auto& profile : previewProfiles) { + CameraStandard::Size picSize = profile.GetSize(); + DHLOGI("width: %d, height: %d", picSize.width, picSize.height); + if (IsValid(picSize)) { + previewResolution.push_back(picSize); + } + } + return DCAMERA_OK; +} + +bool IsValid(const CameraStandard::Size& size) +{ + return (size.width >= RESOLUTION_MIN_WIDTH) && (size.height >= RESOLUTION_MIN_HEIGHT) && + (size.width <= RESOLUTION_MAX_WIDTH_CONTINUOUS) && (size.height <= RESOLUTION_MAX_HEIGHT_CONTINUOUS); +} diff --git a/test/distributedcameraclienttest/dcamera_client_demo.h b/test/distributedcameraclienttest/dcamera_client_demo.h new file mode 100644 index 0000000000000000000000000000000000000000..9059956b157b706bd62d4e4d671b31a252082a39 --- /dev/null +++ b/test/distributedcameraclienttest/dcamera_client_demo.h @@ -0,0 +1,306 @@ +/* + * Copyright (c) 2023 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 OHOS_DCAMERA_CLIENT_DEMO_H +#define OHOS_DCAMERA_CLIENT_DEMO_H + +#include + +#include "anonymous_string.h" +#include "camera_device_ability_items.h" +#include "camera_input.h" +#include "camera_manager.h" +#include "camera_metadata_operator.h" +#include "camera_output_capability.h" +#include "capture_input.h" +#include "capture_output.h" +#include "capture_session.h" +#include "dcamera_capture_info_cmd.h" +#include "dcamera_utils_tools.h" +#include "distributed_camera_constants.h" +#include "distributed_camera_errno.h" +#include "distributed_hardware_log.h" +#include "metadata_utils.h" +#include "photo_output.h" +#include "preview_output.h" +#include "surface.h" +#include "video_output.h" + +namespace OHOS { +namespace DistributedHardware { +class DemoDCameraBufferConsumerListener : public IBufferConsumerListener { +public: + explicit DemoDCameraBufferConsumerListener(const sptr& surface) : surface_(surface) + { + } + + void OnBufferAvailable() + { + DHLOGI("DemoDCameraBufferConsumerListener::OnBufferAvailable"); + if (surface_ == nullptr) { + DHLOGE("DemoDCameraBufferConsumerListener surface is null"); + return; + } + + int32_t flushFence = 0; + int64_t timestamp = 0; + OHOS::Rect damage; + OHOS::sptr buffer = nullptr; + surface_->AcquireBuffer(buffer, flushFence, timestamp, damage); + if (buffer == nullptr) { + DHLOGE("DemoDCameraBufferConsumerListener AcquireBuffer failed"); + return; + } + + width_ = buffer->GetWidth(); + height_ = buffer->GetHeight(); + size_ = buffer->GetSize(); + address_ = static_cast(buffer->GetVirAddr()); + buffer->GetExtraData()->ExtraGet("dataSize", dataSize_); + +#ifdef DCAMERA_COMMON + actualSize_ = width_ * height_ * RGB_BYTES_PER_PIXEL; +#else + actualSize_ = width_ * height_ * YUV_BYTES_PER_PIXEL / Y2UV_RATIO; +#endif + + SaveFile(); + surface_->ReleaseBuffer(buffer, -1); + } + +protected: + virtual void SaveFile() const = 0; + +protected: + constexpr static int32_t Y2UV_RATIO = 2; + constexpr static int32_t YUV_BYTES_PER_PIXEL = 3; + constexpr static int32_t RGB_BYTES_PER_PIXEL = 4; + + char *address_ = nullptr; + int32_t actualSize_ = 0; + int32_t dataSize_ = 0; + int32_t height_ = 0; + int32_t width_ = 0; + int32_t size_ = 0; + sptr surface_; +}; + +class DemoDCameraPhotoSurfaceListener : public DemoDCameraBufferConsumerListener { +public: + explicit DemoDCameraPhotoSurfaceListener(const sptr& surface) + : DemoDCameraBufferConsumerListener(surface) + { + } + +protected: + void SaveFile() const override + { + DHLOGI("DemoDCameraPhotoSurfaceListener::SaveFile width: %d, height: %d, size: %d, dataSize: %d, " + + "actualSize: %d", width_, height_, size_, dataSize_, actualSize_); + if ((address_ == nullptr) || (dataSize_ <= 0)) { + DHLOGE("DemoDCameraPhotoSurfaceListener invalid params, dataSize: %d", dataSize_); + return; + } + + std::ofstream ofs; + std::cout << "saving photo ..." << std::endl; + std::string fileName = "/data/log/dcamera_photo_" + std::to_string(GetNowTimeStampMs()) + ".jpg"; + ofs.open(fileName, std::ios::binary | std::ios::out); + if (!ofs.is_open()) { + DHLOGE("DemoDCameraPhotoSurfaceListener open file failed"); + return; + } + ofs.write(address_, dataSize_); + ofs.close(); + std::cout << "saving photo success" << std::endl; + } +}; + +class DemoDCameraPreviewSurfaceListener : public DemoDCameraBufferConsumerListener { +public: + explicit DemoDCameraPreviewSurfaceListener(const sptr& surface) + : DemoDCameraBufferConsumerListener(surface) + { + } + +protected: + void SaveFile() const override + { + DHLOGI("DemoDCameraPreviewSurfaceListener::SaveFile width: %d, height: %d, size: %d, dataSize: %d, " + + "actualSize: %d", width_, height_, size_, dataSize_, actualSize_); + if ((address_ == nullptr) || (actualSize_ <= 0)) { + DHLOGE("DemoDCameraPreviewSurfaceListener invalid params, actualSize: %d", actualSize_); + return; + } + + std::ofstream ofs; + std::cout << "saving preview ..." << std::endl; + std::string resolution = std::to_string(width_) + "_" + std::to_string(height_); + std::string fileName = "/data/log/dcamera_preview_" + resolution + ".yuv"; + ofs.open(fileName, std::ios::binary | std::ios::out | std::ios::app); + if (!ofs.is_open()) { + DHLOGE("DemoDCameraPreviewSurfaceListener open file failed"); + return; + } + ofs.write(address_, actualSize_); + ofs.close(); + std::cout << "saving preview success" << std::endl; + } +}; + +class DemoDCameraVideoSurfaceListener : public DemoDCameraBufferConsumerListener { +public: + explicit DemoDCameraVideoSurfaceListener(const sptr& surface) + : DemoDCameraBufferConsumerListener(surface) + { + } + +protected: + void SaveFile() const override + { + DHLOGI("DemoDCameraVideoSurfaceListener::SaveFile width: %d, height: %d, size: %d, dataSize: %d, " + + "actualSize: %d", width_, height_, size_, dataSize_, actualSize_); + if ((address_ == nullptr) || (actualSize_ <= 0)) { + DHLOGE("DemoDCameraVideoSurfaceListener invalid params, actualSize: %d", actualSize_); + return; + } + + std::ofstream ofs; + std::cout << "saving video ..." << std::endl; + std::string resolution = std::to_string(width_) + "_" + std::to_string(height_); + std::string fileName = "/data/log/dcamera_video_" + resolution + ".yuv"; + ofs.open(fileName, std::ios::binary | std::ios::out | std::ios::app); + if (!ofs.is_open()) { + DHLOGE("DemoDCameraVideoSurfaceListener open file failed"); + return; + } + ofs.write(address_, actualSize_); + ofs.close(); + std::cout << "saving video success" << std::endl; + } +}; + +class DemoDCameraPhotoCallback : public CameraStandard::PhotoStateCallback { +public: + void OnCaptureStarted(const int32_t captureID) const + { + DHLOGI("DemoDCameraPhotoCallback::OnCaptureStarted captureID: %d", captureID); + } + + void OnCaptureEnded(const int32_t captureID, int32_t frameCount) const + { + DHLOGI("DemoDCameraPhotoCallback::OnCaptureEnded captureID: %d frameCount: %d", captureID, frameCount); + } + + void OnFrameShutter(const int32_t captureId, const uint64_t timestamp) const + { + DHLOGI("DemoDCameraPhotoCallback::OnFrameShutter captureID: %d timestamp: %llu", captureId, timestamp); + } + + void OnCaptureError(const int32_t captureId, const int32_t errorCode) const + { + DHLOGI("DemoDCameraPhotoCallback::OnCaptureError captureID: %d errorCode: %d", captureId, errorCode); + } +}; + +class DemoDCameraPreviewCallback : public CameraStandard::PreviewStateCallback { +public: + void OnFrameStarted() const + { + DHLOGI("DemoDCameraPreviewCallback::OnFrameStarted."); + } + + void OnFrameEnded(const int32_t frameCount) const + { + DHLOGI("DemoDCameraPreviewCallback::OnFrameEnded frameCount: %d", frameCount); + } + + void OnError(const int32_t errorCode) const + { + DHLOGI("DemoDCameraPreviewCallback::OnError errorCode: %d", errorCode); + } +}; + +class DemoDCameraVideoCallback : public CameraStandard::VideoStateCallback { +public: + void OnFrameStarted() const + { + DHLOGI("DemoDCameraVideoCallback::OnFrameStarted."); + } + + void OnFrameEnded(const int32_t frameCount) const + { + DHLOGI("DemoDCameraVideoCallback::OnFrameEnded frameCount: %d", frameCount); + } + + void OnError(const int32_t errorCode) const + { + DHLOGI("DemoDCameraVideoCallback::OnError errorCode: %d", errorCode); + } +}; + +class DemoDCameraInputCallback : public CameraStandard::ErrorCallback { +public: + void OnError(const int32_t errorType, const int32_t errorMsg) const + { + DHLOGI("DemoDCameraInputCallback::OnError errorType: %d errorMsg: %d", errorType, errorMsg); + } +}; + +class DemoDCameraManagerCallback : public CameraStandard::CameraManagerCallback { +public: + void OnCameraStatusChanged(const CameraStandard::CameraStatusInfo &cameraStatusInfo) const + { + DHLOGI("DemoDCameraManagerCallback::OnCameraStatusChanged cameraStatus: %d", cameraStatusInfo.cameraStatus); + } + + void OnFlashlightStatusChanged(const std::string &cameraID, + const CameraStandard::FlashStatus flashStatus) const + { + DHLOGI("DemoDCameraManagerCallback::OnFlashlightStatusChanged cameraID: %s, flashStatus: %d", + GetAnonyString(cameraID).c_str(), flashStatus); + } +}; + +class DemoDCameraSessionCallback : public CameraStandard::SessionCallback, public CameraStandard::FocusCallback { +public: + void OnError(int32_t errorCode) + { + DHLOGI("DemoDCameraSessionCallback::OnError errorCode: %d", errorCode); + } + + void OnFocusState(FocusState state) + { + DHLOGI("DemoDCameraSessionCallback::OnFocusState state: %d", state); + } +}; +} // namespace DistributedHardware +} // namespace OHOS + +int32_t InitCameraStandard(); +int32_t InitCameraStandardBack(); +void InitCaptureInfo(int32_t width, int32_t height); +void InitPhotoOutput(); +void InitPreviewOutput(); +void InitVideoOutput(); +void ConfigCaptureSession(); +void ReleaseResource(); +int32_t Capture(); +int32_t Video(); +std::shared_ptr ConfigPhotoCaptureSetting(); +void ConfigFocusFlashAndExposure(bool video); +int32_t GetPreviewProfiles(std::vector &previewResolution); +bool IsValid(const OHOS::CameraStandard::Size& size); +#endif // OHOS_DCAMERA_CLIENT_DEMO_H \ No newline at end of file diff --git a/test/distributedcameratest/BUILD.gn b/test/distributedcameratest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2f248d3af4b0e176bb7739b766ea69e67070a8bf --- /dev/null +++ b/test/distributedcameratest/BUILD.gn @@ -0,0 +1,77 @@ +# Copyright (c) 2023 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. + +base_root = "../../../../../" +import("//test/xts/tools/build/suite.gni") +module_output_path = "distributed_camera/dcts" + +config("dcamera_hdf_demo_config") { + visibility = [ ":*" ] +} + +ohos_moduletest_suite("SubDctsdisCameraTest") { + module_out_path = module_output_path + install_enable = true + sources = [ + "dcamera_automat_test.cpp", + "dcamera_hdf_demo.cpp", + "stream_customer.cpp", + ] + + include_dirs = [ + "./include", + "$base_root/drivers/peripheral/distributed_camera/hdi_service/include/dcamera_host", + "$base_root/drivers/peripheral/distributed_camera/hdi_service/include/dcamera_device", + "$base_root/drivers/peripheral/distributed_camera/hdi_service/include/dstream_operator", + "$base_root/drivers/peripheral/distributed_camera/hdi_service/include/dstream_provider", + "$base_root/drivers/peripheral/distributed_camera/hdi_service/include/utils", + "$base_root/drivers/hdf_core/framework/include/utils", + "$base_root/drivers/hdf_core/adapter/uhdf2/include/hdi", + "$base_root/drivers/hdf_core/adapter/uhdf2/osal/include", + "$base_root/drivers/peripheral/display/interfaces/include", + "$base_root/drivers/peripheral/camera/interfaces/include", + "$base_root/drivers/peripheral/camera/vdi_base/common/utils", + "$base_root/drivers/peripheral/camera/vdi_base/common/include", + ] + + deps = [ + "$base_root/drivers/hdf_core/adapter/uhdf2/hdi:libhdi", + "$base_root/drivers/hdf_core/adapter/uhdf2/ipc:libhdf_ipc_adapter", + "$base_root/drivers/peripheral/distributed_camera/hdi_service:libdistributed_camera_hdf_service_1.0", + "$base_root/third_party/jsoncpp:jsoncpp", + ] + + cflags = [ + "-fPIC", + "-Wall", + ] + + external_deps = [ + "drivers_interface_camera:libcamera_proxy_1.0", + "drivers_interface_camera:metadata", + "graphic_chipsetsdk:surface", + "hilog:libhilog", + "ipc:ipc_single", + "samgr:samgr_proxy", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SubDctsdisCameraTest\"", + "LOG_DOMAIN=0xD004100", + ] + + cflags_cc = cflags + subsystem_name = "hdf" + part_name = "drivers_peripheral_distributed_camera" +} diff --git a/test/distributedcameratest/Test.json b/test/distributedcameratest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..360b06c93acf08168dfd12406acec0e815332c04 --- /dev/null +++ b/test/distributedcameratest/Test.json @@ -0,0 +1,22 @@ +{ + "description": "Config for disCamera test cases", + "driver": { + "module-name": "SubDctsdisCameraTest", + "native-test-timeout": "120000", + "native-test-device-path": "/data/local/tmp", + "runtime-hint": "1s", + "type": "CppTest" + }, + "kits": [ + { + "post-push" : [ + "chmod -R 777 /data/local/tmp/*" + ], + "push": [ + "SubDctsdisCameraTest->/data/local/tmp/SubDctsdisCameraTest" + ], + "type": "PushKit" + } + ] +} + diff --git a/test/distributedcameratest/dcamera_automat_test.cpp b/test/distributedcameratest/dcamera_automat_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4a5fb003c1709cc0407a9e9b4d760dff0625347b --- /dev/null +++ b/test/distributedcameratest/dcamera_automat_test.cpp @@ -0,0 +1,1135 @@ +/* + * Copyright (c) 2023 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 +#include "dcamera_hdf_demo.h" +#include "distributed_hardware_log.h" + +using namespace testing::ext; +using namespace OHOS::DistributedHardware; + +auto mainDemo = std::make_shared(); +int32_t cameraOk = 0; +int32_t sleepOk = 2; +int32_t camoreError = -1; + +class DCameraAutomatTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + DCameraAutomatTest(); +}; +void DCameraAutomatTest::SetUpTestCase(void) +{ + int32_t ret = mainDemo->InitSensors(); + if (ret == camoreError) { + DHLOGE("main test: mainDemo->InitSensors() error"); + return; + } + + ret = mainDemo->InitCameraDevice(); + if (ret == camoreError) { + DHLOGE("main test: mainDemo->InitCameraDevice() error"); + return; + } + mainDemo->SetEnableResult(); +} + +void DCameraAutomatTest::TearDownTestCase(void) +{ + PreviewOff(mainDemo); + mainDemo->QuitDemo(); +} +void DCameraAutomatTest::SetUp(void) {} +void DCameraAutomatTest::TearDown(void) {} +DCameraAutomatTest::DCameraAutomatTest(void) {} + +/** + * @tc.number : DCameraTest_0100 + * @tc.name :PreviewOn() + * @tc.desc : [STD-DISTRIBUTED-0101]禁止修改分布式相机交互协议 + * @tc.desc : Invoke the preview stream to send the preview file back to the local end and save it to the local end + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_0100, TestSize.Level1) +{ + int32_t ret = PreviewOn(0, mainDemo); + EXPECT_EQ(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_0100 + * @tc.name : CaptureTest() + * @tc.desc : [STD-DISTRIBUTED-0101]禁止修改分布式相机交互协议 + * @tc.desc : Take pictures with a remote camera and save them locally + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_0200, TestSize.Level1) +{ + int32_t ret = CaptureTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "CaptureTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_0700 + * @tc.name :VideoTest() + * @tc.desc : [STD-DISTRIBUTED-0101]禁止修改分布式相机交互协议 + * @tc.desc : Record video with a remote camera and save the video locally + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_0300, TestSize.Level1) +{ + int32_t ret = VideoTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "VideoTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_0200 + * @tc.name : SetAwbMode() + * @tc.desc : [STD-DISTRIBUTED-0101]禁止修改分布式相机交互协议 + * @tc.desc : Set Awb Mode is 0, success is returned + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_0400, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAwbMode(sleepOk); + EXPECT_EQ(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_0300 + * @tc.name : SetAwbMode() + * @tc.desc : [STD-DISTRIBUTED-0101]禁止修改分布式相机交互协议 + * @tc.desc : the Set Awb Mode is 2, success is returned + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_0500, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAwbMode(cameraOk); + EXPECT_EQ(cameraOk, ret) << "SetAwbMode fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_0400 + * @tc.name :mainDemo->SetAeExpo() + * @tc.desc : [STD-DISTRIBUTED-0101]禁止修改分布式相机交互协议 + * @tc.desc : Set the exposure mode update parameters + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_0600, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAeExpo(); + EXPECT_EQ(cameraOk, ret) << "SetAeExpo fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_0500 + * @tc.name :mainDemo->SetMetadata() + * @tc.desc : [STD-DISTRIBUTED-0101]禁止修改分布式相机交互协议 + * @tc.desc : Set the parameters required for taking pictures and recording videos + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_0700, TestSize.Level1) +{ + int32_t ret = mainDemo->SetMetadata(); + EXPECT_EQ(cameraOk, ret) << "SetMetadata fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_0800 + * @tc.name :FlashLightTest() + * @tc.desc : [STD-DISTRIBUTED-0101]禁止修改分布式相机交互协议 + * @tc.desc : Turn off the preview stream, turn on the flashlight, init the camera device, and turn on the preview + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_0800, TestSize.Level1) +{ + int32_t ret = FlashLightTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "FlashLightTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_0900 + * @tc.name :OfflineTest() + * @tc.desc : [STD-DISTRIBUTED-0101]禁止修改分布式相机交互协议 + * @tc.desc : Turn off Preview Turn on dual-stream offline mode delay 5 seconds after init the camera device + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_0900, TestSize.Level1) +{ + int32_t ret = OfflineTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "OfflineTest fail"; +} + +/** + * @tc.number : DCameraTest_1000 + * @tc.name : Test whether preview and awb parameter Settings can be successful + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_1000, TestSize.Level1) +{ + int32_t ret = PreviewOn(0, mainDemo); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); + ret = mainDemo->SetAwbMode(sleepOk); + EXPECT_EQ(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk); + ret = mainDemo->SetAwbMode(cameraOk); + EXPECT_EQ(cameraOk, ret) << "SetAwbMode fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_1100 + * @tc.name : Whether an error occurs when multiple methods are executed consecutively + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_1100, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAeExpo(); + EXPECT_EQ(cameraOk, ret) << "SetAeExpo fail"; + sleep(sleepOk); + ret = mainDemo->SetMetadata(); + EXPECT_EQ(cameraOk, ret) << "SetMetadata fail"; + sleep(sleepOk); + ret = CaptureTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "CaptureTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_1200 + * @tc.name : Whether an error occurs when multiple methods are executed consecutively + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_1200, TestSize.Level1) +{ + int32_t ret = VideoTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "VideoTest fail"; + sleep(sleepOk); + ret = FlashLightTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "FlashLightTest fail"; + sleep(sleepOk); + ret = OfflineTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "OfflineTest fail"; +} + +/** + * @tc.number : DCameraTest_1300 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_1300, TestSize.Level1) +{ + int32_t ret = PreviewOn(0, mainDemo); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); + ret = mainDemo->SetAwbMode(cameraOk); + EXPECT_EQ(cameraOk, ret) << "SetAwbMode fail"; + sleep(sleepOk); + ret = mainDemo->SetAwbMode(sleepOk); + EXPECT_EQ(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_1400 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_1400, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAeExpo(); + EXPECT_EQ(cameraOk, ret) << "SetAeExpo fail"; + sleep(sleepOk); + ret = CaptureTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "CaptureTest fail"; + sleep(sleepOk); + ret = mainDemo->SetMetadata(); + EXPECT_EQ(cameraOk, ret) << "SetMetadata fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_1500 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_1500, TestSize.Level1) +{ + int32_t ret = VideoTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "VideoTest fail"; + sleep(sleepOk); + ret = OfflineTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "OfflineTest fail"; + ret = FlashLightTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "FlashLightTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_1600 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_1600, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAwbMode(sleepOk); + EXPECT_EQ(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk);ret = PreviewOn(0, mainDemo); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); + ret = mainDemo->SetAwbMode(cameraOk); + EXPECT_EQ(cameraOk, ret) << "SetAwbMode fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_1700 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_1700, TestSize.Level1) +{ + int32_t ret = mainDemo->SetMetadata(); + EXPECT_EQ(cameraOk, ret) << "SetMetadata fail"; + sleep(sleepOk); + ret = mainDemo->SetAeExpo(); + EXPECT_EQ(cameraOk, ret) << "SetAeExpo fail"; + sleep(sleepOk); + ret = CaptureTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "CaptureTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_1800 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_1800, TestSize.Level1) +{ + int32_t ret = FlashLightTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "FlashLightTest fail"; + sleep(sleepOk); + ret = VideoTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "VideoTest fail"; + sleep(sleepOk); + ret = OfflineTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "OfflineTest fail"; +} + +/** + * @tc.number : DCameraTest_1900 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_1900, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAwbMode(cameraOk); + EXPECT_EQ(cameraOk, ret) << "SetAwbMode fail"; + sleep(sleepOk); + ret = mainDemo->SetAwbMode(sleepOk); + EXPECT_EQ(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk); + ret = PreviewOn(0, mainDemo); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_2000 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_2000, TestSize.Level1) +{ + int32_t ret = CaptureTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "CaptureTest fail"; + sleep(sleepOk); + ret = mainDemo->SetMetadata(); + EXPECT_EQ(cameraOk, ret) << "SetMetadata fail"; + sleep(sleepOk); + ret = mainDemo->SetAeExpo(); + EXPECT_EQ(cameraOk, ret) << "SetAeExpo fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_2100 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_2100, TestSize.Level1) +{ + int32_t ret = OfflineTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "OfflineTest fail"; + ret = FlashLightTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "FlashLightTest fail"; + sleep(sleepOk); + ret = VideoTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "VideoTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_2200 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_2200, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAeExpo(); + EXPECT_EQ(cameraOk, ret) << "SetAeExpo fail"; + sleep(sleepOk); + ret = mainDemo->SetMetadata(); + EXPECT_EQ(cameraOk, ret) << "SetMetadata fail"; + sleep(sleepOk); + ret = CaptureTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "CaptureTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_2300 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_2300, TestSize.Level1) +{ + int32_t ret = PreviewOn(0, mainDemo); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); + ret = mainDemo->SetAwbMode(sleepOk); + EXPECT_EQ(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk); + ret = mainDemo->SetAwbMode(cameraOk); + EXPECT_EQ(cameraOk, ret) << "SetAwbMode fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_2400 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_2400, TestSize.Level1) +{ + int32_t ret = VideoTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "VideoTest fail"; + sleep(sleepOk); + ret = FlashLightTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "FlashLightTest fail"; + sleep(sleepOk); + ret = OfflineTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "OfflineTest fail"; +} + +/** + * @tc.number : DCameraTest_2500 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_2500, TestSize.Level1) +{ + int32_t ret = VideoTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "VideoTest fail"; + sleep(sleepOk); + ret = FlashLightTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "FlashLightTest fail"; + sleep(sleepOk); + ret = OfflineTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "OfflineTest fail"; +} + +/** + * @tc.number : DCameraTest_2600 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_2600, TestSize.Level1) +{ + int32_t ret = PreviewOn(0, mainDemo); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); + ret = mainDemo->SetAwbMode(sleepOk); + EXPECT_EQ(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk); + ret = mainDemo->SetAwbMode(cameraOk); + EXPECT_EQ(cameraOk, ret) << "SetAwbMode fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_2700 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_2700, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAeExpo(); + EXPECT_EQ(cameraOk, ret) << "SetAeExpo fail"; + sleep(sleepOk); + ret = mainDemo->SetMetadata(); + EXPECT_EQ(cameraOk, ret) << "SetMetadata fail"; + sleep(sleepOk); + ret = CaptureTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "CaptureTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_2800 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_2800, TestSize.Level1) +{ + int32_t ret = VideoTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "VideoTest fail"; + sleep(sleepOk); + ret = OfflineTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "OfflineTest fail"; + ret = FlashLightTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "FlashLightTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_2900 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_2900, TestSize.Level1) +{ + int32_t ret = PreviewOn(0, mainDemo); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); + ret = mainDemo->SetAwbMode(cameraOk); + EXPECT_EQ(cameraOk, ret) << "SetAwbMode fail"; + sleep(sleepOk); + ret = mainDemo->SetAwbMode(sleepOk); + EXPECT_EQ(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_3000 + * @tc.name : Scramble the method invocation order to see if the method invocation fails + * @tc.desc : Composite test function + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_3000, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAeExpo(); + EXPECT_EQ(cameraOk, ret) << "SetAeExpo fail"; + sleep(sleepOk); + ret = CaptureTest(mainDemo); + EXPECT_EQ(cameraOk, ret) << "CaptureTest fail"; + sleep(sleepOk); + ret = mainDemo->SetMetadata(); + EXPECT_EQ(cameraOk, ret) << "SetMetadata fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_3100 + * @tc.name : Preview method Enter error parameters to see the return value + * @tc.desc : Test preview exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_3100, TestSize.Level1) +{ + int32_t ret = PreviewOn(1, mainDemo); + DHLOGI("DCameraTest_3100 = ", ret); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_3200 + * @tc.name : Preview method Enter error parameters to see the return value + * @tc.desc : Test preview exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_3200, TestSize.Level1) +{ + int32_t ret = PreviewOn(1, nullptr); + DHLOGI("DCameraTest_3200 = ", ret); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_3300 + * @tc.name : Preview method Enter error parameters to see the return value + * @tc.desc : Test preview exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_3300, TestSize.Level1) +{ + int32_t ret = PreviewOn(0, nullptr); + DHLOGI("DCameraTest_3300 = ", ret); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_3400 + * @tc.name : Preview method Enter error parameters to see the return value + * @tc.desc : Test preview exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_3400, TestSize.Level1) +{ + int32_t ret = PreviewOn(-1, mainDemo); + DHLOGI("DCameraTest_3400 = ", ret); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_3500 + * @tc.name : Set the wrong awb mode to view the return result + * @tc.desc : Test SetAwbMode exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_3500, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAwbMode(5); + DHLOGI("DCameraTest_3500 = ", ret); + EXPECT_NE(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_3600 + * @tc.name : Set the wrong awb mode to view the return result + * @tc.desc : Test SetAwbMode exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_3600, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAwbMode(camoreError); + DHLOGI("DCameraTest_3600 = ", ret); + EXPECT_NE(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_3700 + * @tc.name : awb mode input error parameters when calling the SetAeExpo method to see the results + * @tc.desc : Test SetAwbMode,SetAeExpo exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_3700, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAwbMode(camoreError); + DHLOGI("DCameraTest_3700 = ", ret); + EXPECT_NE(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk); + ret = mainDemo->SetAeExpo(); + DHLOGI("DCameraTest_3701 = ", ret); + EXPECT_EQ(cameraOk, ret) << "SetAeExpo fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_3800 + * @tc.name : awb mode input error parameters when calling the SetAeExpo method to see the results + * @tc.desc : Test SetAwbMode,SetAeExpo exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_3800, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAwbMode(camoreError); + DHLOGI("DCameraTest_3800 = ", ret); + EXPECT_NE(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk); + ret = mainDemo->SetMetadata(); + DHLOGI("DCameraTest_3801 = ", ret); + EXPECT_EQ(cameraOk, ret) << "SetMetadata fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_3900 + * @tc.name : CaptureTest Enter a null value to view the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_3900, TestSize.Level1) +{ + int32_t ret = CaptureTest(nullptr); + DHLOGI("DCameraTest_3900 = ", ret); + EXPECT_NE(cameraOk, ret) << "CaptureTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_4000 + * @tc.name : VideoTest Enter a null value to view the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_4000, TestSize.Level1) +{ + int32_t ret = VideoTest(nullptr); + DHLOGI("DCameraTest_4000 = ", ret); + EXPECT_NE(cameraOk, ret) << "VideoTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_4100 + * @tc.name : FlashLightTest Enter a null value to view the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_4100, TestSize.Level1) +{ + int32_t ret = FlashLightTest(nullptr); + DHLOGI("DCameraTest_4100 = ", ret); + EXPECT_NE(cameraOk, ret) << "FlashLightTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_4200 + * @tc.name : OfflineTest Enter a null value to view the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_4200, TestSize.Level1) +{ + int32_t ret = OfflineTest(nullptr); + DHLOGI("DCameraTest_4200 = ", ret); + EXPECT_NE(cameraOk, ret) << "OfflineTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_4300 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_4300, TestSize.Level1) +{ + int32_t ret = PreviewOn(1, nullptr); + DHLOGI("DCameraTest_4300 = ", ret); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); + ret = mainDemo->SetAwbMode(5); + DHLOGI("DCameraTest_4301 = ", ret); + EXPECT_NE(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_4400 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_4400, TestSize.Level1) +{ + int32_t ret = PreviewOn(1, nullptr); + DHLOGI("DCameraTest_4400 = ", ret); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); + ret = mainDemo->SetAwbMode(camoreError); + DHLOGI("DCameraTest_4401 = ", ret); + EXPECT_NE(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_4500 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_4500, TestSize.Level1) +{ + int32_t ret = PreviewOn(1, nullptr); + DHLOGI("DCameraTest_4500 = ", ret); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); + ret = CaptureTest(nullptr); + DHLOGI("DCameraTest_4501 = ", ret); + EXPECT_NE(cameraOk, ret) << "CaptureTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_4600 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_4600, TestSize.Level1) +{ + int32_t ret = PreviewOn(1, nullptr); + DHLOGI("DCameraTest_4600 = ", ret); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); + ret = VideoTest(nullptr); + DHLOGI("DCameraTest_4601 = ", ret); + EXPECT_NE(cameraOk, ret) << "VideoTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_4700 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_4700, TestSize.Level1) +{ + int32_t ret = PreviewOn(1, nullptr); + DHLOGI("DCameraTest_4700 = ", ret); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); + ret = PreviewOn(0, nullptr); + DHLOGI("DCameraTest_4701 = ", ret); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_4800 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_4800, TestSize.Level1) +{ + int32_t ret = PreviewOn(1, nullptr); + DHLOGI("DCameraTest_4800 = ", ret); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); + ret = FlashLightTest(nullptr); + DHLOGI("DCameraTest_4801 = ", ret); + EXPECT_NE(cameraOk, ret) << "FlashLightTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_4900 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_4900, TestSize.Level1) +{ + int32_t ret = PreviewOn(1, nullptr); + DHLOGI("DCameraTest_4900 = ", ret); + EXPECT_NE(cameraOk, ret) << "PreviewOn fail"; + sleep(sleepOk); + ret = OfflineTest(nullptr); + DHLOGI("DCameraTest_4901 = ", ret); + EXPECT_NE(cameraOk, ret) << "OfflineTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_5000 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_5000, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAwbMode(camoreError); + DHLOGI("DCameraTest_5000 = ", ret); + EXPECT_NE(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk); + ret = CaptureTest(nullptr); + DHLOGI("DCameraTest_5001 = ", ret); + EXPECT_NE(cameraOk, ret) << "CaptureTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_5100 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_5100, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAwbMode(camoreError); + DHLOGI("DCameraTest_5100 = ", ret); + EXPECT_NE(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk); + ret = VideoTest(nullptr); + DHLOGI("DCameraTest_5101 = ", ret); + EXPECT_NE(cameraOk, ret) << "VideoTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_5200 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_5200, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAwbMode(camoreError); + DHLOGI("DCameraTest_5200 = ", ret); + EXPECT_NE(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk); + ret = FlashLightTest(nullptr); + DHLOGI("DCameraTest_5201 = ", ret); + EXPECT_NE(cameraOk, ret) << "FlashLightTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_5300 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_5300, TestSize.Level1) +{ + int32_t ret = mainDemo->SetAwbMode(camoreError); + DHLOGI("DCameraTest_5300 = ", ret); + EXPECT_NE(cameraOk, ret) << "SetAwbMode incandescent fail"; + sleep(sleepOk); + ret = OfflineTest(nullptr); + DHLOGI("DCameraTest_5301 = ", ret); + EXPECT_NE(cameraOk, ret) << "OfflineTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_5400 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_5400, TestSize.Level1) +{ + int32_t ret = CaptureTest(nullptr); + DHLOGI("DCameraTest_5400 = ", ret); + EXPECT_NE(cameraOk, ret) << "CaptureTest fail"; + sleep(sleepOk); + ret = VideoTest(nullptr); + DHLOGI("DCameraTest_5401 = ", ret); + EXPECT_NE(cameraOk, ret) << "VideoTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_5500 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_5500, TestSize.Level1) +{ + int32_t ret = CaptureTest(nullptr); + DHLOGI("DCameraTest_5500 = ", ret); + EXPECT_NE(cameraOk, ret) << "CaptureTest fail"; + sleep(sleepOk); + ret = FlashLightTest(nullptr); + DHLOGI("DCameraTest_5501 = ", ret); + EXPECT_NE(cameraOk, ret) << "FlashLightTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_5600 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_5600, TestSize.Level1) +{ + int32_t ret = CaptureTest(nullptr); + DHLOGI("DCameraTest_5600 = ", ret); + EXPECT_NE(cameraOk, ret) << "CaptureTest fail"; + sleep(sleepOk); + ret = OfflineTest(nullptr); + DHLOGI("DCameraTest_5601 = ", ret); + EXPECT_NE(cameraOk, ret) << "OfflineTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_5700 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_5700, TestSize.Level1) +{ + int32_t ret = VideoTest(nullptr); + DHLOGI("DCameraTest_5700 = ", ret); + EXPECT_NE(cameraOk, ret) << "VideoTest fail"; + sleep(sleepOk); + ret = FlashLightTest(nullptr); + DHLOGI("DCameraTest_5701 = ", ret); + EXPECT_NE(cameraOk, ret) << "FlashLightTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_5800 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_5800, TestSize.Level1) +{ + int32_t ret = VideoTest(nullptr); + DHLOGI("DCameraTest_5800 = ", ret); + EXPECT_NE(cameraOk, ret) << "VideoTest fail"; + sleep(sleepOk); + ret = OfflineTest(nullptr); + DHLOGI("DCameraTest_5801 = ", ret); + EXPECT_NE(cameraOk, ret) << "OfflineTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_5900 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_5900, TestSize.Level1) +{ + int32_t ret = FlashLightTest(nullptr); + DHLOGI("DCameraTest_5900 = ", ret); + EXPECT_NE(cameraOk, ret) << "FlashLightTest fail"; + sleep(sleepOk); + ret = OfflineTest(nullptr); + DHLOGI("DCameraTest_5901 = ", ret); + EXPECT_NE(cameraOk, ret) << "OfflineTest fail"; + sleep(sleepOk); +} + +/** + * @tc.number : DCameraTest_6000 + * @tc.name : Perform a combination test for different method exceptions and check the return result + * @tc.desc : Test exception + * @tc.type : FUNC + * @tc.size : Medium test + */ +HWTEST_F(DCameraAutomatTest, DCameraTest_6000, TestSize.Level1) +{ + int32_t ret = FlashLightTest(nullptr); + DHLOGI("DCameraTest_6000 = ", ret); + EXPECT_NE(cameraOk, ret) << "FlashLightTest fail"; + sleep(sleepOk); + ret = FlashLightTest(nullptr); + DHLOGI("DCameraTest_6001 = ", ret); + EXPECT_NE(cameraOk, ret) << "FlashLightTest fail"; + sleep(sleepOk); +} \ No newline at end of file diff --git a/test/distributedcameratest/dcamera_hdf_demo.cpp b/test/distributedcameratest/dcamera_hdf_demo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fbee59ba764aa32de30e6235e03ab0ca548d8f69 --- /dev/null +++ b/test/distributedcameratest/dcamera_hdf_demo.cpp @@ -0,0 +1,1336 @@ +/* + * Copyright (c) 2023 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 "dcamera_hdf_demo.h" +#include "distributed_hardware_log.h" +#include "metadata_utils.h" + +namespace OHOS { +namespace DistributedHardware { +DcameraHdfDemo::DcameraHdfDemo() {} +DcameraHdfDemo::~DcameraHdfDemo() {} + +std::vector results_list_; +const int32_t METER_POINT_X = 305; +const int32_t METER_POINT_Y = 205; +const int32_t AF_REGIONS_X = 400; +const int32_t AF_REGIONS_Y = 200; +const int32_t FPS_RANGE = 30; +constexpr uint32_t CAMERA_PREVIEW_WIDTH = 640; +constexpr uint32_t CAMERA_PREVIEW_HEIGHT = 480; +constexpr uint32_t CAMERA_CAPTURE_WIDTH = 1280; +constexpr uint32_t CAMERA_CAPTURE_HEIGHT = 960; +constexpr uint32_t CAMERA_VIDEO_WIDTH = 1280; +constexpr uint32_t CAMERA_VIDEO_HEIGHT = 960; + +void DcameraHdfDemo::SetStreamInfo(StreamInfo& streamInfo, + const std::shared_ptr &streamCustomer, + const int streamId, const StreamIntent intent) +{ + constexpr uint32_t dataspace = 8; + constexpr uint32_t tunneledMode = 5; + sptr producer; + + if (intent == OHOS::HDI::Camera::V1_0::PREVIEW) { + constexpr uint32_t width = CAMERA_PREVIEW_WIDTH; + constexpr uint32_t height = CAMERA_PREVIEW_HEIGHT; + streamInfo.width_ = width; + streamInfo.height_ = height; + producer = streamCustomer->CreateProducer(CAPTURE_PREVIEW, nullptr); + } else if (intent == OHOS::HDI::Camera::V1_0::STILL_CAPTURE) { + constexpr uint32_t width = CAMERA_CAPTURE_WIDTH; + constexpr uint32_t height = CAMERA_CAPTURE_HEIGHT; + streamInfo.width_ = width; + streamInfo.height_ = height; + streamInfo.encodeType_ = CAMERA_CAPTURE_ENCODE_TYPE; + producer = streamCustomer->CreateProducer(CAPTURE_SNAPSHOT, [this](void* addr, const uint32_t size) { + StoreImage((char*)addr, size); + }); + } else { + constexpr uint32_t width = CAMERA_VIDEO_WIDTH; + constexpr uint32_t height = CAMERA_VIDEO_HEIGHT; + streamInfo.width_ = width; + streamInfo.height_ = height; + streamInfo.encodeType_ = CAMERA_VIDEO_ENCODE_TYPE; + OpenVideoFile(); + producer = streamCustomer->CreateProducer(CAPTURE_VIDEO, [this](void* addr, const uint32_t size) { + StoreVideo((char*)addr, size); + }); + } + + streamInfo.streamId_ = streamId; + streamInfo.format_ = CAMERA_FORMAT; + streamInfo.dataspace_ = dataspace; + streamInfo.intent_ = intent; + streamInfo.tunneledMode_ = tunneledMode; + + streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer); + streamInfo.bufferQueue_->producer_->SetQueueSize(8); // 8:set bufferQueue size +} + +void DcameraHdfDemo::GetStreamOpt() +{ + int rc = 0; + + if (streamOperator_ == nullptr) { + const sptr streamOperatorCallback = new DemoStreamOperatorCallback(); + rc = demoCameraDevice_->GetStreamOperator(streamOperatorCallback, streamOperator_); + if (rc != HDI::Camera::V1_0::NO_ERROR) { + DHLOGE("demo test: GetStreamOpt GetStreamOperator fail"); + streamOperator_ = nullptr; + } + } +} + +void DcameraHdfDemo::CaptureSet(std::vector &setNum) +{ + constexpr double latitude = 27.987500; // dummy data: Qomolangma latitde + constexpr double longitude = 86.927500; // dummy data: Qomolangma longituude + constexpr double altitude = 8848.86; // dummy data: Qomolangma altitude + constexpr size_t entryCapacity = 100; + constexpr size_t dataCapacity = 2000; + captureSetting_ = std::make_shared(entryCapacity, dataCapacity); + captureQuality_ = OHOS_CAMERA_JPEG_LEVEL_HIGH; + captureOrientation_ = OHOS_CAMERA_JPEG_ROTATION_270; + mirrorSwitch_ = OHOS_CAMERA_MIRROR_ON; + gps_.push_back(latitude); + gps_.push_back(longitude); + gps_.push_back(altitude); + captureSetting_->addEntry(OHOS_JPEG_QUALITY, static_cast(&captureQuality_), + sizeof(captureQuality_)); + captureSetting_->addEntry(OHOS_JPEG_ORIENTATION, static_cast(&captureOrientation_), + sizeof(captureOrientation_)); + captureSetting_->addEntry(OHOS_CONTROL_CAPTURE_MIRROR, static_cast(&mirrorSwitch_), + sizeof(mirrorSwitch_)); + captureSetting_->addEntry(OHOS_JPEG_GPS_COORDINATES, gps_.data(), gps_.size()); + + OHOS::Camera::MetadataUtils::ConvertMetadataToVec(captureSetting_, setNum); +} + +RetCode DcameraHdfDemo::CaptureON(const int streamId, const int captureId, CaptureMode mode) +{ + DHLOGI("demo test: CaptureON enter streamId == %d and captureId == %d and mode == %d", + streamId, captureId, mode); + std::lock_guard l(metaDatalock_); + std::vector setting; + bool iscapture = true; + + if (mode == CAPTURE_SNAPSHOT) { + CaptureSet(setting); + } else { + OHOS::Camera::MetadataUtils::ConvertMetadataToVec(captureSetting_, setting); + } + + captureInfo_.streamIds_ = {streamId}; + if (mode == CAPTURE_SNAPSHOT) { + captureInfo_.captureSetting_ = setting; + iscapture = false; + } else { + captureInfo_.captureSetting_ = cameraAbility_; + iscapture = true; + } + captureInfo_.enableShutterCallback_ = false; + int rc = streamOperator_->Capture(captureId, captureInfo_, iscapture); + if (rc != HDI::Camera::V1_0::NO_ERROR) { + DHLOGE("demo test: CaptureStart Capture error"); + streamOperator_->ReleaseStreams(captureInfo_.streamIds_); + return RC_ERROR; + } + + DHLOGI("demo test: CaptureON exit"); + return RC_OK; +} + +RetCode DcameraHdfDemo::CaptureOff(const int captureId, const CaptureMode mode) +{ + int rc = 0; + DHLOGI("demo test: CaptureOff enter mode == %d", mode); + + if (streamOperator_ == nullptr) { + DHLOGE("demo test: CaptureOff streamOperator_ is nullptr"); + return RC_ERROR; + } + + if (mode == CAPTURE_PREVIEW) { + rc = streamOperator_->CancelCapture(captureId); + } else if (mode == CAPTURE_SNAPSHOT) { + rc = streamOperator_->CancelCapture(captureId); + } else if (mode == CAPTURE_VIDEO) { + rc = streamOperator_->CancelCapture(captureId); + close(videoFd_); + videoFd_ = -1; + } + + if (rc != HDI::Camera::V1_0::NO_ERROR) { + DHLOGE("demo test: CaptureOff CancelCapture error mode %d rc == %d", mode, rc); + return RC_ERROR; + } + DHLOGI("demo test: CaptureOff exit"); + return RC_OK; +} + +RetCode DcameraHdfDemo::CreateStreamInfo(const int streamId, std::shared_ptr &streamCustomer, + StreamIntent intent) +{ + DHLOGI("demo test: CreateStream enter"); + GetStreamOpt(); + if (streamOperator_ == nullptr) { + DHLOGE("demo test: CreateStream GetStreamOpt() is nullptr"); + return RC_ERROR; + } + + StreamInfo streamInfo = {0}; + SetStreamInfo(streamInfo, streamCustomer, streamId, intent); + if (streamInfo.bufferQueue_->producer_ == nullptr) { + DHLOGE("demo test: CreateStream CreateProducer(); is nullptr"); + return RC_ERROR; + } + streamInfos_.push_back(streamInfo); + streamIds_.push_back(streamId); + return RC_OK; +} + +RetCode DcameraHdfDemo::CreateStream() +{ + int rc = 0; + DHLOGI("demo test: CreateStreams start"); + rc = streamOperator_->CreateStreams(streamInfos_); + if (rc != HDI::Camera::V1_0::NO_ERROR) { + DHLOGE("demo test: CreateStream CreateStreams error"); + return RC_ERROR; + } + DHLOGI("demo test: CommitStreams start"); + rc = streamOperator_->CommitStreams(NORMAL, cameraAbility_); + if (rc != HDI::Camera::V1_0::NO_ERROR) { + DHLOGE("demo test: CreateStream CommitStreams error"); + streamOperator_->ReleaseStreams(streamIds_); + return RC_ERROR; + } + + DHLOGI("demo test: CreateStream exit"); + return RC_OK; +} + +RetCode DcameraHdfDemo::InitCameraDevice() +{ + int rc = 0; + DHLOGI("demo test: InitCameraDevice enter"); + + if (demoCameraHost_ == nullptr) { + DHLOGE("demo test: InitCameraDevice demoCameraHost_ == nullptr"); + return RC_ERROR; + } + + (void)demoCameraHost_->GetCameraIds(cameraIds_); + if (cameraIds_.empty()) { + return RC_ERROR; + } + + const std::string cameraId = cameraIds_.front(); + demoCameraHost_->GetCameraAbility(cameraId, cameraAbility_); + OHOS::Camera::MetadataUtils::ConvertVecToMetadata(cameraAbility_, ability_); + + GetFaceDetectMode(ability_); + GetFocalLength(ability_); + GetAvailableFocusModes(ability_); + GetAvailableExposureModes(ability_); + GetExposureCompensationRange(ability_); + GetExposureCompensationSteps(ability_); + GetAvailableMeterModes(ability_); + GetAvailableFlashModes(ability_); + GetMirrorSupported(ability_); + GetStreamBasicConfigurations(ability_); + GetFpsRange(ability_); + GetCameraPosition(ability_); + GetCameraType(ability_); + GetCameraConnectionType(ability_); + GetFaceDetectMaxNum(ability_); + + sptr callback = new DemoCameraDeviceCallback(); + rc = demoCameraHost_->OpenCamera(cameraIds_.front(), callback, demoCameraDevice_); + if (rc != HDI::Camera::V1_0::NO_ERROR || demoCameraDevice_ == nullptr) { + DHLOGE("demo test: InitCameraDevice OpenCamera failed"); + return RC_ERROR; + } + + DHLOGI("demo test: InitCameraDevice exit"); + return RC_OK; +} + +void DcameraHdfDemo::ReleaseCameraDevice() +{ + if (demoCameraDevice_ != nullptr) { + DHLOGI("demo test: ReleaseCameraDevice close Device"); + demoCameraDevice_->Close(); + demoCameraDevice_ = nullptr; + } +} + +RetCode DcameraHdfDemo::InitSensors() +{ + int rc = 0; + DHLOGI("demo test: InitSensors enter"); + + if (demoCameraHost_ != nullptr) { + return RC_OK; + } + + constexpr const char *demoServiceName = "distributed_camera_service"; + demoCameraHost_ = ICameraHost::Get(demoServiceName, false); + if (demoCameraHost_ == nullptr) { + DHLOGE("demo test: ICameraHost::Get error"); + return RC_ERROR; + } + + hostCallback_ = new DemoCameraHostCallback(); + rc = demoCameraHost_->SetCallback(hostCallback_); + if (rc != HDI::Camera::V1_0::NO_ERROR) { + DHLOGE("demo test: demoCameraHost_->SetCallback(hostCallback_) error"); + return RC_ERROR; + } + + DHLOGI("demo test: InitSensors exit"); + return RC_OK; +} + +void DcameraHdfDemo::StoreImage(const char *bufStart, const uint32_t size) const +{ + DHLOGI("demo test:StoreImage buf_start == %p size == %d", bufStart, size); + constexpr uint32_t pathLen = 64; + char path[pathLen] = {0}; + char prefix[] = "/data/"; + + int imgFD = 0; + int ret; + struct timeval start = {}; + gettimeofday(&start, nullptr); + if (sprintf_s(path, sizeof(path), "%spicture_%ld.jpeg", prefix, start.tv_usec) < 0) { + DHLOGE("sprintf_s error ....."); + return; + } + + imgFD = open(path, O_RDWR | O_CREAT, 00766); // 00766:file operate permission + if (imgFD == -1) { + DHLOGE("demo test:open image file error %s.....", strerror(errno)); + return; + } + + ret = write(imgFD, bufStart, size); + if (ret == -1) { + DHLOGE("demo test:write image file error %s.....", strerror(errno)); + } + + close(imgFD); + DHLOGI("demo test:StoreImage save success"); +} + +void DcameraHdfDemo::StoreVideo(const char *bufStart, const uint32_t size) const +{ + int ret = 0; + + ret = write(videoFd_, bufStart, size); + if (ret == -1) { + DHLOGE("demo test:write video file error %s.....", strerror(errno)); + } + DHLOGI("demo test:StoreVideo buf_start == %p size == %d", bufStart, size); +} + +void DcameraHdfDemo::OpenVideoFile() +{ + constexpr uint32_t pathLen = 64; + char path[pathLen] = {0}; + char prefix[] = "/data/"; + auto seconds = time(nullptr); + if (sprintf_s(path, sizeof(path), "%svideo%ld.h264", prefix, seconds) < 0) { + DHLOGE("%s: sprintf failed", __func__); + return; + } + videoFd_ = open(path, O_RDWR | O_CREAT, 00766); // 00766:file operate permission + if (videoFd_ < 0) { + DHLOGE("demo test: StartVideo open %s %s failed", path, strerror(errno)); + } +} + +RetCode DcameraHdfDemo::CreateStreams(const int streamIdSecond, StreamIntent intent) +{ + int rc = 0; + std::vector streamInfos; + std::vector().swap(streamInfos); + + DHLOGI("demo test: CreateStreams streamIdSecond = %d", streamIdSecond); + GetStreamOpt(); + if (streamOperator_ == nullptr) { + DHLOGE("demo test: CreateStreams GetStreamOpt() is nullptr"); + return RC_ERROR; + } + + StreamInfo previewStreamInfo = {0}; + SetStreamInfo(previewStreamInfo, streamCustomerPreview_, STREAM_ID_PREVIEW, OHOS::HDI::Camera::V1_0::PREVIEW); + if (previewStreamInfo.bufferQueue_->producer_ == nullptr) { + DHLOGE("demo test: CreateStream CreateProducer(); is nullptr"); + return RC_ERROR; + } + streamInfos.push_back(previewStreamInfo); + + StreamInfo secondStreamInfo = {0}; + if (streamIdSecond == STREAM_ID_CAPTURE) { + SetStreamInfo(secondStreamInfo, streamCustomerCapture_, STREAM_ID_CAPTURE, intent); + } else { + SetStreamInfo(secondStreamInfo, streamCustomerVideo_, STREAM_ID_VIDEO, intent); + } + + if (secondStreamInfo.bufferQueue_->producer_ == nullptr) { + DHLOGE("demo test: CreateStreams CreateProducer() secondStreamInfo is nullptr"); + return RC_ERROR; + } + streamInfos.push_back(secondStreamInfo); + + rc = streamOperator_->CreateStreams(streamInfos); + if (rc != HDI::Camera::V1_0::NO_ERROR) { + DHLOGE("demo test: CreateStream CreateStreams error"); + return RC_ERROR; + } + + rc = streamOperator_->CommitStreams(NORMAL, cameraAbility_); + if (rc != HDI::Camera::V1_0::NO_ERROR) { + DHLOGE("demo test: CreateStream CommitStreams error"); + std::vector streamIds = {STREAM_ID_PREVIEW, streamIdSecond}; + streamOperator_->ReleaseStreams(streamIds); + return RC_ERROR; + } + return RC_OK; +} + +RetCode DcameraHdfDemo::CaptureOnDualStreams(const int streamIdSecond) +{ + int rc = 0; + DHLOGI("demo test: CaptuCaptureOnDualStreamsreON enter"); + + CaptureInfo previewCaptureInfo; + previewCaptureInfo.streamIds_ = {STREAM_ID_PREVIEW}; + previewCaptureInfo.captureSetting_ = cameraAbility_; + previewCaptureInfo.enableShutterCallback_ = false; + + rc = streamOperator_->Capture(CAPTURE_ID_PREVIEW, previewCaptureInfo, true); + if (rc != HDI::Camera::V1_0::NO_ERROR) { + DHLOGE("demo test: CaptureOnDualStreams preview Capture error"); + streamOperator_->ReleaseStreams(previewCaptureInfo.streamIds_); + return RC_ERROR; + } + + CaptureInfo secondCaptureInfo; + secondCaptureInfo.streamIds_ = {streamIdSecond}; + secondCaptureInfo.captureSetting_ = cameraAbility_; + previewCaptureInfo.enableShutterCallback_ = false; + + if (streamIdSecond == STREAM_ID_CAPTURE) { + rc = streamOperator_->Capture(CAPTURE_ID_CAPTURE, secondCaptureInfo, true); + if (rc != HDI::Camera::V1_0::NO_ERROR) { + DHLOGE("demo test: CaptureOnDualStreams CAPTURE_ID_CAPTURE error"); + streamOperator_->ReleaseStreams(secondCaptureInfo.streamIds_); + return RC_ERROR; + } + } else { + rc = streamOperator_->Capture(CAPTURE_ID_VIDEO, secondCaptureInfo, true); + if (rc != HDI::Camera::V1_0::NO_ERROR) { + DHLOGE("demo test: CaptureOnDualStreams CAPTURE_ID_VIDEO error"); + streamOperator_->ReleaseStreams(secondCaptureInfo.streamIds_); + return RC_ERROR; + } + } + + DHLOGI("demo test: CaptuCaptureOnDualStreamsreON exit"); + return RC_OK; +} + +RetCode DcameraHdfDemo::StartDualStreams(const int streamIdSecond) +{ + RetCode rc = RC_OK; + DHLOGI("demo test: StartDualStreams enter"); + + if (streamCustomerPreview_ == nullptr) { + streamCustomerPreview_ = std::make_shared(); + } + if (isPreviewOn_ != 0) { + return RC_OK; + } + isPreviewOn_ = 1; + if (streamIdSecond == STREAM_ID_CAPTURE) { + if (streamCustomerCapture_ == nullptr) { + streamCustomerCapture_ = std::make_shared(); + } + + if (isCaptureOn_ == 0) { + isCaptureOn_ = 1; + rc = CreateStreams(streamIdSecond, OHOS::HDI::Camera::V1_0::STILL_CAPTURE); + if (rc != RC_OK) { + DHLOGE("demo test:StartPreviewStream CreateStreams error"); + return RC_ERROR; + } + } + } else { + if (streamCustomerVideo_ == nullptr) { + streamCustomerVideo_ = std::make_shared(); + } + + if (isVideoOn_ == 0) { + isVideoOn_ = 1; + rc = CreateStreams(streamIdSecond, OHOS::HDI::Camera::V1_0::VIDEO); + if (rc != RC_OK) { + DHLOGE("demo test:StartPreviewStream CreateStreams error"); + return RC_ERROR; + } + } + } + + DHLOGI("demo test: StartDualStreams exit"); + return RC_OK; +} + +RetCode DcameraHdfDemo::StartCaptureStream() +{ + RetCode rc = RC_OK; + + DHLOGI("demo test: StartCaptureStream enter"); + if (streamCustomerCapture_ == nullptr) { + streamCustomerCapture_ = std::make_shared(); + } + + if (isCaptureOn_ == 0) { + isCaptureOn_ = 1; + + rc = CreateStreamInfo(STREAM_ID_CAPTURE, streamCustomerCapture_, OHOS::HDI::Camera::V1_0::STILL_CAPTURE); + if (rc != RC_OK) { + DHLOGE("demo test:StartCaptureStream CreateStream error"); + return RC_ERROR; + } + } + + DHLOGI("demo test: StartCaptureStream exit"); + return RC_OK; +} + +RetCode DcameraHdfDemo::StartVideoStream() +{ + RetCode rc = RC_OK; + DHLOGI("demo test: StartVideoStream enter"); + if (streamCustomerVideo_ == nullptr) { + streamCustomerVideo_ = std::make_shared(); + } + + if (isVideoOn_ == 0) { + isVideoOn_ = 1; + + rc = CreateStreamInfo(STREAM_ID_VIDEO, streamCustomerVideo_, OHOS::HDI::Camera::V1_0::VIDEO); + if (rc != RC_OK) { + DHLOGE("demo test:StartVideoStream CreateStream error"); + return RC_ERROR; + } + } + + DHLOGI("demo test: StartVideoStream exit"); + return RC_OK; +} + +RetCode DcameraHdfDemo::StartPreviewStream() +{ + RetCode rc = RC_OK; + DHLOGI("demo test: StartPreviewStream enter"); + + if (streamCustomerPreview_ == nullptr) { + streamCustomerPreview_ = std::make_shared(); + } + + if (isPreviewOn_ == 0) { + isPreviewOn_ = 1; + + rc = CreateStreamInfo(STREAM_ID_PREVIEW, streamCustomerPreview_, OHOS::HDI::Camera::V1_0::PREVIEW); + if (rc != RC_OK) { + DHLOGE("demo test:StartPreviewStream CreateStream error"); + return RC_ERROR; + } + } + + DHLOGI("demo test: StartPreviewStream exit"); + return RC_OK; +} + +RetCode DcameraHdfDemo::ReleaseAllStream() +{ + std::vector streamIds = {}; + DHLOGI("demo test: ReleaseAllStream enter"); + + if (isPreviewOn_ != 1) { + DHLOGE("demo test: ReleaseAllStream preview is not running"); + return RC_ERROR; + } + + if (isCaptureOn_ == 1) { + DHLOGI("demo test: ReleaseAllStream STREAM_ID_PREVIEW STREAM_ID_CAPTURE"); + streamIds = {STREAM_ID_PREVIEW, STREAM_ID_CAPTURE}; + streamOperator_->ReleaseStreams(streamIds); + } else { + DHLOGI("demo test: ReleaseAllStream STREAM_ID_PREVIEW STREAM_ID_VIDEO"); + streamIds = {STREAM_ID_PREVIEW, STREAM_ID_VIDEO}; + streamOperator_->ReleaseStreams(streamIds); + } + + streamInfos_.clear(); + streamIds_.clear(); + + isPreviewOn_ = 0; + isCaptureOn_ = 0; + isVideoOn_ = 0; + + DHLOGI("demo test: ReleaseAllStream exit"); + return RC_OK; +} + +void DcameraHdfDemo::QuitDemo() +{ + ReleaseCameraDevice(); + DHLOGI("demo test: QuitDemo done"); +} + +void DcameraHdfDemo::SetEnableResult() +{ + DHLOGI("demo test: SetEnableResult enter"); + + results_list_.push_back(OHOS_CONTROL_EXPOSURE_MODE); + results_list_.push_back(OHOS_CONTROL_FOCUS_MODE); + demoCameraDevice_->EnableResult(results_list_); + + DHLOGI("demo test: SetEnableResult exit"); +} + +RetCode DcameraHdfDemo::SetAwbMode(const int mode) const +{ + DHLOGI("demo test: SetAwbMode enter"); + + if (mode < 0 || mode > OHOS_CAMERA_AWB_MODE_INCANDESCENT) { + DHLOGI("demo test: SetAwbMode mode error"); + return RC_ERROR; + } + + constexpr size_t entryCapacity = 100; + constexpr size_t dataCapacity = 2000; + + std::shared_ptr metaData = std::make_shared(entryCapacity, dataCapacity); + std::vector result; + + const uint8_t awbMode = mode; + metaData->addEntry(OHOS_CONTROL_AWB_MODE, &awbMode, 1); + OHOS::Camera::MetadataUtils::ConvertMetadataToVec(metaData, result); + if (demoCameraDevice_ != nullptr) { + demoCameraDevice_->UpdateSettings(result); + } + + DHLOGI("demo test: SetAwbMode exit"); + return RC_OK; +} + +RetCode DcameraHdfDemo::SetAeExpo() +{ + int32_t expo; + DHLOGI("demo test: SetAeExpo enter"); + + constexpr size_t entryCapacity = 100; + constexpr size_t dataCapacity = 2000; + + std::shared_ptr metaData = std::make_shared(entryCapacity, dataCapacity); + std::vector result; + + if (aeStatus_) { + expo = 0xa0; + } else { + expo = 0x30; + } + aeStatus_ = !aeStatus_; + metaData->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1); + OHOS::Camera::MetadataUtils::ConvertMetadataToVec(metaData, result); + if (demoCameraDevice_ != nullptr) { + demoCameraDevice_->UpdateSettings(result); + } + + DHLOGI("demo test: SetAeExpo exit"); + return RC_OK; +} + +RetCode DcameraHdfDemo::SetMetadata() +{ + DHLOGI("demo test: SetMetadata enter"); + constexpr size_t entryCapacity = 100; + constexpr size_t dataCapacity = 2000; + std::shared_ptr metaData = std::make_shared(entryCapacity, dataCapacity); + + // awb + SetAwbMode(OHOS_CAMERA_AWB_MODE_INCANDESCENT); + + // ae + uint8_t aeMode = OHOS_CAMERA_EXPOSURE_MODE_CONTINUOUS_AUTO; + metaData->addEntry(OHOS_CONTROL_EXPOSURE_MODE, &aeMode, sizeof(aeMode)); + + int64_t exposureTime = 400; + metaData->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &exposureTime, sizeof(exposureTime)); + + int32_t aeExposureCompensation = 4; + metaData->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &aeExposureCompensation, sizeof(aeExposureCompensation)); + + // meter + std::vector meterPoint; + meterPoint.push_back(METER_POINT_X); + meterPoint.push_back(METER_POINT_Y); + metaData->addEntry(OHOS_CONTROL_METER_POINT, meterPoint.data(), meterPoint.size()); + + uint8_t meterMode = OHOS_CAMERA_OVERALL_METERING; + metaData->addEntry(OHOS_CONTROL_METER_MODE, &meterMode, sizeof(meterMode)); + + // flash + uint8_t flashMode = OHOS_CAMERA_FLASH_MODE_ALWAYS_OPEN; + metaData->addEntry(OHOS_CONTROL_FLASH_MODE, &flashMode, sizeof(flashMode)); + + // mirror + uint8_t mirror = OHOS_CAMERA_MIRROR_ON; + metaData->addEntry(OHOS_CONTROL_CAPTURE_MIRROR, &mirror, sizeof(mirror)); + + // fps + std::vector fpsRange; + fpsRange.push_back(FPS_RANGE); + fpsRange.push_back(FPS_RANGE); + metaData->addEntry(OHOS_CONTROL_FPS_RANGES, fpsRange.data(), fpsRange.size()); + + // jpeg + int32_t orientation = OHOS_CAMERA_JPEG_ROTATION_180; + metaData->addEntry(OHOS_JPEG_ORIENTATION, &orientation, sizeof(orientation)); + + uint8_t quality = OHOS_CAMERA_JPEG_LEVEL_HIGH; + metaData->addEntry(OHOS_JPEG_QUALITY, &quality, sizeof(quality)); + + // af + uint8_t afMode = OHOS_CAMERA_FOCUS_MODE_AUTO; + metaData->addEntry(OHOS_CONTROL_FOCUS_MODE, &afMode, sizeof(afMode)); + + std::vector afRegions; + afRegions.push_back(AF_REGIONS_X); + afRegions.push_back(AF_REGIONS_Y); + metaData->addEntry(OHOS_CONTROL_AF_REGIONS, afRegions.data(), afRegions.size()); + + // face + uint8_t faceMode = OHOS_CAMERA_FACE_DETECT_MODE_SIMPLE; + metaData->addEntry(OHOS_STATISTICS_FACE_DETECT_SWITCH, &faceMode, sizeof(faceMode)); + + std::vector result; + OHOS::Camera::MetadataUtils::ConvertMetadataToVec(metaData, result); + if (demoCameraDevice_ != nullptr) { + demoCameraDevice_->UpdateSettings(result); + } + + DHLOGI("demo test: SetMetadata exit"); + return RC_OK; +} + +void DcameraHdfDemo::FlashlightOnOff(bool onOff) +{ + DHLOGI("demo test: FlashlightOnOff enter"); + + if (demoCameraHost_ == nullptr) { + DHLOGE("demo test: FlashlightOnOff demoCameraHost_ == nullptr"); + return; + } + + demoCameraHost_->SetFlashlight(cameraIds_.front(), onOff); + + DHLOGI("demo test: FlashlightOnOff exit "); +} + +RetCode DcameraHdfDemo::StreamOffline(const int streamId) +{ + int rc = 0; + constexpr size_t offlineDelayTime = 4; + DHLOGI("demo test: StreamOffline enter"); + sptr streamOperatorCallback = new DemoStreamOperatorCallback(); + sptr offlineStreamOperator = nullptr; + std::vector streamIds; + streamIds.push_back(streamId); + rc = streamOperator_->ChangeToOfflineStream(streamIds, streamOperatorCallback, offlineStreamOperator); + if (rc != CamRetCode::METHOD_NOT_SUPPORTED) { + DHLOGE("demo test: StreamOffline ChangeToOfflineStream error"); + return RC_ERROR; + } + + CaptureOff(CAPTURE_ID_PREVIEW, CAPTURE_PREVIEW); + CaptureOff(CAPTURE_ID_CAPTURE, CAPTURE_SNAPSHOT); + sleep(1); + ReleaseAllStream(); + ReleaseCameraDevice(); + sleep(offlineDelayTime); + + DHLOGI("demo test: begin to release offlne stream"); + if (offlineStreamOperator != nullptr) { + rc = offlineStreamOperator->CancelCapture(CAPTURE_ID_CAPTURE); + if (rc != CamRetCode::METHOD_NOT_SUPPORTED) { + DHLOGE("demo test: StreamOffline offlineStreamOperator->CancelCapture error"); + return RC_ERROR; + } + + rc = offlineStreamOperator->Release(); + if (rc != CamRetCode::METHOD_NOT_SUPPORTED) { + DHLOGE("demo test: StreamOffline offlineStreamOperator->Release() error"); + return RC_ERROR; + } + } + + DHLOGI("demo test: StreamOffline exit"); + return RC_OK; +} + +RetCode DcameraHdfDemo::GetFaceDetectMode(std::shared_ptr &ability) +{ + common_metadata_header_t* data = ability->get(); + uint8_t faceDetectMode; + camera_metadata_item_t entry; + int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_STATISTICS_FACE_DETECT_MODE, &entry); + if (ret != 0) { + DHLOGE("demo test: get OHOS_STATISTICS_FACE_DETECT_MODE error"); + return RC_ERROR; + } + faceDetectMode = *(entry.data.u8); + DHLOGI("demo test: faceDetectMode %d", faceDetectMode); + return RC_OK; +} + +RetCode DcameraHdfDemo::GetFocalLength(std::shared_ptr &ability) +{ + common_metadata_header_t* data = ability->get(); + float focalLength = 0.0; + camera_metadata_item_t entry; + int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_FOCAL_LENGTH, &entry); + if (ret != 0) { + DHLOGE("demo test: get OHOS_ABILITY_FOCAL_LENGTH error"); + return RC_ERROR; + } + focalLength = *(entry.data.f); + DHLOGI("demo test: focalLength %{public}f", focalLength); + return RC_OK; +} + +RetCode DcameraHdfDemo::GetAvailableFocusModes(std::shared_ptr &ability) +{ + common_metadata_header_t* data = ability->get(); + std::vector focusMode; + camera_metadata_item_t entry; + int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_FOCUS_MODES, &entry); + if (ret != 0) { + DHLOGE("demo test: get OHOS_ABILITY_FOCUS_MODES error"); + return RC_ERROR; + } + uint32_t count = entry.count; + DHLOGI("demo test: count %d", count); + + for (uint32_t i = 0 ; i < count; i++) { + focusMode.push_back(*(entry.data.u8 + i)); + } + + for (auto it = focusMode.begin(); it != focusMode.end(); it++) { + DHLOGI("demo test: focusMode : %d ", *it); + } + return RC_OK; +} + +RetCode DcameraHdfDemo::GetAvailableExposureModes(std::shared_ptr &ability) +{ + common_metadata_header_t* data = ability->get(); + std::vector exposureMode; + camera_metadata_item_t entry; + int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_EXPOSURE_MODES, &entry); + if (ret != 0) { + DHLOGE("demo test: get OHOS_ABILITY_EXPOSURE_MODES error"); + return RC_ERROR; + } + uint32_t count = entry.count; + DHLOGI("demo test: count %d", count); + + for (uint32_t i = 0 ; i < count; i++) { + exposureMode.push_back(*(entry.data.u8 + i)); + } + + for (auto it = exposureMode.begin(); it != exposureMode.end(); it++) { + DHLOGI("demo test: exposureMode : %d ", *it); + } + return RC_OK; +} + +RetCode DcameraHdfDemo::GetExposureCompensationRange(std::shared_ptr &ability) +{ + common_metadata_header_t* data = ability->get(); + std::vector exposureCompensationRange; + camera_metadata_item_t entry; + int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_CONTROL_AE_COMPENSATION_RANGE, &entry); + if (ret != 0) { + DHLOGE("demo test: get OHOS_CONTROL_AE_COMPENSATION_RANGE error"); + return RC_ERROR; + } + + uint32_t count = entry.count; + DHLOGI("demo test: exposureCompensationRange count %d", count); + for (uint32_t i = 0 ; i < count; i++) { + exposureCompensationRange.push_back(*(entry.data.i32 + i)); + } + + for (auto it = exposureCompensationRange.begin(); it != exposureCompensationRange.end(); it++) { + DHLOGI("demo test: exposureCompensationRange %d ", *it); + } + + return RC_OK; +} + +RetCode DcameraHdfDemo::GetExposureCompensationSteps(std::shared_ptr &ability) +{ + common_metadata_header_t* data = ability->get(); + camera_rational_t exposureCompensationSteps; + camera_metadata_item_t entry; + int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_CONTROL_AE_COMPENSATION_STEP, &entry); + if (ret != 0) { + DHLOGE("demo test: get OHOS_CONTROL_AE_COMPENSATION_STEP error"); + return RC_ERROR; + } + exposureCompensationSteps.numerator = entry.data.r->numerator; + exposureCompensationSteps.denominator = entry.data.r->denominator; + DHLOGI("demo test: steps.numerator %d and steps.denominator %d ", + exposureCompensationSteps.numerator, exposureCompensationSteps.denominator); + return RC_OK; +} + +RetCode DcameraHdfDemo::GetAvailableMeterModes(std::shared_ptr &ability) +{ + common_metadata_header_t* data = ability->get(); + std::vector meterModes; + camera_metadata_item_t entry; + int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_METER_MODES, &entry); + if (ret != 0) { + DHLOGE("demo test: get OHOS_ABILITY_METER_MODES error"); + return RC_ERROR; + } + uint32_t count = entry.count; + DHLOGI("demo test: count %d", count); + + for (uint32_t i = 0 ; i < count; i++) { + meterModes.push_back(*(entry.data.u8 + i)); + } + + for (auto it = meterModes.begin(); it != meterModes.end(); it++) { + DHLOGI("demo test: meterModes : %d ", *it); + } + return RC_OK; +} + +RetCode DcameraHdfDemo::GetAvailableFlashModes(std::shared_ptr &ability) +{ + common_metadata_header_t* data = ability->get(); + std::vector flashModes; + camera_metadata_item_t entry; + int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_FLASH_MODES, &entry); + if (ret != 0) { + DHLOGE("demo test: get OHOS_ABILITY_FLASH_MODES error"); + return RC_ERROR; + } + uint32_t count = entry.count; + DHLOGI("demo test: count %d", count); + + for (uint32_t i = 0 ; i < count; i++) { + flashModes.push_back(*(entry.data.u8 + i)); + } + + for (auto it = flashModes.begin(); it != flashModes.end(); it++) { + DHLOGI("demo test: flashModes : %d ", *it); + } + return RC_OK; +} + +RetCode DcameraHdfDemo::GetMirrorSupported(std::shared_ptr &ability) +{ + common_metadata_header_t* data = ability->get(); + uint8_t mirrorSupported; + camera_metadata_item_t entry; + int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_CONTROL_CAPTURE_MIRROR_SUPPORTED, &entry); + if (ret != 0) { + DHLOGE("demo test: get OHOS_CONTROL_CAPTURE_MIRROR_SUPPORTED error"); + return RC_ERROR; + } + mirrorSupported = *(entry.data.u8); + DHLOGI("demo test: mirrorSupported %d", mirrorSupported); + return RC_OK; +} + +RetCode DcameraHdfDemo::GetStreamBasicConfigurations(std::shared_ptr &ability) +{ + common_metadata_header_t* data = ability->get(); + std::vector streamBasicConfigurations; + camera_metadata_item_t entry; + int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_STREAM_AVAILABLE_BASIC_CONFIGURATIONS, &entry); + if (ret != 0) { + DHLOGE("demo test: get OHOS_ABILITY_STREAM_AVAILABLE_BASIC_CONFIGURATIONS error"); + return RC_ERROR; + } + + uint32_t count = entry.count; + DHLOGI("demo test: streamBasicConfigurations count %d", count); + for (uint32_t i = 0 ; i < count; i++) { + streamBasicConfigurations.push_back(*(entry.data.i32 + i)); + } + + for (auto it = streamBasicConfigurations.begin(); it != streamBasicConfigurations.end(); it++) { + DHLOGI("demo test: streamBasicConfigurations %d ", *it); + } + + return RC_OK; +} + +RetCode DcameraHdfDemo::GetFpsRange(std::shared_ptr &ability) +{ + common_metadata_header_t* data = ability->get(); + std::vector fpsRange; + camera_metadata_item_t entry; + int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_FPS_RANGES, &entry); + if (ret != 0) { + DHLOGE("demo test: get OHOS_ABILITY_FPS_RANGES error"); + return RC_ERROR; + } + + uint32_t count = entry.count; + DHLOGI("demo test: fpsRange count %d", count); + for (uint32_t i = 0 ; i < count; i++) { + fpsRange.push_back(*(entry.data.i32 + i)); + } + + for (auto it = fpsRange.begin(); it != fpsRange.end(); it++) { + DHLOGI("demo test: fpsRange %d ", *it); + } + + return RC_OK; +} + +RetCode DcameraHdfDemo::GetCameraPosition(std::shared_ptr &ability) +{ + common_metadata_header_t* data = ability->get(); + uint8_t cameraPosition; + camera_metadata_item_t entry; + int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_CAMERA_POSITION, &entry); + if (ret != 0) { + DHLOGE("demo test: get OHOS_ABILITY_CAMERA_POSITION error"); + return RC_ERROR; + } + + cameraPosition= *(entry.data.u8); + DHLOGI("demo test: cameraPosition %d", cameraPosition); + return RC_OK; +} + +RetCode DcameraHdfDemo::GetCameraType(std::shared_ptr &ability) +{ + common_metadata_header_t* data = ability->get(); + uint8_t cameraType; + camera_metadata_item_t entry; + int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_CAMERA_TYPE, &entry); + if (ret != 0) { + DHLOGE("demo test: get OHOS_ABILITY_CAMERA_TYPE error"); + return RC_ERROR; + } + + cameraType= *(entry.data.u8); + DHLOGI("demo test: cameraType %d", cameraType); + return RC_OK; +} + +RetCode DcameraHdfDemo::GetCameraConnectionType(std::shared_ptr &ability) +{ + common_metadata_header_t* data = ability->get(); + uint8_t cameraConnectionType; + camera_metadata_item_t entry; + int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_CAMERA_CONNECTION_TYPE, &entry); + if (ret != 0) { + DHLOGE("demo test: get OHOS_ABILITY_CAMERA_CONNECTION_TYPE error"); + return RC_ERROR; + } + + cameraConnectionType= *(entry.data.u8); + DHLOGI("demo test: cameraConnectionType %d", cameraConnectionType); + return RC_OK; +} + +RetCode DcameraHdfDemo::GetFaceDetectMaxNum(std::shared_ptr &ability) +{ + common_metadata_header_t* data = ability->get(); + uint8_t faceDetectMaxNum; + camera_metadata_item_t entry; + int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_STATISTICS_FACE_DETECT_MAX_NUM, &entry); + if (ret != 0) { + DHLOGE("demo test: get OHOS_STATISTICS_FACE_DETECT_MAX_NUM error"); + return RC_ERROR; + } + faceDetectMaxNum = *(entry.data.u8); + DHLOGI("demo test: faceDetectMaxNum %d ", faceDetectMaxNum); + return RC_OK; +} + +int32_t DemoCameraDeviceCallback::OnError(ErrorType type, int32_t errorCode) +{ + DHLOGI("demo test: OnError type : %d, errorCode : %d", type, errorCode); + return RC_OK; +} + +int32_t DemoCameraDeviceCallback::OnResult(uint64_t timestamp, const std::vector& result) +{ + DHLOGI("demo test: OnResult timestamp : %{public}ld,", timestamp); + std::shared_ptr updateSettings; + + OHOS::Camera::MetadataUtils::ConvertVecToMetadata(result, updateSettings); + for (auto it = results_list_.cbegin(); it != results_list_.cend(); it++) { + switch (*it) { + case OHOS_CONTROL_FOCUS_MODE: { + common_metadata_header_t* data = updateSettings->get(); + uint8_t focusMode; + camera_metadata_item_t entry; + int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_CONTROL_FOCUS_MODE, &entry); + if (ret != 0) { + DHLOGE("demo test: get OHOS_CONTROL_FOCUS_MODE error"); + return RC_ERROR; + } + focusMode = *(entry.data.u8); + DHLOGI("demo test: focusMode %d", focusMode); + break; + } + case OHOS_CONTROL_EXPOSURE_MODE: { + common_metadata_header_t* data = updateSettings->get(); + uint8_t exposureMode; + camera_metadata_item_t entry; + int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_CONTROL_EXPOSURE_MODE, &entry); + if (ret != 0) { + DHLOGE("demo test: get OHOS_CONTROL_EXPOSURE_MODE error"); + return RC_ERROR; + } + exposureMode = *(entry.data.u8); + DHLOGI("demo test: exposureMode %d", exposureMode); + break; + } + } + } + + return RC_OK; +} + +int32_t DemoCameraHostCallback::OnCameraStatus(const std::string& cameraId, CameraStatus status) +{ + DHLOGI("%s, enter.", __func__); + return RC_OK; +} + +int32_t DemoCameraHostCallback::OnFlashlightStatus(const std::string& cameraId, FlashlightStatus status) +{ + DHLOGI("%s, enter. cameraId = %s, status = %d", + __func__, cameraId.c_str(), static_cast(status)); + return RC_OK; +} + +int32_t DemoCameraHostCallback::OnCameraEvent(const std::string& cameraId, CameraEvent event) +{ + DHLOGI("%s, enter. cameraId = %s, event = %d", + __func__, cameraId.c_str(), static_cast(event)); + return RC_OK; +} + +int32_t DemoStreamOperatorCallback::OnCaptureStarted(int32_t captureId, const std::vector& streamIds) +{ + DHLOGI("%s, enter.", __func__); + return RC_OK; +} + +int32_t DemoStreamOperatorCallback::OnCaptureEnded(int32_t captureId, const std::vector& infos) +{ + DHLOGI("%s, enter.", __func__); + return RC_OK; +} + +int32_t DemoStreamOperatorCallback::OnCaptureError(int32_t captureId, const std::vector& infos) +{ + DHLOGI("%s, enter.", __func__); + return RC_OK; +} + +int32_t DemoStreamOperatorCallback::OnFrameShutter(int32_t captureId, + const std::vector& streamIds, uint64_t timestamp) +{ + DHLOGI("%s, enter.", __func__); + return RC_OK; +} + +RetCode PreviewOn(int mode, const std::shared_ptr& mainDemo) +{ + RetCode rc = RC_OK; + DHLOGI("main test: PreviewOn enter"); + + if (mode != 0 || mainDemo == nullptr) { + DHLOGE("main test: mainDemo is nullptr or mode is 0"); + return RC_ERROR; + } + + rc = mainDemo->StartPreviewStream(); + if (rc != RC_OK) { + DHLOGE("main test: PreviewOn StartPreviewStream error"); + return RC_ERROR; + } + DHLOGI("main test: StartPreviewStream enter"); + if (mode == 0) { + rc = mainDemo->StartCaptureStream(); + if (rc != RC_OK) { + DHLOGE("main test: PreviewOn StartCaptureStream error"); + return RC_ERROR; + } + DHLOGI("main test: StartCaptureStream enter"); + } else { + rc = mainDemo->StartVideoStream(); + if (rc != RC_OK) { + DHLOGE("main test: PreviewOn StartVideoStream error"); + return RC_ERROR; + } + DHLOGI("main test: StartVideoStream enter"); + } + rc = mainDemo->CreateStream(); + rc = mainDemo->CaptureON(STREAM_ID_PREVIEW, CAPTURE_ID_PREVIEW, CAPTURE_PREVIEW); + if (rc != RC_OK) { + DHLOGE("main test: PreviewOn mainDemo->CaptureON() preview error"); + return RC_ERROR; + } + + DHLOGI("main test: PreviewOn exit"); + return RC_OK; +} + +void PreviewOff(const std::shared_ptr& mainDemo) +{ + DHLOGI("main test: PreviewOff enter"); + + mainDemo->CaptureOff(CAPTURE_ID_PREVIEW, CAPTURE_PREVIEW); + mainDemo->ReleaseAllStream(); + + DHLOGI("main test: PreviewOff exit"); +} + +RetCode FlashLightTest(const std::shared_ptr& mainDemo) +{ + constexpr size_t delayTime = 5; + + if (mainDemo == nullptr) { + DHLOGE("main test: FlashLightTest mainDemo is nullptr"); + return RC_ERROR; + } + + PreviewOff(mainDemo); + mainDemo->ReleaseCameraDevice(); + sleep(1); + mainDemo->FlashlightOnOff(true); + sleep(delayTime); + mainDemo->FlashlightOnOff(false); + mainDemo->InitCameraDevice(); + PreviewOn(0, mainDemo); + return RC_OK; +} + +RetCode OfflineTest(const std::shared_ptr& mainDemo) +{ + RetCode rc = RC_OK; + int32_t dalayTime = 5; + + if (mainDemo == nullptr) { + DHLOGE("main test: OfflineTest mainDemo is nullptr"); + return RC_ERROR; + } + + PreviewOff(mainDemo); + + mainDemo->StartDualStreams(STREAM_ID_CAPTURE); + mainDemo->CaptureOnDualStreams(STREAM_ID_CAPTURE); + sleep(1); + + rc = mainDemo->StreamOffline(STREAM_ID_CAPTURE); + if (rc != RC_OK) { + DHLOGE("main test: mainDemo->StreamOffline error"); + return RC_ERROR; + } + + sleep(dalayTime); + mainDemo->InitCameraDevice(); + rc = PreviewOn(0, mainDemo); + if (rc != RC_OK) { + DHLOGE("main test: PreviewOn() error"); + return RC_ERROR; + } + return RC_OK; +} + +RetCode CaptureTest(const std::shared_ptr& mainDemo) +{ + RetCode rc = RC_OK; + constexpr size_t delayTime = 5; + + if (mainDemo == nullptr) { + DHLOGE("main test: CaptureTest mainDemo is nullptr"); + return RC_ERROR; + } + + rc = mainDemo->CaptureON(STREAM_ID_CAPTURE, CAPTURE_ID_CAPTURE, CAPTURE_SNAPSHOT); + if (rc != RC_OK) { + DHLOGE("main test: mainDemo->CaptureON() capture error"); + return RC_ERROR; + } + + sleep(delayTime); + rc = mainDemo->CaptureOff(CAPTURE_ID_CAPTURE, CAPTURE_SNAPSHOT); + if (rc != RC_OK) { + DHLOGE("main test: mainDemo->CaptureOff() capture error"); + return RC_ERROR; + } + DHLOGI("main test: CaptureON success"); + return RC_OK; +} + +RetCode VideoTest(const std::shared_ptr& mainDemo) +{ + RetCode rc = RC_OK; + constexpr size_t delayTime = 5; + + if (mainDemo == nullptr) { + DHLOGE("main test: VideoTest mainDemo is nullptr"); + return RC_ERROR; + } + + PreviewOff(mainDemo); + mainDemo->StartDualStreams(STREAM_ID_VIDEO); + mainDemo->CaptureOnDualStreams(STREAM_ID_VIDEO); + + sleep(delayTime); + mainDemo->CaptureOff(CAPTURE_ID_PREVIEW, CAPTURE_PREVIEW); + mainDemo->CaptureOff(CAPTURE_ID_VIDEO, CAPTURE_VIDEO); + mainDemo->ReleaseAllStream(); + + rc = PreviewOn(0, mainDemo); + if (rc != RC_OK) { + DHLOGE("main test: video PreviewOn() error please -q exit demo"); + return RC_ERROR; + } + return RC_OK; +} +} +} // namespace OHOS::Camera diff --git a/test/distributedcameratest/dcamera_hdf_demo.h b/test/distributedcameratest/dcamera_hdf_demo.h new file mode 100644 index 0000000000000000000000000000000000000000..3247bb08496d06a53980ea44a79e60acfe29fad5 --- /dev/null +++ b/test/distributedcameratest/dcamera_hdf_demo.h @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2023 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 DISTRIBUTED_DCAMERA_HDF_DEMO_H +#define DISTRIBUTED_DCAMERA_HDF_DEMO_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "constants.h" +#include "camera_metadata_operator.h" +#include "display_type.h" +#include "v1_0/icamera_device.h" +#include "v1_0/icamera_host.h" +#include "v1_0/ioffline_stream_operator.h" +#include "v1_0/istream_operator.h" +#include "v1_0/types.h" +#include "v1_0/istream_operator_callback.h" +#include "metadata_utils.h" +#include "stream_customer.h" +#include "securec.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +using namespace OHOS::Camera; +using namespace OHOS::HDI::Camera::V1_0; +using CameraAbility = OHOS::Camera::CameraMetadata; +using CameraSetting = OHOS::Camera::CameraMetadata; +#define CAMERA_CAPTURE_ENCODE_TYPE OHOS::HDI::Camera::V1_0::ENCODE_TYPE_JPEG +#define CAMERA_VIDEO_ENCODE_TYPE OHOS::HDI::Camera::V1_0::ENCODE_TYPE_H264 + +#ifdef DCAMERA_DRIVER_YUV + #define CAMERA_FORMAT PIXEL_FMT_YCRCB_420_SP +#else + #define CAMERA_FORMAT PIXEL_FMT_RGBA_8888 +#endif + +typedef enum { + STREAM_ID_PREVIEW = 1001, + STREAM_ID_CAPTURE, + STREAM_ID_VIDEO, + CAPTURE_ID_PREVIEW = 2001, + CAPTURE_ID_CAPTURE, + CAPTURE_ID_VIDEO, +} DemoActionID; + +typedef enum { + OHOS_CAMERA_AWB_MODE_OFF, + OHOS_CAMERA_AWB_MODE_AUTO, + OHOS_CAMERA_AWB_MODE_INCANDESCENT, + OHOS_CAMERA_AWB_MODE_FLUORESCENT, + OHOS_CAMERA_AWB_MODE_WARM_FLUORESCENT, + OHOS_CAMERA_AWB_MODE_DAYLIGHT, + OHOS_CAMERA_AWB_MODE_CLOUDY_DAYLIGHT, + OHOS_CAMERA_AWB_MODE_TWILIGHT, + OHOS_CAMERA_AWB_MODE_SHADE, +} CameraAwbMode; + +class DemoCameraHostCallback; +class DcameraHdfDemo { +public: + DcameraHdfDemo(); + ~DcameraHdfDemo(); + + RetCode InitCameraDevice(); + void ReleaseCameraDevice(); + RetCode InitSensors(); + + RetCode StartPreviewStream(); + RetCode StartCaptureStream(); + RetCode StartVideoStream(); + RetCode StartDualStreams(const int streamIdSecond); + RetCode CreateStream(); + RetCode ReleaseAllStream(); + + RetCode CaptureOnDualStreams(const int streamIdSecond); + RetCode CaptureON(const int streamId, const int captureId, CaptureMode mode); + void CaptureSet(std::vector &setNum); + RetCode CaptureOff(const int captureId, const CaptureMode mode); + + RetCode SetAwbMode(const int mode) const; + RetCode SetAeExpo(); + RetCode SetMetadata(); + void SetEnableResult(); + void FlashlightOnOff(bool onOff); + + RetCode StreamOffline(const int streamId); + + void QuitDemo(); + +private: + void SetStreamInfo(StreamInfo& streamInfo, + const std::shared_ptr& streamCustomer, + const int streamId, const StreamIntent intent); + void GetStreamOpt(); + + RetCode CreateStreams(const int streamIdSecond, StreamIntent intent); + + void StoreImage(const char *bufStart, const uint32_t size) const; + void StoreVideo(const char *bufStart, const uint32_t size) const; + void OpenVideoFile(); + + RetCode GetFaceDetectMode(std::shared_ptr &ability); + RetCode GetFocalLength(std::shared_ptr &ability); + RetCode GetAvailableFocusModes(std::shared_ptr &ability); + RetCode GetAvailableExposureModes(std::shared_ptr &ability); + RetCode GetExposureCompensationRange(std::shared_ptr &ability); + RetCode GetExposureCompensationSteps(std::shared_ptr &ability); + RetCode GetAvailableMeterModes(std::shared_ptr &ability); + RetCode GetAvailableFlashModes(std::shared_ptr &ability); + RetCode GetMirrorSupported(std::shared_ptr &ability); + RetCode GetStreamBasicConfigurations(std::shared_ptr &ability); + RetCode GetFpsRange(std::shared_ptr &ability); + RetCode GetCameraPosition(std::shared_ptr &ability); + RetCode GetCameraType(std::shared_ptr &ability); + RetCode GetCameraConnectionType(std::shared_ptr &ability); + RetCode GetFaceDetectMaxNum(std::shared_ptr &ability); + RetCode CreateStreamInfo(const int streamId, std::shared_ptr &streamCustomer, + StreamIntent intent); + + int aeStatus_ = 1; + int videoFd_ = -1; + unsigned int isPreviewOn_ = 0; + unsigned int isCaptureOn_ = 0; + unsigned int isVideoOn_ = 0; + + uint8_t captureQuality_ = 0; + int32_t captureOrientation_ = 0; + uint8_t mirrorSwitch_ = 0; + std::vector gps_; + CaptureInfo captureInfo_; + + std::shared_ptr streamCustomerPreview_ = nullptr; + std::shared_ptr streamCustomerCapture_ = nullptr; + std::shared_ptr streamCustomerVideo_ = nullptr; + std::shared_ptr ability_ = nullptr; + std::shared_ptr captureSetting_ = nullptr; + std::mutex metaDatalock_; + std::vector cameraAbility_; + std::vector streamInfos_; + std::vector streamIds_; + + OHOS::sptr hostCallback_ = nullptr; + OHOS::sptr streamOperator_ = nullptr; + OHOS::sptr demoCameraHost_ = nullptr; + OHOS::sptr demoCameraDevice_ = nullptr; + + std::vector cameraIds_ = {}; + friend class StreamCustomer; +}; + +class DemoCameraDeviceCallback : public ICameraDeviceCallback { +public: + DemoCameraDeviceCallback() = default; + virtual ~DemoCameraDeviceCallback() = default; + int32_t OnError(ErrorType type, int32_t errorCode) override; + int32_t OnResult(uint64_t timestamp, const std::vector& result) override; +}; + +class DemoCameraHostCallback : public ICameraHostCallback { +public: + DemoCameraHostCallback() = default; + virtual ~DemoCameraHostCallback() = default; + +public: + int32_t OnCameraStatus(const std::string& cameraId, CameraStatus status) override; + + int32_t OnFlashlightStatus(const std::string& cameraId, FlashlightStatus status) override; + + int32_t OnCameraEvent(const std::string& cameraId, CameraEvent event) override; +}; + +class DemoStreamOperatorCallback : public IStreamOperatorCallback { +public: + DemoStreamOperatorCallback() = default; + virtual ~DemoStreamOperatorCallback() = default; + +public: + int32_t OnCaptureStarted(int32_t captureId, const std::vector& streamIds) override; + int32_t OnCaptureEnded(int32_t captureId, const std::vector& infos) override; + int32_t OnCaptureError(int32_t captureId, const std::vector& infos) override; + int32_t OnFrameShutter(int32_t captureId, const std::vector& streamIds, uint64_t timestamp) override; +}; +void PreviewOff(const std::shared_ptr& mainDemo); +RetCode PreviewOn(int mode, const std::shared_ptr& mainDemo); +RetCode FlashLightTest(const std::shared_ptr& mainDemo); +RetCode CaptureTest(const std::shared_ptr& mainDemo); +RetCode VideoTest(const std::shared_ptr& mainDemo); +RetCode OfflineTest(const std::shared_ptr& mainDemo); +} +} // namespace OHOS::DistributedHardware +#endif // DISTRIBUTED_DCAMERA_HDF_DEMO_H diff --git a/test/distributedcameratest/stream_customer.cpp b/test/distributedcameratest/stream_customer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d37b0cf02b62c3751f83182e28b4b654b0674f97 --- /dev/null +++ b/test/distributedcameratest/stream_customer.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 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 "stream_customer.h" +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +StreamCustomer::StreamCustomer() {} +StreamCustomer::~StreamCustomer() {} + +sptr StreamCustomer::CreateProducer(CaptureMode mode, + const std::function callback) +{ + consumer_ = OHOS::IConsumerSurface::Create(); + if (consumer_ == nullptr) { + return nullptr; + } + sptr listener = nullptr; + if (mode == CAPTURE_SNAPSHOT) { + listener = new TestBuffersConsumerListener(consumer_, callback); + } else if (mode == CAPTURE_VIDEO) { + listener = new TestBuffersConsumerListener(consumer_, callback); + } + consumer_->RegisterConsumerListener(listener); + + auto producer = consumer_->GetProducer(); + if (producer == nullptr) { + return nullptr; + } + + DHLOGI("demo test, create a buffer queue producer %p", producer.GetRefPtr()); + return producer; +} +} +} \ No newline at end of file diff --git a/test/distributedcameratest/stream_customer.h b/test/distributedcameratest/stream_customer.h new file mode 100644 index 0000000000000000000000000000000000000000..0f1793bfb2be522535bf6e2b3fca08b2a94abe14 --- /dev/null +++ b/test/distributedcameratest/stream_customer.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2023 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 DISTRIBUTED_STREAM_CUSTOMER_H +#define DISTRIBUTED_STREAM_CUSTOMER_H + +#include +#include +#include +#include +#include +#include +#include +#include "constants.h" +#include "distributed_hardware_log.h" +#include "iconsumer_surface.h" +#include "v1_0/ioffline_stream_operator.h" + +namespace OHOS { +namespace DistributedHardware { + +typedef enum { + CAPTURE_PREVIEW = 0, + CAPTURE_SNAPSHOT, + CAPTURE_VIDEO, +} CaptureMode; + +class TestBuffersConsumerListener : public IBufferConsumerListener { +public: + TestBuffersConsumerListener(const sptr& surface, + const std::function callback):callback_(callback), consumer_(surface) + { + } + + ~TestBuffersConsumerListener() + { + } + + void OnBufferAvailable() + { + DHLOGI("demo test:enter OnBufferAvailable start"); + OHOS::Rect damage; + int32_t flushFence = 0; + int64_t timestamp = 0; + + OHOS::sptr buff = nullptr; + consumer_->AcquireBuffer(buff, flushFence, timestamp, damage); + if (buff != nullptr) { + void* addr = buff->GetVirAddr(); + if (callback_ != nullptr) { + int32_t size = buff->GetSize(); + callback_(addr, size); + } + consumer_->ReleaseBuffer(buff, -1); + DHLOGI("demo test:Exiting OnBufferAvailable end"); + } + } +private: + std::function callback_; + sptr consumer_; +}; + +class StreamCustomer { +public: + StreamCustomer(); + ~StreamCustomer(); + sptr CreateProducer(CaptureMode mode, const std::function callback); + +private: + sptr consumer_ = nullptr; +}; +} // namespace OHOS::Camera +} +#endif // DISTRIBUTED_STREAM_CUSTOMER_H