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.
This commit is contained in:
Timo Rothenpieler
2025-09-17 22:03:28 +02:00
parent c4e537793b
commit 61835e1d8b

View File

@@ -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(