Go to the documentation of this file.
47 #define OFFSET(x) offsetof(RemapOpenCLContext, x)
48 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
65 static const char *
kernels[] = {
"remap_near",
"remap_linear" };
80 const float scale = 1.f / 255.f;
86 ctx->cl_fill_color.s[rgba_map[0]] =
ctx->fill_rgba[0] *
scale;
87 ctx->cl_fill_color.s[rgba_map[1]] =
ctx->fill_rgba[1] *
scale;
88 ctx->cl_fill_color.s[rgba_map[2]] =
ctx->fill_rgba[2] *
scale;
89 ctx->cl_fill_color.s[rgba_map[3]] =
ctx->fill_rgba[3] *
scale;
94 ctx->cl_fill_color.s[3] =
ctx->fill_rgba[3] *
scale;
101 main_planes =
FFMAX(main_planes,
104 ctx->nb_planes = main_planes;
110 ctx->command_queue = clCreateCommandQueue(
ctx->ocf.hwctx->context,
111 ctx->ocf.hwctx->device_id,
114 "command queue %d.\n", cle);
116 ctx->kernel = clCreateKernel(
ctx->ocf.program, kernel, &cle);
119 ctx->initialised = 1;
123 if (
ctx->command_queue)
124 clReleaseCommandQueue(
ctx->command_queue);
126 clReleaseKernel(
ctx->kernel);
135 AVFrame *input_main, *input_xmap, *input_ymap;
139 size_t global_work[2];
153 if (!
ctx->initialised) {
174 for (plane = 0; plane <
ctx->nb_planes; plane++) {
175 cl_float4 cl_fill_color;
178 if (
ctx->nb_planes == 1)
179 cl_fill_color =
ctx->cl_fill_color;
181 cl_fill_color.s[0] =
ctx->cl_fill_color.s[plane];
183 mem = (cl_mem)
output->data[plane];
187 mem = (cl_mem)input_main->
data[plane];
191 mem = (cl_mem)input_xmap->
data[0];
195 mem = (cl_mem)input_ymap->
data[0];
207 cle = clEnqueueNDRangeKernel(
ctx->command_queue,
ctx->kernel, 2,
NULL,
210 "for plane %d: %d.\n", plane, cle);
213 cle = clFinish(
ctx->command_queue);
239 if (xlink->
w != ylink->
w || xlink->
h != ylink->
h) {
241 "(size %dx%d) do not match the corresponding "
242 "third input link %s parameters (%dx%d)\n",
243 ctx->input_pads[1].name, xlink->
w, xlink->
h,
244 ctx->input_pads[2].name, ylink->
w, ylink->
h);
248 outlink->
w = xlink->
w;
249 outlink->
h = xlink->
h;
278 s->ocf.output_width = outlink->
w;
279 s->ocf.output_height = outlink->
h;
296 cle = clReleaseKernel(
ctx->kernel);
297 if (cle != CL_SUCCESS)
299 "kernel: %d.\n", cle);
302 if (
ctx->command_queue) {
303 cle = clReleaseCommandQueue(
ctx->command_queue);
304 if (cle != CL_SUCCESS)
306 "command queue: %d.\n", cle);
341 .
name =
"remap_opencl",
350 .priv_class = &remap_opencl_class,
static int remap_opencl_load(AVFilterContext *avctx, enum AVPixelFormat main_format, enum AVPixelFormat xmap_format, enum AVPixelFormat ymap_format)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
AVRational time_base
Time base for the incoming frames.
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
AVPixelFormat
Pixel format.
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.
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
#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)
uint8_t * data
The data buffer.
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
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
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.
static int activate(AVFilterContext *ctx)
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.
static int config_output(AVFilterLink *outlink)
const char * name
Filter name.
@ EXT_INFINITY
Extend the frame to infinity.
A link between two filters.
const char * ff_source_remap_cl
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
@ EXT_STOP
Completely stop all streams with this one.
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
@ EXT_NULL
Ignore this stream and continue processing the other ones.
static av_always_inline float scale(float x, float s)
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events.
static const AVOption remap_opencl_options[]
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.
static av_cold void remap_opencl_uninit(AVFilterContext *avctx)
#define RGB_TO_Y_BT709(r, g, b)
#define RGB_TO_U_BT709(r1, g1, b1, max)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
int(* init)(AVBSFContext *ctx)
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static const char * kernels[]
#define FILTER_INPUTS(array)
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.
#define fs(width, name, subs,...)
uint8_t nb_components
The number of components each pixel has, (1-4)
int plane
Which of the 4 planes contains the component.
@ AV_PIX_FMT_OPENCL
Hardware surfaces for OpenCL.
const AVFilter ff_vf_remap_opencl
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 the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a source
static int remap_opencl_process_frame(FFFrameSync *fs)
#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.
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
AVFilterContext * src
source filter
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_)
#define i(width, name, range_min, range_max)
int w
agreed upon image width
const char * name
Pad name.
This struct describes a set or pool of "hardware" frames (i.e.
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
static const AVFilterPad remap_opencl_inputs[]
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
int h
agreed upon image height
static const AVFilterPad remap_opencl_outputs[]
static av_cold int remap_opencl_init(AVFilterContext *avctx)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
void ff_opencl_filter_uninit(AVFilterContext *avctx)
Uninitialise an OpenCL filter context.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVFILTER_DEFINE_CLASS(remap_opencl)
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)
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
#define CL_FAIL_ON_ERROR(errcode,...)
A helper macro to handle OpenCL errors.
static av_cold int uninit(AVCodecContext *avctx)
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
cl_command_queue command_queue
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.
AVFilterLink ** outputs
array of pointers to output links