From 8cd7c8358f7a7fa93b090e9034c4aa49af5fa1a6 Mon Sep 17 00:00:00 2001 From: byndyx Date: Fri, 24 Nov 2023 11:27:10 +0800 Subject: [PATCH] add hicollie Signed-off-by: byndyx --- bundle.json | 1 + .../constants/distributed_camera_constants.h | 4 ++ services/cameraservice/sourceservice/BUILD.gn | 1 + .../distributed_camera_source_service.h | 3 ++ .../distributedcameramgr/dcamera_source_dev.h | 4 ++ .../dcamera_source_event.h | 1 + .../distributed_camera_source_service.cpp | 38 +++++++++++++++++++ .../dcamera_source_dev.cpp | 22 +++++++++++ .../common/distributedcamera/BUILD.gn | 1 + ...distributed_camera_source_service_test.cpp | 2 + .../dcamera_source_dev_test.cpp | 16 +++++++- 11 files changed, 92 insertions(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index 158a29ac..4c321285 100644 --- a/bundle.json +++ b/bundle.json @@ -41,6 +41,7 @@ "drivers_peripheral_display", "c_utils", "dsoftbus", + "hicollie", "hisysevent", "hilog", "samgr", diff --git a/common/include/constants/distributed_camera_constants.h b/common/include/constants/distributed_camera_constants.h index 294421a6..8cf94e1a 100644 --- a/common/include/constants/distributed_camera_constants.h +++ b/common/include/constants/distributed_camera_constants.h @@ -116,6 +116,9 @@ const int32_t RESOLUTION_MAX_HEIGHT_CONTINUOUS = 1080; const int32_t RESOLUTION_MIN_WIDTH = 320; const int32_t RESOLUTION_MIN_HEIGHT = 240; const int32_t DUMP_FILE_MAX_SIZE = 295 * 1024 *1024; +const int32_t HICOLLIE_INTERVAL_TIME_MS = 20 * 1000; +const int32_t HICOLLIE_DELAY_TIME_MS = 5 * 1000; +const size_t HICOLLIE_SLEEP_TIME_MS = 5 * 1000; const uint32_t DCAMERA_SHIFT_32 = 32; const uint32_t DCAMERA_SHIFT_24 = 24; @@ -142,6 +145,7 @@ const std::string TO_DISPLAY = "AfterDecodeToDisplay.yuv"; const std::string SINK_PHOTO = "_SinkPhoto.jpg"; const std::string AFTER_ENCODE = "SinkAfterEncode.h265"; const std::string BEFORE_DECODE = "SourceBeforeDecode.h265"; +const std::string CAMERA_HICOLLIE = "CameraHicollie"; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DISTRIBUTED_CAMERA_CONSTANTS_H \ No newline at end of file diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index 9c028629..cc1ee7cb 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -130,6 +130,7 @@ ohos_shared_library("distributed_camera_source") { "graphic_2d:surface", "hdf_core:libhdi", "hdf_core:libpub_utils", + "hicollie:libhicollie", "hitrace:hitrace_meter", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h b/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h index 4b29786b..fc175368 100644 --- a/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h +++ b/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h @@ -54,6 +54,7 @@ public: static std::shared_ptr GetCamDevByIndex(DCameraIndex& index); static void CamDevErase(DCameraIndex& index); static uint32_t GetCamDevNum(); + void StartHicollieThread(); protected: void OnStart() override; @@ -75,6 +76,8 @@ private: static std::map> camerasMap_; static std::mutex camDevMutex_; + std::thread hicollieThread_; + std::atomic isHicollieRunning_ = false; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h index fce546f0..37998994 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h @@ -55,6 +55,9 @@ public: std::string GetVersion(); int32_t OnChannelConnectedEvent(); int32_t OnChannelDisconnectedEvent(); + int32_t PostHicollieEvent(); + void SetHicollieFlag(bool flag); + bool GetHicollieFlag(); public: virtual int32_t Register(std::shared_ptr& param); @@ -89,6 +92,7 @@ private: std::shared_ptr stateMachine_; std::shared_ptr controller_; std::shared_ptr input_; + std::atomic hicollieFlag_ = false; sptr hdiCallback_; std::map memberFuncMap_; diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_event.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_event.h index 725bba07..3a7ed351 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_event.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_event.h @@ -38,6 +38,7 @@ typedef enum { DCAMERA_EVENT_STOP_CAPTURE = 7, DCAMERA_EVENT_UPDATE_SETTINGS = 8, DCAMERA_EVENT_NOFIFY = 9, + DCAMERA_EVENT_HICOLLIE = 10, } DCAMERA_EVENT; class DCameraRegistParam { diff --git a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp index 952e4144..9ca0cde3 100644 --- a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp +++ b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp @@ -21,6 +21,7 @@ #include "iservice_registry.h" #include "string_ex.h" #include "system_ability_definition.h" +#include "xcollie/watchdog.h" #include "anonymous_string.h" #include "dcamera_hdf_operate.h" @@ -72,6 +73,10 @@ bool DistributedCameraSourceService::Init() registerToService_ = true; } listener_ = std::make_shared(); + if (!isHicollieRunning_.load()) { + isHicollieRunning_.store(true); + hicollieThread_ = std::thread(&DistributedCameraSourceService::StartHicollieThread, this); + } DHLOGI("DistributedCameraSourceService init success"); return true; } @@ -83,6 +88,10 @@ void DistributedCameraSourceService::OnStop() registerToService_ = false; listener_ = nullptr; DCameraSourceServiceIpc::GetInstance().UnInit(); + isHicollieRunning_.store(false); + if (hicollieThread_.joinable()) { + hicollieThread_.join(); + } } int32_t DistributedCameraSourceService::InitSource(const std::string& params, @@ -300,5 +309,34 @@ uint32_t DistributedCameraSourceService::GetCamDevNum() std::lock_guard camLock(camDevMutex_); return camerasMap_.size(); } + +void DistributedCameraSourceService::StartHicollieThread() +{ + auto taskFunc = [this]() { + std::lock_guard lock(camDevMutex_); + for (auto &iter : camerasMap_) { + if (iter.second->GetHicollieFlag()) { + iter.second->SetHicollieFlag(false); + } else { + DHLOGE("Hicollie : Flag = false, exit the current process"); + _Exit(0); + } + } + }; + OHOS::HiviewDFX::Watchdog::GetInstance().RunPeriodicalTask(CAMERA_HICOLLIE, taskFunc, + HICOLLIE_INTERVAL_TIME_MS, HICOLLIE_DELAY_TIME_MS); + + while (isHicollieRunning_.load()) { + { + std::lock_guard lock(camDevMutex_); + if (!camerasMap_.empty()) { + for (auto &iter : camerasMap_) { + iter.second->PostHicollieEvent(); + } + } + } + usleep(HICOLLIE_SLEEP_TIME_MS); + } +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp index ba11a523..1b12ec86 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp @@ -208,6 +208,10 @@ void DCameraSourceDev::OnEvent(DCameraSourceEvent& event) { DHLOGI("DCameraSourceDev OnEvent devId %s dhId %s eventType: %d", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), event.GetEventType()); + if (event.GetEventType() == DCAMERA_EVENT_HICOLLIE) { + SetHicollieFlag(true); + return; + } int32_t ret = stateMachine_->Execute(event.GetEventType(), event); if (ret != DCAMERA_OK) { DHLOGE("DCameraSourceDev OnEvent failed, ret: %d, devId: %s dhId: %s", ret, @@ -631,5 +635,23 @@ int32_t DCameraSourceDev::OnChannelDisconnectedEvent() eventBus_->PostEvent(eventNotify); return DCAMERA_OK; } + +int32_t DCameraSourceDev::PostHicollieEvent() +{ + DCameraIndex camIndex(devId_, dhId_); + DCameraSourceEvent event(*this, DCAMERA_EVENT_HICOLLIE, camIndex); + eventBus_->PostEvent(event); + return DCAMERA_OK; +} + +void DCameraSourceDev::SetHicollieFlag(bool flag) +{ + hicollieFlag_.store(flag); +} + +bool DCameraSourceDev::GetHicollieFlag() +{ + return hicollieFlag_.load(); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/BUILD.gn b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/BUILD.gn index f079e282..a274a906 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/BUILD.gn +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/BUILD.gn @@ -80,6 +80,7 @@ ohos_unittest("DCameraSourceTest") { "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0", "dsoftbus:softbus_client", "eventhandler:libeventhandler", + "hicollie:libhicollie", "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_service_test.cpp b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_service_test.cpp index d45a0144..9d55180a 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_service_test.cpp +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_service_test.cpp @@ -26,6 +26,7 @@ #include "distributed_hardware_log.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" +#include "xcollie/watchdog.h" using namespace testing::ext; @@ -154,6 +155,7 @@ HWTEST_F(DistributedCameraSourceServiceTest, dcamera_source_service_test_005, Te int32_t ret = 0; testSrcService_->registerToService_ = true; testSrcService_->Init(); + testSrcService_->OnStop(); EXPECT_EQ(DCAMERA_OK, ret); } diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_dev_test.cpp b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_dev_test.cpp index 447935fc..4b9ee5f8 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_dev_test.cpp +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_dev_test.cpp @@ -637,5 +637,19 @@ HWTEST_F(DCameraSourceDevTest, dcamera_source_dev_test_022, TestSize.Level1) camDev_->NotifyResult(eventType, event, result); EXPECT_EQ(DCAMERA_OK, ret); } + +/** + * @tc.name: SetHicollieFlag_001 + * @tc.desc: Verify source dev SetHicollieFlag. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DCameraSourceDevTest, SetHicollieFlag_001, TestSize.Level1) +{ + camDev_->SetHicollieFlag(true); + EXPECT_EQ(true, camDev_->GetHicollieFlag()); + camDev_->SetHicollieFlag(false); + EXPECT_EQ(false, camDev_->GetHicollieFlag()); } -} \ No newline at end of file +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file -- Gitee