vf_cuda_grid: Phase 6 — process_command 'reload_icon <name>'

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 <noreply@anthropic.com>
This commit is contained in:
gx
2026-05-20 21:48:09 +01:00
parent c5130cb15c
commit a326ef146c
+33
View File
@@ -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 */