History

lavfi/vulkan: split off lavfi-specific code into vulkan_filter.c

The issue is that libavfilter depends on libavcodec, and when doing a static build, if libavcodec also includes "libavfilter/vulkan.c", then during link-time, compiling programs will fail as there would be multiple definitions of the same symbols in both libavfilter and libavcodec's object files. Linkers are, however, more permitting if both files that include a common file that's used as a template are one-to-one identical. Hence, to make both files the same in the future, export all avfilter specific functions to a separate file. There is some work in progress to make templated files like this be compiled only once, so this is not a long-term solution. This also removes a macro that could be used to toggle SPIRV compilation capability on #include-time, as this could cause the files to be different.

Lynne committed 4 years ago

Commit f6dd30d1 parent e7f327913 files · +240 −200Browse files

Showing the changes to libavfilter (11 of 13 files). Show all

Unified · Split

11 files
  1. libavfilter/Makefile +6 −6
  2. libavfilter/vf_avgblur_vulkan.c +1 −1
  3. libavfilter/vf_chromaber_vulkan.c +1 −1
  4. libavfilter/vf_gblur_vulkan.c +1 −1
  5. libavfilter/vf_libplacebo.c +1 −1
  6. libavfilter/vf_overlay_vulkan.c +1 −1
  7. libavfilter/vf_scale_vulkan.c +1 −1
  8. libavfilter/vulkan.c +0 −173
  9. libavfilter/vulkan.h +0 −9
  10. libavfilter/vulkan_filter.c +191 −0
  11. libavfilter/vulkan_filter.h +34 −0
