FFmpeg
vf_program_opencl.c
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 
19 #include "libavutil/avstring.h"
20 #include "libavutil/log.h"
21 #include "libavutil/mem.h"
22 #include "libavutil/opt.h"
23 #include "libavutil/pixdesc.h"
24 
25 #include "avfilter.h"
26 #include "framesync.h"
27 #include "internal.h"
28 #include "opencl.h"
29 #include "video.h"
30 
31 typedef struct ProgramOpenCLContext {
33 
34  int loaded;
35  cl_uint index;
36  cl_kernel kernel;
37  cl_command_queue command_queue;
38 
41 
42  const char *source_file;
43  const char *kernel_name;
44  int nb_inputs;
45  int width, height;
49 
51 {
52  ProgramOpenCLContext *ctx = avctx->priv;
53  cl_int cle;
54  int err;
55 
57  if (err < 0)
58  return err;
59 
60  ctx->command_queue = clCreateCommandQueue(ctx->ocf.hwctx->context,
61  ctx->ocf.hwctx->device_id,
62  0, &cle);
63  if (!ctx->command_queue) {
64  av_log(avctx, AV_LOG_ERROR, "Failed to create OpenCL "
65  "command queue: %d.\n", cle);
66  return AVERROR(EIO);
67  }
68 
69  ctx->kernel = clCreateKernel(ctx->ocf.program, ctx->kernel_name, &cle);
70  if (!ctx->kernel) {
71  if (cle == CL_INVALID_KERNEL_NAME) {
72  av_log(avctx, AV_LOG_ERROR, "Kernel function '%s' not found in "
73  "program.\n", ctx->kernel_name);
74  } else {
75  av_log(avctx, AV_LOG_ERROR, "Failed to create kernel: %d.\n", cle);
76  }
77  return AVERROR(EIO);
78  }
79 
80  ctx->loaded = 1;
81  return 0;
82 }
83 
85 {
86  AVFilterLink *outlink = avctx->outputs[0];
87  ProgramOpenCLContext *ctx = avctx->priv;
88  AVFrame *output = NULL;
89  cl_int cle;
90  size_t global_work[2];
91  cl_mem src, dst;
92  int err, input, plane;
93 
94  if (!ctx->loaded) {
95  err = program_opencl_load(avctx);
96  if (err < 0)
97  return err;
98  }
99 
100  output = ff_get_video_buffer(outlink, outlink->w, outlink->h);
101  if (!output) {
102  err = AVERROR(ENOMEM);
103  goto fail;
104  }
105 
106  for (plane = 0; plane < FF_ARRAY_ELEMS(output->data); plane++) {
107  dst = (cl_mem)output->data[plane];
108  if (!dst)
109  break;
110 
111  cle = clSetKernelArg(ctx->kernel, 0, sizeof(cl_mem), &dst);
112  if (cle != CL_SUCCESS) {
113  av_log(avctx, AV_LOG_ERROR, "Failed to set kernel "
114  "destination image argument: %d.\n", cle);
115  err = AVERROR_UNKNOWN;
116  goto fail;
117  }
118  cle = clSetKernelArg(ctx->kernel, 1, sizeof(cl_uint), &ctx->index);
119  if (cle != CL_SUCCESS) {
120  av_log(avctx, AV_LOG_ERROR, "Failed to set kernel "
121  "index argument: %d.\n", cle);
122  err = AVERROR_UNKNOWN;
123  goto fail;
124  }
125 
126  for (input = 0; input < ctx->nb_inputs; input++) {
127  av_assert0(ctx->frames[input]);
128 
129  src = (cl_mem)ctx->frames[input]->data[plane];
130  av_assert0(src);
131 
132  cle = clSetKernelArg(ctx->kernel, 2 + input, sizeof(cl_mem), &src);
133  if (cle != CL_SUCCESS) {
134  av_log(avctx, AV_LOG_ERROR, "Failed to set kernel "
135  "source image argument %d: %d.\n", input, cle);
136  err = AVERROR_UNKNOWN;
137  goto fail;
138  }
139  }
140 
141  err = ff_opencl_filter_work_size_from_image(avctx, global_work,
142  output, plane, 0);
143  if (err < 0)
144  goto fail;
145 
146  av_log(avctx, AV_LOG_DEBUG, "Run kernel on plane %d "
147  "(%"SIZE_SPECIFIER"x%"SIZE_SPECIFIER").\n",
148  plane, global_work[0], global_work[1]);
149 
150  cle = clEnqueueNDRangeKernel(ctx->command_queue, ctx->kernel, 2, NULL,
151  global_work, NULL, 0, NULL, NULL);
152  CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to enqueue kernel: %d.\n", cle);
153  }
154 
155  cle = clFinish(ctx->command_queue);
156  CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to finish command queue: %d.\n", cle);
157 
158  if (ctx->nb_inputs > 0) {
159  err = av_frame_copy_props(output, ctx->frames[0]);
160  if (err < 0)
161  goto fail;
162  } else {
163  output->pts = ctx->index;
164  }
165  ++ctx->index;
166 
167  av_log(ctx, AV_LOG_DEBUG, "Filter output: %s, %ux%u (%"PRId64").\n",
168  av_get_pix_fmt_name(output->format),
169  output->width, output->height, output->pts);
170 
171  return ff_filter_frame(outlink, output);
172 
173 fail:
174  clFinish(ctx->command_queue);
175  av_frame_free(&output);
176  return err;
177 }
178 
180 {
181  AVFilterContext *avctx = outlink->src;
182 
183  return program_opencl_run(avctx);
184 }
185 
187 {
188  AVFilterContext *avctx = fs->parent;
189  ProgramOpenCLContext *ctx = avctx->priv;
190  int err, i;
191 
192  for (i = 0; i < ctx->nb_inputs; i++) {
193  err = ff_framesync_get_frame(&ctx->fs, i, &ctx->frames[i], 0);
194  if (err < 0)
195  return err;
196  }
197 
198  return program_opencl_run(avctx);
199 }
200 
202 {
203  ProgramOpenCLContext *ctx = avctx->priv;
204 
205  av_assert0(ctx->nb_inputs > 0);
206 
207  return ff_framesync_activate(&ctx->fs);
208 }
209 
211 {
212  AVFilterContext *avctx = outlink->src;
213  ProgramOpenCLContext *ctx = avctx->priv;
214  int err;
215 
216  err = ff_opencl_filter_config_output(outlink);
217  if (err < 0)
218  return err;
219 
220  if (ctx->nb_inputs > 0) {
221  FFFrameSyncIn *in;
222  int i;
223 
224  err = ff_framesync_init(&ctx->fs, avctx, ctx->nb_inputs);
225  if (err < 0)
226  return err;
227 
228  ctx->fs.opaque = ctx;
230 
231  in = ctx->fs.in;
232  for (i = 0; i < ctx->nb_inputs; i++) {
233  const AVFilterLink *inlink = avctx->inputs[i];
234 
235  in[i].time_base = inlink->time_base;
236  in[i].sync = 1;
237  in[i].before = EXT_STOP;
238  in[i].after = EXT_INFINITY;
239  }
240 
241  err = ff_framesync_configure(&ctx->fs);
242  if (err < 0)
243  return err;
244 
245  } else {
246  outlink->time_base = av_inv_q(ctx->source_rate);
247  }
248 
249  return 0;
250 }
251 
253 {
254  ProgramOpenCLContext *ctx = avctx->priv;
255  int err;
256 
257  ff_opencl_filter_init(avctx);
258 
259  ctx->ocf.output_width = ctx->width;
260  ctx->ocf.output_height = ctx->height;
261 
262  if (!strcmp(avctx->filter->name, "openclsrc")) {
263  if (!ctx->ocf.output_width || !ctx->ocf.output_height) {
264  av_log(avctx, AV_LOG_ERROR, "OpenCL source requires output "
265  "dimensions to be specified.\n");
266  return AVERROR(EINVAL);
267  }
268 
269  ctx->nb_inputs = 0;
270  ctx->ocf.output_format = ctx->source_format;
271  } else {
272  int i;
273 
274  ctx->frames = av_mallocz_array(ctx->nb_inputs,
275  sizeof(*ctx->frames));
276  if (!ctx->frames)
277  return AVERROR(ENOMEM);
278 
279  for (i = 0; i < ctx->nb_inputs; i++) {
281  memset(&input, 0, sizeof(input));
282 
283  input.type = AVMEDIA_TYPE_VIDEO;
284  input.name = av_asprintf("input%d", i);
285  if (!input.name)
286  return AVERROR(ENOMEM);
287 
289 
290  err = ff_insert_inpad(avctx, i, &input);
291  if (err < 0) {
292  av_freep(&input.name);
293  return err;
294  }
295  }
296  }
297 
298  return 0;
299 }
300 
302 {
303  ProgramOpenCLContext *ctx = avctx->priv;
304  cl_int cle;
305  int i;
306 
307  if (ctx->nb_inputs > 0) {
308  ff_framesync_uninit(&ctx->fs);
309 
310  av_freep(&ctx->frames);
311  for (i = 0; i < avctx->nb_inputs; i++)
312  av_freep(&avctx->input_pads[i].name);
313  }
314 
315  if (ctx->kernel) {
316  cle = clReleaseKernel(ctx->kernel);
317  if (cle != CL_SUCCESS)
318  av_log(avctx, AV_LOG_ERROR, "Failed to release "
319  "kernel: %d.\n", cle);
320  }
321 
322  if (ctx->command_queue) {
323  cle = clReleaseCommandQueue(ctx->command_queue);
324  if (cle != CL_SUCCESS)
325  av_log(avctx, AV_LOG_ERROR, "Failed to release "
326  "command queue: %d.\n", cle);
327  }
328 
330 }
331 
332 #define OFFSET(x) offsetof(ProgramOpenCLContext, x)
333 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM)
334 
335 #if CONFIG_PROGRAM_OPENCL_FILTER
336 
337 static const AVOption program_opencl_options[] = {
338  { "source", "OpenCL program source file", OFFSET(source_file),
339  AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
340  { "kernel", "Kernel name in program", OFFSET(kernel_name),
341  AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
342 
343  { "inputs", "Number of inputs", OFFSET(nb_inputs),
344  AV_OPT_TYPE_INT, { .i64 = 1 }, 1, INT_MAX, FLAGS },
345 
346  { "size", "Video size", OFFSET(width),
347  AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, FLAGS },
348  { "s", "Video size", OFFSET(width),
349  AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, FLAGS },
350 
351  { NULL },
352 };
353 
355 
356 static const AVFilterPad program_opencl_outputs[] = {
357  {
358  .name = "default",
359  .type = AVMEDIA_TYPE_VIDEO,
360  .config_props = &program_opencl_config_output,
361  },
362  { NULL }
363 };
364 
366  .name = "program_opencl",
367  .description = NULL_IF_CONFIG_SMALL("Filter video using an OpenCL program"),
368  .priv_size = sizeof(ProgramOpenCLContext),
369  .priv_class = &program_opencl_class,
370  .preinit = &program_opencl_framesync_preinit,
375  .inputs = NULL,
376  .outputs = program_opencl_outputs,
377  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
378 };
379 
380 #endif
381 
382 #if CONFIG_OPENCLSRC_FILTER
383 
384 static const AVOption openclsrc_options[] = {
385  { "source", "OpenCL program source file", OFFSET(source_file),
386  AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
387  { "kernel", "Kernel name in program", OFFSET(kernel_name),
388  AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
389 
390  { "size", "Video size", OFFSET(width),
391  AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, FLAGS },
392  { "s", "Video size", OFFSET(width),
393  AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, FLAGS },
394 
395  { "format", "Video format", OFFSET(source_format),
396  AV_OPT_TYPE_PIXEL_FMT, { .i64 = AV_PIX_FMT_NONE }, -1, INT_MAX, FLAGS },
397 
398  { "rate", "Video frame rate", OFFSET(source_rate),
399  AV_OPT_TYPE_VIDEO_RATE, { .str = "25" }, 0, INT_MAX, FLAGS },
400  { "r", "Video frame rate", OFFSET(source_rate),
401  AV_OPT_TYPE_VIDEO_RATE, { .str = "25" }, 0, INT_MAX, FLAGS },
402 
403  { NULL },
404 };
405 
406 AVFILTER_DEFINE_CLASS(openclsrc);
407 
408 static const AVFilterPad openclsrc_outputs[] = {
409  {
410  .name = "default",
411  .type = AVMEDIA_TYPE_VIDEO,
412  .config_props = &program_opencl_config_output,
413  .request_frame = &program_opencl_request_frame,
414  },
415  { NULL }
416 };
417 
419  .name = "openclsrc",
420  .description = NULL_IF_CONFIG_SMALL("Generate video using an OpenCL program"),
421  .priv_size = sizeof(ProgramOpenCLContext),
422  .priv_class = &openclsrc_class,
426  .inputs = NULL,
427  .outputs = openclsrc_outputs,
428  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
429 };
430 
431 #endif
int plane
Definition: avisynth_c.h:384
#define NULL
Definition: coverity.c:32
#define FRAMESYNC_DEFINE_CLASS(name, context, field)
Definition: framesync.h:300
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition: internal.h:385
static av_cold int program_opencl_init(AVFilterContext *avctx)
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
AVOption.
Definition: opt.h:246
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.
Definition: opencl.c:278
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...
Definition: opencl.c:60
int ff_opencl_filter_query_formats(AVFilterContext *avctx)
Return that all inputs and outputs support only AV_PIX_FMT_OPENCL.
Definition: opencl.c:28
Main libavfilter public API header.
Memory handling functions.
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
OpenCLFilterContext ocf
#define FLAGS
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:65
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
Definition: framesync.c:117
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:99
#define src
Definition: vp8dsp.c:254
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
Definition: opencl.c:147
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
Definition: framesync.h:86
AVOpenCLDeviceContext * hwctx
Definition: opencl.h:41
const char * name
Pad name.
Definition: internal.h:60
AVFilterContext * parent
Parent filter context.
Definition: framesync.h:152
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
#define av_cold
Definition: attributes.h:82
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:279
AVOptions.
filter_frame For filters that do not use the activate() callback
cl_device_id device_id
The primary device ID of the device.
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:388
FFFrameSyncIn * in
Pointer to array of inputs.
Definition: framesync.h:203
static int program_opencl_run(AVFilterContext *avctx)
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
Definition: framesync.h:91
Input stream structure.
Definition: framesync.h:81
int ff_opencl_filter_config_output(AVFilterLink *outlink)
Create a suitable hardware frames context for the output.
Definition: opencl.c:96
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:54
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:345
static int program_opencl_request_frame(AVFilterLink *outlink)
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
int width
Definition: frame.h:353
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static int program_opencl_activate(AVFilterContext *avctx)
cl_command_queue command_queue
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
Definition: framesync.c:293
Frame sync structure.
Definition: framesync.h:146
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
void * priv
private data for use by the filter
Definition: avfilter.h:353
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
static av_cold void program_opencl_uninit(AVFilterContext *avctx)
AVRational time_base
Time base for the incoming frames.
Definition: framesync.h:96
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter&#39;s input and try to produce output.
Definition: framesync.c:344
int(* on_event)(struct FFFrameSync *fs)
Callback called when a frame event is ready.
Definition: framesync.h:172
#define fail()
Definition: checkasm.h:121
enum AVPixelFormat output_format
Definition: opencl.h:45
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:113
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition: internal.h:129
unsigned nb_inputs
number of input pads
Definition: avfilter.h:347
AVFilter ff_vsrc_openclsrc
AVFormatContext * ctx
Definition: movenc.c:48
enum AVPixelFormat source_format
int ff_opencl_filter_load_program_from_file(AVFilterContext *avctx, const char *filename)
Load a new OpenCL program from a file.
Definition: opencl.c:219
void * opaque
Opaque pointer, not used by the API.
Definition: framesync.h:177
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
#define FF_ARRAY_ELEMS(a)
if(ret)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:368
Extend the frame to infinity.
Definition: framesync.h:75
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
Definition: framesync.c:77
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events...
Definition: framesync.h:139
Filter definition.
Definition: avfilter.h:144
Rational number (pair of numerator and denominator).
Definition: rational.h:58
offset must point to AVRational
Definition: opt.h:236
const char * name
Filter name.
Definition: avfilter.h:148
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
offset must point to two consecutive integers
Definition: opt.h:233
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
#define CL_FAIL_ON_ERROR(errcode,...)
A helper macro to handle OpenCL errors.
Definition: opencl.h:74
#define SIZE_SPECIFIER
Definition: internal.h:262
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:309
static int program_opencl_load(AVFilterContext *avctx)
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
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
static int query_formats(AVFilterContext *ctx)
Definition: aeval.c:244
AVFilter ff_vf_program_opencl
void ff_opencl_filter_uninit(AVFilterContext *avctx)
Uninitialise an OpenCL filter context.
Definition: opencl.c:156
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
Completely stop all streams with this one.
Definition: framesync.h:65
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:334
cl_context context
The OpenCL context which will contain all operations and frames on this device.
An instance of a filter.
Definition: avfilter.h:338
#define OFFSET(x)
int height
Definition: frame.h:353
#define av_freep(p)
cl_program program
Definition: opencl.h:43
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2438
internal API functions
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
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
Definition: framesync.c:256
static int program_opencl_filter(FFFrameSync *fs)
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:341
static int program_opencl_config_output(AVFilterLink *outlink)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:654
void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.c:191
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.
Definition: internal.h:277