mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2026-04-20 03:19:40 +02:00
swscale: switch to refstruct for hw_priv
This is a bit more forward-facing than a bare allocation, and importantly, allows the `swscale/utils.c` code to remain agnostic about how to correctly uninit this struct. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas <git@haasn.dev>
This commit is contained in:
@@ -696,7 +696,7 @@ struct SwsInternal {
|
||||
Half2FloatTables *h2f_tables;
|
||||
|
||||
// Hardware specific private data
|
||||
void *hw_priv;
|
||||
void *hw_priv; /* refstruct */
|
||||
};
|
||||
//FIXME check init (where 0)
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
#include "libavutil/mem.h"
|
||||
#include "libavutil/opt.h"
|
||||
#include "libavutil/pixdesc.h"
|
||||
#include "libavutil/refstruct.h"
|
||||
#include "libavutil/slicethread.h"
|
||||
#include "libavutil/thread.h"
|
||||
#include "libavutil/aarch64/cpu.h"
|
||||
@@ -2248,9 +2249,7 @@ void sws_freeContext(SwsContext *sws)
|
||||
if (!c)
|
||||
return;
|
||||
|
||||
#if CONFIG_UNSTABLE && CONFIG_VULKAN
|
||||
ff_sws_vk_uninit(sws);
|
||||
#endif
|
||||
av_refstruct_unref(&c->hw_priv);
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(c->graph); i++)
|
||||
ff_sws_graph_free(&c->graph[i]);
|
||||
|
||||
@@ -21,14 +21,12 @@
|
||||
#include "../ops_internal.h"
|
||||
#include "../swscale_internal.h"
|
||||
#include "libavutil/mem.h"
|
||||
#include "libavutil/refstruct.h"
|
||||
#include "ops.h"
|
||||
|
||||
void ff_sws_vk_uninit(SwsContext *sws)
|
||||
static void ff_sws_vk_uninit(AVRefStructOpaque opaque, void *obj)
|
||||
{
|
||||
SwsInternal *c = sws_internal(sws);
|
||||
FFVulkanOpsCtx *s = c->hw_priv;
|
||||
if (!s)
|
||||
return;
|
||||
FFVulkanOpsCtx *s = obj;
|
||||
|
||||
#if CONFIG_LIBSHADERC || CONFIG_LIBGLSLANG
|
||||
if (s->spvc)
|
||||
@@ -36,7 +34,6 @@ void ff_sws_vk_uninit(SwsContext *sws)
|
||||
#endif
|
||||
ff_vk_exec_pool_free(&s->vkctx, &s->e);
|
||||
ff_vk_uninit(&s->vkctx);
|
||||
av_freep(&c->hw_priv);
|
||||
}
|
||||
|
||||
int ff_sws_vk_init(SwsContext *sws, AVBufferRef *dev_ref)
|
||||
@@ -45,7 +42,8 @@ int ff_sws_vk_init(SwsContext *sws, AVBufferRef *dev_ref)
|
||||
SwsInternal *c = sws_internal(sws);
|
||||
|
||||
if (!c->hw_priv) {
|
||||
c->hw_priv = av_mallocz(sizeof(FFVulkanOpsCtx));
|
||||
c->hw_priv = av_refstruct_alloc_ext(sizeof(FFVulkanOpsCtx), 0, NULL,
|
||||
ff_sws_vk_uninit);
|
||||
if (!c->hw_priv)
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,5 @@ typedef struct FFVulkanOpsCtx {
|
||||
} FFVulkanOpsCtx;
|
||||
|
||||
int ff_sws_vk_init(SwsContext *sws, AVBufferRef *dev_ref);
|
||||
void ff_sws_vk_uninit(SwsContext *sws);
|
||||
|
||||
#endif /* SWSCALE_VULKAN_OPS_H */
|
||||
|
||||
Reference in New Issue
Block a user