libavfilter/Makefile+6−6
@@ -180,7 +180,7 @@ OBJS-$(CONFIG_ATADENOISE_FILTER) += vf_atadenoise.o · 179 unmodified lines
180OBJS-$(CONFIG_AVGBLUR_FILTER) += vf_avgblur.o180OBJS-$(CONFIG_AVGBLUR_FILTER) += vf_avgblur.o
181OBJS-$(CONFIG_AVGBLUR_OPENCL_FILTER) += vf_avgblur_opencl.o opencl.o \181OBJS-$(CONFIG_AVGBLUR_OPENCL_FILTER) += vf_avgblur_opencl.o opencl.o \
182 opencl/avgblur.o boxblur.o182 opencl/avgblur.o boxblur.o
183OBJS-$(CONFIG_AVGBLUR_VULKAN_FILTER) += vf_avgblur_vulkan.o vulkan.o183OBJS-$(CONFIG_AVGBLUR_VULKAN_FILTER) += vf_avgblur_vulkan.o vulkan.o vulkan_filter.o
184OBJS-$(CONFIG_BBOX_FILTER) += bbox.o vf_bbox.o184OBJS-$(CONFIG_BBOX_FILTER) += bbox.o vf_bbox.o
185OBJS-$(CONFIG_BENCH_FILTER) += f_bench.o185OBJS-$(CONFIG_BENCH_FILTER) += f_bench.o
186OBJS-$(CONFIG_BILATERAL_FILTER) += vf_bilateral.o186OBJS-$(CONFIG_BILATERAL_FILTER) += vf_bilateral.o
@@ -194,7 +194,7 @@ OBJS-$(CONFIG_BOXBLUR_OPENCL_FILTER) += vf_avgblur_opencl.o opencl.o \ · 7 unmodified lines
194 opencl/avgblur.o boxblur.o194 opencl/avgblur.o boxblur.o
195OBJS-$(CONFIG_BWDIF_FILTER) += vf_bwdif.o yadif_common.o195OBJS-$(CONFIG_BWDIF_FILTER) += vf_bwdif.o yadif_common.o
196OBJS-$(CONFIG_CAS_FILTER) += vf_cas.o196OBJS-$(CONFIG_CAS_FILTER) += vf_cas.o
197OBJS-$(CONFIG_CHROMABER_VULKAN_FILTER) += vf_chromaber_vulkan.o vulkan.o197OBJS-$(CONFIG_CHROMABER_VULKAN_FILTER) += vf_chromaber_vulkan.o vulkan.o vulkan_filter.o
198OBJS-$(CONFIG_CHROMAHOLD_FILTER) += vf_chromakey.o198OBJS-$(CONFIG_CHROMAHOLD_FILTER) += vf_chromakey.o
199OBJS-$(CONFIG_CHROMAKEY_FILTER) += vf_chromakey.o199OBJS-$(CONFIG_CHROMAKEY_FILTER) += vf_chromakey.o
200OBJS-$(CONFIG_CHROMANR_FILTER) += vf_chromanr.o200OBJS-$(CONFIG_CHROMANR_FILTER) += vf_chromanr.o
@@ -289,7 +289,7 @@ OBJS-$(CONFIG_FREEZEFRAMES_FILTER) += vf_freezeframes.o · 88 unmodified lines
289OBJS-$(CONFIG_FREI0R_FILTER) += vf_frei0r.o289OBJS-$(CONFIG_FREI0R_FILTER) += vf_frei0r.o
290OBJS-$(CONFIG_FSPP_FILTER) += vf_fspp.o qp_table.o290OBJS-$(CONFIG_FSPP_FILTER) += vf_fspp.o qp_table.o
291OBJS-$(CONFIG_GBLUR_FILTER) += vf_gblur.o291OBJS-$(CONFIG_GBLUR_FILTER) += vf_gblur.o
292OBJS-$(CONFIG_GBLUR_VULKAN_FILTER) += vf_gblur_vulkan.o vulkan.o292OBJS-$(CONFIG_GBLUR_VULKAN_FILTER) += vf_gblur_vulkan.o vulkan.o vulkan_filter.o
293OBJS-$(CONFIG_GEQ_FILTER) += vf_geq.o293OBJS-$(CONFIG_GEQ_FILTER) += vf_geq.o
294OBJS-$(CONFIG_GRADFUN_FILTER) += vf_gradfun.o294OBJS-$(CONFIG_GRADFUN_FILTER) += vf_gradfun.o
295OBJS-$(CONFIG_GRAPHMONITOR_FILTER) += f_graphmonitor.o295OBJS-$(CONFIG_GRAPHMONITOR_FILTER) += f_graphmonitor.o
@@ -324,7 +324,7 @@ OBJS-$(CONFIG_LAGFUN_FILTER) += vf_lagfun.o · 28 unmodified lines
324OBJS-$(CONFIG_LATENCY_FILTER) += f_latency.o324OBJS-$(CONFIG_LATENCY_FILTER) += f_latency.o
325OBJS-$(CONFIG_LENSCORRECTION_FILTER) += vf_lenscorrection.o325OBJS-$(CONFIG_LENSCORRECTION_FILTER) += vf_lenscorrection.o
326OBJS-$(CONFIG_LENSFUN_FILTER) += vf_lensfun.o326OBJS-$(CONFIG_LENSFUN_FILTER) += vf_lensfun.o
327OBJS-$(CONFIG_LIBPLACEBO_FILTER) += vf_libplacebo.o vulkan.o327OBJS-$(CONFIG_LIBPLACEBO_FILTER) += vf_libplacebo.o vulkan.o vulkan_filter.o
328OBJS-$(CONFIG_LIBVMAF_FILTER) += vf_libvmaf.o framesync.o328OBJS-$(CONFIG_LIBVMAF_FILTER) += vf_libvmaf.o framesync.o
329OBJS-$(CONFIG_LIMITDIFF_FILTER) += vf_limitdiff.o framesync.o329OBJS-$(CONFIG_LIMITDIFF_FILTER) += vf_limitdiff.o framesync.o
330OBJS-$(CONFIG_LIMITER_FILTER) += vf_limiter.o330OBJS-$(CONFIG_LIMITER_FILTER) += vf_limiter.o
@@ -370,7 +370,7 @@ OBJS-$(CONFIG_OVERLAY_CUDA_FILTER) += vf_overlay_cuda.o framesync.o vf · 39 unmodified lines
370OBJS-$(CONFIG_OVERLAY_OPENCL_FILTER) += vf_overlay_opencl.o opencl.o \370OBJS-$(CONFIG_OVERLAY_OPENCL_FILTER) += vf_overlay_opencl.o opencl.o \
371 opencl/overlay.o framesync.o371 opencl/overlay.o framesync.o
372OBJS-$(CONFIG_OVERLAY_QSV_FILTER) += vf_overlay_qsv.o framesync.o372OBJS-$(CONFIG_OVERLAY_QSV_FILTER) += vf_overlay_qsv.o framesync.o
373OBJS-$(CONFIG_OVERLAY_VULKAN_FILTER) += vf_overlay_vulkan.o vulkan.o373OBJS-$(CONFIG_OVERLAY_VULKAN_FILTER) += vf_overlay_vulkan.o vulkan.o vulkan_filter.o
374OBJS-$(CONFIG_OWDENOISE_FILTER) += vf_owdenoise.o374OBJS-$(CONFIG_OWDENOISE_FILTER) += vf_owdenoise.o
375OBJS-$(CONFIG_PAD_FILTER) += vf_pad.o375OBJS-$(CONFIG_PAD_FILTER) += vf_pad.o
376OBJS-$(CONFIG_PAD_OPENCL_FILTER) += vf_pad_opencl.o opencl.o opencl/pad.o376OBJS-$(CONFIG_PAD_OPENCL_FILTER) += vf_pad_opencl.o opencl.o opencl/pad.o
@@ -415,7 +415,7 @@ OBJS-$(CONFIG_SCALE_CUDA_FILTER) += vf_scale_cuda.o scale_eval.o \ · 38 unmodified lines
415OBJS-$(CONFIG_SCALE_NPP_FILTER) += vf_scale_npp.o scale_eval.o415OBJS-$(CONFIG_SCALE_NPP_FILTER) += vf_scale_npp.o scale_eval.o
416OBJS-$(CONFIG_SCALE_QSV_FILTER) += vf_scale_qsv.o416OBJS-$(CONFIG_SCALE_QSV_FILTER) += vf_scale_qsv.o
417OBJS-$(CONFIG_SCALE_VAAPI_FILTER) += vf_scale_vaapi.o scale_eval.o vaapi_vpp.o417OBJS-$(CONFIG_SCALE_VAAPI_FILTER) += vf_scale_vaapi.o scale_eval.o vaapi_vpp.o
418OBJS-$(CONFIG_SCALE_VULKAN_FILTER) += vf_scale_vulkan.o vulkan.o418OBJS-$(CONFIG_SCALE_VULKAN_FILTER) += vf_scale_vulkan.o vulkan.o vulkan_filter.o
419OBJS-$(CONFIG_SCALE2REF_FILTER) += vf_scale.o scale_eval.o419OBJS-$(CONFIG_SCALE2REF_FILTER) += vf_scale.o scale_eval.o
420OBJS-$(CONFIG_SCALE2REF_NPP_FILTER) += vf_scale_npp.o scale_eval.o420OBJS-$(CONFIG_SCALE2REF_NPP_FILTER) += vf_scale_npp.o scale_eval.o
421OBJS-$(CONFIG_SCDET_FILTER) += vf_scdet.o421OBJS-$(CONFIG_SCDET_FILTER) += vf_scdet.o
libavfilter/vf_avgblur_vulkan.c+1−1
@@ -18,7 +18,7 @@ · 17 unmodified lines
18 18
19#include "libavutil/random_seed.h"19#include "libavutil/random_seed.h"
20#include "libavutil/opt.h"20#include "libavutil/opt.h"
21#include "vulkan.h"21#include "vulkan_filter.h"
22#include "internal.h"22#include "internal.h"
23 23
24#define CGS 3224#define CGS 32
libavfilter/vf_chromaber_vulkan.c+1−1
@@ -18,7 +18,7 @@ · 17 unmodified lines
18 18
19#include "libavutil/random_seed.h"19#include "libavutil/random_seed.h"
20#include "libavutil/opt.h"20#include "libavutil/opt.h"
21#include "vulkan.h"21#include "vulkan_filter.h"
22#include "internal.h"22#include "internal.h"
23 23
24#define CGROUPS (int [3]){ 32, 32, 1 }24#define CGROUPS (int [3]){ 32, 32, 1 }
libavfilter/vf_gblur_vulkan.c+1−1
@@ -19,7 +19,7 @@ · 18 unmodified lines
19 19
20#include "libavutil/random_seed.h"20#include "libavutil/random_seed.h"
21#include "libavutil/opt.h"21#include "libavutil/opt.h"
22#include "vulkan.h"22#include "vulkan_filter.h"
23#include "internal.h"23#include "internal.h"
24 24
25#define CGS 3225#define CGS 32
libavfilter/vf_libplacebo.c+1−1
@@ -19,7 +19,7 @@ · 18 unmodified lines
19#include "libavutil/file.h"19#include "libavutil/file.h"
20#include "libavutil/opt.h"20#include "libavutil/opt.h"
21#include "internal.h"21#include "internal.h"
22#include "vulkan.h"22#include "vulkan_filter.h"
23#include "scale_eval.h"23#include "scale_eval.h"
24 24
25#include <libplacebo/renderer.h>25#include <libplacebo/renderer.h>
libavfilter/vf_overlay_vulkan.c+1−1
@@ -18,7 +18,7 @@ · 17 unmodified lines
18 18
19#include "libavutil/random_seed.h"19#include "libavutil/random_seed.h"
20#include "libavutil/opt.h"20#include "libavutil/opt.h"
21#include "vulkan.h"21#include "vulkan_filter.h"
22#include "internal.h"22#include "internal.h"
23#include "framesync.h"23#include "framesync.h"
24 24
libavfilter/vf_scale_vulkan.c+1−1
@@ -18,7 +18,7 @@ · 17 unmodified lines
18 18
19#include "libavutil/random_seed.h"19#include "libavutil/random_seed.h"
20#include "libavutil/opt.h"20#include "libavutil/opt.h"
21#include "vulkan.h"21#include "vulkan_filter.h"
22#include "scale_eval.h"22#include "scale_eval.h"
23#include "internal.h"23#include "internal.h"
24#include "colorspace.h"24#include "colorspace.h"
libavfilter/vulkan.c+0−173
@@ -16,177 +16,4 @@ · 15 unmodified lines
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */17 */
18 18
19#include "vulkan.h"
20#include "libavutil/vulkan.c"19#include "libavutil/vulkan.c"
21
22static int vulkan_filter_set_device(AVFilterContext *avctx,
23 AVBufferRef *device)
24{
25 FFVulkanContext *s = avctx->priv;
26
27 av_buffer_unref(&s->device_ref);
28
29 s->device_ref = av_buffer_ref(device);
30 if (!s->device_ref)
31 return AVERROR(ENOMEM);
32
33 s->device = (AVHWDeviceContext*)s->device_ref->data;
34 s->hwctx = s->device->hwctx;
35
36 return 0;
37}
38
39static int vulkan_filter_set_frames(AVFilterContext *avctx,
40 AVBufferRef *frames)
41{
42 FFVulkanContext *s = avctx->priv;
43
44 av_buffer_unref(&s->frames_ref);
45
46 s->frames_ref = av_buffer_ref(frames);
47 if (!s->frames_ref)
48 return AVERROR(ENOMEM);
49
50 return 0;
51}
52
53int ff_vk_filter_config_input(AVFilterLink *inlink)
54{
55 int err;
56 AVFilterContext *avctx = inlink->dst;
57 FFVulkanContext *s = avctx->priv;
58 FFVulkanFunctions *vk = &s->vkfn;
59 AVHWFramesContext *input_frames;
60
61 if (!inlink->hw_frames_ctx) {
62 av_log(avctx, AV_LOG_ERROR, "Vulkan filtering requires a "
63 "hardware frames context on the input.\n");
64 return AVERROR(EINVAL);
65 }
66
67 /* Extract the device and default output format from the first input. */
68 if (avctx->inputs[0] != inlink)
69 return 0;
70
71 input_frames = (AVHWFramesContext *)inlink->hw_frames_ctx->data;
72 if (input_frames->format != AV_PIX_FMT_VULKAN)
73 return AVERROR(EINVAL);
74
75 err = vulkan_filter_set_device(avctx, input_frames->device_ref);
76 if (err < 0)
77 return err;
78 err = vulkan_filter_set_frames(avctx, inlink->hw_frames_ctx);
79 if (err < 0)
80 return err;
81
82 s->extensions = ff_vk_extensions_to_mask(s->hwctx->enabled_dev_extensions,
83 s->hwctx->nb_enabled_dev_extensions);
84
85 err = ff_vk_load_functions(s->device, &s->vkfn, s->extensions, 1, 1);
86 if (err < 0)
87 return err;
88
89 vk->GetPhysicalDeviceProperties(s->hwctx->phys_dev, &s->props);
90 vk->GetPhysicalDeviceMemoryProperties(s->hwctx->phys_dev, &s->mprops);
91
92 /* Default output parameters match input parameters. */
93 s->input_format = input_frames->sw_format;
94 if (s->output_format == AV_PIX_FMT_NONE)
95 s->output_format = input_frames->sw_format;
96 if (!s->output_width)
97 s->output_width = inlink->w;
98 if (!s->output_height)
99 s->output_height = inlink->h;
100
101 return 0;
102}
103
104int ff_vk_filter_config_output_inplace(AVFilterLink *outlink)
105{
106 int err;
107 AVFilterContext *avctx = outlink->src;
108 FFVulkanContext *s = avctx->priv;
109
110 av_buffer_unref(&outlink->hw_frames_ctx);
111
112 if (!s->device_ref) {
113 if (!avctx->hw_device_ctx) {
114 av_log(avctx, AV_LOG_ERROR, "Vulkan filtering requires a "
115 "Vulkan device.\n");
116 return AVERROR(EINVAL);
117 }
118
119 err = vulkan_filter_set_device(avctx, avctx->hw_device_ctx);
120 if (err < 0)
121 return err;
122 }
123
124 outlink->hw_frames_ctx = av_buffer_ref(s->frames_ref);
125 if (!outlink->hw_frames_ctx)
126 return AVERROR(ENOMEM);
127
128 outlink->w = s->output_width;
129 outlink->h = s->output_height;
130
131 return 0;
132}
133
134int ff_vk_filter_config_output(AVFilterLink *outlink)
135{
136 int err;
137 AVFilterContext *avctx = outlink->src;
138 FFVulkanContext *s = avctx->priv;
139 AVBufferRef *output_frames_ref;
140 AVHWFramesContext *output_frames;
141
142 av_buffer_unref(&outlink->hw_frames_ctx);
143
144 if (!s->device_ref) {
145 if (!avctx->hw_device_ctx) {
146 av_log(avctx, AV_LOG_ERROR, "Vulkan filtering requires a "
147 "Vulkan device.\n");
148 return AVERROR(EINVAL);
149 }
150
151 err = vulkan_filter_set_device(avctx, avctx->hw_device_ctx);
152 if (err < 0)
153 return err;
154 }
155
156 output_frames_ref = av_hwframe_ctx_alloc(s->device_ref);
157 if (!output_frames_ref) {
158 err = AVERROR(ENOMEM);
159 goto fail;
160 }
161 output_frames = (AVHWFramesContext*)output_frames_ref->data;
162
163 output_frames->format = AV_PIX_FMT_VULKAN;
164 output_frames->sw_format = s->output_format;
165 output_frames->width = s->output_width;
166 output_frames->height = s->output_height;
167
168 err = av_hwframe_ctx_init(output_frames_ref);
169 if (err < 0) {
170 av_log(avctx, AV_LOG_ERROR, "Failed to initialise output "
171 "frames: %d.\n", err);
172 goto fail;
173 }
174
175 outlink->hw_frames_ctx = output_frames_ref;
176 outlink->w = s->output_width;
177 outlink->h = s->output_height;
178
179 return 0;
180fail:
181 av_buffer_unref(&output_frames_ref);
182 return err;
183}
184
185int ff_vk_filter_init(AVFilterContext *avctx)
186{
187 FFVulkanContext *s = avctx->priv;
188
189 s->output_format = AV_PIX_FMT_NONE;
190
191 return 0;
192}
libavfilter/vulkan.h+0−9
@@ -19,15 +19,6 @@ · 18 unmodified lines
19#ifndef AVFILTER_VULKAN_H19#ifndef AVFILTER_VULKAN_H
20#define AVFILTER_VULKAN_H20#define AVFILTER_VULKAN_H
21 21
22#include "avfilter.h"
23#include "libavutil/vulkan.h"22#include "libavutil/vulkan.h"
24 23
25/**
26 * General lavfi IO functions
27 */
28int ff_vk_filter_init (AVFilterContext *avctx);
29int ff_vk_filter_config_input (AVFilterLink *inlink);
30int ff_vk_filter_config_output (AVFilterLink *outlink);
31int ff_vk_filter_config_output_inplace(AVFilterLink *outlink);
32
33#endif /* AVFILTER_VULKAN_H */24#endif /* AVFILTER_VULKAN_H */
libavfilter/vulkan_filter.c+191−0
@@ -0,0 +1,191 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "vulkan_filter.h"
20
21static int vulkan_filter_set_device(AVFilterContext *avctx,
22 AVBufferRef *device)
23{
24 FFVulkanContext *s = avctx->priv;
25
26 av_buffer_unref(&s->device_ref);
27
28 s->device_ref = av_buffer_ref(device);
29 if (!s->device_ref)
30 return AVERROR(ENOMEM);
31
32 s->device = (AVHWDeviceContext*)s->device_ref->data;
33 s->hwctx = s->device->hwctx;
34
35 return 0;
36}
37
38static int vulkan_filter_set_frames(AVFilterContext *avctx,
39 AVBufferRef *frames)
40{
41 FFVulkanContext *s = avctx->priv;
42
43 av_buffer_unref(&s->frames_ref);
44
45 s->frames_ref = av_buffer_ref(frames);
46 if (!s->frames_ref)
47 return AVERROR(ENOMEM);
48
49 return 0;
50}
51
52int ff_vk_filter_config_input(AVFilterLink *inlink)
53{
54 int err;
55 AVFilterContext *avctx = inlink->dst;
56 FFVulkanContext *s = avctx->priv;
57 FFVulkanFunctions *vk = &s->vkfn;
58 AVHWFramesContext *input_frames;
59
60 if (!inlink->hw_frames_ctx) {
61 av_log(avctx, AV_LOG_ERROR, "Vulkan filtering requires a "
62 "hardware frames context on the input.\n");
63 return AVERROR(EINVAL);
64 }
65
66 /* Extract the device and default output format from the first input. */
67 if (avctx->inputs[0] != inlink)
68 return 0;
69
70 input_frames = (AVHWFramesContext *)inlink->hw_frames_ctx->data;
71 if (input_frames->format != AV_PIX_FMT_VULKAN)
72 return AVERROR(EINVAL);
73
74 err = vulkan_filter_set_device(avctx, input_frames->device_ref);
75 if (err < 0)
76 return err;
77 err = vulkan_filter_set_frames(avctx, inlink->hw_frames_ctx);
78 if (err < 0)
79 return err;
80
81 s->extensions = ff_vk_extensions_to_mask(s->hwctx->enabled_dev_extensions,
82 s->hwctx->nb_enabled_dev_extensions);
83
84 err = ff_vk_load_functions(s->device, &s->vkfn, s->extensions, 1, 1);
85 if (err < 0)
86 return err;
87
88 vk->GetPhysicalDeviceProperties(s->hwctx->phys_dev, &s->props);
89 vk->GetPhysicalDeviceMemoryProperties(s->hwctx->phys_dev, &s->mprops);
90
91 /* Default output parameters match input parameters. */
92 s->input_format = input_frames->sw_format;
93 if (s->output_format == AV_PIX_FMT_NONE)
94 s->output_format = input_frames->sw_format;
95 if (!s->output_width)
96 s->output_width = inlink->w;
97 if (!s->output_height)
98 s->output_height = inlink->h;
99
100 return 0;
101}
102
103int ff_vk_filter_config_output_inplace(AVFilterLink *outlink)
104{
105 int err;
106 AVFilterContext *avctx = outlink->src;
107 FFVulkanContext *s = avctx->priv;
108
109 av_buffer_unref(&outlink->hw_frames_ctx);
110
111 if (!s->device_ref) {
112 if (!avctx->hw_device_ctx) {
113 av_log(avctx, AV_LOG_ERROR, "Vulkan filtering requires a "
114 "Vulkan device.\n");
115 return AVERROR(EINVAL);
116 }
117
118 err = vulkan_filter_set_device(avctx, avctx->hw_device_ctx);
119 if (err < 0)
120 return err;
121 }
122
123 outlink->hw_frames_ctx = av_buffer_ref(s->frames_ref);
124 if (!outlink->hw_frames_ctx)
125 return AVERROR(ENOMEM);
126
127 outlink->w = s->output_width;
128 outlink->h = s->output_height;
129
130 return 0;
131}
132
133int ff_vk_filter_config_output(AVFilterLink *outlink)
134{
135 int err;
136 AVFilterContext *avctx = outlink->src;
137 FFVulkanContext *s = avctx->priv;
138 AVBufferRef *output_frames_ref;
139 AVHWFramesContext *output_frames;
140
141 av_buffer_unref(&outlink->hw_frames_ctx);
142
143 if (!s->device_ref) {
144 if (!avctx->hw_device_ctx) {
145 av_log(avctx, AV_LOG_ERROR, "Vulkan filtering requires a "
146 "Vulkan device.\n");
147 return AVERROR(EINVAL);
148 }
149
150 err = vulkan_filter_set_device(avctx, avctx->hw_device_ctx);
151 if (err < 0)
152 return err;
153 }
154
155 output_frames_ref = av_hwframe_ctx_alloc(s->device_ref);
156 if (!output_frames_ref) {
157 err = AVERROR(ENOMEM);
158 goto fail;
159 }
160 output_frames = (AVHWFramesContext*)output_frames_ref->data;
161
162 output_frames->format = AV_PIX_FMT_VULKAN;
163 output_frames->sw_format = s->output_format;
164 output_frames->width = s->output_width;
165 output_frames->height = s->output_height;
166
167 err = av_hwframe_ctx_init(output_frames_ref);
168 if (err < 0) {
169 av_log(avctx, AV_LOG_ERROR, "Failed to initialise output "
170 "frames: %d.\n", err);
171 goto fail;
172 }
173
174 outlink->hw_frames_ctx = output_frames_ref;
175 outlink->w = s->output_width;
176 outlink->h = s->output_height;
177
178 return 0;
179fail:
180 av_buffer_unref(&output_frames_ref);
181 return err;
182}
183
184int ff_vk_filter_init(AVFilterContext *avctx)
185{
186 FFVulkanContext *s = avctx->priv;
187
188 s->output_format = AV_PIX_FMT_NONE;
189
190 return 0;
191}
libavfilter/vulkan_filter.h+34−0
@@ -0,0 +1,34 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef AVFILTER_VULKAN_FILTER_H
20#define AVFILTER_VULKAN_FILTER_H
21
22#include "avfilter.h"
23
24#include "vulkan.h"
25
26/**
27 * General lavfi IO functions
28 */
29int ff_vk_filter_init (AVFilterContext *avctx);
30int ff_vk_filter_config_input (AVFilterLink *inlink);
31int ff_vk_filter_config_output (AVFilterLink *outlink);
32int ff_vk_filter_config_output_inplace(AVFilterLink *outlink);
33
34#endif /* AVFILTER_VULKAN_FILTER_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t