47#define OFFSET(x) offsetof(RemapOpenCLContext, x)
48#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
65static 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);
241 if (xlink->
w != ylink->
w || xlink->
h != ylink->
h) {
243 "(size %dx%d) do not match the corresponding "
244 "third input link %s parameters (%dx%d)\n",
245 ctx->input_pads[1].name, xlink->
w, xlink->
h,
246 ctx->input_pads[2].name, ylink->
w, ylink->
h);
250 outlink->
w = xlink->
w;
251 outlink->
h = xlink->
h;
280 s->ocf.output_width = outlink->
w;
281 s->ocf.output_height = outlink->
h;
298 cle = clReleaseKernel(
ctx->kernel);
299 if (cle != CL_SUCCESS)
301 "kernel: %d.\n", cle);
304 if (
ctx->command_queue) {
305 cle = clReleaseCommandQueue(
ctx->command_queue);
306 if (cle != CL_SUCCESS)
308 "command queue: %d.\n", cle);
343 .p.name =
"remap_opencl",
345 .p.priv_class = &remap_opencl_class,
const FFFilter ff_vf_remap_opencl
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
#define fs(width, name, subs,...)
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
int(* init)(AVBSFContext *ctx)
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
@ EXT_INFINITY
Extend the frame to infinity.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
static FilterLink * ff_filter_link(AVFilterLink *link)
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
#define AVFILTER_DEFINE_CLASS(fname)
Various defines for YUV<->RGB conversion.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void ff_opencl_filter_uninit(AVFilterContext *avctx)
Uninitialise an OpenCL filter context.
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.
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.
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
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.
int ff_opencl_filter_config_output(AVFilterLink *outlink)
Create a suitable hardware frames context for the output.
#define CL_SET_KERNEL_ARG(kernel, arg_num, type, arg)
set argument to specific Kernel.
#define CL_FAIL_ON_ERROR(errcode,...)
A helper macro to handle OpenCL errors.
const char * ff_source_remap_cl
@ EXT_STOP
Completely stop all streams with this one.
@ EXT_NULL
Ignore this stream and continue processing the other ones.
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.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_OPENCL
Hardware surfaces for OpenCL.
uint8_t * data
The data buffer.
int plane
Which of the 4 planes contains the component.
void * priv
private data for use by the filter
AVFilterLink ** outputs
array of pointers to output links
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
This struct describes a set or pool of "hardware" frames (i.e.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
uint8_t nb_components
The number of components each pixel has, (1-4)
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
AVRational time_base
Time base for the incoming frames.
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events.
Link properties exposed to filter code, but not external callers.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
cl_command_queue command_queue
static AVFormatContext * ctx
#define RGB_TO_Y_BT709(r, g, b)
#define RGB_TO_U_BT709(r1, g1, b1, max)
#define RGB_TO_V_BT709(r1, g1, b1, max)
static av_cold int remap_opencl_init(AVFilterContext *avctx)
static int remap_opencl_process_frame(FFFrameSync *fs)
static int remap_opencl_load(AVFilterContext *avctx, enum AVPixelFormat main_format, enum AVPixelFormat xmap_format, enum AVPixelFormat ymap_format)
static const AVOption remap_opencl_options[]
static const AVFilterPad remap_opencl_inputs[]
static const AVFilterPad remap_opencl_outputs[]
static const char * kernels[]
static av_cold void remap_opencl_uninit(AVFilterContext *avctx)
static int activate(AVFilterContext *ctx)
static int config_output(AVFilterLink *outlink)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.