From a326ef146ca510eb0a5d615e5cc33f731b5d79d3 Mon Sep 17 00:00:00 2001 From: gx Date: Wed, 20 May 2026 21:48:09 +0100 Subject: [PATCH] =?UTF-8?q?vf=5Fcuda=5Fgrid:=20Phase=206=20=E2=80=94=20pro?= =?UTF-8?q?cess=5Fcommand=20'reload=5Ficon=20'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Invalidate cached icon atlas by name. Next render автоматически re-reads PNG file с disk. Used controller'ом для periodic re-render dynamic overlays (charts/chats) — write new PNG → send reload_icon → filter подхватывает. Без этого pattern dynamic overlay невозможен — icon overlay cached forever after first load by icon_name. Co-Authored-By: Claude Opus 4.7 --- libavfilter/vf_cuda_grid.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/libavfilter/vf_cuda_grid.c b/libavfilter/vf_cuda_grid.c index 32c4922..3bb2852 100644 --- a/libavfilter/vf_cuda_grid.c +++ b/libavfilter/vf_cuda_grid.c @@ -1450,6 +1450,39 @@ static int cuda_grid_process_command(AVFilterContext *ctx, const char *cmd, return 0; } + if (!strcmp(cmd, "reload_icon")) { + /* Invalidate cached icon atlas by name — next render re-reads file from disk. + * Used Phase 6 by controller для periodic chart/chat re-rendering. */ + char name[OVERLAY_ICON_NAME_MAX]; + int i, found = -1; + if (!arg || sscanf(arg, "%31s", name) != 1) { + if (res) av_strlcpy(res, "err parse", res_len); + return AVERROR(EINVAL); + } + pthread_mutex_lock(&s->overlay_lock); + if (s->hwctx) { + CUcontext dummy; + CHECK_CU(s->hwctx->internal->cuda_dl->cuCtxPushCurrent(s->cu_ctx)); + for (i = 0; i < s->nb_icon_atlases; i++) { + if (!strcmp(s->icon_atlases[i].icon_name, name)) { + if (s->icon_atlases[i].device_ptr) { + s->hwctx->internal->cuda_dl->cuMemFree(s->icon_atlases[i].device_ptr); + s->icon_atlases[i].device_ptr = 0; + } + memmove(&s->icon_atlases[i], &s->icon_atlases[i + 1], + (s->nb_icon_atlases - i - 1) * sizeof(IconAtlas)); + s->nb_icon_atlases--; + found = i; + break; + } + } + CHECK_CU(s->hwctx->internal->cuda_dl->cuCtxPopCurrent(&dummy)); + } + pthread_mutex_unlock(&s->overlay_lock); + if (res) snprintf(res, res_len, found >= 0 ? "ok %s reloaded" : "not_cached %s", name); + return 0; + } + /* Future: set_layout (Phase 3 на filter side — пока nb_inputs хардкодится в init) */ /* Fall back to standard option/command handling */