FFmpeg: libavfilter/vf_pad_opencl.c Source File
Go to the documentation of this file. 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
30
32 "in_w", "iw",
33 "in_h", "ih",
34 "out_w", "ow",
35 "out_h", "oh",
36 "x",
37 "y",
38 "a",
39 "sar",
40 "dar",
42 };
43
55 };
56
63
69
72
80
82 {
86 uint8_t rgba_map[4];
87 cl_int cle;
88 int err;
89
93 ctx->hsub =
desc->log2_chroma_w;
94 ctx->vsub =
desc->log2_chroma_h;
95
97 if (err < 0)
99
100 ctx->command_queue = clCreateCommandQueue(
101 ctx->ocf.hwctx->context,
102 ctx->ocf.hwctx->device_id,
103 0,
104 &cle
105 );
106
108 ctx->pad_color[rgba_map[0]] =
ctx->pad_rgba[0];
109 ctx->pad_color[rgba_map[1]] =
ctx->pad_rgba[1];
110 ctx->pad_color[rgba_map[2]] =
ctx->pad_rgba[2];
111 ctx->pad_color[rgba_map[3]] =
ctx->pad_rgba[3];
112 } else {
116 ctx->pad_color[3] =
ctx->pad_rgba[3];
117 }
118
120
121 ctx->kernel_pad = clCreateKernel(
ctx->ocf.program,
"pad", &cle);
123
124 for (
int i = 0;
i < 4; ++
i) {
125 ctx->pad_color_float.s[
i] = (
float)
ctx->pad_color[
i] / 255.0;
126 }
127
128 ctx->pad_pos.s[0] =
ctx->x;
129 ctx->pad_pos.s[1] =
ctx->y;
130
131 ctx->initialized = 1;
132 return 0;
133
135 if (
ctx->command_queue)
136 clReleaseCommandQueue(
ctx->command_queue);
138 clReleaseKernel(
ctx->kernel_pad);
139 return err;
140 }
141
143 {
148 int err;
149 cl_int cle;
150 size_t global_work[2];
152
155
158 if (err < 0)
160 }
161
166 }
167
169 cl_float4 pad_color_float;
170 cl_int2 pad_pos;
171
174 } else {
177 }
178
179 if (p > 0 && p < 3) {
180 pad_pos.s[0] = pad_ctx->
pad_pos.s[0] >> pad_ctx->
hsub;
181 pad_pos.s[1] = pad_ctx->
pad_pos.s[1] >> pad_ctx->
vsub;
182 } else {
183 pad_pos.s[0] = pad_ctx->
pad_pos.s[0];
184 pad_pos.s[1] = pad_ctx->
pad_pos.s[1];
185 }
186
187 src = (cl_mem)input_frame->
data[p];
189
190 if (!dst)
191 break;
192
197
199 if (err < 0)
201
204
206 }
207
208 // Run queued kernel
211
213 if (err < 0)
215
217
219
224 return err;
225 }
226
228 {
230 cl_int cle;
231
232 if (
ctx->kernel_pad) {
233 cle = clReleaseKernel(
ctx->kernel_pad);
234 if (cle != CL_SUCCESS)
236 "kernel: %d.\n", cle);
237 }
238
239 if (
ctx->command_queue) {
240 cle = clReleaseCommandQueue(
ctx->command_queue);
241 if (cle != CL_SUCCESS)
243 "command queue: %d.\n", cle);
244 }
245
247 }
248
250 {
255 double var_values[
VARS_NB], res;
257 char *expr;
258
265 (
double)
inlink->sample_aspect_ratio.num /
inlink->sample_aspect_ratio.den : 1;
267
279
280 /* evaluate the width again, as it may depend on the evaluated output height */
288
289 if (adjusted_aspect.
num && adjusted_aspect.
den) {
290 adjusted_aspect =
av_div_q(adjusted_aspect,
inlink->sample_aspect_ratio);
293 } else {
295 }
296 }
297
298 /* evaluate x and y */
308 /* evaluate x again, as it may depend on the evaluated y value */
314
319
320 /* sanity check params */
324 }
325
327 ctx->ocf.output_width =
ctx->w;
328 } else {
330 }
331
333 ctx->ocf.output_height =
ctx->h;
334 } else {
336 }
337
341 }
342
344 if (err < 0)
345 return err;
346
347 return 0;
348 }
349
351 {
356 },
357 };
358
360 {
364 },
365 };
366
367 #define OFFSET(x) offsetof(PadOpenCLContext, x)
368 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
369
380 };
381
383
385 .
name =
"pad_opencl",
388 .priv_class = &pad_opencl_class,
395 };
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
#define CL_SET_KERNEL_ARG(kernel, arg_num, type, arg)
set argument to specific Kernel.
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
static const AVFilterPad pad_opencl_inputs[]
uint8_t * data
The data buffer.
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
int ff_opencl_filter_load_program(AVFilterContext *avctx, const char **program_source_array, int nb_strings)
Load a new OpenCL program from strings in memory.
const char * name
Filter name.
static int filter_frame(AVFilterLink *link, AVFrame *input_frame)
A link between two filters.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static av_cold void pad_opencl_uninit(AVFilterContext *avctx)
int ff_opencl_filter_work_size_from_image(AVFilterContext *avctx, size_t *work_size, AVFrame *frame, int plane, int block_alignment)
Find the work size needed needed for a given plane of an image.
void * priv
private data for use by the filter
int ff_opencl_filter_config_output(AVFilterLink *outlink)
Create a suitable hardware frames context for the output.
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
#define RGB_TO_Y_BT709(r, g, b)
static int pad_opencl_init(AVFilterContext *avctx, AVFrame *input_frame)
#define RGB_TO_U_BT709(r1, g1, b1, max)
int(* init)(AVBSFContext *ctx)
#define FILTER_INPUTS(array)
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Rational number (pair of numerator and denominator).
AVFilterLink ** inputs
array of pointers to input links
static const AVOption pad_opencl_options[]
@ AV_PIX_FMT_OPENCL
Hardware surfaces for OpenCL.
const AVFilter ff_vf_pad_opencl
#define RGB_TO_V_BT709(r1, g1, b1, max)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
AVFilterContext * src
source filter
static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
static int pad_opencl_config_output(AVFilterLink *outlink)
int ff_opencl_filter_config_input(AVFilterLink *inlink)
Check that the input link contains a suitable hardware frames context and extract the device from it.
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
cl_float4 pad_color_float
#define i(width, name, range_min, range_max)
int w
agreed upon image width
static const char *const var_names[]
const char * name
Pad name.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
This struct describes a set or pool of "hardware" frames (i.e.
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
AVFILTER_DEFINE_CLASS(pad_opencl)
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
int h
agreed upon image height
static const AVFilterPad pad_opencl_outputs[]
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
void ff_opencl_filter_uninit(AVFilterContext *avctx)
Uninitialise an OpenCL filter context.
cl_command_queue command_queue
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define FILTER_OUTPUTS(array)
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
#define CL_FAIL_ON_ERROR(errcode,...)
A helper macro to handle OpenCL errors.
static av_cold int uninit(AVCodecContext *avctx)
const char * ff_opencl_source_pad
AVFilterLink ** outputs
array of pointers to output links
Generated on Tue Feb 28 2023 21:33:57 for FFmpeg by
doxygen
1.8.17