summaryrefslogtreecommitdiffstats
path: root/libavfilter/vsrc_gfxcapture_winrt.cpp
diff options
context:
space:
mode:
authorTimo Rothenpieler <[email protected]>2025-09-17 22:03:28 +0200
committerTimo Rothenpieler <[email protected]>2025-09-18 01:04:59 +0000
commit61835e1d8be9ace611e82b64f136a50f191a6e25 (patch)
tree8da5c216a4162bd4a27cdaba5febcce0323ad4c7 /libavfilter/vsrc_gfxcapture_winrt.cpp
parentc4e537793b5939262cabb708ff798a732b8aba33 (diff)
avfilter/vsrc_gfxcapture: keep cbdata object alive
Depending on the threading backend the stdlib uses, creating a mutex/condvar can be quite expensive. So keep this object alive in the ctx, on which we synchronize via the uninit mutex anyway.
Diffstat (limited to 'libavfilter/vsrc_gfxcapture_winrt.cpp')
-rw-r--r--libavfilter/vsrc_gfxcapture_winrt.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/libavfilter/vsrc_gfxcapture_winrt.cpp b/libavfilter/vsrc_gfxcapture_winrt.cpp
index 62b1a94802..1738fa23af 100644
--- a/libavfilter/vsrc_gfxcapture_winrt.cpp
+++ b/libavfilter/vsrc_gfxcapture_winrt.cpp
@@ -149,6 +149,7 @@ struct GfxCaptureContextCpp {
volatile int wgc_thread_init_res { INT_MAX };
std::recursive_mutex wgc_thread_uninit_mutex;
volatile int wgc_thread_res { 0 };
+ std::shared_ptr<void> wgc_thread_cb_data;
HWND capture_hwnd { nullptr };
HMONITOR capture_hmonitor { nullptr };
@@ -716,11 +717,17 @@ static int run_on_wgc_thread(AVFilterContext *avctx, F &&cb)
struct CBData {
std::mutex mutex;
std::condition_variable cond;
- bool done { false };
- bool cancel { false };
- int ret { AVERROR_BUG };
+ bool done;
+ bool cancel;
+ int ret;
};
- auto cbdata = std::make_shared<CBData>();
+ auto cbdata = ctx->wgc_thread_cb_data ?
+ std::static_pointer_cast<CBData>(ctx->wgc_thread_cb_data) :
+ std::make_shared<CBData>();
+ ctx->wgc_thread_cb_data = cbdata;
+
+ cbdata->done = cbdata->cancel = false;
+ cbdata->ret = AVERROR_BUG;
boolean res = 0;
CHECK_HR_RET(wgctx->dispatcher_queue->TryEnqueue(