From 6a6ef5e45782140e9f0a43ce58b9ea34d63cd681 Mon Sep 17 00:00:00 2001 From: ry521 Date: Thu, 23 Nov 2023 07:45:12 +0000 Subject: [PATCH 1/8] update bundle.json. Signed-off-by: ry521 --- bundle.json | 1 + 1 file changed, 1 insertion(+) 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", -- Gitee From 93388e2d24b9e9c2e85afd5ab7ea071a1d0f8584 Mon Sep 17 00:00:00 2001 From: ry521 Date: Thu, 23 Nov 2023 07:46:48 +0000 Subject: [PATCH 2/8] . Signed-off-by: ry521 --- .../distributedcamera/distributed_camera_source_service.h | 6 ++++++ 1 file changed, 6 insertions(+) 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..93dcd1cf 100644 --- a/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h +++ b/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h @@ -64,6 +64,7 @@ private: bool Init(); int32_t LoadDCameraHDF(); int32_t UnLoadCameraHDF(); + void ListenCameraDev(); bool registerToService_ = false; DCameraServiceState state_ = DCameraServiceState::DCAMERA_SRV_STATE_NOT_START; @@ -72,9 +73,14 @@ private: std::string sourceVer_; const size_t MAX_CAMERAS_NUMBER = 32; const size_t DUMP_MAX_SIZE = 10 * 1024; + static constexpr const char* LISTEN_THREAD = "sourceListenTh"; + static constexpr int32_t WATCHDOG_INTERVAL_TIME = 20000; + static constexpr int32_t WATCHDOG_DELAY_TIME = 5000; + static constexpr size_t SLEEP_TIME = 5000; static std::map> camerasMap_; static std::mutex camDevMutex_; + std::thread listenThread_; }; } // namespace DistributedHardware } // namespace OHOS -- Gitee From e63275fbd4427568e96c249fa507d500238bc4e0 Mon Sep 17 00:00:00 2001 From: ry521 Date: Thu, 23 Nov 2023 07:48:13 +0000 Subject: [PATCH 3/8] update services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h. Signed-off-by: ry521 --- .../include/distributedcameramgr/dcamera_source_dev.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h index fce546f0..0c1de647 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h @@ -56,6 +56,10 @@ public: int32_t OnChannelConnectedEvent(); int32_t OnChannelDisconnectedEvent(); + int32_t RestoreThreadStatus(); + void SetThreadStatusFlag(); + bool GetThreadStatusFlag(); + public: virtual int32_t Register(std::shared_ptr& param); virtual int32_t UnRegister(std::shared_ptr& param); @@ -78,6 +82,7 @@ private: void NotifyRegisterResult(DCAMERA_EVENT eventType, DCameraSourceEvent& event, int32_t result); void NotifyHalResult(DCAMERA_EVENT eventType, DCameraSourceEvent& event, int32_t result); void HitraceAndHisyseventImpl(std::vector>& captureInfos); + void SetThreadStatusFlagTrue(const AppExecFwk::InnerEvent::Pointer &event); private: std::string devId_; @@ -90,6 +95,8 @@ private: std::shared_ptr controller_; std::shared_ptr input_; sptr hdiCallback_; + std::atomic threadStatusFlag_ = false; + std::weak_ptr sourceDev_; std::map memberFuncMap_; std::map eventResultMap_; -- Gitee From a981520b5b373b4956b436c0d851bb693ba95940 Mon Sep 17 00:00:00 2001 From: ry521 Date: Thu, 23 Nov 2023 07:48:44 +0000 Subject: [PATCH 4/8] update services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_event.h. Signed-off-by: ry521 --- .../include/distributedcameramgr/dcamera_source_event.h | 1 + 1 file changed, 1 insertion(+) diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_event.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_event.h index 725bba07..bc43f911 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_SET_THREAD_STATUS = 10, } DCAMERA_EVENT; class DCameraRegistParam { -- Gitee From f6ed4cfdf8b7b170daad1a7993158c6514f55615 Mon Sep 17 00:00:00 2001 From: ry521 Date: Thu, 23 Nov 2023 07:49:29 +0000 Subject: [PATCH 5/8] . Signed-off-by: ry521 --- .../dcameradata/dcamera_stream_data_process_producer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.h index f133fcfd..18283b28 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.h @@ -60,6 +60,7 @@ private: std::thread eventThread_; std::thread producerThread_; + std::thread listenThread_; std::condition_variable eventCon_; std::condition_variable producerCon_; std::mutex bufferMutex_; -- Gitee From 87705959ae2db6054e62097fbf5b693a322c0624 Mon Sep 17 00:00:00 2001 From: ry521 Date: Thu, 23 Nov 2023 07:52:40 +0000 Subject: [PATCH 6/8] . Signed-off-by: ry521 --- .../distributed_camera_source_service.cpp | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) 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..9e8ecf8f 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" @@ -55,6 +56,10 @@ void DistributedCameraSourceService::OnStart() DHLOGE("DistributedCameraSourceService init failed"); return; } + listenThread_ = std::thread(&DistributedCameraSourceService::ListenCameraDev, this); + if (pthread_setname_np(listenThread_.native_handle(), LISTEN_THREAD) != DH_SUCCESS) { + DHLOGE("Dev clear thread setname failed."); + } state_ = DCameraServiceState::DCAMERA_SRV_STATE_RUNNING; DHLOGI("start service success."); } @@ -82,6 +87,9 @@ void DistributedCameraSourceService::OnStop() state_ = DCameraServiceState::DCAMERA_SRV_STATE_NOT_START; registerToService_ = false; listener_ = nullptr; + if (listenThread_.joinable()) { + listenThread_.join(); + } DCameraSourceServiceIpc::GetInstance().UnInit(); } @@ -279,6 +287,33 @@ void DistributedCameraSourceService::CamDevInsert(DCameraIndex& index, std::shar camerasMap_.emplace(index, camDev); } +void DistributedCameraSourceService::ListenCameraDev() +{ + auto taskFunc = [this]() { + std::lock_guard lock(devMapMtx_); + for (auto &iter : audioDevMap_) { + if (iter.second.dev->GetThreadStatusFlag()) { + iter.second.dev->SetThreadStatusFlag(); + } else { + DHLOGE("Exit the current proces"); + _Exit(0); + } + } + }; + OHOS::HiviewDFX::Watchdog::GetInstance().RunPeriodicalTask("SourceService", taskFunc, + WATCHDOG_INTERVAL_TIME, WATCHDOG_DELAY_TIME); + + while (true) { + std::lock_guard lock(devMapMtx_); + if (!eventBus_.empty()) { + for (auto &iter : eventBus_) { + iter.second.dev->RestoreThreadStatus(); + } + } + usleep(SLEEP_TIME); + } +} + std::shared_ptr DistributedCameraSourceService::GetCamDevByIndex(DCameraIndex& index) { std::lock_guard camLock(camDevMutex_); -- Gitee From 3949ca1d32db8745571ccff43e30c462662b9fc6 Mon Sep 17 00:00:00 2001 From: ry521 Date: Thu, 23 Nov 2023 08:11:20 +0000 Subject: [PATCH 7/8] update services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp. Signed-off-by: ry521 --- .../dcamera_source_dev.cpp | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp index ba11a523..9630e080 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp @@ -45,6 +45,7 @@ DCameraSourceDev::DCameraSourceDev(std::string devId, std::string dhId, memberFuncMap_[DCAMERA_EVENT_START_CAPTURE] = &DCameraSourceDev::NotifyHalResult; memberFuncMap_[DCAMERA_EVENT_STOP_CAPTURE] = &DCameraSourceDev::NotifyHalResult; memberFuncMap_[DCAMERA_EVENT_UPDATE_SETTINGS] = &DCameraSourceDev::NotifyHalResult; + memberFuncMap_[DCAMERA_EVENT_SET_THREAD_STATUS] = &DCameraSourceDev::SetThreadStatusFlagTrue; eventResultMap_[DCAMERA_EVENT_OPEN] = DCAMERA_EVENT_OPEN_CHANNEL_ERROR; eventResultMap_[DCAMERA_EVENT_CLOSE] = DCAMERA_EVENT_CLOSE_CHANNEL_ERROR; @@ -545,6 +546,44 @@ int32_t DCameraSourceDev::CameraEventNotify(std::shared_ptr& event return DCAMERA_OK; } +int32_t DCameraSourceDev::RestoreThreadStatus() +{ + if (eventBus_ == nullptr) { + DHLOGI("Event handler is null."); + return DCAMERA_DEVICE_BUSY; + } + json jParam; + auto eventParam = std::make_shared(jParam); + auto msgEvent = AppExecFwk::InnerEvent::Get(DCAMERA_EVENT_SET_THREAD_STATUS, eventParam, 0); + if (!eventBus_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE)) { + DHLOGE("Send event failed."); + return DCAMERA_DEVICE_BUSY; + } + DHLOGD("Enable audio task generate successfully."); + return DCAMERA_OK; +} + +bool DCameraSourceDev::GetThreadStatusFlag() +{ + return threadStatusFlag_; +} + +void DCameraSourceDev::SetThreadStatusFlag() +{ + threadStatusFlag_ = false; +} + +void DCameraSourceDev::SetThreadStatusFlagTrue(const AppExecFwk::InnerEvent::Pointer &event) +{ + (void) event; + auto sourceDevobj = sourceDev_.lock(); + if (sourceDevobj == nullptr) { + DHLOGE("Source dev is invaild."); + return; + } + sourceDevobj->threadStatusFlag_ = true; +} + void DCameraSourceDev::NotifyResult(DCAMERA_EVENT eventType, DCameraSourceEvent& event, int32_t result) { auto itFunc = memberFuncMap_.find(eventType); -- Gitee From 95d48ee7321550bbe1ed34365483fa1a2e55fc48 Mon Sep 17 00:00:00 2001 From: ry521 Date: Thu, 23 Nov 2023 08:12:52 +0000 Subject: [PATCH 8/8] update services/cameraservice/sourceservice/BUILD.gn. Signed-off-by: ry521 --- services/cameraservice/sourceservice/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index ff69dc8b..fb5bdc9d 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -126,6 +126,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", -- Gitee