From 45bb594090483497e6e87e64218b18ad169f83cd Mon Sep 17 00:00:00 2001 From: Topologist Date: Mon, 8 Nov 2021 23:02:23 +0100 Subject: [PATCH 1/3] Use atomic shared ptr instead of deprecated overload --- include/internal/SCCommon.h | 4 ++-- include/internal/ThreadManager.h | 4 ++-- src_cpp/ScreenCapture.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/internal/SCCommon.h b/include/internal/SCCommon.h index b1d13d78..697aa932 100644 --- a/include/internal/SCCommon.h +++ b/include/internal/SCCommon.h @@ -7,10 +7,10 @@ namespace SL { namespace Screen_Capture { template struct CaptureData { - std::shared_ptr FrameTimer; + std::atomic > FrameTimer; F OnNewFrame; F OnFrameChanged; - std::shared_ptr MouseTimer; + std::atomic > MouseTimer; M OnMouseChanged; W getThingsToWatch; }; diff --git a/include/internal/ThreadManager.h b/include/internal/ThreadManager.h index 15752f7a..83f38ab6 100644 --- a/include/internal/ThreadManager.h +++ b/include/internal/ThreadManager.h @@ -99,7 +99,7 @@ namespace Screen_Capture { // get a copy of the shared_ptr in a safe way frameprocessor.Resume(); - auto timer = std::atomic_load(&data->ScreenCaptureData.FrameTimer); + auto timer = data->ScreenCaptureData.FrameTimer.load(); timer->start(); auto monitors = GetMonitors(); if (isMonitorInsideBounds(monitors, monitor) && !HasMonitorsChanged(startmonitors, monitors)) { @@ -145,7 +145,7 @@ namespace Screen_Capture { } while (!data->CommonData_.TerminateThreadsEvent) { // get a copy of the shared_ptr in a safe way - auto timer = std::atomic_load(&data->WindowCaptureData.FrameTimer); + auto timer = data->WindowCaptureData.FrameTimer.load(); timer->start(); ret = frameprocessor.ProcessFrame(wnd); if (ret != DUPL_RETURN_SUCCESS) { diff --git a/src_cpp/ScreenCapture.cpp b/src_cpp/ScreenCapture.cpp index 3052098a..d49c4a5a 100644 --- a/src_cpp/ScreenCapture.cpp +++ b/src_cpp/ScreenCapture.cpp @@ -137,13 +137,13 @@ namespace Screen_Capture { } virtual void setFrameChangeInterval(const std::shared_ptr &timer) override { - std::atomic_store(&Thread_Data_->ScreenCaptureData.FrameTimer, timer); - std::atomic_store(&Thread_Data_->WindowCaptureData.FrameTimer, timer); + Thread_Data_->ScreenCaptureData.FrameTimer.store(timer); + Thread_Data_->WindowCaptureData.FrameTimer.store(timer); } virtual void setMouseChangeInterval(const std::shared_ptr &timer) override { - std::atomic_store(&Thread_Data_->ScreenCaptureData.MouseTimer, timer); - std::atomic_store(&Thread_Data_->WindowCaptureData.MouseTimer, timer); + Thread_Data_->ScreenCaptureData.MouseTimer.store(timer); + Thread_Data_->WindowCaptureData.MouseTimer.store(timer); } virtual void pause() override { Thread_Data_->CommonData_.Paused = true; } virtual bool isPaused() const override { return Thread_Data_->CommonData_.Paused; } From 04ff0c394fac280e8e302d3392f8a15d2c1e775c Mon Sep 17 00:00:00 2001 From: Six Jonathan Date: Thu, 6 Oct 2022 22:53:28 +0200 Subject: [PATCH 2/3] Use define to fix deprecated atomic shared ptr --- include/internal/SCCommon.h | 12 ++++++++++-- include/internal/ThreadManager.h | 8 ++++++++ src_cpp/ScreenCapture.cpp | 10 ++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/internal/SCCommon.h b/include/internal/SCCommon.h index 697aa932..bf72f7e0 100644 --- a/include/internal/SCCommon.h +++ b/include/internal/SCCommon.h @@ -7,10 +7,18 @@ namespace SL { namespace Screen_Capture { template struct CaptureData { - std::atomic > FrameTimer; +#if defined(_WIN32) && defined(__cplusplus) && __cplusplus >= 202002L + std::atomic > FrameTimer; +#else + std::shared_ptr FrameTimer; +#endif F OnNewFrame; F OnFrameChanged; - std::atomic > MouseTimer; +#if defined(_WIN32) && defined(__cplusplus) && __cplusplus >= 202002L + std::atomic > MouseTimer; +#else + std::shared_ptr MouseTimer; +#endif M OnMouseChanged; W getThingsToWatch; }; diff --git a/include/internal/ThreadManager.h b/include/internal/ThreadManager.h index 83f38ab6..fe639404 100644 --- a/include/internal/ThreadManager.h +++ b/include/internal/ThreadManager.h @@ -99,7 +99,11 @@ namespace Screen_Capture { // get a copy of the shared_ptr in a safe way frameprocessor.Resume(); +#if defined(_WIN32) && defined(__cplusplus) && __cplusplus >= 202002L auto timer = data->ScreenCaptureData.FrameTimer.load(); +#else + auto timer = std::atomic_load(&data->ScreenCaptureData.FrameTimer); +#endif timer->start(); auto monitors = GetMonitors(); if (isMonitorInsideBounds(monitors, monitor) && !HasMonitorsChanged(startmonitors, monitors)) { @@ -145,7 +149,11 @@ namespace Screen_Capture { } while (!data->CommonData_.TerminateThreadsEvent) { // get a copy of the shared_ptr in a safe way +#if defined(_WIN32) && defined(__cplusplus) && __cplusplus >= 202002L auto timer = data->WindowCaptureData.FrameTimer.load(); +#else + auto timer = std::atomic_load(&data->WindowCaptureData.FrameTimer); +#endif timer->start(); ret = frameprocessor.ProcessFrame(wnd); if (ret != DUPL_RETURN_SUCCESS) { diff --git a/src_cpp/ScreenCapture.cpp b/src_cpp/ScreenCapture.cpp index d49c4a5a..42e26d0d 100644 --- a/src_cpp/ScreenCapture.cpp +++ b/src_cpp/ScreenCapture.cpp @@ -137,13 +137,23 @@ namespace Screen_Capture { } virtual void setFrameChangeInterval(const std::shared_ptr &timer) override { +#if defined(_WIN32) && defined(__cplusplus) && __cplusplus >= 202002L Thread_Data_->ScreenCaptureData.FrameTimer.store(timer); Thread_Data_->WindowCaptureData.FrameTimer.store(timer); +#else + std::atomic_store(&Thread_Data_->ScreenCaptureData.FrameTimer, timer); + std::atomic_store(&Thread_Data_->WindowCaptureData.FrameTimer, timer); +#endif } virtual void setMouseChangeInterval(const std::shared_ptr &timer) override { +#if defined(_WIN32) && defined(__cplusplus) && __cplusplus >= 202002L Thread_Data_->ScreenCaptureData.MouseTimer.store(timer); Thread_Data_->WindowCaptureData.MouseTimer.store(timer); +#else + std::atomic_store(&Thread_Data_->ScreenCaptureData.MouseTimer, timer); + std::atomic_store(&Thread_Data_->WindowCaptureData.MouseTimer, timer); +#endif } virtual void pause() override { Thread_Data_->CommonData_.Paused = true; } virtual bool isPaused() const override { return Thread_Data_->CommonData_.Paused; } From 95d897cfe98fa50b34b55c1e78dd1f8d7eb8e257 Mon Sep 17 00:00:00 2001 From: Six Jonathan Date: Thu, 6 Oct 2022 22:57:09 +0200 Subject: [PATCH 3/3] Fix space --- include/internal/SCCommon.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/internal/SCCommon.h b/include/internal/SCCommon.h index bf72f7e0..2e573821 100644 --- a/include/internal/SCCommon.h +++ b/include/internal/SCCommon.h @@ -8,16 +8,16 @@ namespace SL { namespace Screen_Capture { template struct CaptureData { #if defined(_WIN32) && defined(__cplusplus) && __cplusplus >= 202002L - std::atomic > FrameTimer; + std::atomic > FrameTimer; #else - std::shared_ptr FrameTimer; + std::shared_ptr FrameTimer; #endif F OnNewFrame; F OnFrameChanged; #if defined(_WIN32) && defined(__cplusplus) && __cplusplus >= 202002L - std::atomic > MouseTimer; + std::atomic > MouseTimer; #else - std::shared_ptr MouseTimer; + std::shared_ptr MouseTimer; #endif M OnMouseChanged; W getThingsToWatch;