From f12e9b60d66077f0d1b7a97105c77f68dc0cee7d Mon Sep 17 00:00:00 2001 From: linchengfeng Date: Tue, 22 Jul 2025 16:19:31 +0800 Subject: [PATCH] rm cameraTimer Signed-off-by: linchengfeng --- frameworks/native/camera/base/BUILD.gn | 1 - .../camera/base/src/input/camera_input.cpp | 10 +-- .../camera/base/src/input/camera_manager.cpp | 1 - .../base/src/utils/camera_counting_timer.cpp | 79 ------------------- .../include/utils/camera_counting_timer.h | 43 ---------- .../camera_timer_fuzzer.cpp | 3 - 6 files changed, 3 insertions(+), 134 deletions(-) delete mode 100644 frameworks/native/camera/base/src/utils/camera_counting_timer.cpp delete mode 100644 interfaces/inner_api/native/camera/include/utils/camera_counting_timer.h diff --git a/frameworks/native/camera/base/BUILD.gn b/frameworks/native/camera/base/BUILD.gn index b54e28a7f..1e1946f01 100644 --- a/frameworks/native/camera/base/BUILD.gn +++ b/frameworks/native/camera/base/BUILD.gn @@ -88,7 +88,6 @@ ohos_shared_library("camera_framework") { "src/session/secure_camera_session.cpp", "src/session/video_session.cpp", "src/utils/camera_buffer_handle_utils.cpp", - "src/utils/camera_counting_timer.cpp", "src/utils/camera_rotation_api_utils.cpp", "src/utils/camera_security_utils.cpp", "src/utils/camera_thread_utils.cpp", diff --git a/frameworks/native/camera/base/src/input/camera_input.cpp b/frameworks/native/camera/base/src/input/camera_input.cpp index 49f8a3dfd..742d48e9d 100644 --- a/frameworks/native/camera/base/src/input/camera_input.cpp +++ b/frameworks/native/camera/base/src/input/camera_input.cpp @@ -29,7 +29,6 @@ #include "metadata_common_utils.h" #include "timer/camera_deferred_timer.h" #include "timer/time_broker.h" -#include "camera_counting_timer.h" namespace OHOS { namespace CameraStandard { @@ -136,7 +135,6 @@ void CameraInput::InitCameraInput() }); bool result = object->AddDeathRecipient(deathRecipient_); CHECK_RETURN_ELOG(!result, "CameraInput::InitCameraInput failed to add deathRecipient"); - CameraCountingTimer::GetInstance().IncreaseUserCount(); } void CameraInput::CameraServerDied(pid_t pid) @@ -175,7 +173,6 @@ CameraInput::~CameraInput() deviceObj->UnSetCallback(); } UnregisterTime(); - CameraCountingTimer::GetInstance().DecreaseUserCount(); std::lock_guard lock(interfaceMutex_); if (cameraObj_) { MEDIA_INFO_LOG("CameraInput::CameraInput Destructor Camera: %{public}s", cameraObj_->GetID().c_str()); @@ -357,15 +354,14 @@ int CameraInput::closeDelayed(int32_t delayTime) auto thiswptr = wptr(this); const int delayTaskTime = delayTime * 1000; UnregisterTime(); - uint32_t timeIdFirst = CameraCountingTimer::GetInstance().Register( + uint32_t timeIdFirst = CameraTimer::GetInstance().Register( [thiswptr] { auto input = thiswptr.promote(); if (input) { MEDIA_INFO_LOG("Enter Into CameraInput::closeDelayed obj->close"); input->Close(); } - }, - delayTaskTime, true); + }, delayTaskTime, true); timeQueue_.push(timeIdFirst); return ServiceToCameraError(retCode); @@ -377,7 +373,7 @@ void CameraInput::UnregisterTime() while (!timeQueue_.empty()) { uint32_t timeIdFirst = timeQueue_.front(); timeQueue_.pop(); - CameraCountingTimer::GetInstance().Unregister(timeIdFirst); + CameraTimer::GetInstance().Unregister(timeIdFirst); } } diff --git a/frameworks/native/camera/base/src/input/camera_manager.cpp b/frameworks/native/camera/base/src/input/camera_manager.cpp index 2f35a268d..1bd3d7370 100644 --- a/frameworks/native/camera/base/src/input/camera_manager.cpp +++ b/frameworks/native/camera/base/src/input/camera_manager.cpp @@ -30,7 +30,6 @@ #include "ability/camera_ability_parse_util.h" #include "bundle_mgr_interface.h" -#include "camera_counting_timer.h" #include "camera_device.h" #include "camera_device_ability_items.h" #include "camera_error_code.h" diff --git a/frameworks/native/camera/base/src/utils/camera_counting_timer.cpp b/frameworks/native/camera/base/src/utils/camera_counting_timer.cpp deleted file mode 100644 index 24eab37b9..000000000 --- a/frameworks/native/camera/base/src/utils/camera_counting_timer.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "camera_counting_timer.h" -#include "camera_log.h" - -namespace OHOS { -namespace CameraStandard { -CameraCountingTimer& CameraCountingTimer::GetInstance() -{ - static CameraCountingTimer instance; - return instance; -} - -CameraCountingTimer::CameraCountingTimer() - : userCount_(0), - timer_(nullptr) -{ - MEDIA_INFO_LOG("entered."); -}; - -CameraCountingTimer::~CameraCountingTimer() -{ - MEDIA_INFO_LOG("entered."); - CHECK_RETURN(!timer_); - timer_->Shutdown(); - timer_ = nullptr; -} - -void CameraCountingTimer::IncreaseUserCount() -{ - MEDIA_INFO_LOG("entered, num of user: %d + 1", static_cast(userCount_.load())); - if (timer_ == nullptr) { - timer_ = std::make_unique("CameraServiceTimer"); - timer_->Setup(); - MEDIA_INFO_LOG("create timer thread"); - } - ++userCount_; -} - -void CameraCountingTimer::DecreaseUserCount() -{ - MEDIA_INFO_LOG("entered, num of user: %u - 1", userCount_.load()); - --userCount_; - if (userCount_.load() == 0 && timer_ != nullptr) { - MEDIA_INFO_LOG("delete timer thread"); - } -} - -uint32_t CameraCountingTimer::Register(const TimerCallback& callback, uint32_t interval, bool once) -{ - CHECK_RETURN_RET_ELOG(timer_ == nullptr, 0, "timer is nullptr"); - - uint32_t timerId = timer_->Register(callback, interval, once); - MEDIA_DEBUG_LOG("timerId: %{public}u", timerId); - return timerId; -} - -void CameraCountingTimer::Unregister(uint32_t timerId) -{ - MEDIA_DEBUG_LOG("timerId: %{public}d", timerId); - CHECK_RETURN(!timer_); - MEDIA_DEBUG_LOG("timerId: %{public}d", timerId); - timer_->Unregister(timerId); -} -} // namespace CameraStandard -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/native/camera/include/utils/camera_counting_timer.h b/interfaces/inner_api/native/camera/include/utils/camera_counting_timer.h deleted file mode 100644 index b1ba966ce..000000000 --- a/interfaces/inner_api/native/camera/include/utils/camera_counting_timer.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef CAMERA_COUNTING_TIMER_H -#define CAMERA_COUNTING_TIMER_H - -#include -#include -#include - -namespace OHOS { -namespace CameraStandard { -using TimerCallback = std::function; - -class CameraCountingTimer { -public: - CameraCountingTimer(); - ~CameraCountingTimer(); - - static CameraCountingTimer& GetInstance(); - void IncreaseUserCount(); - void DecreaseUserCount(); - uint32_t Register(const TimerCallback& callback, uint32_t interval, bool once); - void Unregister(uint32_t timerId); - -private: - std::atomic userCount_; - std::unique_ptr timer_; -}; -} // namespace CameraStandard -} // namespace OHOS -#endif // CAMERA_COUNTING_TIMER_H \ No newline at end of file diff --git a/test/fuzztest/cameratimer_fuzzer/camera_timer_fuzzer.cpp b/test/fuzztest/cameratimer_fuzzer/camera_timer_fuzzer.cpp index 01865e03d..f004ccfc0 100644 --- a/test/fuzztest/cameratimer_fuzzer/camera_timer_fuzzer.cpp +++ b/test/fuzztest/cameratimer_fuzzer/camera_timer_fuzzer.cpp @@ -49,9 +49,6 @@ void CameraTimerFuzzer::Test(uint8_t *rawData, size_t size) data.RewindRead(0); - fuzz_->IncreaseUserCount(); - fuzz_->DecreaseUserCount(); - TimerCallback callback = [] { // do nothing }; -- Gitee