Browse code

lavu,lavfi,ffmpeg: Remove experimental OpenCL API

This was added in early 2013 and abandoned several months later; as far as
I can tell, there are no external users. Future OpenCL use will be via
hwcontext, which requires neither special OpenCL-only API nor global state
in libavutil.

All internal users are also deleted - this is just the unsharp filter
(replaced by unsharp_opencl, which is more flexible) and the deshake filter
(no replacement).

Mark Thompson authored on 2017/11/15 04:47:30
Showing 26 changed files
... ...
@@ -3209,7 +3209,6 @@ deinterlace_qsv_filter_deps="libmfx"
3209 3209
 deinterlace_vaapi_filter_deps="vaapi"
3210 3210
 delogo_filter_deps="gpl"
3211 3211
 deshake_filter_select="pixelutils"
3212
-deshake_filter_suggest="opencl"
3213 3212
 drawtext_filter_deps="libfreetype"
3214 3213
 drawtext_filter_suggest="libfontconfig libfribidi"
3215 3214
 elbg_filter_deps="avcodec"
... ...
@@ -3285,7 +3284,6 @@ tinterlace_pad_test_deps="tinterlace_filter"
3285 3285
 tonemap_filter_deps="const_nan"
3286 3286
 unsharp_opencl_filter_deps="opencl"
3287 3287
 uspp_filter_deps="gpl avcodec"
3288
-unsharp_filter_suggest="opencl"
3289 3288
 vaguedenoiser_filter_deps="gpl"
3290 3289
 vidstabdetect_filter_deps="libvidstab"
3291 3290
 vidstabtransform_filter_deps="libvidstab"
... ...
@@ -15,6 +15,9 @@ libavutil:     2017-10-21
15 15
 
16 16
 API changes, most recent first:
17 17
 
18
+2017-11-xx - xxxxxxx - lavu 55.3.0 - opencl.h
19
+  Remove experiental OpenCL API (av_opencl_*).
20
+
18 21
 2017-11-xx - xxxxxxx - lavu 55.2.0 - hwcontext.h hwcontext_opencl.h
19 22
   Add AV_HWDEVICE_TYPE_OPENCL and a new installed header with
20 23
   OpenCL-specific hwcontext definitions.
... ...
@@ -6913,10 +6913,6 @@ Default value is @samp{exhaustive}.
6913 6913
 If set then a detailed log of the motion search is written to the
6914 6914
 specified file.
6915 6915
 
6916
-@item opencl
6917
-If set to 1, specify using OpenCL capabilities, only available if
6918
-FFmpeg was configured with @code{--enable-opencl}. Default value is 0.
6919
-
6920 6916
 @end table
6921 6917
 
6922 6918
 @section despill
... ...
@@ -15048,10 +15044,6 @@ sharpen it, a value of zero will disable the effect.
15048 15048
 
15049 15049
 Default value is 0.0.
15050 15050
 
15051
-@item opencl
15052
-If set to 1, specify using OpenCL capabilities, only available if
15053
-FFmpeg was configured with @code{--enable-opencl}. Default value is 0.
15054
-
15055 15051
 @end table
15056 15052
 
15057 15053
 All parameters are optional and default to the equivalent of the
... ...
@@ -1057,33 +1057,3 @@ indication of the corresponding powers of 10 and of 2.
1057 1057
 @end table
1058 1058
 
1059 1059
 @c man end EXPRESSION EVALUATION
1060
-
1061
-@chapter OpenCL Options
1062
-@c man begin OPENCL OPTIONS
1063
-
1064
-When FFmpeg is configured with @code{--enable-opencl}, it is possible
1065
-to set the options for the global OpenCL context.
1066
-
1067
-The list of supported options follows:
1068
-
1069
-@table @option
1070
-@item build_options
1071
-Set build options used to compile the registered kernels.
1072
-
1073
-See reference "OpenCL Specification Version: 1.2 chapter 5.6.4".
1074
-
1075
-@item platform_idx
1076
-Select the index of the platform to run OpenCL code.
1077
-
1078
-The specified index must be one of the indexes in the device list
1079
-which can be obtained with @code{ffmpeg -opencl_bench} or @code{av_opencl_get_device_list()}.
1080
-
1081
-@item device_idx
1082
-Select the index of the device used to run OpenCL code.
1083
-
1084
-The specified index must be one of the indexes in the device list which
1085
-can be obtained with @code{ffmpeg -opencl_bench} or @code{av_opencl_get_device_list()}.
1086
-
1087
-@end table
1088
-
1089
-@c man end OPENCL OPTIONS
... ...
@@ -29,7 +29,6 @@ $(1)$(PROGSSUF)_g$(EXESUF): FF_EXTRALIBS += $(EXTRALIBS-$(1))
29 29
 -include $$(OBJS-$(1):.o=.d)
30 30
 endef
31 31
 
32
-$(foreach P,$(AVPROGS-yes),$(eval OBJS-$(P)-$(CONFIG_OPENCL) += fftools/cmdutils_opencl.o))
33 32
 $(foreach P,$(AVPROGS-yes),$(eval $(call DOFFTOOL,$(P))))
34 33
 
35 34
 all: $(AVPROGS)
... ...
@@ -105,12 +105,6 @@ int opt_max_alloc(void *optctx, const char *opt, const char *arg);
105 105
 
106 106
 int opt_codec_debug(void *optctx, const char *opt, const char *arg);
107 107
 
108
-#if CONFIG_OPENCL
109
-int opt_opencl(void *optctx, const char *opt, const char *arg);
110
-
111
-int opt_opencl_bench(void *optctx, const char *opt, const char *arg);
112
-#endif
113
-
114 108
 /**
115 109
  * Limit the execution time.
116 110
  */
... ...
@@ -207,17 +201,6 @@ typedef struct OptionDef {
207 207
 void show_help_options(const OptionDef *options, const char *msg, int req_flags,
208 208
                        int rej_flags, int alt_flags);
209 209
 
210
-#if CONFIG_OPENCL
211
-#define CMDUTILS_COMMON_OPTIONS_OPENCL                                                                                  \
212
-    { "opencl_bench", OPT_EXIT, {.func_arg = opt_opencl_bench},                                                         \
213
-       "run benchmark on all OpenCL devices and show results" },                                                        \
214
-    { "opencl_options", HAS_ARG, {.func_arg = opt_opencl},                                                              \
215
-       "set OpenCL environment options" },                                                                              \
216
-
217
-#else
218
-#define CMDUTILS_COMMON_OPTIONS_OPENCL
219
-#endif
220
-
221 210
 #if CONFIG_AVDEVICE
222 211
 #define CMDUTILS_COMMON_OPTIONS_AVDEVICE                                                                                \
223 212
     { "sources"    , OPT_EXIT | HAS_ARG, { .func_arg = show_sources },                                                  \
... ...
@@ -257,7 +240,6 @@ void show_help_options(const OptionDef *options, const char *msg, int req_flags,
257 257
     { "max_alloc",   HAS_ARG,              { .func_arg = opt_max_alloc },    "set maximum size of a single allocated block", "bytes" }, \
258 258
     { "cpuflags",    HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags },     "force specific cpu flags", "flags" },     \
259 259
     { "hide_banner", OPT_BOOL | OPT_EXPERT, {&hide_banner},     "do not show program banner", "hide_banner" },          \
260
-    CMDUTILS_COMMON_OPTIONS_OPENCL                                                                                      \
261 260
     CMDUTILS_COMMON_OPTIONS_AVDEVICE                                                                                    \
262 261
 
263 262
 /**
264 263
deleted file mode 100644
... ...
@@ -1,283 +0,0 @@
1
-/*
2
- * Copyright (C) 2013 Lenny Wang
3
- *
4
- * This file is part of FFmpeg.
5
- *
6
- * FFmpeg is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2.1 of the License, or (at your option) any later version.
10
- *
11
- * FFmpeg is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public
17
- * License along with FFmpeg; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
- */
20
-
21
-#include "libavutil/opt.h"
22
-#include "libavutil/time.h"
23
-#include "libavutil/log.h"
24
-#include "libavutil/opencl.h"
25
-#include "libavutil/avstring.h"
26
-#include "cmdutils.h"
27
-
28
-typedef struct {
29
-    int platform_idx;
30
-    int device_idx;
31
-    char device_name[64];
32
-    int64_t runtime;
33
-} OpenCLDeviceBenchmark;
34
-
35
-const char *ocl_bench_source = AV_OPENCL_KERNEL(
36
-inline unsigned char clip_uint8(int a)
37
-{
38
-    if (a & (~0xFF))
39
-        return (-a)>>31;
40
-    else
41
-        return a;
42
-}
43
-
44
-kernel void unsharp_bench(
45
-                    global unsigned char *src,
46
-                    global unsigned char *dst,
47
-                    global int *mask,
48
-                    int width,
49
-                    int height)
50
-{
51
-    int i, j, local_idx, lc_idx, sum = 0;
52
-    int2 thread_idx, block_idx, global_idx, lm_idx;
53
-    thread_idx.x = get_local_id(0);
54
-    thread_idx.y = get_local_id(1);
55
-    block_idx.x = get_group_id(0);
56
-    block_idx.y = get_group_id(1);
57
-    global_idx.x = get_global_id(0);
58
-    global_idx.y = get_global_id(1);
59
-    local uchar data[32][32];
60
-    local int lc[128];
61
-
62
-    for (i = 0; i <= 1; i++) {
63
-        lm_idx.y = -8 + (block_idx.y + i) * 16 + thread_idx.y;
64
-        lm_idx.y = lm_idx.y < 0 ? 0 : lm_idx.y;
65
-        lm_idx.y = lm_idx.y >= height ? height - 1: lm_idx.y;
66
-        for (j = 0; j <= 1; j++) {
67
-            lm_idx.x = -8 + (block_idx.x + j) * 16 + thread_idx.x;
68
-            lm_idx.x = lm_idx.x < 0 ? 0 : lm_idx.x;
69
-            lm_idx.x = lm_idx.x >= width ? width - 1: lm_idx.x;
70
-            data[i*16 + thread_idx.y][j*16 + thread_idx.x] = src[lm_idx.y*width + lm_idx.x];
71
-        }
72
-    }
73
-    local_idx = thread_idx.y*16 + thread_idx.x;
74
-    if (local_idx < 128)
75
-        lc[local_idx] = mask[local_idx];
76
-    barrier(CLK_LOCAL_MEM_FENCE);
77
-
78
-    \n#pragma unroll\n
79
-    for (i = -4; i <= 4; i++) {
80
-        lm_idx.y = 8 + i + thread_idx.y;
81
-        \n#pragma unroll\n
82
-        for (j = -4; j <= 4; j++) {
83
-            lm_idx.x = 8 + j + thread_idx.x;
84
-            lc_idx = (i + 4)*8 + j + 4;
85
-            sum += (int)data[lm_idx.y][lm_idx.x] * lc[lc_idx];
86
-        }
87
-    }
88
-    int temp = (int)data[thread_idx.y + 8][thread_idx.x + 8];
89
-    int res = temp + (((temp - (int)((sum + 1<<15) >> 16))) >> 16);
90
-    if (global_idx.x < width && global_idx.y < height)
91
-        dst[global_idx.x + global_idx.y*width] = clip_uint8(res);
92
-}
93
-);
94
-
95
-#define OCLCHECK(method, ... )                                                 \
96
-do {                                                                           \
97
-    status = method(__VA_ARGS__);                                              \
98
-    if (status != CL_SUCCESS) {                                                \
99
-        av_log(NULL, AV_LOG_ERROR, # method " error '%s'\n",                   \
100
-               av_opencl_errstr(status));                                      \
101
-        ret = AVERROR_EXTERNAL;                                                \
102
-        goto end;                                                              \
103
-    }                                                                          \
104
-} while (0)
105
-
106
-#define CREATEBUF(out, flags, size)                                            \
107
-do {                                                                           \
108
-    out = clCreateBuffer(ext_opencl_env->context, flags, size, NULL, &status); \
109
-    if (status != CL_SUCCESS) {                                                \
110
-        av_log(NULL, AV_LOG_ERROR, "Could not create OpenCL buffer\n");        \
111
-        ret = AVERROR_EXTERNAL;                                                \
112
-        goto end;                                                              \
113
-    }                                                                          \
114
-} while (0)
115
-
116
-static void fill_rand_int(int *data, int n)
117
-{
118
-    int i;
119
-    srand(av_gettime());
120
-    for (i = 0; i < n; i++)
121
-        data[i] = rand();
122
-}
123
-
124
-#define OPENCL_NB_ITER 5
125
-static int64_t run_opencl_bench(AVOpenCLExternalEnv *ext_opencl_env)
126
-{
127
-    int i, arg = 0, width = 1920, height = 1088;
128
-    int64_t start, ret = 0;
129
-    cl_int status;
130
-    size_t kernel_len;
131
-    char *inbuf;
132
-    int *mask = NULL;
133
-    int buf_size = width * height * sizeof(char);
134
-    int mask_size = sizeof(uint32_t) * 128;
135
-
136
-    cl_mem cl_mask = NULL, cl_inbuf = NULL, cl_outbuf = NULL;
137
-    cl_kernel kernel = NULL;
138
-    cl_program program = NULL;
139
-    size_t local_work_size_2d[2] = {16, 16};
140
-    size_t global_work_size_2d[2] = {(size_t)width, (size_t)height};
141
-
142
-    if (!(inbuf = av_malloc(buf_size)) || !(mask = av_malloc(mask_size))) {
143
-        av_log(NULL, AV_LOG_ERROR, "Out of memory\n");
144
-        ret = AVERROR(ENOMEM);
145
-        goto end;
146
-    }
147
-    fill_rand_int((int*)inbuf, buf_size/4);
148
-    fill_rand_int(mask, mask_size/4);
149
-
150
-    CREATEBUF(cl_mask, CL_MEM_READ_ONLY, mask_size);
151
-    CREATEBUF(cl_inbuf, CL_MEM_READ_ONLY, buf_size);
152
-    CREATEBUF(cl_outbuf, CL_MEM_READ_WRITE, buf_size);
153
-
154
-    kernel_len = strlen(ocl_bench_source);
155
-    program = clCreateProgramWithSource(ext_opencl_env->context, 1, &ocl_bench_source,
156
-                                        &kernel_len, &status);
157
-    if (status != CL_SUCCESS || !program) {
158
-        av_log(NULL, AV_LOG_ERROR, "OpenCL unable to create benchmark program\n");
159
-        ret = AVERROR_EXTERNAL;
160
-        goto end;
161
-    }
162
-    status = clBuildProgram(program, 1, &(ext_opencl_env->device_id), NULL, NULL, NULL);
163
-    if (status != CL_SUCCESS) {
164
-        av_log(NULL, AV_LOG_ERROR, "OpenCL unable to build benchmark program\n");
165
-        ret = AVERROR_EXTERNAL;
166
-        goto end;
167
-    }
168
-    kernel = clCreateKernel(program, "unsharp_bench", &status);
169
-    if (status != CL_SUCCESS) {
170
-        av_log(NULL, AV_LOG_ERROR, "OpenCL unable to create benchmark kernel\n");
171
-        ret = AVERROR_EXTERNAL;
172
-        goto end;
173
-    }
174
-
175
-    OCLCHECK(clEnqueueWriteBuffer, ext_opencl_env->command_queue, cl_inbuf, CL_TRUE, 0,
176
-             buf_size, inbuf, 0, NULL, NULL);
177
-    OCLCHECK(clEnqueueWriteBuffer, ext_opencl_env->command_queue, cl_mask, CL_TRUE, 0,
178
-             mask_size, mask, 0, NULL, NULL);
179
-    OCLCHECK(clSetKernelArg, kernel, arg++, sizeof(cl_mem), &cl_inbuf);
180
-    OCLCHECK(clSetKernelArg, kernel, arg++, sizeof(cl_mem), &cl_outbuf);
181
-    OCLCHECK(clSetKernelArg, kernel, arg++, sizeof(cl_mem), &cl_mask);
182
-    OCLCHECK(clSetKernelArg, kernel, arg++, sizeof(cl_int), &width);
183
-    OCLCHECK(clSetKernelArg, kernel, arg++, sizeof(cl_int), &height);
184
-
185
-    start = av_gettime_relative();
186
-    for (i = 0; i < OPENCL_NB_ITER; i++)
187
-        OCLCHECK(clEnqueueNDRangeKernel, ext_opencl_env->command_queue, kernel, 2, NULL,
188
-                 global_work_size_2d, local_work_size_2d, 0, NULL, NULL);
189
-    clFinish(ext_opencl_env->command_queue);
190
-    ret = (av_gettime_relative() - start)/OPENCL_NB_ITER;
191
-end:
192
-    if (kernel)
193
-        clReleaseKernel(kernel);
194
-    if (program)
195
-        clReleaseProgram(program);
196
-    if (cl_inbuf)
197
-        clReleaseMemObject(cl_inbuf);
198
-    if (cl_outbuf)
199
-        clReleaseMemObject(cl_outbuf);
200
-    if (cl_mask)
201
-        clReleaseMemObject(cl_mask);
202
-    av_free(inbuf);
203
-    av_free(mask);
204
-    return ret;
205
-}
206
-
207
-static int compare_ocl_device_desc(const void *a, const void *b)
208
-{
209
-    const OpenCLDeviceBenchmark* va = (const OpenCLDeviceBenchmark*)a;
210
-    const OpenCLDeviceBenchmark* vb = (const OpenCLDeviceBenchmark*)b;
211
-    return FFDIFFSIGN(va->runtime , vb->runtime);
212
-}
213
-
214
-int opt_opencl_bench(void *optctx, const char *opt, const char *arg)
215
-{
216
-    int i, j, nb_devices = 0, count = 0, ret = 0;
217
-    int64_t score = 0;
218
-    AVOpenCLDeviceList *device_list;
219
-    AVOpenCLDeviceNode *device_node = NULL;
220
-    OpenCLDeviceBenchmark *devices = NULL;
221
-    cl_platform_id platform;
222
-
223
-    ret = av_opencl_get_device_list(&device_list);
224
-    if (ret < 0) {
225
-        return ret;
226
-    }
227
-    for (i = 0; i < device_list->platform_num; i++)
228
-        nb_devices += device_list->platform_node[i]->device_num;
229
-    if (!nb_devices) {
230
-        av_log(NULL, AV_LOG_ERROR, "No OpenCL device detected!\n");
231
-        av_opencl_free_device_list(&device_list);
232
-        return AVERROR(EINVAL);
233
-    }
234
-    if (!(devices = av_malloc_array(nb_devices, sizeof(OpenCLDeviceBenchmark)))) {
235
-        av_log(NULL, AV_LOG_ERROR, "Could not allocate buffer\n");
236
-        av_opencl_free_device_list(&device_list);
237
-        return AVERROR(ENOMEM);
238
-    }
239
-
240
-    for (i = 0; i < device_list->platform_num; i++) {
241
-        for (j = 0; j < device_list->platform_node[i]->device_num; j++) {
242
-            device_node = device_list->platform_node[i]->device_node[j];
243
-            platform = device_list->platform_node[i]->platform_id;
244
-            score = av_opencl_benchmark(device_node, platform, run_opencl_bench);
245
-            if (score > 0) {
246
-                devices[count].platform_idx = i;
247
-                devices[count].device_idx = j;
248
-                devices[count].runtime = score;
249
-                av_strlcpy(devices[count].device_name, device_node->device_name,
250
-                           sizeof(devices[count].device_name));
251
-                count++;
252
-            }
253
-        }
254
-    }
255
-    qsort(devices, count, sizeof(OpenCLDeviceBenchmark), compare_ocl_device_desc);
256
-    fprintf(stderr, "platform_idx\tdevice_idx\tdevice_name\truntime\n");
257
-    for (i = 0; i < count; i++)
258
-        fprintf(stdout, "%d\t%d\t%s\t%"PRId64"\n",
259
-                devices[i].platform_idx, devices[i].device_idx,
260
-                devices[i].device_name, devices[i].runtime);
261
-
262
-    av_opencl_free_device_list(&device_list);
263
-    av_free(devices);
264
-    return 0;
265
-}
266
-
267
-int opt_opencl(void *optctx, const char *opt, const char *arg)
268
-{
269
-    char *key, *value;
270
-    const char *opts = arg;
271
-    int ret = 0;
272
-    while (*opts) {
273
-        ret = av_opt_get_key_value(&opts, "=", ":", 0, &key, &value);
274
-        if (ret < 0)
275
-            return ret;
276
-        ret = av_opencl_set_option(key, value);
277
-        if (ret < 0)
278
-            return ret;
279
-        if (*opts)
280
-            opts++;
281
-    }
282
-    return ret;
283
-}
... ...
@@ -19,7 +19,6 @@ OBJS = allfilters.o                                                     \
19 19
        framequeue.o                                                     \
20 20
        graphdump.o                                                      \
21 21
        graphparser.o                                                    \
22
-       opencl_allkernels.o                                              \
23 22
        transform.o                                                      \
24 23
        video.o                                                          \
25 24
 
... ...
@@ -250,7 +249,6 @@ OBJS-$(CONFIG_NOISE_FILTER)                  += vf_noise.o
250 250
 OBJS-$(CONFIG_NULL_FILTER)                   += vf_null.o
251 251
 OBJS-$(CONFIG_OCR_FILTER)                    += vf_ocr.o
252 252
 OBJS-$(CONFIG_OCV_FILTER)                    += vf_libopencv.o
253
-OBJS-$(CONFIG_OPENCL)                        += deshake_opencl.o unsharp_opencl.o
254 253
 OBJS-$(CONFIG_OSCILLOSCOPE_FILTER)           += vf_datascope.o
255 254
 OBJS-$(CONFIG_OVERLAY_FILTER)                += vf_overlay.o framesync.o
256 255
 OBJS-$(CONFIG_OVERLAY_OPENCL_FILTER)         += vf_overlay_opencl.o opencl.o \
... ...
@@ -396,7 +394,6 @@ OBJS-$(CONFIG_MOVIE_FILTER)                  += src_movie.o
396 396
 SLIBOBJS-$(HAVE_GNU_WINDRES)                 += avfilterres.o
397 397
 
398 398
 SKIPHEADERS-$(CONFIG_LIBVIDSTAB)             += vidstabutils.h
399
-SKIPHEADERS-$(CONFIG_OPENCL)                 += opencl_internal.h deshake_opencl_kernel.h unsharp_opencl_kernel.h
400 399
 
401 400
 OBJS-$(CONFIG_SHARED)                        += log2_tab.o
402 401
 
... ...
@@ -22,7 +22,6 @@
22 22
 #include "libavutil/thread.h"
23 23
 #include "avfilter.h"
24 24
 #include "config.h"
25
-#include "opencl_allkernels.h"
26 25
 
27 26
 
28 27
 #define REGISTER_FILTER(X, x, y)                                        \
... ...
@@ -407,7 +406,6 @@ static void register_all(void)
407 407
     REGISTER_FILTER_UNCONDITIONAL(vsink_buffer);
408 408
     REGISTER_FILTER_UNCONDITIONAL(af_afifo);
409 409
     REGISTER_FILTER_UNCONDITIONAL(vf_fifo);
410
-    ff_opencl_register_filter_kernel_code_all();
411 410
 }
412 411
 
413 412
 void avfilter_register_all(void)
... ...
@@ -26,9 +26,6 @@
26 26
 #include "avfilter.h"
27 27
 #include "transform.h"
28 28
 #include "libavutil/pixelutils.h"
29
-#if CONFIG_OPENCL
30
-#include "libavutil/opencl.h"
31
-#endif
32 29
 
33 30
 
34 31
 enum SearchMethod {
... ...
@@ -53,24 +50,6 @@ typedef struct Transform {
53 53
     double zoom;          ///< Zoom percentage
54 54
 } Transform;
55 55
 
56
-#if CONFIG_OPENCL
57
-
58
-typedef struct DeshakeOpenclContext {
59
-    cl_command_queue command_queue;
60
-    cl_program program;
61
-    cl_kernel kernel_luma;
62
-    cl_kernel kernel_chroma;
63
-    int in_plane_size[8];
64
-    int out_plane_size[8];
65
-    int plane_num;
66
-    cl_mem cl_inbuf;
67
-    size_t cl_inbuf_size;
68
-    cl_mem cl_outbuf;
69
-    size_t cl_outbuf_size;
70
-} DeshakeOpenclContext;
71
-
72
-#endif
73
-
74 56
 #define MAX_R 64
75 57
 
76 58
 typedef struct DeshakeContext {
... ...
@@ -96,9 +75,6 @@ typedef struct DeshakeContext {
96 96
     int cy;
97 97
     char *filename;            ///< Motion search detailed log filename
98 98
     int opencl;
99
-#if CONFIG_OPENCL
100
-    DeshakeOpenclContext opencl_ctx;
101
-#endif
102 99
     int (* transform)(AVFilterContext *ctx, int width, int height, int cw, int ch,
103 100
                       const float *matrix_y, const float *matrix_uv, enum InterpolateMethod interpolate,
104 101
                       enum FillMethod fill, AVFrame *in, AVFrame *out);
105 102
deleted file mode 100644
... ...
@@ -1,198 +0,0 @@
1
-/*
2
- * Copyright (C) 2013 Wei Gao <weigao@multicorewareinc.com>
3
- * Copyright (C) 2013 Lenny Wang
4
- *
5
- * This file is part of FFmpeg.
6
- *
7
- * FFmpeg is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * FFmpeg is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with FFmpeg; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- */
21
-
22
-/**
23
- * @file
24
- * transform input video
25
- */
26
-
27
-#include "libavutil/common.h"
28
-#include "libavutil/dict.h"
29
-#include "libavutil/pixdesc.h"
30
-#include "deshake_opencl.h"
31
-#include "libavutil/opencl_internal.h"
32
-
33
-#define PLANE_NUM 3
34
-#define ROUND_TO_16(a) (((((a) - 1)/16)+1)*16)
35
-
36
-int ff_opencl_transform(AVFilterContext *ctx,
37
-                        int width, int height, int cw, int ch,
38
-                        const float *matrix_y, const float *matrix_uv,
39
-                        enum InterpolateMethod interpolate,
40
-                        enum FillMethod fill, AVFrame *in, AVFrame *out)
41
-{
42
-    int ret = 0;
43
-    cl_int status;
44
-    DeshakeContext *deshake = ctx->priv;
45
-    float4 packed_matrix_lu = {matrix_y[0], matrix_y[1], matrix_y[2], matrix_y[5]};
46
-    float4 packed_matrix_ch = {matrix_uv[0], matrix_uv[1], matrix_uv[2], matrix_uv[5]};
47
-    size_t global_worksize_lu[2] = {(size_t)ROUND_TO_16(width), (size_t)ROUND_TO_16(height)};
48
-    size_t global_worksize_ch[2] = {(size_t)ROUND_TO_16(cw), (size_t)(2*ROUND_TO_16(ch))};
49
-    size_t local_worksize[2] = {16, 16};
50
-    FFOpenclParam param_lu = {0};
51
-    FFOpenclParam param_ch = {0};
52
-    param_lu.ctx = param_ch.ctx = ctx;
53
-    param_lu.kernel = deshake->opencl_ctx.kernel_luma;
54
-    param_ch.kernel = deshake->opencl_ctx.kernel_chroma;
55
-
56
-    if ((unsigned int)interpolate > INTERPOLATE_BIQUADRATIC) {
57
-        av_log(ctx, AV_LOG_ERROR, "Selected interpolate method is invalid\n");
58
-        return AVERROR(EINVAL);
59
-    }
60
-    ret = avpriv_opencl_set_parameter(&param_lu,
61
-                                  FF_OPENCL_PARAM_INFO(deshake->opencl_ctx.cl_inbuf),
62
-                                  FF_OPENCL_PARAM_INFO(deshake->opencl_ctx.cl_outbuf),
63
-                                  FF_OPENCL_PARAM_INFO(packed_matrix_lu),
64
-                                  FF_OPENCL_PARAM_INFO(interpolate),
65
-                                  FF_OPENCL_PARAM_INFO(fill),
66
-                                  FF_OPENCL_PARAM_INFO(in->linesize[0]),
67
-                                  FF_OPENCL_PARAM_INFO(out->linesize[0]),
68
-                                  FF_OPENCL_PARAM_INFO(height),
69
-                                  FF_OPENCL_PARAM_INFO(width),
70
-                                  NULL);
71
-    if (ret < 0)
72
-        return ret;
73
-    ret = avpriv_opencl_set_parameter(&param_ch,
74
-                                  FF_OPENCL_PARAM_INFO(deshake->opencl_ctx.cl_inbuf),
75
-                                  FF_OPENCL_PARAM_INFO(deshake->opencl_ctx.cl_outbuf),
76
-                                  FF_OPENCL_PARAM_INFO(packed_matrix_ch),
77
-                                  FF_OPENCL_PARAM_INFO(interpolate),
78
-                                  FF_OPENCL_PARAM_INFO(fill),
79
-                                  FF_OPENCL_PARAM_INFO(in->linesize[0]),
80
-                                  FF_OPENCL_PARAM_INFO(out->linesize[0]),
81
-                                  FF_OPENCL_PARAM_INFO(in->linesize[1]),
82
-                                  FF_OPENCL_PARAM_INFO(out->linesize[1]),
83
-                                  FF_OPENCL_PARAM_INFO(height),
84
-                                  FF_OPENCL_PARAM_INFO(width),
85
-                                  FF_OPENCL_PARAM_INFO(ch),
86
-                                  FF_OPENCL_PARAM_INFO(cw),
87
-                                  NULL);
88
-    if (ret < 0)
89
-        return ret;
90
-    status = clEnqueueNDRangeKernel(deshake->opencl_ctx.command_queue,
91
-                                    deshake->opencl_ctx.kernel_luma, 2, NULL,
92
-                                    global_worksize_lu, local_worksize, 0, NULL, NULL);
93
-    status |= clEnqueueNDRangeKernel(deshake->opencl_ctx.command_queue,
94
-                                    deshake->opencl_ctx.kernel_chroma, 2, NULL,
95
-                                    global_worksize_ch, local_worksize, 0, NULL, NULL);
96
-    if (status != CL_SUCCESS) {
97
-        av_log(ctx, AV_LOG_ERROR, "OpenCL run kernel error occurred: %s\n", av_opencl_errstr(status));
98
-        return AVERROR_EXTERNAL;
99
-    }
100
-    ret = av_opencl_buffer_read_image(out->data, deshake->opencl_ctx.out_plane_size,
101
-                                      deshake->opencl_ctx.plane_num, deshake->opencl_ctx.cl_outbuf,
102
-                                      deshake->opencl_ctx.cl_outbuf_size);
103
-    if (ret < 0)
104
-        return ret;
105
-    return ret;
106
-}
107
-
108
-int ff_opencl_deshake_init(AVFilterContext *ctx)
109
-{
110
-    int ret = 0;
111
-    DeshakeContext *deshake = ctx->priv;
112
-    ret = av_opencl_init(NULL);
113
-    if (ret < 0)
114
-        return ret;
115
-    deshake->opencl_ctx.plane_num = PLANE_NUM;
116
-    deshake->opencl_ctx.command_queue = av_opencl_get_command_queue();
117
-    if (!deshake->opencl_ctx.command_queue) {
118
-        av_log(ctx, AV_LOG_ERROR, "Unable to get OpenCL command queue in filter 'deshake'\n");
119
-        return AVERROR(EINVAL);
120
-    }
121
-    deshake->opencl_ctx.program = av_opencl_compile("avfilter_transform", NULL);
122
-    if (!deshake->opencl_ctx.program) {
123
-        av_log(ctx, AV_LOG_ERROR, "OpenCL failed to compile program 'avfilter_transform'\n");
124
-        return AVERROR(EINVAL);
125
-    }
126
-    if (!deshake->opencl_ctx.kernel_luma) {
127
-        deshake->opencl_ctx.kernel_luma = clCreateKernel(deshake->opencl_ctx.program,
128
-                                                         "avfilter_transform_luma", &ret);
129
-        if (ret != CL_SUCCESS) {
130
-            av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel 'avfilter_transform_luma'\n");
131
-            return AVERROR(EINVAL);
132
-        }
133
-    }
134
-    if (!deshake->opencl_ctx.kernel_chroma) {
135
-        deshake->opencl_ctx.kernel_chroma = clCreateKernel(deshake->opencl_ctx.program,
136
-                                                           "avfilter_transform_chroma", &ret);
137
-        if (ret != CL_SUCCESS) {
138
-            av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel 'avfilter_transform_chroma'\n");
139
-            return AVERROR(EINVAL);
140
-        }
141
-    }
142
-    return ret;
143
-}
144
-
145
-void ff_opencl_deshake_uninit(AVFilterContext *ctx)
146
-{
147
-    DeshakeContext *deshake = ctx->priv;
148
-    av_opencl_buffer_release(&deshake->opencl_ctx.cl_inbuf);
149
-    av_opencl_buffer_release(&deshake->opencl_ctx.cl_outbuf);
150
-    clReleaseKernel(deshake->opencl_ctx.kernel_luma);
151
-    clReleaseKernel(deshake->opencl_ctx.kernel_chroma);
152
-    clReleaseProgram(deshake->opencl_ctx.program);
153
-    deshake->opencl_ctx.command_queue = NULL;
154
-    av_opencl_uninit();
155
-}
156
-
157
-int ff_opencl_deshake_process_inout_buf(AVFilterContext *ctx, AVFrame *in, AVFrame *out)
158
-{
159
-    int ret = 0;
160
-    AVFilterLink *link = ctx->inputs[0];
161
-    DeshakeContext *deshake = ctx->priv;
162
-    const int hshift = av_pix_fmt_desc_get(link->format)->log2_chroma_h;
163
-    int chroma_height = AV_CEIL_RSHIFT(link->h, hshift);
164
-
165
-    if ((!deshake->opencl_ctx.cl_inbuf) || (!deshake->opencl_ctx.cl_outbuf)) {
166
-        deshake->opencl_ctx.in_plane_size[0]  = (in->linesize[0] * in->height);
167
-        deshake->opencl_ctx.in_plane_size[1]  = (in->linesize[1] * chroma_height);
168
-        deshake->opencl_ctx.in_plane_size[2]  = (in->linesize[2] * chroma_height);
169
-        deshake->opencl_ctx.out_plane_size[0] = (out->linesize[0] * out->height);
170
-        deshake->opencl_ctx.out_plane_size[1] = (out->linesize[1] * chroma_height);
171
-        deshake->opencl_ctx.out_plane_size[2] = (out->linesize[2] * chroma_height);
172
-        deshake->opencl_ctx.cl_inbuf_size  = deshake->opencl_ctx.in_plane_size[0] +
173
-                                             deshake->opencl_ctx.in_plane_size[1] +
174
-                                             deshake->opencl_ctx.in_plane_size[2];
175
-        deshake->opencl_ctx.cl_outbuf_size = deshake->opencl_ctx.out_plane_size[0] +
176
-                                             deshake->opencl_ctx.out_plane_size[1] +
177
-                                             deshake->opencl_ctx.out_plane_size[2];
178
-        if (!deshake->opencl_ctx.cl_inbuf) {
179
-            ret = av_opencl_buffer_create(&deshake->opencl_ctx.cl_inbuf,
180
-                                            deshake->opencl_ctx.cl_inbuf_size,
181
-                                            CL_MEM_READ_ONLY, NULL);
182
-            if (ret < 0)
183
-                return ret;
184
-        }
185
-        if (!deshake->opencl_ctx.cl_outbuf) {
186
-            ret = av_opencl_buffer_create(&deshake->opencl_ctx.cl_outbuf,
187
-                                            deshake->opencl_ctx.cl_outbuf_size,
188
-                                            CL_MEM_READ_WRITE, NULL);
189
-            if (ret < 0)
190
-                return ret;
191
-        }
192
-    }
193
-    ret = av_opencl_buffer_write_image(deshake->opencl_ctx.cl_inbuf,
194
-                                 deshake->opencl_ctx.cl_inbuf_size,
195
-                                 0, in->data,deshake->opencl_ctx.in_plane_size,
196
-                                 deshake->opencl_ctx.plane_num);
197
-    return ret;
198
-}
199 1
deleted file mode 100644
... ...
@@ -1,45 +0,0 @@
1
-/*
2
- * Copyright (C) 2013 Wei Gao <weigao@multicorewareinc.com>
3
- *
4
- * This file is part of FFmpeg.
5
- *
6
- * FFmpeg is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2.1 of the License, or (at your option) any later version.
10
- *
11
- * FFmpeg is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public
17
- * License along with FFmpeg; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
- */
20
-
21
-#ifndef AVFILTER_DESHAKE_OPENCL_H
22
-#define AVFILTER_DESHAKE_OPENCL_H
23
-
24
-#include "deshake.h"
25
-
26
-typedef struct float4 {
27
-    float x;
28
-    float y;
29
-    float z;
30
-    float w;
31
-} float4;
32
-
33
-int ff_opencl_deshake_init(AVFilterContext *ctx);
34
-
35
-void ff_opencl_deshake_uninit(AVFilterContext *ctx);
36
-
37
-int ff_opencl_deshake_process_inout_buf(AVFilterContext *ctx, AVFrame *in, AVFrame *out);
38
-
39
-int ff_opencl_transform(AVFilterContext *ctx,
40
-                        int width, int height, int cw, int ch,
41
-                        const float *matrix_y, const float *matrix_uv,
42
-                        enum InterpolateMethod interpolate,
43
-                        enum FillMethod fill, AVFrame *in, AVFrame *out);
44
-
45
-#endif /* AVFILTER_DESHAKE_OPENCL_H */
46 1
deleted file mode 100644
... ...
@@ -1,225 +0,0 @@
1
-/*
2
- * Copyright (C) 2013 Wei Gao <weigao@multicorewareinc.com>
3
- * Copyright (C) 2013 Lenny Wang
4
- *
5
- *
6
- * This file is part of FFmpeg.
7
- *
8
- * FFmpeg is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU Lesser General Public
10
- * License as published by the Free Software Foundation; either
11
- * version 2.1 of the License, or (at your option) any later version.
12
- *
13
- * FFmpeg is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
- * Lesser General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU Lesser General Public
19
- * License along with FFmpeg; if not, write to the Free Software
20
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
- */
22
-
23
-#ifndef AVFILTER_DESHAKE_OPENCL_KERNEL_H
24
-#define AVFILTER_DESHAKE_OPENCL_KERNEL_H
25
-
26
-#include "libavutil/opencl.h"
27
-
28
-const char *ff_kernel_deshake_opencl = AV_OPENCL_KERNEL(
29
-inline unsigned char pixel(global const unsigned char *src, int x, int y,
30
-                           int w, int h,int stride, unsigned char def)
31
-{
32
-    return (x < 0 || y < 0 || x >= w || y >= h) ? def : src[x + y * stride];
33
-}
34
-
35
-unsigned char interpolate_nearest(float x, float y, global const unsigned char *src,
36
-                                  int width, int height, int stride, unsigned char def)
37
-{
38
-    return pixel(src, (int)(x + 0.5f), (int)(y + 0.5f), width, height, stride, def);
39
-}
40
-
41
-unsigned char interpolate_bilinear(float x, float y, global const unsigned char *src,
42
-                                   int width, int height, int stride, unsigned char def)
43
-{
44
-    int x_c, x_f, y_c, y_f;
45
-    int v1, v2, v3, v4;
46
-    x_f = (int)x;
47
-    y_f = (int)y;
48
-    x_c = x_f + 1;
49
-    y_c = y_f + 1;
50
-
51
-    if (x_f < -1 || x_f > width || y_f < -1 || y_f > height) {
52
-        return def;
53
-    } else {
54
-        v4 = pixel(src, x_f, y_f, width, height, stride, def);
55
-        v2 = pixel(src, x_c, y_f, width, height, stride, def);
56
-        v3 = pixel(src, x_f, y_c, width, height, stride, def);
57
-        v1 = pixel(src, x_c, y_c, width, height, stride, def);
58
-        return (v1*(x - x_f)*(y - y_f) + v2*((x - x_f)*(y_c - y)) +
59
-                v3*(x_c - x)*(y - y_f) + v4*((x_c - x)*(y_c - y)));
60
-    }
61
-}
62
-
63
-unsigned char interpolate_biquadratic(float x, float y, global const unsigned char *src,
64
-                                      int width, int height, int stride, unsigned char def)
65
-{
66
-    int     x_c, x_f, y_c, y_f;
67
-    unsigned char v1,  v2,  v3,  v4;
68
-    float   f1,  f2,  f3,  f4;
69
-    x_f = (int)x;
70
-    y_f = (int)y;
71
-    x_c = x_f + 1;
72
-    y_c = y_f + 1;
73
-
74
-    if (x_f < - 1 || x_f > width || y_f < -1 || y_f > height)
75
-        return def;
76
-    else {
77
-        v4 = pixel(src, x_f, y_f, width, height, stride, def);
78
-        v2 = pixel(src, x_c, y_f, width, height, stride, def);
79
-        v3 = pixel(src, x_f, y_c, width, height, stride, def);
80
-        v1 = pixel(src, x_c, y_c, width, height, stride, def);
81
-
82
-        f1 = 1 - sqrt((x_c - x) * (y_c - y));
83
-        f2 = 1 - sqrt((x_c - x) * (y - y_f));
84
-        f3 = 1 - sqrt((x - x_f) * (y_c - y));
85
-        f4 = 1 - sqrt((x - x_f) * (y - y_f));
86
-        return (v1 * f1 + v2 * f2 + v3 * f3 + v4 * f4) / (f1 + f2 + f3 + f4);
87
-    }
88
-}
89
-
90
-inline const float clipf(float a, float amin, float amax)
91
-{
92
-    if      (a < amin) return amin;
93
-    else if (a > amax) return amax;
94
-    else               return a;
95
-}
96
-
97
-inline int mirror(int v, int m)
98
-{
99
-    while ((unsigned)v > (unsigned)m) {
100
-        v = -v;
101
-        if (v < 0)
102
-            v += 2 * m;
103
-    }
104
-    return v;
105
-}
106
-
107
-kernel void avfilter_transform_luma(global unsigned char *src,
108
-                                    global unsigned char *dst,
109
-                                    float4 matrix,
110
-                                    int interpolate,
111
-                                    int fill,
112
-                                    int src_stride_lu,
113
-                                    int dst_stride_lu,
114
-                                    int height,
115
-                                    int width)
116
-{
117
-    int x = get_global_id(0);
118
-    int y = get_global_id(1);
119
-    int idx_dst = y * dst_stride_lu + x;
120
-    unsigned char def = 0;
121
-    float x_s = x * matrix.x + y * matrix.y + matrix.z;
122
-    float y_s = x * (-matrix.y) + y * matrix.x + matrix.w;
123
-
124
-    if (x < width && y < height) {
125
-        switch (fill) {
126
-            case 0: //FILL_BLANK
127
-                def = 0;
128
-                break;
129
-            case 1: //FILL_ORIGINAL
130
-                def = src[y*src_stride_lu + x];
131
-                break;
132
-            case 2: //FILL_CLAMP
133
-                y_s = clipf(y_s, 0, height - 1);
134
-                x_s = clipf(x_s, 0, width - 1);
135
-                def = src[(int)y_s * src_stride_lu + (int)x_s];
136
-                break;
137
-            case 3: //FILL_MIRROR
138
-                y_s = mirror(y_s, height - 1);
139
-                x_s = mirror(x_s, width - 1);
140
-                def = src[(int)y_s * src_stride_lu + (int)x_s];
141
-                break;
142
-        }
143
-        switch (interpolate) {
144
-            case 0: //INTERPOLATE_NEAREST
145
-                dst[idx_dst] = interpolate_nearest(x_s, y_s, src, width, height, src_stride_lu, def);
146
-                break;
147
-            case 1: //INTERPOLATE_BILINEAR
148
-                dst[idx_dst] = interpolate_bilinear(x_s, y_s, src, width, height, src_stride_lu, def);
149
-                break;
150
-            case 2: //INTERPOLATE_BIQUADRATIC
151
-                dst[idx_dst] = interpolate_biquadratic(x_s, y_s, src, width, height, src_stride_lu, def);
152
-                break;
153
-            default:
154
-                return;
155
-        }
156
-    }
157
-}
158
-
159
-kernel void avfilter_transform_chroma(global unsigned char *src,
160
-                                      global unsigned char *dst,
161
-                                      float4 matrix,
162
-                                      int interpolate,
163
-                                      int fill,
164
-                                      int src_stride_lu,
165
-                                      int dst_stride_lu,
166
-                                      int src_stride_ch,
167
-                                      int dst_stride_ch,
168
-                                      int height,
169
-                                      int width,
170
-                                      int ch,
171
-                                      int cw)
172
-{
173
-
174
-    int x = get_global_id(0);
175
-    int y = get_global_id(1);
176
-    int pad_ch = get_global_size(1)>>1;
177
-    global unsigned char *dst_u = dst + height * dst_stride_lu;
178
-    global unsigned char *src_u = src + height * src_stride_lu;
179
-    global unsigned char *dst_v = dst_u + ch * dst_stride_ch;
180
-    global unsigned char *src_v = src_u + ch * src_stride_ch;
181
-    src = y < pad_ch ? src_u : src_v;
182
-    dst = y < pad_ch ? dst_u : dst_v;
183
-    y = select(y - pad_ch, y, y < pad_ch);
184
-    float x_s = x * matrix.x + y * matrix.y + matrix.z;
185
-    float y_s = x * (-matrix.y) + y * matrix.x + matrix.w;
186
-    int idx_dst = y * dst_stride_ch + x;
187
-    unsigned char def;
188
-
189
-    if (x < cw && y < ch) {
190
-        switch (fill) {
191
-            case 0: //FILL_BLANK
192
-                def = 0;
193
-                break;
194
-            case 1: //FILL_ORIGINAL
195
-                def = src[y*src_stride_ch + x];
196
-                break;
197
-            case 2: //FILL_CLAMP
198
-                y_s = clipf(y_s, 0, ch - 1);
199
-                x_s = clipf(x_s, 0, cw - 1);
200
-                def = src[(int)y_s * src_stride_ch + (int)x_s];
201
-                break;
202
-            case 3: //FILL_MIRROR
203
-                y_s = mirror(y_s, ch - 1);
204
-                x_s = mirror(x_s, cw - 1);
205
-                def = src[(int)y_s * src_stride_ch + (int)x_s];
206
-                break;
207
-        }
208
-        switch (interpolate) {
209
-            case 0: //INTERPOLATE_NEAREST
210
-                dst[idx_dst] = interpolate_nearest(x_s, y_s, src, cw, ch, src_stride_ch, def);
211
-                break;
212
-            case 1: //INTERPOLATE_BILINEAR
213
-                dst[idx_dst] = interpolate_bilinear(x_s, y_s, src, cw, ch, src_stride_ch, def);
214
-                break;
215
-            case 2: //INTERPOLATE_BIQUADRATIC
216
-                dst[idx_dst] = interpolate_biquadratic(x_s, y_s, src, cw, ch, src_stride_ch, def);
217
-                break;
218
-            default:
219
-                return;
220
-        }
221
-    }
222
-}
223
-);
224
-
225
-#endif /* AVFILTER_DESHAKE_OPENCL_KERNEL_H */
226 1
deleted file mode 100644
... ...
@@ -1,41 +0,0 @@
1
-/*
2
- * Copyright (C) 2013 Wei Gao <weigao@multicorewareinc.com>
3
- *
4
- * This file is part of FFmpeg.
5
- *
6
- * FFmpeg is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2.1 of the License, or (at your option) any later version.
10
- *
11
- * FFmpeg is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public
17
- * License along with FFmpeg; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
- */
20
-
21
-#include "opencl_allkernels.h"
22
-#if CONFIG_OPENCL
23
-#include "libavutil/opencl.h"
24
-#include "deshake_opencl_kernel.h"
25
-#include "unsharp_opencl_kernel.h"
26
-#endif
27
-
28
-#define OPENCL_REGISTER_KERNEL_CODE(X, x)                                              \
29
-    {                                                                                  \
30
-        if (CONFIG_##X##_FILTER) {                                                     \
31
-            av_opencl_register_kernel_code(ff_kernel_##x##_opencl);                    \
32
-        }                                                                              \
33
-    }
34
-
35
-void ff_opencl_register_filter_kernel_code_all(void)
36
-{
37
- #if CONFIG_OPENCL
38
-   OPENCL_REGISTER_KERNEL_CODE(DESHAKE,     deshake);
39
-   OPENCL_REGISTER_KERNEL_CODE(UNSHARP,     unsharp);
40
- #endif
41
-}
42 1
deleted file mode 100644
... ...
@@ -1,29 +0,0 @@
1
-/*
2
- * Copyright (C) 2013 Wei Gao <weigao@multicorewareinc.com>
3
- *
4
- * This file is part of FFmpeg.
5
- *
6
- * FFmpeg is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2.1 of the License, or (at your option) any later version.
10
- *
11
- * FFmpeg is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public
17
- * License along with FFmpeg; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
- */
20
-
21
-#ifndef AVFILTER_OPENCL_ALLKERNELS_H
22
-#define AVFILTER_OPENCL_ALLKERNELS_H
23
-
24
-#include "avfilter.h"
25
-#include "config.h"
26
-
27
-void ff_opencl_register_filter_kernel_code_all(void);
28
-
29
-#endif /* AVFILTER_OPENCL_ALLKERNELS_H */
... ...
@@ -24,38 +24,10 @@
24 24
 
25 25
 #include "config.h"
26 26
 #include "avfilter.h"
27
-#if CONFIG_OPENCL
28
-#include "libavutil/opencl.h"
29
-#endif
30 27
 
31 28
 #define MIN_MATRIX_SIZE 3
32 29
 #define MAX_MATRIX_SIZE 63
33 30
 
34
-#if CONFIG_OPENCL
35
-
36
-typedef struct UnsharpOpenclContext {
37
-    cl_command_queue command_queue;
38
-    cl_program program;
39
-    cl_kernel kernel_default;
40
-    cl_kernel kernel_luma;
41
-    cl_kernel kernel_chroma;
42
-    cl_mem cl_luma_mask;
43
-    cl_mem cl_chroma_mask;
44
-    cl_mem cl_luma_mask_x;
45
-    cl_mem cl_chroma_mask_x;
46
-    cl_mem cl_luma_mask_y;
47
-    cl_mem cl_chroma_mask_y;
48
-    int in_plane_size[8];
49
-    int out_plane_size[8];
50
-    int plane_num;
51
-    cl_mem cl_inbuf;
52
-    size_t cl_inbuf_size;
53
-    cl_mem cl_outbuf;
54
-    size_t cl_outbuf_size;
55
-    int use_fast_kernels;
56
-} UnsharpOpenclContext;
57
-
58
-#endif
59 31
 
60 32
 typedef struct UnsharpFilterParam {
61 33
     int msize_x;                             ///< matrix width
... ...
@@ -76,9 +48,6 @@ typedef struct UnsharpContext {
76 76
     UnsharpFilterParam chroma; ///< chroma parameters (width, height, amount)
77 77
     int hsub, vsub;
78 78
     int opencl;
79
-#if CONFIG_OPENCL
80
-    UnsharpOpenclContext opencl_ctx;
81
-#endif
82 79
     int (* apply_unsharp)(AVFilterContext *ctx, AVFrame *in, AVFrame *out);
83 80
 } UnsharpContext;
84 81
 
85 82
deleted file mode 100644
... ...
@@ -1,422 +0,0 @@
1
-/*
2
- * Copyright (C) 2013 Wei Gao <weigao@multicorewareinc.com>
3
- * Copyright (C) 2013 Lenny Wang
4
- *
5
- * This file is part of FFmpeg.
6
- *
7
- * FFmpeg is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * FFmpeg is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with FFmpeg; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- */
21
-
22
-/**
23
- * @file
24
- * unsharp input video
25
- */
26
-
27
-#include "unsharp_opencl.h"
28
-#include "libavutil/common.h"
29
-#include "libavutil/opencl_internal.h"
30
-
31
-#define PLANE_NUM 3
32
-#define ROUND_TO_16(a) (((((a) - 1)/16)+1)*16)
33
-
34
-static inline void add_mask_counter(uint32_t *dst, uint32_t *counter1, uint32_t *counter2, int len)
35
-{
36
-    int i;
37
-    for (i = 0; i < len; i++) {
38
-        dst[i] = counter1[i] + counter2[i];
39
-    }
40
-}
41
-
42
-static int compute_mask(int step, uint32_t *mask)
43
-{
44
-    int i, z, ret = 0;
45
-    int counter_size = sizeof(uint32_t) * (2 * step + 1);
46
-    uint32_t *temp1_counter, *temp2_counter, **counter = NULL;
47
-    temp1_counter = av_mallocz(counter_size);
48
-    if (!temp1_counter) {
49
-        ret = AVERROR(ENOMEM);
50
-        goto end;
51
-    }
52
-    temp2_counter = av_mallocz(counter_size);
53
-    if (!temp2_counter) {
54
-        ret = AVERROR(ENOMEM);
55
-        goto end;
56
-    }
57
-    counter = av_mallocz_array(2 * step + 1, sizeof(uint32_t *));
58
-    if (!counter) {
59
-        ret = AVERROR(ENOMEM);
60
-        goto end;
61
-    }
62
-    for (i = 0; i < 2 * step + 1; i++) {
63
-        counter[i] = av_mallocz(counter_size);
64
-        if (!counter[i]) {
65
-            ret = AVERROR(ENOMEM);
66
-            goto end;
67
-        }
68
-    }
69
-    for (i = 0; i < 2 * step + 1; i++) {
70
-        memset(temp1_counter, 0, counter_size);
71
-        temp1_counter[i] = 1;
72
-        for (z = 0; z < step * 2; z += 2) {
73
-            add_mask_counter(temp2_counter, counter[z], temp1_counter, step * 2);
74
-            memcpy(counter[z], temp1_counter, counter_size);
75
-            add_mask_counter(temp1_counter, counter[z + 1], temp2_counter, step * 2);
76
-            memcpy(counter[z + 1], temp2_counter, counter_size);
77
-        }
78
-    }
79
-    memcpy(mask, temp1_counter, counter_size);
80
-end:
81
-    av_freep(&temp1_counter);
82
-    av_freep(&temp2_counter);
83
-    for (i = 0; counter && i < 2 * step + 1; i++) {
84
-        av_freep(&counter[i]);
85
-    }
86
-    av_freep(&counter);
87
-    return ret;
88
-}
89
-
90
-static int copy_separable_masks(cl_mem cl_mask_x, cl_mem cl_mask_y, int step_x, int step_y)
91
-{
92
-    int ret = 0;
93
-    uint32_t *mask_x, *mask_y;
94
-    size_t size_mask_x = sizeof(uint32_t) * (2 * step_x + 1);
95
-    size_t size_mask_y = sizeof(uint32_t) * (2 * step_y + 1);
96
-    mask_x = av_mallocz_array(2 * step_x + 1, sizeof(uint32_t));
97
-    if (!mask_x) {
98
-        ret = AVERROR(ENOMEM);
99
-        goto end;
100
-    }
101
-    mask_y = av_mallocz_array(2 * step_y + 1, sizeof(uint32_t));
102
-    if (!mask_y) {
103
-        ret = AVERROR(ENOMEM);
104
-        goto end;
105
-    }
106
-
107
-    ret = compute_mask(step_x, mask_x);
108
-    if (ret < 0)
109
-        goto end;
110
-    ret = compute_mask(step_y, mask_y);
111
-    if (ret < 0)
112
-        goto end;
113
-
114
-    ret = av_opencl_buffer_write(cl_mask_x, (uint8_t *)mask_x, size_mask_x);
115
-    ret = av_opencl_buffer_write(cl_mask_y, (uint8_t *)mask_y, size_mask_y);
116
-end:
117
-    av_freep(&mask_x);
118
-    av_freep(&mask_y);
119
-
120
-    return ret;
121
-}
122
-
123
-static int generate_mask(AVFilterContext *ctx)
124
-{
125
-    cl_mem masks[4];
126
-    cl_mem mask_matrix[2];
127
-    int i, ret = 0, step_x[2], step_y[2];
128
-
129
-    UnsharpContext *unsharp = ctx->priv;
130
-    mask_matrix[0] = unsharp->opencl_ctx.cl_luma_mask;
131
-    mask_matrix[1] = unsharp->opencl_ctx.cl_chroma_mask;
132
-    masks[0] = unsharp->opencl_ctx.cl_luma_mask_x;
133
-    masks[1] = unsharp->opencl_ctx.cl_luma_mask_y;
134
-    masks[2] = unsharp->opencl_ctx.cl_chroma_mask_x;
135
-    masks[3] = unsharp->opencl_ctx.cl_chroma_mask_y;
136
-    step_x[0] = unsharp->luma.steps_x;
137
-    step_x[1] = unsharp->chroma.steps_x;
138
-    step_y[0] = unsharp->luma.steps_y;
139
-    step_y[1] = unsharp->chroma.steps_y;
140
-
141
-    /* use default kernel if any matrix dim larger than 8 due to limited local mem size */
142
-    if (step_x[0]>8 || step_x[1]>8 || step_y[0]>8 || step_y[1]>8)
143
-        unsharp->opencl_ctx.use_fast_kernels = 0;
144
-    else
145
-        unsharp->opencl_ctx.use_fast_kernels = 1;
146
-
147
-    if (!masks[0] || !masks[1] || !masks[2] || !masks[3]) {
148
-        av_log(ctx, AV_LOG_ERROR, "Luma mask and chroma mask should not be NULL\n");
149
-        return AVERROR(EINVAL);
150
-    }
151
-    if (!mask_matrix[0] || !mask_matrix[1]) {
152
-        av_log(ctx, AV_LOG_ERROR, "Luma mask and chroma mask should not be NULL\n");
153
-        return AVERROR(EINVAL);
154
-    }
155
-    for (i = 0; i < 2; i++) {
156
-        ret = copy_separable_masks(masks[2*i], masks[2*i+1], step_x[i], step_y[i]);
157
-        if (ret < 0)
158
-            return ret;
159
-    }
160
-    return ret;
161
-}
162
-
163
-int ff_opencl_apply_unsharp(AVFilterContext *ctx, AVFrame *in, AVFrame *out)
164
-{
165
-    int ret;
166
-    AVFilterLink *link = ctx->inputs[0];
167
-    UnsharpContext *unsharp = ctx->priv;
168
-    cl_int status;
169
-    FFOpenclParam kernel1 = {0};
170
-    FFOpenclParam kernel2 = {0};
171
-    int width = link->w;
172
-    int height = link->h;
173
-    int cw = AV_CEIL_RSHIFT(link->w, unsharp->hsub);
174
-    int ch = AV_CEIL_RSHIFT(link->h, unsharp->vsub);
175
-    size_t globalWorkSize1d = width * height + 2 * ch * cw;
176
-    size_t globalWorkSize2dLuma[2];
177
-    size_t globalWorkSize2dChroma[2];
178
-    size_t localWorkSize2d[2] = {16, 16};
179
-
180
-    if (unsharp->opencl_ctx.use_fast_kernels) {
181
-        globalWorkSize2dLuma[0] = (size_t)ROUND_TO_16(width);
182
-        globalWorkSize2dLuma[1] = (size_t)ROUND_TO_16(height);
183
-        globalWorkSize2dChroma[0] = (size_t)ROUND_TO_16(cw);
184
-        globalWorkSize2dChroma[1] = (size_t)(2*ROUND_TO_16(ch));
185
-
186
-        kernel1.ctx = ctx;
187
-        kernel1.kernel = unsharp->opencl_ctx.kernel_luma;
188
-        ret = avpriv_opencl_set_parameter(&kernel1,
189
-                                      FF_OPENCL_PARAM_INFO(unsharp->opencl_ctx.cl_inbuf),
190
-                                      FF_OPENCL_PARAM_INFO(unsharp->opencl_ctx.cl_outbuf),
191
-                                      FF_OPENCL_PARAM_INFO(unsharp->opencl_ctx.cl_luma_mask_x),
192
-                                      FF_OPENCL_PARAM_INFO(unsharp->opencl_ctx.cl_luma_mask_y),
193
-                                      FF_OPENCL_PARAM_INFO(unsharp->luma.amount),
194
-                                      FF_OPENCL_PARAM_INFO(unsharp->luma.scalebits),
195
-                                      FF_OPENCL_PARAM_INFO(unsharp->luma.halfscale),
196
-                                      FF_OPENCL_PARAM_INFO(in->linesize[0]),
197
-                                      FF_OPENCL_PARAM_INFO(out->linesize[0]),
198
-                                      FF_OPENCL_PARAM_INFO(width),
199
-                                      FF_OPENCL_PARAM_INFO(height),
200
-                                      NULL);
201
-        if (ret < 0)
202
-            return ret;
203
-
204
-        kernel2.ctx = ctx;
205
-        kernel2.kernel = unsharp->opencl_ctx.kernel_chroma;
206
-        ret = avpriv_opencl_set_parameter(&kernel2,
207
-                                      FF_OPENCL_PARAM_INFO(unsharp->opencl_ctx.cl_inbuf),
208
-                                      FF_OPENCL_PARAM_INFO(unsharp->opencl_ctx.cl_outbuf),
209
-                                      FF_OPENCL_PARAM_INFO(unsharp->opencl_ctx.cl_chroma_mask_x),
210
-                                      FF_OPENCL_PARAM_INFO(unsharp->opencl_ctx.cl_chroma_mask_y),
211
-                                      FF_OPENCL_PARAM_INFO(unsharp->chroma.amount),
212
-                                      FF_OPENCL_PARAM_INFO(unsharp->chroma.scalebits),
213
-                                      FF_OPENCL_PARAM_INFO(unsharp->chroma.halfscale),
214
-                                      FF_OPENCL_PARAM_INFO(in->linesize[0]),
215
-                                      FF_OPENCL_PARAM_INFO(in->linesize[1]),
216
-                                      FF_OPENCL_PARAM_INFO(out->linesize[0]),
217
-                                      FF_OPENCL_PARAM_INFO(out->linesize[1]),
218
-                                      FF_OPENCL_PARAM_INFO(link->w),
219
-                                      FF_OPENCL_PARAM_INFO(link->h),
220
-                                      FF_OPENCL_PARAM_INFO(cw),
221
-                                      FF_OPENCL_PARAM_INFO(ch),
222
-                                      NULL);
223
-        if (ret < 0)
224
-            return ret;
225
-        status = clEnqueueNDRangeKernel(unsharp->opencl_ctx.command_queue,
226
-                                        unsharp->opencl_ctx.kernel_luma, 2, NULL,
227
-                                        globalWorkSize2dLuma, localWorkSize2d, 0, NULL, NULL);
228
-        status |=clEnqueueNDRangeKernel(unsharp->opencl_ctx.command_queue,
229
-                                        unsharp->opencl_ctx.kernel_chroma, 2, NULL,
230
-                                        globalWorkSize2dChroma, localWorkSize2d, 0, NULL, NULL);
231
-        if (status != CL_SUCCESS) {
232
-            av_log(ctx, AV_LOG_ERROR, "OpenCL run kernel error occurred: %s\n", av_opencl_errstr(status));
233
-            return AVERROR_EXTERNAL;
234
-        }
235
-    } else {    /* use default kernel */
236
-        kernel1.ctx = ctx;
237
-        kernel1.kernel = unsharp->opencl_ctx.kernel_default;
238
-
239
-        ret = avpriv_opencl_set_parameter(&kernel1,
240
-                                      FF_OPENCL_PARAM_INFO(unsharp->opencl_ctx.cl_inbuf),
241
-                                      FF_OPENCL_PARAM_INFO(unsharp->opencl_ctx.cl_outbuf),
242
-                                      FF_OPENCL_PARAM_INFO(unsharp->opencl_ctx.cl_luma_mask),
243
-                                      FF_OPENCL_PARAM_INFO(unsharp->opencl_ctx.cl_chroma_mask),
244
-                                      FF_OPENCL_PARAM_INFO(unsharp->luma.amount),
245
-                                      FF_OPENCL_PARAM_INFO(unsharp->chroma.amount),
246
-                                      FF_OPENCL_PARAM_INFO(unsharp->luma.steps_x),
247
-                                      FF_OPENCL_PARAM_INFO(unsharp->luma.steps_y),
248
-                                      FF_OPENCL_PARAM_INFO(unsharp->chroma.steps_x),
249
-                                      FF_OPENCL_PARAM_INFO(unsharp->chroma.steps_y),
250
-                                      FF_OPENCL_PARAM_INFO(unsharp->luma.scalebits),
251
-                                      FF_OPENCL_PARAM_INFO(unsharp->chroma.scalebits),
252
-                                      FF_OPENCL_PARAM_INFO(unsharp->luma.halfscale),
253
-                                      FF_OPENCL_PARAM_INFO(unsharp->chroma.halfscale),
254
-                                      FF_OPENCL_PARAM_INFO(in->linesize[0]),
255
-                                      FF_OPENCL_PARAM_INFO(in->linesize[1]),
256
-                                      FF_OPENCL_PARAM_INFO(out->linesize[0]),
257
-                                      FF_OPENCL_PARAM_INFO(out->linesize[1]),
258
-                                      FF_OPENCL_PARAM_INFO(link->h),
259
-                                      FF_OPENCL_PARAM_INFO(link->w),
260
-                                      FF_OPENCL_PARAM_INFO(ch),
261
-                                      FF_OPENCL_PARAM_INFO(cw),
262
-                                      NULL);
263
-        if (ret < 0)
264
-            return ret;
265
-        status = clEnqueueNDRangeKernel(unsharp->opencl_ctx.command_queue,
266
-                                        unsharp->opencl_ctx.kernel_default, 1, NULL,
267
-                                        &globalWorkSize1d, NULL, 0, NULL, NULL);
268
-        if (status != CL_SUCCESS) {
269
-            av_log(ctx, AV_LOG_ERROR, "OpenCL run kernel error occurred: %s\n", av_opencl_errstr(status));
270
-            return AVERROR_EXTERNAL;
271
-        }
272
-    }
273
-    //blocking map is suffficient, no need for clFinish
274
-    //clFinish(unsharp->opencl_ctx.command_queue);
275
-
276
-    return av_opencl_buffer_read_image(out->data, unsharp->opencl_ctx.out_plane_size,
277
-                                       unsharp->opencl_ctx.plane_num, unsharp->opencl_ctx.cl_outbuf,
278
-                                       unsharp->opencl_ctx.cl_outbuf_size);
279
-}
280
-
281
-int ff_opencl_unsharp_init(AVFilterContext *ctx)
282
-{
283
-    int ret = 0;
284
-    char build_opts[96];
285
-    UnsharpContext *unsharp = ctx->priv;
286
-    ret = av_opencl_init(NULL);
287
-    if (ret < 0)
288
-        return ret;
289
-    ret = av_opencl_buffer_create(&unsharp->opencl_ctx.cl_luma_mask,
290
-                                  sizeof(uint32_t) * (2 * unsharp->luma.steps_x + 1) * (2 * unsharp->luma.steps_y + 1),
291
-                                  CL_MEM_READ_ONLY, NULL);
292
-    if (ret < 0)
293
-        return ret;
294
-    ret = av_opencl_buffer_create(&unsharp->opencl_ctx.cl_chroma_mask,
295
-                                  sizeof(uint32_t) * (2 * unsharp->chroma.steps_x + 1) * (2 * unsharp->chroma.steps_y + 1),
296
-                                  CL_MEM_READ_ONLY, NULL);
297
-    // separable filters
298
-    if (ret < 0)
299
-        return ret;
300
-    ret = av_opencl_buffer_create(&unsharp->opencl_ctx.cl_luma_mask_x,
301
-                                  sizeof(uint32_t) * (2 * unsharp->luma.steps_x + 1),
302
-                                  CL_MEM_READ_ONLY, NULL);
303
-    if (ret < 0)
304
-        return ret;
305
-    ret = av_opencl_buffer_create(&unsharp->opencl_ctx.cl_luma_mask_y,
306
-                                  sizeof(uint32_t) * (2 * unsharp->luma.steps_y + 1),
307
-                                  CL_MEM_READ_ONLY, NULL);
308
-    if (ret < 0)
309
-        return ret;
310
-    ret = av_opencl_buffer_create(&unsharp->opencl_ctx.cl_chroma_mask_x,
311
-                                  sizeof(uint32_t) * (2 * unsharp->chroma.steps_x + 1),
312
-                                  CL_MEM_READ_ONLY, NULL);
313
-    if (ret < 0)
314
-        return ret;
315
-    ret = av_opencl_buffer_create(&unsharp->opencl_ctx.cl_chroma_mask_y,
316
-                                  sizeof(uint32_t) * (2 * unsharp->chroma.steps_y + 1),
317
-                                  CL_MEM_READ_ONLY, NULL);
318
-    if (ret < 0)
319
-        return ret;
320
-    ret = generate_mask(ctx);
321
-    if (ret < 0)
322
-        return ret;
323
-    unsharp->opencl_ctx.plane_num = PLANE_NUM;
324
-    unsharp->opencl_ctx.command_queue = av_opencl_get_command_queue();
325
-    if (!unsharp->opencl_ctx.command_queue) {
326
-        av_log(ctx, AV_LOG_ERROR, "Unable to get OpenCL command queue in filter 'unsharp'\n");
327
-        return AVERROR(EINVAL);
328
-    }
329
-    snprintf(build_opts, 96, "-D LU_RADIUS_X=%d -D LU_RADIUS_Y=%d -D CH_RADIUS_X=%d -D CH_RADIUS_Y=%d",
330
-            2*unsharp->luma.steps_x+1, 2*unsharp->luma.steps_y+1, 2*unsharp->chroma.steps_x+1, 2*unsharp->chroma.steps_y+1);
331
-    unsharp->opencl_ctx.program = av_opencl_compile("unsharp", build_opts);
332
-    if (!unsharp->opencl_ctx.program) {
333
-        av_log(ctx, AV_LOG_ERROR, "OpenCL failed to compile program 'unsharp'\n");
334
-        return AVERROR(EINVAL);
335
-    }
336
-    if (unsharp->opencl_ctx.use_fast_kernels) {
337
-        if (!unsharp->opencl_ctx.kernel_luma) {
338
-            unsharp->opencl_ctx.kernel_luma = clCreateKernel(unsharp->opencl_ctx.program, "unsharp_luma", &ret);
339
-            if (ret != CL_SUCCESS) {
340
-                av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel 'unsharp_luma'\n");
341
-                return ret;
342
-            }
343
-        }
344
-        if (!unsharp->opencl_ctx.kernel_chroma) {
345
-            unsharp->opencl_ctx.kernel_chroma = clCreateKernel(unsharp->opencl_ctx.program, "unsharp_chroma", &ret);
346
-            if (ret < 0) {
347
-                av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel 'unsharp_chroma'\n");
348
-                return ret;
349
-            }
350
-        }
351
-    }
352
-    else {
353
-        if (!unsharp->opencl_ctx.kernel_default) {
354
-            unsharp->opencl_ctx.kernel_default = clCreateKernel(unsharp->opencl_ctx.program, "unsharp_default", &ret);
355
-            if (ret < 0) {
356
-                av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel 'unsharp_default'\n");
357
-                return ret;
358
-            }
359
-        }
360
-    }
361
-    return ret;
362
-}
363
-
364
-void ff_opencl_unsharp_uninit(AVFilterContext *ctx)
365
-{
366
-    UnsharpContext *unsharp = ctx->priv;
367
-    av_opencl_buffer_release(&unsharp->opencl_ctx.cl_inbuf);
368
-    av_opencl_buffer_release(&unsharp->opencl_ctx.cl_outbuf);
369
-    av_opencl_buffer_release(&unsharp->opencl_ctx.cl_luma_mask);
370
-    av_opencl_buffer_release(&unsharp->opencl_ctx.cl_chroma_mask);
371
-    av_opencl_buffer_release(&unsharp->opencl_ctx.cl_luma_mask_x);
372
-    av_opencl_buffer_release(&unsharp->opencl_ctx.cl_chroma_mask_x);
373
-    av_opencl_buffer_release(&unsharp->opencl_ctx.cl_luma_mask_y);
374
-    av_opencl_buffer_release(&unsharp->opencl_ctx.cl_chroma_mask_y);
375
-    clReleaseKernel(unsharp->opencl_ctx.kernel_default);
376
-    clReleaseKernel(unsharp->opencl_ctx.kernel_luma);
377
-    clReleaseKernel(unsharp->opencl_ctx.kernel_chroma);
378
-    clReleaseProgram(unsharp->opencl_ctx.program);
379
-    unsharp->opencl_ctx.command_queue = NULL;
380
-    av_opencl_uninit();
381
-}
382
-
383
-int ff_opencl_unsharp_process_inout_buf(AVFilterContext *ctx, AVFrame *in, AVFrame *out)
384
-{
385
-    int ret = 0;
386
-    AVFilterLink *link = ctx->inputs[0];
387
-    UnsharpContext *unsharp = ctx->priv;
388
-    int ch = AV_CEIL_RSHIFT(link->h, unsharp->vsub);
389
-
390
-    if ((!unsharp->opencl_ctx.cl_inbuf) || (!unsharp->opencl_ctx.cl_outbuf)) {
391
-        unsharp->opencl_ctx.in_plane_size[0]  = (in->linesize[0] * in->height);
392
-        unsharp->opencl_ctx.in_plane_size[1]  = (in->linesize[1] * ch);
393
-        unsharp->opencl_ctx.in_plane_size[2]  = (in->linesize[2] * ch);
394
-        unsharp->opencl_ctx.out_plane_size[0] = (out->linesize[0] * out->height);
395
-        unsharp->opencl_ctx.out_plane_size[1] = (out->linesize[1] * ch);
396
-        unsharp->opencl_ctx.out_plane_size[2] = (out->linesize[2] * ch);
397
-        unsharp->opencl_ctx.cl_inbuf_size  = unsharp->opencl_ctx.in_plane_size[0] +
398
-                                             unsharp->opencl_ctx.in_plane_size[1] +
399
-                                             unsharp->opencl_ctx.in_plane_size[2];
400
-        unsharp->opencl_ctx.cl_outbuf_size = unsharp->opencl_ctx.out_plane_size[0] +
401
-                                             unsharp->opencl_ctx.out_plane_size[1] +
402
-                                             unsharp->opencl_ctx.out_plane_size[2];
403
-        if (!unsharp->opencl_ctx.cl_inbuf) {
404
-            ret = av_opencl_buffer_create(&unsharp->opencl_ctx.cl_inbuf,
405
-                                          unsharp->opencl_ctx.cl_inbuf_size,
406
-                                          CL_MEM_READ_ONLY, NULL);
407
-            if (ret < 0)
408
-                return ret;
409
-        }
410
-        if (!unsharp->opencl_ctx.cl_outbuf) {
411
-            ret = av_opencl_buffer_create(&unsharp->opencl_ctx.cl_outbuf,
412
-                                          unsharp->opencl_ctx.cl_outbuf_size,
413
-                                          CL_MEM_READ_WRITE, NULL);
414
-            if (ret < 0)
415
-                return ret;
416
-        }
417
-    }
418
-    return av_opencl_buffer_write_image(unsharp->opencl_ctx.cl_inbuf,
419
-                                        unsharp->opencl_ctx.cl_inbuf_size,
420
-                                        0, in->data, unsharp->opencl_ctx.in_plane_size,
421
-                                        unsharp->opencl_ctx.plane_num);
422
-}
423 1
deleted file mode 100644
... ...
@@ -1,34 +0,0 @@
1
-/*
2
- * Copyright (C) 2013 Wei Gao <weigao@multicorewareinc.com>
3
- *
4
- * This file is part of FFmpeg.
5
- *
6
- * FFmpeg is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2.1 of the License, or (at your option) any later version.
10
- *
11
- * FFmpeg is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public
17
- * License along with FFmpeg; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
- */
20
-
21
-#ifndef AVFILTER_UNSHARP_OPENCL_H
22
-#define AVFILTER_UNSHARP_OPENCL_H
23
-
24
-#include "unsharp.h"
25
-
26
-int ff_opencl_unsharp_init(AVFilterContext *ctx);
27
-
28
-void ff_opencl_unsharp_uninit(AVFilterContext *ctx);
29
-
30
-int ff_opencl_unsharp_process_inout_buf(AVFilterContext *ctx, AVFrame *in, AVFrame *out);
31
-
32
-int ff_opencl_apply_unsharp(AVFilterContext *ctx, AVFrame *in, AVFrame *out);
33
-
34
-#endif /* AVFILTER_UNSHARP_OPENCL_H */
35 1
deleted file mode 100644
... ...
@@ -1,342 +0,0 @@
1
-/*
2
- * Copyright (C) 2013 Wei Gao <weigao@multicorewareinc.com>
3
- * Copyright (C) 2013 Lenny Wang
4
- *
5
- * This file is part of FFmpeg.
6
- *
7
- * FFmpeg is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * FFmpeg is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with FFmpeg; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- */
21
-
22
-#ifndef AVFILTER_UNSHARP_OPENCL_KERNEL_H
23
-#define AVFILTER_UNSHARP_OPENCL_KERNEL_H
24
-
25
-#include "libavutil/opencl.h"
26
-
27
-const char *ff_kernel_unsharp_opencl = AV_OPENCL_KERNEL(
28
-inline unsigned char clip_uint8(int a)
29
-{
30
-    if (a & (~0xFF))
31
-        return (-a)>>31;
32
-    else
33
-        return a;
34
-}
35
-
36
-kernel void unsharp_luma(
37
-                    global unsigned char *src,
38
-                    global unsigned char *dst,
39
-                    global int *mask_x,
40
-                    global int *mask_y,
41
-                    int amount,
42
-                    int scalebits,
43
-                    int halfscale,
44
-                    int src_stride,
45
-                    int dst_stride,
46
-                    int width,
47
-                    int height)
48
-{
49
-    int2 threadIdx, blockIdx, globalIdx;
50
-    threadIdx.x = get_local_id(0);
51
-    threadIdx.y = get_local_id(1);
52
-    blockIdx.x = get_group_id(0);
53
-    blockIdx.y = get_group_id(1);
54
-    globalIdx.x = get_global_id(0);
55
-    globalIdx.y = get_global_id(1);
56
-
57
-    if (!amount) {
58
-        if (globalIdx.x < width && globalIdx.y < height)
59
-            dst[globalIdx.x + globalIdx.y*dst_stride] = src[globalIdx.x + globalIdx.y*src_stride];
60
-        return;
61
-    }
62
-
63
-    local unsigned int l[32][32];
64
-    local unsigned int lcx[LU_RADIUS_X];
65
-    local unsigned int lcy[LU_RADIUS_Y];
66
-    int indexIx, indexIy, i, j;
67
-
68
-    //load up tile: actual workspace + halo of 8 points in x and y \n
69
-    for(i = 0; i <= 1; i++) {
70
-        indexIy = -8 + (blockIdx.y + i) * 16 + threadIdx.y;
71
-        indexIy = indexIy < 0 ? 0 : indexIy;
72
-        indexIy = indexIy >= height ? height - 1: indexIy;
73
-        for(j = 0; j <= 1; j++) {
74
-            indexIx = -8 + (blockIdx.x + j) * 16 + threadIdx.x;
75
-            indexIx = indexIx < 0 ? 0 : indexIx;
76
-            indexIx = indexIx >= width ? width - 1: indexIx;
77
-            l[i*16 + threadIdx.y][j*16 + threadIdx.x] = src[indexIy*src_stride + indexIx];
78
-        }
79
-    }
80
-
81
-    int indexL = threadIdx.y*16 + threadIdx.x;
82
-    if (indexL < LU_RADIUS_X)
83
-        lcx[indexL] = mask_x[indexL];
84
-    if (indexL < LU_RADIUS_Y)
85
-        lcy[indexL] = mask_y[indexL];
86
-    barrier(CLK_LOCAL_MEM_FENCE);
87
-
88
-    //needed for unsharp mask application in the end \n
89
-    int orig_value = (int)l[threadIdx.y + 8][threadIdx.x + 8];
90
-
91
-    int idx, idy, maskIndex;
92
-    int temp[2] = {0};
93
-    int steps_x = (LU_RADIUS_X-1)/2;
94
-    int steps_y = (LU_RADIUS_Y-1)/2;
95
-
96
-    // compute the actual workspace + left&right halos \n
97
-      \n#pragma unroll\n
98
-    for (j = 0; j <=1; j++) {
99
-      //extra work to cover left and right halos \n
100
-      idx = 16*j + threadIdx.x;
101
-      \n#pragma unroll\n
102
-        for (i = -steps_y; i <= steps_y; i++) {
103
-          idy = 8 + i + threadIdx.y;
104
-          maskIndex = (i + steps_y);
105
-          temp[j] += (int)l[idy][idx] * lcy[maskIndex];
106
-        }
107
-    }
108
-    barrier(CLK_LOCAL_MEM_FENCE);
109
-    //save results from the vertical filter in local memory \n
110
-    idy = 8 + threadIdx.y;
111
-      \n#pragma unroll\n
112
-    for (j = 0; j <=1; j++) {
113
-      idx = 16*j + threadIdx.x;
114
-      l[idy][idx] = temp[j];
115
-    }
116
-    barrier(CLK_LOCAL_MEM_FENCE);
117
-
118
-    //compute results with the horizontal filter \n
119
-    int sum = 0;
120
-    idy = 8 + threadIdx.y;
121
-    \n#pragma unroll\n
122
-      for (j = -steps_x; j <= steps_x; j++) {
123
-        idx = 8 + j + threadIdx.x;
124
-        maskIndex = j + steps_x;
125
-        sum += (int)l[idy][idx] * lcx[maskIndex];
126
-      }
127
-
128
-    int res = orig_value + (((orig_value - (int)((sum + halfscale) >> scalebits)) * amount) >> 16);
129
-
130
-    if (globalIdx.x < width && globalIdx.y < height)
131
-        dst[globalIdx.x + globalIdx.y*dst_stride] = clip_uint8(res);
132
-}
133
-
134
-kernel void unsharp_chroma(
135
-                    global unsigned char *src_y,
136
-                    global unsigned char *dst_y,
137
-                    global int *mask_x,
138
-                    global int *mask_y,
139
-                    int amount,
140
-                    int scalebits,
141
-                    int halfscale,
142
-                    int src_stride_lu,
143
-                    int src_stride_ch,
144
-                    int dst_stride_lu,
145
-                    int dst_stride_ch,
146
-                    int width,
147
-                    int height,
148
-                    int cw,
149
-                    int ch)
150
-{
151
-    global unsigned char *dst_u = dst_y + height * dst_stride_lu;
152
-    global unsigned char *dst_v = dst_u + ch * dst_stride_ch;
153
-    global unsigned char *src_u = src_y + height * src_stride_lu;
154
-    global unsigned char *src_v = src_u + ch * src_stride_ch;
155
-    int2 threadIdx, blockIdx, globalIdx;
156
-    threadIdx.x = get_local_id(0);
157
-    threadIdx.y = get_local_id(1);
158
-    blockIdx.x = get_group_id(0);
159
-    blockIdx.y = get_group_id(1);
160
-    globalIdx.x = get_global_id(0);
161
-    globalIdx.y = get_global_id(1);
162
-    int padch = get_global_size(1)/2;
163
-    global unsigned char *src = globalIdx.y>=padch ? src_v : src_u;
164
-    global unsigned char *dst = globalIdx.y>=padch ? dst_v : dst_u;
165
-
166
-    blockIdx.y = globalIdx.y>=padch ? blockIdx.y - get_num_groups(1)/2 : blockIdx.y;
167
-    globalIdx.y = globalIdx.y>=padch ? globalIdx.y - padch : globalIdx.y;
168
-
169
-    if (!amount) {
170
-        if (globalIdx.x < cw && globalIdx.y < ch)
171
-            dst[globalIdx.x + globalIdx.y*dst_stride_ch] = src[globalIdx.x + globalIdx.y*src_stride_ch];
172
-        return;
173
-    }
174
-
175
-    local unsigned int l[32][32];
176
-    local unsigned int lcx[CH_RADIUS_X];
177
-    local unsigned int lcy[CH_RADIUS_Y];
178
-    int indexIx, indexIy, i, j;
179
-    for(i = 0; i <= 1; i++) {
180
-        indexIy = -8 + (blockIdx.y + i) * 16 + threadIdx.y;
181
-        indexIy = indexIy < 0 ? 0 : indexIy;
182
-        indexIy = indexIy >= ch ? ch - 1: indexIy;
183
-        for(j = 0; j <= 1; j++) {
184
-            indexIx = -8 + (blockIdx.x + j) * 16 + threadIdx.x;
185
-            indexIx = indexIx < 0 ? 0 : indexIx;
186
-            indexIx = indexIx >= cw ? cw - 1: indexIx;
187
-            l[i*16 + threadIdx.y][j*16 + threadIdx.x] = src[indexIy * src_stride_ch + indexIx];
188
-        }
189
-    }
190
-
191
-    int indexL = threadIdx.y*16 + threadIdx.x;
192
-    if (indexL < CH_RADIUS_X)
193
-        lcx[indexL] = mask_x[indexL];
194
-    if (indexL < CH_RADIUS_Y)
195
-        lcy[indexL] = mask_y[indexL];
196
-    barrier(CLK_LOCAL_MEM_FENCE);
197
-
198
-    int orig_value = (int)l[threadIdx.y + 8][threadIdx.x + 8];
199
-
200
-    int idx, idy, maskIndex;
201
-    int steps_x = CH_RADIUS_X/2;
202
-    int steps_y = CH_RADIUS_Y/2;
203
-    int temp[2] = {0,0};
204
-
205
-    \n#pragma unroll\n
206
-      for (j = 0; j <= 1; j++) {
207
-        idx = 16*j + threadIdx.x;
208
-        \n#pragma unroll\n
209
-          for (i = -steps_y; i <= steps_y; i++) {
210
-            idy = 8 + i + threadIdx.y;
211
-            maskIndex = i + steps_y;
212
-            temp[j] += (int)l[idy][idx] * lcy[maskIndex];
213
-          }
214
-      }
215
-
216
-    barrier(CLK_LOCAL_MEM_FENCE);
217
-    idy = 8 + threadIdx.y;
218
-    \n#pragma unroll\n
219
-    for (j = 0; j <= 1; j++) {
220
-      idx = 16*j + threadIdx.x;
221
-      l[idy][idx] = temp[j];
222
-    }
223
-    barrier(CLK_LOCAL_MEM_FENCE);
224
-
225
-    //compute results with the horizontal filter \n
226
-    int sum = 0;
227
-    idy = 8 + threadIdx.y;
228
-    \n#pragma unroll\n
229
-      for (j = -steps_x; j <= steps_x; j++) {
230
-        idx = 8 + j + threadIdx.x;
231
-        maskIndex = j + steps_x;
232
-        sum += (int)l[idy][idx] * lcx[maskIndex];
233
-      }
234
-
235
-    int res = orig_value + (((orig_value - (int)((sum + halfscale) >> scalebits)) * amount) >> 16);
236
-
237
-    if (globalIdx.x < cw && globalIdx.y < ch)
238
-        dst[globalIdx.x + globalIdx.y*dst_stride_ch] = clip_uint8(res);
239
-}
240
-
241
-kernel void unsharp_default(global  unsigned char *src,
242
-                    global  unsigned char *dst,
243
-                    const global  unsigned int *mask_lu,
244
-                    const global  unsigned int *mask_ch,
245
-                    int amount_lu,
246
-                    int amount_ch,
247
-                    int step_x_lu,
248
-                    int step_y_lu,
249
-                    int step_x_ch,
250
-                    int step_y_ch,
251
-                    int scalebits_lu,
252
-                    int scalebits_ch,
253
-                    int halfscale_lu,
254
-                    int halfscale_ch,
255
-                    int src_stride_lu,
256
-                    int src_stride_ch,
257
-                    int dst_stride_lu,
258
-                    int dst_stride_ch,
259
-                    int height,
260
-                    int width,
261
-                    int ch,
262
-                    int cw)
263
-{
264
-    global unsigned char *dst_y = dst;
265
-    global unsigned char *dst_u = dst_y + height * dst_stride_lu;
266
-    global unsigned char *dst_v = dst_u + ch * dst_stride_ch;
267
-
268
-    global unsigned char *src_y = src;
269
-    global unsigned char *src_u = src_y + height * src_stride_lu;
270
-    global unsigned char *src_v = src_u + ch * src_stride_ch;
271
-
272
-    global unsigned char *temp_dst;
273
-    global unsigned char *temp_src;
274
-    const global unsigned int *temp_mask;
275
-    int global_id = get_global_id(0);
276
-    int i, j, x, y, temp_src_stride, temp_dst_stride, temp_height, temp_width, temp_steps_x, temp_steps_y,
277
-        temp_amount, temp_scalebits, temp_halfscale, sum, idx_x, idx_y, temp, res;
278
-    if (global_id < width * height) {
279
-        y = global_id / width;
280
-        x = global_id % width;
281
-        temp_dst = dst_y;
282
-        temp_src = src_y;
283
-        temp_src_stride = src_stride_lu;
284
-        temp_dst_stride = dst_stride_lu;
285
-        temp_height = height;
286
-        temp_width = width;
287
-        temp_steps_x = step_x_lu;
288
-        temp_steps_y = step_y_lu;
289
-        temp_mask = mask_lu;
290
-        temp_amount = amount_lu;
291
-        temp_scalebits = scalebits_lu;
292
-        temp_halfscale = halfscale_lu;
293
-    } else if ((global_id >= width * height) && (global_id < width * height + ch * cw)) {
294
-        y = (global_id - width * height) / cw;
295
-        x = (global_id - width * height) % cw;
296
-        temp_dst = dst_u;
297
-        temp_src = src_u;
298
-        temp_src_stride = src_stride_ch;
299
-        temp_dst_stride = dst_stride_ch;
300
-        temp_height = ch;
301
-        temp_width = cw;
302
-        temp_steps_x = step_x_ch;
303
-        temp_steps_y = step_y_ch;
304
-        temp_mask = mask_ch;
305
-        temp_amount = amount_ch;
306
-        temp_scalebits = scalebits_ch;
307
-        temp_halfscale = halfscale_ch;
308
-    } else {
309
-        y = (global_id - width * height - ch * cw) / cw;
310
-        x = (global_id - width * height - ch * cw) % cw;
311
-        temp_dst = dst_v;
312
-        temp_src = src_v;
313
-        temp_src_stride = src_stride_ch;
314
-        temp_dst_stride = dst_stride_ch;
315
-        temp_height = ch;
316
-        temp_width = cw;
317
-        temp_steps_x = step_x_ch;
318
-        temp_steps_y = step_y_ch;
319
-        temp_mask = mask_ch;
320
-        temp_amount = amount_ch;
321
-        temp_scalebits = scalebits_ch;
322
-        temp_halfscale = halfscale_ch;
323
-    }
324
-    if (temp_amount) {
325
-        sum = 0;
326
-        for (j = 0; j <= 2 * temp_steps_y; j++) {
327
-            idx_y = (y - temp_steps_y + j) <= 0 ? 0 : (y - temp_steps_y + j) >= temp_height ? temp_height-1 : y - temp_steps_y + j;
328
-            for (i = 0; i <= 2 * temp_steps_x; i++) {
329
-                idx_x = (x - temp_steps_x + i) <= 0 ? 0 : (x - temp_steps_x + i) >= temp_width ? temp_width-1 : x - temp_steps_x + i;
330
-                sum += temp_mask[i + j * (2 * temp_steps_x + 1)] * temp_src[idx_x + idx_y * temp_src_stride];
331
-            }
332
-        }
333
-        temp = (int)temp_src[x + y * temp_src_stride];
334
-        res = temp + (((temp - (int)((sum + temp_halfscale) >> temp_scalebits)) * temp_amount) >> 16);
335
-        temp_dst[x + y * temp_dst_stride] = clip_uint8(res);
336
-    } else {
337
-        temp_dst[x + y * temp_dst_stride] = temp_src[x + y * temp_src_stride];
338
-    }
339
-}
340
-);
341
-
342
-#endif /* AVFILTER_UNSHARP_OPENCL_KERNEL_H */
... ...
@@ -60,7 +60,6 @@
60 60
 #include "libavutil/qsort.h"
61 61
 
62 62
 #include "deshake.h"
63
-#include "deshake_opencl.h"
64 63
 
65 64
 #define OFFSET(x) offsetof(DeshakeContext, x)
66 65
 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
... ...
@@ -83,7 +82,7 @@ static const AVOption deshake_options[] = {
83 83
         { "exhaustive", "exhaustive search",      0, AV_OPT_TYPE_CONST, {.i64=EXHAUSTIVE},       INT_MIN, INT_MAX, FLAGS, "smode" },
84 84
         { "less",       "less exhaustive search", 0, AV_OPT_TYPE_CONST, {.i64=SMART_EXHAUSTIVE}, INT_MIN, INT_MAX, FLAGS, "smode" },
85 85
     { "filename", "set motion search detailed log file name", OFFSET(filename), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
86
-    { "opencl", "use OpenCL filtering capabilities", OFFSET(opencl), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, .flags = FLAGS },
86
+    { "opencl", "ignored",                              OFFSET(opencl), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, .flags = FLAGS },
87 87
     { NULL }
88 88
 };
89 89
 
... ...
@@ -341,7 +340,6 @@ static int deshake_transform_c(AVFilterContext *ctx,
341 341
 
342 342
 static av_cold int init(AVFilterContext *ctx)
343 343
 {
344
-    int ret;
345 344
     DeshakeContext *deshake = ctx->priv;
346 345
 
347 346
     deshake->sad = av_pixelutils_get_sad_fn(4, 4, 1, deshake); // 16x16, 2nd source unaligned
... ...
@@ -369,17 +367,7 @@ static av_cold int init(AVFilterContext *ctx)
369 369
         deshake->cx &= ~15;
370 370
     }
371 371
     deshake->transform = deshake_transform_c;
372
-    if (!CONFIG_OPENCL && deshake->opencl) {
373
-        av_log(ctx, AV_LOG_ERROR, "OpenCL support was not enabled in this build, cannot be selected\n");
374
-        return AVERROR(EINVAL);
375
-    }
376 372
 
377
-    if (CONFIG_OPENCL && deshake->opencl) {
378
-        deshake->transform = ff_opencl_transform;
379
-        ret = ff_opencl_deshake_init(ctx);
380
-        if (ret < 0)
381
-            return ret;
382
-    }
383 373
     av_log(ctx, AV_LOG_VERBOSE, "cx: %d, cy: %d, cw: %d, ch: %d, rx: %d, ry: %d, edge: %d blocksize: %d contrast: %d search: %d\n",
384 374
            deshake->cx, deshake->cy, deshake->cw, deshake->ch,
385 375
            deshake->rx, deshake->ry, deshake->edge, deshake->blocksize * 2, deshake->contrast, deshake->search);
... ...
@@ -416,9 +404,6 @@ static int config_props(AVFilterLink *link)
416 416
 static av_cold void uninit(AVFilterContext *ctx)
417 417
 {
418 418
     DeshakeContext *deshake = ctx->priv;
419
-    if (CONFIG_OPENCL && deshake->opencl) {
420
-        ff_opencl_deshake_uninit(ctx);
421
-    }
422 419
     av_frame_free(&deshake->ref);
423 420
     av_freep(&deshake->angles);
424 421
     deshake->angles_size = 0;
... ...
@@ -447,12 +432,6 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
447 447
     }
448 448
     av_frame_copy_props(out, in);
449 449
 
450
-    if (CONFIG_OPENCL && deshake->opencl) {
451
-        ret = ff_opencl_deshake_process_inout_buf(link->dst,in, out);
452
-        if (ret < 0)
453
-            goto fail;
454
-    }
455
-
456 450
     if (deshake->cx < 0 || deshake->cy < 0 || deshake->cw < 0 || deshake->ch < 0) {
457 451
         // Find the most likely global motion for the current frame
458 452
         find_motion(deshake, (deshake->ref == NULL) ? in->data[0] : deshake->ref->data[0], in->data[0], link->w, link->h, in->linesize[0], &t);
... ...
@@ -46,7 +46,6 @@
46 46
 #include "libavutil/opt.h"
47 47
 #include "libavutil/pixdesc.h"
48 48
 #include "unsharp.h"
49
-#include "unsharp_opencl.h"
50 49
 
51 50
 static void apply_unsharp(      uint8_t *dst, int dst_stride,
52 51
                           const uint8_t *src, int src_stride,
... ...
@@ -134,10 +133,8 @@ static void set_filter_param(UnsharpFilterParam *fp, int msize_x, int msize_y, f
134 134
 
135 135
 static av_cold int init(AVFilterContext *ctx)
136 136
 {
137
-    int ret = 0;
138 137
     UnsharpContext *s = ctx->priv;
139 138
 
140
-
141 139
     set_filter_param(&s->luma,   s->lmsize_x, s->lmsize_y, s->lamount);
142 140
     set_filter_param(&s->chroma, s->cmsize_x, s->cmsize_y, s->camount);
143 141
 
... ...
@@ -146,16 +143,6 @@ static av_cold int init(AVFilterContext *ctx)
146 146
         return AVERROR(EINVAL);
147 147
     }
148 148
     s->apply_unsharp = apply_unsharp_c;
149
-    if (!CONFIG_OPENCL && s->opencl) {
150
-        av_log(ctx, AV_LOG_ERROR, "OpenCL support was not enabled in this build, cannot be selected\n");
151
-        return AVERROR(EINVAL);
152
-    }
153
-    if (CONFIG_OPENCL && s->opencl) {
154
-        s->apply_unsharp = ff_opencl_apply_unsharp;
155
-        ret = ff_opencl_unsharp_init(ctx);
156
-        if (ret < 0)
157
-            return ret;
158
-    }
159 149
     return 0;
160 150
 }
161 151
 
... ...
@@ -227,10 +214,6 @@ static av_cold void uninit(AVFilterContext *ctx)
227 227
 {
228 228
     UnsharpContext *s = ctx->priv;
229 229
 
230
-    if (CONFIG_OPENCL && s->opencl) {
231
-        ff_opencl_unsharp_uninit(ctx);
232
-    }
233
-
234 230
     free_filter_param(&s->luma);
235 231
     free_filter_param(&s->chroma);
236 232
 }
... ...
@@ -248,14 +231,9 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
248 248
         return AVERROR(ENOMEM);
249 249
     }
250 250
     av_frame_copy_props(out, in);
251
-    if (CONFIG_OPENCL && s->opencl) {
252
-        ret = ff_opencl_unsharp_process_inout_buf(link->dst, in, out);
253
-        if (ret < 0)
254
-            goto end;
255
-    }
256 251
 
257 252
     ret = s->apply_unsharp(link->dst, in, out);
258
-end:
253
+
259 254
     av_frame_free(&in);
260 255
 
261 256
     if (ret < 0) {
... ...
@@ -282,7 +260,7 @@ static const AVOption unsharp_options[] = {
282 282
     { "cy",             "set chroma matrix vertical size",   OFFSET(cmsize_y), AV_OPT_TYPE_INT,   { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
283 283
     { "chroma_amount",  "set chroma effect strength",        OFFSET(camount),  AV_OPT_TYPE_FLOAT, { .dbl = 0 },       -2,        5, FLAGS },
284 284
     { "ca",             "set chroma effect strength",        OFFSET(camount),  AV_OPT_TYPE_FLOAT, { .dbl = 0 },       -2,        5, FLAGS },
285
-    { "opencl",         "use OpenCL filtering capabilities", OFFSET(opencl),   AV_OPT_TYPE_BOOL,  { .i64 = 0 },        0,        1, FLAGS },
285
+    { "opencl",         "ignored",                           OFFSET(opencl),   AV_OPT_TYPE_BOOL,  { .i64 = 0 },        0,        1, FLAGS },
286 286
     { NULL }
287 287
 };
288 288
 
... ...
@@ -79,8 +79,6 @@ HEADERS = adler32.h                                                     \
79 79
 
80 80
 HEADERS-$(CONFIG_LZO)                   += lzo.h
81 81
 
82
-HEADERS-$(CONFIG_OPENCL)                += opencl.h
83
-
84 82
 ARCH_HEADERS = bswap.h                                                  \
85 83
                intmath.h                                                \
86 84
                intreadwrite.h                                           \
... ...
@@ -164,7 +162,6 @@ OBJS-$(CONFIG_DXVA2)                    += hwcontext_dxva2.o
164 164
 OBJS-$(CONFIG_QSV)                   += hwcontext_qsv.o
165 165
 OBJS-$(CONFIG_LIBDRM)                   += hwcontext_drm.o
166 166
 OBJS-$(CONFIG_LZO)                      += lzo.o
167
-OBJS-$(CONFIG_OPENCL)                   += opencl.o opencl_internal.o
168 167
 OBJS-$(CONFIG_OPENCL)                   += hwcontext_opencl.o
169 168
 OBJS-$(CONFIG_VAAPI)                    += hwcontext_vaapi.o
170 169
 OBJS-$(CONFIG_VIDEOTOOLBOX)             += hwcontext_videotoolbox.o
... ...
@@ -187,7 +184,6 @@ SKIPHEADERS-$(CONFIG_VDPAU)            += hwcontext_vdpau.h
187 187
 SKIPHEADERS-$(HAVE_ATOMICS_GCC)        += atomic_gcc.h
188 188
 SKIPHEADERS-$(HAVE_ATOMICS_SUNCC)      += atomic_suncc.h
189 189
 SKIPHEADERS-$(HAVE_ATOMICS_WIN32)      += atomic_win32.h
190
-SKIPHEADERS-$(CONFIG_OPENCL)           += opencl.h
191 190
 
192 191
 TESTPROGS = adler32                                                     \
193 192
             aes                                                         \
194 193
deleted file mode 100644
... ...
@@ -1,875 +0,0 @@
1
-/*
2
- * Copyright (C) 2012 Peng  Gao     <peng@multicorewareinc.com>
3
- * Copyright (C) 2012 Li    Cao     <li@multicorewareinc.com>
4
- * Copyright (C) 2012 Wei   Gao     <weigao@multicorewareinc.com>
5
- * Copyright (C) 2013 Lenny Wang    <lwanghpc@gmail.com>
6
- *
7
- * This file is part of FFmpeg.
8
- *
9
- * FFmpeg is free software; you can redistribute it and/or
10
- * modify it under the terms of the GNU Lesser General Public
11
- * License as published by the Free Software Foundation; either
12
- * version 2.1 of the License, or (at your option) any later version.
13
- *
14
- * FFmpeg is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
- * Lesser General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU Lesser General Public
20
- * License along with FFmpeg; if not, write to the Free Software
21
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
- */
23
-
24
-#include "opencl.h"
25
-#include "avstring.h"
26
-#include "log.h"
27
-#include "avassert.h"
28
-#include "opt.h"
29
-
30
-#if HAVE_THREADS
31
-#include "thread.h"
32
-#include "atomic.h"
33
-
34
-static pthread_mutex_t * volatile atomic_opencl_lock = NULL;
35
-#define LOCK_OPENCL pthread_mutex_lock(atomic_opencl_lock)
36
-#define UNLOCK_OPENCL pthread_mutex_unlock(atomic_opencl_lock)
37
-#else
38
-#define LOCK_OPENCL
39
-#define UNLOCK_OPENCL
40
-#endif
41
-
42
-#define MAX_KERNEL_CODE_NUM 200
43
-
44
-typedef struct {
45
-    int is_compiled;
46
-    const char *kernel_string;
47
-} KernelCode;
48
-
49
-typedef struct {
50
-    const AVClass *class;
51
-    int log_offset;
52
-    void *log_ctx;
53
-    int init_count;
54
-    int opt_init_flag;
55
-     /**
56
-     * if set to 1, the OpenCL environment was created by the user and
57
-     * passed as AVOpenCLExternalEnv when initing ,0:created by opencl wrapper.
58
-     */
59
-    int is_user_created;
60
-    int platform_idx;
61
-    int device_idx;
62
-    cl_platform_id platform_id;
63
-    cl_device_type device_type;
64
-    cl_context context;
65
-    cl_device_id device_id;
66
-    cl_command_queue command_queue;
67
-    int kernel_code_count;
68
-    KernelCode kernel_code[MAX_KERNEL_CODE_NUM];
69
-    AVOpenCLDeviceList device_list;
70
-} OpenclContext;
71
-
72
-#define OFFSET(x) offsetof(OpenclContext, x)
73
-
74
-static const AVOption opencl_options[] = {
75
-     { "platform_idx",        "set platform index value",  OFFSET(platform_idx),  AV_OPT_TYPE_INT,    {.i64=-1}, -1, INT_MAX},
76
-     { "device_idx",          "set device index value",    OFFSET(device_idx),    AV_OPT_TYPE_INT,    {.i64=-1}, -1, INT_MAX},
77
-     { NULL }
78
-};
79
-
80
-static const AVClass openclutils_class = {
81
-    .class_name                = "opencl",
82
-    .option                    = opencl_options,
83
-    .item_name                 = av_default_item_name,
84
-    .version                   = LIBAVUTIL_VERSION_INT,
85
-    .log_level_offset_offset   = offsetof(OpenclContext, log_offset),
86
-    .parent_log_context_offset = offsetof(OpenclContext, log_ctx),
87
-};
88
-
89
-static OpenclContext opencl_ctx = {&openclutils_class};
90
-
91
-static const cl_device_type device_type[] = {CL_DEVICE_TYPE_GPU, CL_DEVICE_TYPE_CPU};
92
-
93
-typedef struct {
94
-    int err_code;
95
-    const char *err_str;
96
-} OpenclErrorMsg;
97
-
98
-static const OpenclErrorMsg opencl_err_msg[] = {
99
-    {CL_DEVICE_NOT_FOUND,                               "DEVICE NOT FOUND"},
100
-    {CL_DEVICE_NOT_AVAILABLE,                           "DEVICE NOT AVAILABLE"},
101
-    {CL_COMPILER_NOT_AVAILABLE,                         "COMPILER NOT AVAILABLE"},
102
-    {CL_MEM_OBJECT_ALLOCATION_FAILURE,                  "MEM OBJECT ALLOCATION FAILURE"},
103
-    {CL_OUT_OF_RESOURCES,                               "OUT OF RESOURCES"},
104
-    {CL_OUT_OF_HOST_MEMORY,                             "OUT OF HOST MEMORY"},
105
-    {CL_PROFILING_INFO_NOT_AVAILABLE,                   "PROFILING INFO NOT AVAILABLE"},
106
-    {CL_MEM_COPY_OVERLAP,                               "MEM COPY OVERLAP"},
107
-    {CL_IMAGE_FORMAT_MISMATCH,                          "IMAGE FORMAT MISMATCH"},
108
-    {CL_IMAGE_FORMAT_NOT_SUPPORTED,                     "IMAGE FORMAT NOT_SUPPORTED"},
109
-    {CL_BUILD_PROGRAM_FAILURE,                          "BUILD PROGRAM FAILURE"},
110
-    {CL_MAP_FAILURE,                                    "MAP FAILURE"},
111
-    {CL_MISALIGNED_SUB_BUFFER_OFFSET,                   "MISALIGNED SUB BUFFER OFFSET"},
112
-    {CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST,      "EXEC STATUS ERROR FOR EVENTS IN WAIT LIST"},
113
-    {CL_COMPILE_PROGRAM_FAILURE,                        "COMPILE PROGRAM FAILURE"},
114
-    {CL_LINKER_NOT_AVAILABLE,                           "LINKER NOT AVAILABLE"},
115
-    {CL_LINK_PROGRAM_FAILURE,                           "LINK PROGRAM FAILURE"},
116
-    {CL_DEVICE_PARTITION_FAILED,                        "DEVICE PARTITION FAILED"},
117
-    {CL_KERNEL_ARG_INFO_NOT_AVAILABLE,                  "KERNEL ARG INFO NOT AVAILABLE"},
118
-    {CL_INVALID_VALUE,                                  "INVALID VALUE"},
119
-    {CL_INVALID_DEVICE_TYPE,                            "INVALID DEVICE TYPE"},
120
-    {CL_INVALID_PLATFORM,                               "INVALID PLATFORM"},
121
-    {CL_INVALID_DEVICE,                                 "INVALID DEVICE"},
122
-    {CL_INVALID_CONTEXT,                                "INVALID CONTEXT"},
123
-    {CL_INVALID_QUEUE_PROPERTIES,                       "INVALID QUEUE PROPERTIES"},
124
-    {CL_INVALID_COMMAND_QUEUE,                          "INVALID COMMAND QUEUE"},
125
-    {CL_INVALID_HOST_PTR,                               "INVALID HOST PTR"},
126
-    {CL_INVALID_MEM_OBJECT,                             "INVALID MEM OBJECT"},
127
-    {CL_INVALID_IMAGE_FORMAT_DESCRIPTOR,                "INVALID IMAGE FORMAT DESCRIPTOR"},
128
-    {CL_INVALID_IMAGE_SIZE,                             "INVALID IMAGE SIZE"},
129
-    {CL_INVALID_SAMPLER,                                "INVALID SAMPLER"},
130
-    {CL_INVALID_BINARY,                                 "INVALID BINARY"},
131
-    {CL_INVALID_BUILD_OPTIONS,                          "INVALID BUILD OPTIONS"},
132
-    {CL_INVALID_PROGRAM,                                "INVALID PROGRAM"},
133
-    {CL_INVALID_PROGRAM_EXECUTABLE,                     "INVALID PROGRAM EXECUTABLE"},
134
-    {CL_INVALID_KERNEL_NAME,                            "INVALID KERNEL NAME"},
135
-    {CL_INVALID_KERNEL_DEFINITION,                      "INVALID KERNEL DEFINITION"},
136
-    {CL_INVALID_KERNEL,                                 "INVALID KERNEL"},
137
-    {CL_INVALID_ARG_INDEX,                              "INVALID ARG INDEX"},
138
-    {CL_INVALID_ARG_VALUE,                              "INVALID ARG VALUE"},
139
-    {CL_INVALID_ARG_SIZE,                               "INVALID ARG_SIZE"},
140
-    {CL_INVALID_KERNEL_ARGS,                            "INVALID KERNEL ARGS"},
141
-    {CL_INVALID_WORK_DIMENSION,                         "INVALID WORK DIMENSION"},
142
-    {CL_INVALID_WORK_GROUP_SIZE,                        "INVALID WORK GROUP SIZE"},
143
-    {CL_INVALID_WORK_ITEM_SIZE,                         "INVALID WORK ITEM SIZE"},
144
-    {CL_INVALID_GLOBAL_OFFSET,                          "INVALID GLOBAL OFFSET"},
145
-    {CL_INVALID_EVENT_WAIT_LIST,                        "INVALID EVENT WAIT LIST"},
146
-    {CL_INVALID_EVENT,                                  "INVALID EVENT"},
147
-    {CL_INVALID_OPERATION,                              "INVALID OPERATION"},
148
-    {CL_INVALID_GL_OBJECT,                              "INVALID GL OBJECT"},
149
-    {CL_INVALID_BUFFER_SIZE,                            "INVALID BUFFER SIZE"},
150
-    {CL_INVALID_MIP_LEVEL,                              "INVALID MIP LEVEL"},
151
-    {CL_INVALID_GLOBAL_WORK_SIZE,                       "INVALID GLOBAL WORK SIZE"},
152
-    {CL_INVALID_PROPERTY,                               "INVALID PROPERTY"},
153
-    {CL_INVALID_IMAGE_DESCRIPTOR,                       "INVALID IMAGE DESCRIPTOR"},
154
-    {CL_INVALID_COMPILER_OPTIONS,                       "INVALID COMPILER OPTIONS"},
155
-    {CL_INVALID_LINKER_OPTIONS,                         "INVALID LINKER OPTIONS"},
156
-    {CL_INVALID_DEVICE_PARTITION_COUNT,                 "INVALID DEVICE PARTITION COUNT"},
157
-};
158
-
159
-const char *av_opencl_errstr(cl_int status)
160
-{
161
-    int i;
162
-    for (i = 0; i < FF_ARRAY_ELEMS(opencl_err_msg); i++) {
163
-        if (opencl_err_msg[i].err_code == status)
164
-            return opencl_err_msg[i].err_str;
165
-    }
166
-    return "unknown error";
167
-}
168
-
169
-static void free_device_list(AVOpenCLDeviceList *device_list)
170
-{
171
-    int i, j;
172
-    if (!device_list || !device_list->platform_node)
173
-        return;
174
-    for (i = 0; i < device_list->platform_num; i++) {
175
-        if (!device_list->platform_node[i])
176
-            continue;
177
-        for (j = 0; j < device_list->platform_node[i]->device_num; j++) {
178
-            av_freep(&(device_list->platform_node[i]->device_node[j]->device_name));
179
-            av_freep(&(device_list->platform_node[i]->device_node[j]));
180
-        }
181
-        av_freep(&device_list->platform_node[i]->device_node);
182
-        av_freep(&(device_list->platform_node[i]->platform_name));
183
-        av_freep(&device_list->platform_node[i]);
184
-    }
185
-    av_freep(&device_list->platform_node);
186
-    device_list->platform_num = 0;
187
-}
188
-
189
-static int get_device_list(AVOpenCLDeviceList *device_list)
190
-{
191
-    cl_int status;
192
-    int i, j, k, device_num, total_devices_num, ret = 0;
193
-    int *devices_num;
194
-    cl_platform_id *platform_ids = NULL;
195
-    cl_device_id *device_ids = NULL;
196
-    AVOpenCLDeviceNode *device_node = NULL;
197
-    size_t platform_name_size = 0;
198
-    size_t device_name_size = 0;
199
-    status = clGetPlatformIDs(0, NULL, &device_list->platform_num);
200
-    if (status != CL_SUCCESS) {
201
-        av_log(&opencl_ctx, AV_LOG_ERROR,
202
-               "Could not get OpenCL platform ids: %s\n", av_opencl_errstr(status));
203
-        return AVERROR_EXTERNAL;
204
-    }
205
-    platform_ids = av_mallocz_array(device_list->platform_num, sizeof(cl_platform_id));
206
-    if (!platform_ids)
207
-        return AVERROR(ENOMEM);
208
-    status = clGetPlatformIDs(device_list->platform_num, platform_ids, NULL);
209
-    if (status != CL_SUCCESS) {
210
-        av_log(&opencl_ctx, AV_LOG_ERROR,
211
-                "Could not get OpenCL platform ids: %s\n", av_opencl_errstr(status));
212
-        ret = AVERROR_EXTERNAL;
213
-        goto end;
214
-    }
215
-    device_list->platform_node = av_mallocz_array(device_list->platform_num, sizeof(AVOpenCLPlatformNode *));
216
-    if (!device_list->platform_node) {
217
-        ret = AVERROR(ENOMEM);
218
-        goto end;
219
-    }
220
-    devices_num = av_mallocz(sizeof(int) * FF_ARRAY_ELEMS(device_type));
221
-    if (!devices_num) {
222
-        ret = AVERROR(ENOMEM);
223
-        goto end;
224
-    }
225
-    for (i = 0; i < device_list->platform_num; i++) {
226
-        device_list->platform_node[i] = av_mallocz(sizeof(AVOpenCLPlatformNode));
227
-        if (!device_list->platform_node[i]) {
228
-            ret = AVERROR(ENOMEM);
229
-            goto end;
230
-        }
231
-        device_list->platform_node[i]->platform_id = platform_ids[i];
232
-        status = clGetPlatformInfo(platform_ids[i], CL_PLATFORM_VENDOR,
233
-                                   0, NULL, &platform_name_size);
234
-        if (status != CL_SUCCESS) {
235
-            av_log(&opencl_ctx, AV_LOG_WARNING,
236
-                    "Could not get size of platform name: %s\n", av_opencl_errstr(status));
237
-        } else {
238
-            device_list->platform_node[i]->platform_name = av_malloc(platform_name_size * sizeof(char));
239
-            if (!device_list->platform_node[i]->platform_name) {
240
-                av_log(&opencl_ctx, AV_LOG_WARNING,
241
-                        "Could not allocate memory for device name: %s\n", av_opencl_errstr(status));
242
-            } else {
243
-                status = clGetPlatformInfo(platform_ids[i], CL_PLATFORM_VENDOR,
244
-                                           platform_name_size * sizeof(char),
245
-                                           device_list->platform_node[i]->platform_name, NULL);
246
-                if (status != CL_SUCCESS) {
247
-                    av_log(&opencl_ctx, AV_LOG_WARNING,
248
-                            "Could not get platform name: %s\n", av_opencl_errstr(status));
249
-                }
250
-            }
251
-        }
252
-        total_devices_num = 0;
253
-        for (j = 0; j < FF_ARRAY_ELEMS(device_type); j++) {
254
-            status = clGetDeviceIDs(device_list->platform_node[i]->platform_id,
255
-                                    device_type[j], 0, NULL, &devices_num[j]);
256
-            total_devices_num += devices_num[j];
257
-        }
258
-        device_list->platform_node[i]->device_node = av_mallocz_array(total_devices_num, sizeof(AVOpenCLDeviceNode *));
259
-        if (!device_list->platform_node[i]->device_node) {
260
-            ret = AVERROR(ENOMEM);
261
-            goto end;
262
-        }
263
-        for (j = 0; j < FF_ARRAY_ELEMS(device_type); j++) {
264
-            if (devices_num[j]) {
265
-                device_ids = av_mallocz_array(devices_num[j], sizeof(cl_device_id));
266
-                if (!device_ids) {
267
-                    ret = AVERROR(ENOMEM);
268
-                    goto end;
269
-                }
270
-                status = clGetDeviceIDs(device_list->platform_node[i]->platform_id, device_type[j],
271
-                                        devices_num[j], device_ids, NULL);
272
-                if (status != CL_SUCCESS) {
273
-                    av_log(&opencl_ctx, AV_LOG_WARNING,
274
-                            "Could not get device ID: %s:\n", av_opencl_errstr(status));
275
-                    av_freep(&device_ids);
276
-                    continue;
277
-                }
278
-                for (k = 0; k < devices_num[j]; k++) {
279
-                    device_num = device_list->platform_node[i]->device_num;
280
-                    device_list->platform_node[i]->device_node[device_num] = av_mallocz(sizeof(AVOpenCLDeviceNode));
281
-                    if (!device_list->platform_node[i]->device_node[device_num]) {
282
-                        ret = AVERROR(ENOMEM);
283
-                        goto end;
284
-                    }
285
-                    device_node = device_list->platform_node[i]->device_node[device_num];
286
-                    device_node->device_id = device_ids[k];
287
-                    device_node->device_type = device_type[j];
288
-                    status = clGetDeviceInfo(device_node->device_id, CL_DEVICE_NAME,
289
-                                             0, NULL, &device_name_size);
290
-                    if (status != CL_SUCCESS) {
291
-                        av_log(&opencl_ctx, AV_LOG_WARNING,
292
-                                "Could not get size of device name: %s\n", av_opencl_errstr(status));
293
-                        continue;
294
-                    }
295
-                    device_node->device_name = av_malloc(device_name_size * sizeof(char));
296
-                    if (!device_node->device_name) {
297
-                        av_log(&opencl_ctx, AV_LOG_WARNING,
298
-                                "Could not allocate memory for device name: %s\n", av_opencl_errstr(status));
299
-                        continue;
300
-                    }
301
-                    status = clGetDeviceInfo(device_node->device_id, CL_DEVICE_NAME,
302
-                                             device_name_size * sizeof(char),
303
-                                             device_node->device_name, NULL);
304
-                    if (status != CL_SUCCESS) {
305
-                        av_log(&opencl_ctx, AV_LOG_WARNING,
306
-                                "Could not get device name: %s\n", av_opencl_errstr(status));
307
-                        continue;
308
-                    }
309
-                    device_list->platform_node[i]->device_num++;
310
-                }
311
-                av_freep(&device_ids);
312
-            }
313
-        }
314
-    }
315
-end:
316
-    av_freep(&platform_ids);
317
-    av_freep(&devices_num);
318
-    av_freep(&device_ids);
319
-    if (ret < 0)
320
-        free_device_list(device_list);
321
-    return ret;
322
-}
323
-
324
-int av_opencl_get_device_list(AVOpenCLDeviceList **device_list)
325
-{
326
-    int ret = 0;
327
-    *device_list = av_mallocz(sizeof(AVOpenCLDeviceList));
328
-    if (!(*device_list)) {
329
-        av_log(&opencl_ctx, AV_LOG_ERROR, "Could not allocate opencl device list\n");
330
-        return AVERROR(ENOMEM);
331
-    }
332
-    ret = get_device_list(*device_list);
333
-    if (ret < 0) {
334
-        av_log(&opencl_ctx, AV_LOG_ERROR, "Could not get device list from environment\n");
335
-        free_device_list(*device_list);
336
-        av_freep(device_list);
337
-        return ret;
338
-    }
339
-    return ret;
340
-}
341
-
342
-void av_opencl_free_device_list(AVOpenCLDeviceList **device_list)
343
-{
344
-    free_device_list(*device_list);
345
-    av_freep(device_list);
346
-}
347
-
348
-static inline int init_opencl_mtx(void)
349
-{
350
-#if HAVE_THREADS
351
-    if (!atomic_opencl_lock) {
352
-        int err;
353
-        pthread_mutex_t *tmp = av_malloc(sizeof(pthread_mutex_t));
354
-        if (!tmp)
355
-            return AVERROR(ENOMEM);
356
-        if ((err = pthread_mutex_init(tmp, NULL))) {
357
-            av_free(tmp);
358
-            return AVERROR(err);
359
-        }
360
-        if (avpriv_atomic_ptr_cas((void * volatile *)&atomic_opencl_lock, NULL, tmp)) {
361
-            pthread_mutex_destroy(tmp);
362
-            av_free(tmp);
363
-        }
364
-    }
365
-#endif
366
-    return 0;
367
-}
368
-
369
-int av_opencl_set_option(const char *key, const char *val)
370
-{
371
-    int ret = init_opencl_mtx( );
372
-    if (ret < 0)
373
-        return ret;
374
-    LOCK_OPENCL;
375
-    if (!opencl_ctx.opt_init_flag) {
376
-        av_opt_set_defaults(&opencl_ctx);
377
-        opencl_ctx.opt_init_flag = 1;
378
-    }
379
-    ret = av_opt_set(&opencl_ctx, key, val, 0);
380
-    UNLOCK_OPENCL;
381
-    return ret;
382
-}
383
-
384
-int av_opencl_get_option(const char *key, uint8_t **out_val)
385
-{
386
-    int ret = 0;
387
-    LOCK_OPENCL;
388
-    ret = av_opt_get(&opencl_ctx, key, 0, out_val);
389
-    UNLOCK_OPENCL;
390
-    return ret;
391
-}
392
-
393
-void av_opencl_free_option(void)
394
-{
395
-    /*FIXME: free openclutils context*/
396
-    LOCK_OPENCL;
397
-    av_opt_free(&opencl_ctx);
398
-    UNLOCK_OPENCL;
399
-}
400
-
401
-AVOpenCLExternalEnv *av_opencl_alloc_external_env(void)
402
-{
403
-    AVOpenCLExternalEnv *ext = av_mallocz(sizeof(AVOpenCLExternalEnv));
404
-    if (!ext) {
405
-        av_log(&opencl_ctx, AV_LOG_ERROR,
406
-               "Could not malloc external opencl environment data space\n");
407
-    }
408
-    return ext;
409
-}
410
-
411
-void av_opencl_free_external_env(AVOpenCLExternalEnv **ext_opencl_env)
412
-{
413
-    av_freep(ext_opencl_env);
414
-}
415
-
416
-int av_opencl_register_kernel_code(const char *kernel_code)
417
-{
418
-    int i, ret = init_opencl_mtx( );
419
-    if (ret < 0)
420
-        return ret;
421
-    LOCK_OPENCL;
422
-    if (opencl_ctx.kernel_code_count >= MAX_KERNEL_CODE_NUM) {
423
-        av_log(&opencl_ctx, AV_LOG_ERROR,
424
-               "Could not register kernel code, maximum number of registered kernel code %d already reached\n",
425
-               MAX_KERNEL_CODE_NUM);
426
-        ret = AVERROR(EINVAL);
427
-        goto end;
428
-    }
429
-    for (i = 0; i < opencl_ctx.kernel_code_count; i++) {
430
-        if (opencl_ctx.kernel_code[i].kernel_string == kernel_code) {
431
-            av_log(&opencl_ctx, AV_LOG_WARNING, "Same kernel code has been registered\n");
432
-            goto end;
433
-        }
434
-    }
435
-    opencl_ctx.kernel_code[opencl_ctx.kernel_code_count].kernel_string = kernel_code;
436
-    opencl_ctx.kernel_code[opencl_ctx.kernel_code_count].is_compiled = 0;
437
-    opencl_ctx.kernel_code_count++;
438
-end:
439
-    UNLOCK_OPENCL;
440
-    return ret;
441
-}
442
-
443
-cl_program av_opencl_compile(const char *program_name, const char *build_opts)
444
-{
445
-    int i;
446
-    cl_int status, build_status;
447
-    int kernel_code_idx = 0;
448
-    const char *kernel_source = NULL;
449
-    size_t kernel_code_len;
450
-    char* ptr = NULL;
451
-    cl_program program = NULL;
452
-    size_t log_size;
453
-    char *log = NULL;
454
-
455
-    LOCK_OPENCL;
456
-    for (i = 0; i < opencl_ctx.kernel_code_count; i++) {
457
-        // identify a program using a unique name within the kernel source
458
-        ptr = av_stristr(opencl_ctx.kernel_code[i].kernel_string, program_name);
459
-        if (ptr && !opencl_ctx.kernel_code[i].is_compiled) {
460
-            kernel_source = opencl_ctx.kernel_code[i].kernel_string;
461
-            kernel_code_len = strlen(opencl_ctx.kernel_code[i].kernel_string);
462
-            kernel_code_idx = i;
463
-            break;
464
-        }
465
-    }
466
-    if (!kernel_source) {
467
-        av_log(&opencl_ctx, AV_LOG_ERROR,
468
-               "Unable to find OpenCL kernel source '%s'\n", program_name);
469
-        goto end;
470
-    }
471
-
472
-    /* create a CL program from kernel source */
473
-    program = clCreateProgramWithSource(opencl_ctx.context, 1, &kernel_source, &kernel_code_len, &status);
474
-    if(status != CL_SUCCESS) {
475
-        av_log(&opencl_ctx, AV_LOG_ERROR,
476
-               "Unable to create OpenCL program '%s': %s\n", program_name, av_opencl_errstr(status));
477
-        program = NULL;
478
-        goto end;
479
-    }
480
-
481
-    build_status = clBuildProgram(program, 1, &(opencl_ctx.device_id), build_opts, NULL, NULL);
482
-    status = clGetProgramBuildInfo(program, opencl_ctx.device_id,
483
-                                   CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);
484
-    if (status != CL_SUCCESS) {
485
-        av_log(&opencl_ctx, AV_LOG_WARNING,
486
-               "Failed to get compilation log: %s\n",
487
-               av_opencl_errstr(status));
488
-    } else {
489
-        log = av_malloc(log_size);
490
-        if (log) {
491
-            status = clGetProgramBuildInfo(program, opencl_ctx.device_id,
492
-                                           CL_PROGRAM_BUILD_LOG, log_size,
493
-                                           log, NULL);
494
-            if (status != CL_SUCCESS) {
495
-                av_log(&opencl_ctx, AV_LOG_WARNING,
496
-                       "Failed to get compilation log: %s\n",
497
-                       av_opencl_errstr(status));
498
-            } else {
499
-                int level = build_status == CL_SUCCESS ? AV_LOG_DEBUG :
500
-                                                         AV_LOG_ERROR;
501
-                av_log(&opencl_ctx, level, "Compilation log:\n%s\n", log);
502
-            }
503
-        }
504
-        av_freep(&log);
505
-    }
506
-    if (build_status != CL_SUCCESS) {
507
-        av_log(&opencl_ctx, AV_LOG_ERROR,
508
-               "Compilation failed with OpenCL program '%s': %s\n",
509
-               program_name, av_opencl_errstr(build_status));
510
-        program = NULL;
511
-        goto end;
512
-    }
513
-
514
-    opencl_ctx.kernel_code[kernel_code_idx].is_compiled = 1;
515
-end:
516
-    UNLOCK_OPENCL;
517
-    return program;
518
-}
519
-
520
-cl_command_queue av_opencl_get_command_queue(void)
521
-{
522
-    return opencl_ctx.command_queue;
523
-}
524
-
525
-static int init_opencl_env(OpenclContext *opencl_ctx, AVOpenCLExternalEnv *ext_opencl_env)
526
-{
527
-    cl_int status;
528
-    cl_context_properties cps[3];
529
-    int i, ret = 0;
530
-    AVOpenCLDeviceNode *device_node = NULL;
531
-
532
-    if (ext_opencl_env) {
533
-        if (opencl_ctx->is_user_created)
534
-            return 0;
535
-        opencl_ctx->platform_id     = ext_opencl_env->platform_id;
536
-        opencl_ctx->is_user_created = 1;
537
-        opencl_ctx->command_queue   = ext_opencl_env->command_queue;
538
-        opencl_ctx->context         = ext_opencl_env->context;
539
-        opencl_ctx->device_id       = ext_opencl_env->device_id;
540
-        opencl_ctx->device_type     = ext_opencl_env->device_type;
541
-    } else {
542
-        if (!opencl_ctx->is_user_created) {
543
-            if (!opencl_ctx->device_list.platform_num) {
544
-                ret = get_device_list(&opencl_ctx->device_list);
545
-                if (ret < 0) {
546
-                    return ret;
547
-                }
548
-            }
549
-            if (opencl_ctx->platform_idx >= 0) {
550
-                if (opencl_ctx->device_list.platform_num < opencl_ctx->platform_idx + 1) {
551
-                    av_log(opencl_ctx, AV_LOG_ERROR, "User set platform index not exist\n");
552
-                    return AVERROR(EINVAL);
553
-                }
554
-                if (!opencl_ctx->device_list.platform_node[opencl_ctx->platform_idx]->device_num) {
555
-                    av_log(opencl_ctx, AV_LOG_ERROR, "No devices in user specific platform with index %d\n",
556
-                           opencl_ctx->platform_idx);
557
-                    return AVERROR(EINVAL);
558
-                }
559
-                opencl_ctx->platform_id = opencl_ctx->device_list.platform_node[opencl_ctx->platform_idx]->platform_id;
560
-            } else {
561
-                /* get a usable platform by default*/
562
-                for (i = 0; i < opencl_ctx->device_list.platform_num; i++) {
563
-                    if (opencl_ctx->device_list.platform_node[i]->device_num) {
564
-                        opencl_ctx->platform_id = opencl_ctx->device_list.platform_node[i]->platform_id;
565
-                        opencl_ctx->platform_idx = i;
566
-                        break;
567
-                    }
568
-                }
569
-            }
570
-            if (!opencl_ctx->platform_id) {
571
-                av_log(opencl_ctx, AV_LOG_ERROR, "Could not get OpenCL platforms\n");
572
-                return AVERROR_EXTERNAL;
573
-            }
574
-            /* get a usable device*/
575
-            if (opencl_ctx->device_idx >= 0) {
576
-                if (opencl_ctx->device_list.platform_node[opencl_ctx->platform_idx]->device_num < opencl_ctx->device_idx + 1) {
577
-                    av_log(opencl_ctx, AV_LOG_ERROR,
578
-                           "Could not get OpenCL device idx %d in the user set platform\n", opencl_ctx->platform_idx);
579
-                    return AVERROR(EINVAL);
580
-                }
581
-            } else {
582
-                opencl_ctx->device_idx = 0;
583
-            }
584
-
585
-            device_node = opencl_ctx->device_list.platform_node[opencl_ctx->platform_idx]->device_node[opencl_ctx->device_idx];
586
-            opencl_ctx->device_id = device_node->device_id;
587
-            opencl_ctx->device_type = device_node->device_type;
588
-
589
-            /*
590
-             * Use available platform.
591
-             */
592
-            av_log(opencl_ctx, AV_LOG_VERBOSE, "Platform Name: %s, Device Name: %s\n",
593
-                   opencl_ctx->device_list.platform_node[opencl_ctx->platform_idx]->platform_name,
594
-                   device_node->device_name);
595
-            cps[0] = CL_CONTEXT_PLATFORM;
596
-            cps[1] = (cl_context_properties)opencl_ctx->platform_id;
597
-            cps[2] = 0;
598
-
599
-            opencl_ctx->context = clCreateContextFromType(cps, opencl_ctx->device_type,
600
-                                                       NULL, NULL, &status);
601
-            if (status != CL_SUCCESS) {
602
-                av_log(opencl_ctx, AV_LOG_ERROR,
603
-                       "Could not get OpenCL context from device type: %s\n", av_opencl_errstr(status));
604
-                return AVERROR_EXTERNAL;
605
-            }
606
-            opencl_ctx->command_queue = clCreateCommandQueue(opencl_ctx->context, opencl_ctx->device_id,
607
-                                                          0, &status);
608
-            if (status != CL_SUCCESS) {
609
-                av_log(opencl_ctx, AV_LOG_ERROR,
610
-                       "Could not create OpenCL command queue: %s\n", av_opencl_errstr(status));
611
-                return AVERROR_EXTERNAL;
612
-            }
613
-        }
614
-    }
615
-    return ret;
616
-}
617
-
618
-int av_opencl_init(AVOpenCLExternalEnv *ext_opencl_env)
619
-{
620
-    int ret = init_opencl_mtx( );
621
-    if (ret < 0)
622
-        return ret;
623
-    LOCK_OPENCL;
624
-    if (!opencl_ctx.init_count) {
625
-        if (!opencl_ctx.opt_init_flag) {
626
-            av_opt_set_defaults(&opencl_ctx);
627
-            opencl_ctx.opt_init_flag = 1;
628
-        }
629
-        ret = init_opencl_env(&opencl_ctx, ext_opencl_env);
630
-        if (ret < 0)
631
-            goto end;
632
-        if (opencl_ctx.kernel_code_count <= 0) {
633
-            av_log(&opencl_ctx, AV_LOG_ERROR,
634
-                   "No kernel code is registered, compile kernel file failed\n");
635
-            ret = AVERROR(EINVAL);
636
-            goto end;
637
-        }
638
-    }
639
-    opencl_ctx.init_count++;
640
-end:
641
-    UNLOCK_OPENCL;
642
-    return ret;
643
-}
644
-
645
-void av_opencl_uninit(void)
646
-{
647
-    int i;
648
-    cl_int status;
649
-    LOCK_OPENCL;
650
-    opencl_ctx.init_count--;
651
-    if (opencl_ctx.is_user_created)
652
-        goto end;
653
-    if (opencl_ctx.init_count > 0)
654
-        goto end;
655
-    if (opencl_ctx.command_queue) {
656
-        status = clReleaseCommandQueue(opencl_ctx.command_queue);
657
-        if (status != CL_SUCCESS) {
658
-            av_log(&opencl_ctx, AV_LOG_ERROR,
659
-                   "Could not release OpenCL command queue: %s\n", av_opencl_errstr(status));
660
-        }
661
-        opencl_ctx.command_queue = NULL;
662
-    }
663
-    if (opencl_ctx.context) {
664
-        status = clReleaseContext(opencl_ctx.context);
665
-        if (status != CL_SUCCESS) {
666
-            av_log(&opencl_ctx, AV_LOG_ERROR,
667
-                   "Could not release OpenCL context: %s\n", av_opencl_errstr(status));
668
-        }
669
-        opencl_ctx.context = NULL;
670
-    }
671
-    for (i = 0; i < opencl_ctx.kernel_code_count; i++) {
672
-        opencl_ctx.kernel_code[i].is_compiled = 0;
673
-    }
674
-    free_device_list(&opencl_ctx.device_list);
675
-end:
676
-    if (opencl_ctx.init_count <= 0)
677
-        av_opt_free(&opencl_ctx); //FIXME: free openclutils context
678
-    UNLOCK_OPENCL;
679
-}
680
-
681
-int av_opencl_buffer_create(cl_mem *cl_buf, size_t cl_buf_size, int flags, void *host_ptr)
682
-{
683
-    cl_int status;
684
-    *cl_buf = clCreateBuffer(opencl_ctx.context, flags, cl_buf_size, host_ptr, &status);
685
-    if (status != CL_SUCCESS) {
686
-        av_log(&opencl_ctx, AV_LOG_ERROR, "Could not create OpenCL buffer: %s\n", av_opencl_errstr(status));
687
-        return AVERROR_EXTERNAL;
688
-    }
689
-    return 0;
690
-}
691
-
692
-void av_opencl_buffer_release(cl_mem *cl_buf)
693
-{
694
-    cl_int status = 0;
695
-    if (!cl_buf)
696
-        return;
697
-    status = clReleaseMemObject(*cl_buf);
698
-    if (status != CL_SUCCESS) {
699
-        av_log(&opencl_ctx, AV_LOG_ERROR,
700
-               "Could not release OpenCL buffer: %s\n", av_opencl_errstr(status));
701
-    }
702
-    memset(cl_buf, 0, sizeof(*cl_buf));
703
-}
704
-
705
-int av_opencl_buffer_write(cl_mem dst_cl_buf, uint8_t *src_buf, size_t buf_size)
706
-{
707
-    cl_int status;
708
-    void *mapped = clEnqueueMapBuffer(opencl_ctx.command_queue, dst_cl_buf,
709
-                                      CL_TRUE, CL_MAP_WRITE, 0, sizeof(uint8_t) * buf_size,
710
-                                      0, NULL, NULL, &status);
711
-
712
-    if (status != CL_SUCCESS) {
713
-        av_log(&opencl_ctx, AV_LOG_ERROR,
714
-               "Could not map OpenCL buffer: %s\n", av_opencl_errstr(status));
715
-        return AVERROR_EXTERNAL;
716
-    }
717
-    memcpy(mapped, src_buf, buf_size);
718
-
719
-    status = clEnqueueUnmapMemObject(opencl_ctx.command_queue, dst_cl_buf, mapped, 0, NULL, NULL);
720
-    if (status != CL_SUCCESS) {
721
-        av_log(&opencl_ctx, AV_LOG_ERROR,
722
-               "Could not unmap OpenCL buffer: %s\n", av_opencl_errstr(status));
723
-        return AVERROR_EXTERNAL;
724
-    }
725
-    return 0;
726
-}
727
-
728
-int av_opencl_buffer_read(uint8_t *dst_buf, cl_mem src_cl_buf, size_t buf_size)
729
-{
730
-    cl_int status;
731
-    void *mapped = clEnqueueMapBuffer(opencl_ctx.command_queue, src_cl_buf,
732
-                                      CL_TRUE, CL_MAP_READ, 0, buf_size,
733
-                                      0, NULL, NULL, &status);
734
-
735
-    if (status != CL_SUCCESS) {
736
-        av_log(&opencl_ctx, AV_LOG_ERROR,
737
-               "Could not map OpenCL buffer: %s\n", av_opencl_errstr(status));
738
-        return AVERROR_EXTERNAL;
739
-    }
740
-    memcpy(dst_buf, mapped, buf_size);
741
-
742
-    status = clEnqueueUnmapMemObject(opencl_ctx.command_queue, src_cl_buf, mapped, 0, NULL, NULL);
743
-    if (status != CL_SUCCESS) {
744
-        av_log(&opencl_ctx, AV_LOG_ERROR,
745
-               "Could not unmap OpenCL buffer: %s\n", av_opencl_errstr(status));
746
-        return AVERROR_EXTERNAL;
747
-    }
748
-    return 0;
749
-}
750
-
751
-int av_opencl_buffer_write_image(cl_mem dst_cl_buf, size_t cl_buffer_size, int dst_cl_offset,
752
-                                 uint8_t **src_data, int *plane_size, int plane_num)
753
-{
754
-    int i, buffer_size = 0;
755
-    uint8_t *temp;
756
-    cl_int status;
757
-    void *mapped;
758
-    if ((unsigned int)plane_num > 8) {
759
-        return AVERROR(EINVAL);
760
-    }
761
-    for (i = 0;i < plane_num;i++) {
762
-        buffer_size += plane_size[i];
763
-    }
764
-    if (buffer_size > cl_buffer_size) {
765
-        av_log(&opencl_ctx, AV_LOG_ERROR,
766
-               "Cannot write image to OpenCL buffer: buffer too small\n");
767
-        return AVERROR(EINVAL);
768
-    }
769
-    mapped = clEnqueueMapBuffer(opencl_ctx.command_queue, dst_cl_buf,
770
-                                CL_TRUE, CL_MAP_WRITE, 0, buffer_size + dst_cl_offset,
771
-                                0, NULL, NULL, &status);
772
-    if (status != CL_SUCCESS) {
773
-        av_log(&opencl_ctx, AV_LOG_ERROR,
774
-               "Could not map OpenCL buffer: %s\n", av_opencl_errstr(status));
775
-        return AVERROR_EXTERNAL;
776
-    }
777
-    temp = mapped;
778
-    temp += dst_cl_offset;
779
-    for (i = 0; i < plane_num; i++) {
780
-        memcpy(temp, src_data[i], plane_size[i]);
781
-        temp += plane_size[i];
782
-    }
783
-    status = clEnqueueUnmapMemObject(opencl_ctx.command_queue, dst_cl_buf, mapped, 0, NULL, NULL);
784
-    if (status != CL_SUCCESS) {
785
-        av_log(&opencl_ctx, AV_LOG_ERROR,
786
-               "Could not unmap OpenCL buffer: %s\n", av_opencl_errstr(status));
787
-        return AVERROR_EXTERNAL;
788
-    }
789
-    return 0;
790
-}
791
-
792
-int av_opencl_buffer_read_image(uint8_t **dst_data, int *plane_size, int plane_num,
793
-                                cl_mem src_cl_buf, size_t cl_buffer_size)
794
-{
795
-    int i,buffer_size = 0,ret = 0;
796
-    uint8_t *temp;
797
-    void *mapped;
798
-    cl_int status;
799
-    if ((unsigned int)plane_num > 8) {
800
-        return AVERROR(EINVAL);
801
-    }
802
-    for (i = 0; i < plane_num; i++) {
803
-        buffer_size += plane_size[i];
804
-    }
805
-    if (buffer_size > cl_buffer_size) {
806
-        av_log(&opencl_ctx, AV_LOG_ERROR,
807
-               "Cannot write image to CPU buffer: OpenCL buffer too small\n");
808
-        return AVERROR(EINVAL);
809
-    }
810
-    mapped = clEnqueueMapBuffer(opencl_ctx.command_queue, src_cl_buf,
811
-                                CL_TRUE, CL_MAP_READ, 0, buffer_size,
812
-                                0, NULL, NULL, &status);
813
-
814
-    if (status != CL_SUCCESS) {
815
-        av_log(&opencl_ctx, AV_LOG_ERROR,
816
-               "Could not map OpenCL buffer: %s\n", av_opencl_errstr(status));
817
-        return AVERROR_EXTERNAL;
818
-    }
819
-    temp = mapped;
820
-    if (ret >= 0) {
821
-        for (i = 0; i < plane_num; i++) {
822
-            memcpy(dst_data[i], temp, plane_size[i]);
823
-            temp += plane_size[i];
824
-        }
825
-    }
826
-    status = clEnqueueUnmapMemObject(opencl_ctx.command_queue, src_cl_buf, mapped, 0, NULL, NULL);
827
-    if (status != CL_SUCCESS) {
828
-        av_log(&opencl_ctx, AV_LOG_ERROR,
829
-               "Could not unmap OpenCL buffer: %s\n", av_opencl_errstr(status));
830
-        return AVERROR_EXTERNAL;
831
-    }
832
-    return 0;
833
-}
834
-
835
-int64_t av_opencl_benchmark(AVOpenCLDeviceNode *device_node, cl_platform_id platform,
836
-                            int64_t (*benchmark)(AVOpenCLExternalEnv *ext_opencl_env))
837
-{
838
-    int64_t ret = 0;
839
-    cl_int status;
840
-    cl_context_properties cps[3];
841
-    AVOpenCLExternalEnv *ext_opencl_env = NULL;
842
-
843
-    ext_opencl_env = av_opencl_alloc_external_env();
844
-    ext_opencl_env->device_id = device_node->device_id;
845
-    ext_opencl_env->device_type = device_node->device_type;
846
-    av_log(&opencl_ctx, AV_LOG_VERBOSE, "Performing test on OpenCL device %s\n",
847
-           device_node->device_name);
848
-
849
-    cps[0] = CL_CONTEXT_PLATFORM;
850
-    cps[1] = (cl_context_properties)platform;
851
-    cps[2] = 0;
852
-    ext_opencl_env->context = clCreateContextFromType(cps, ext_opencl_env->device_type,
853
-                                                      NULL, NULL, &status);
854
-    if (status != CL_SUCCESS || !ext_opencl_env->context) {
855
-        ret = AVERROR_EXTERNAL;
856
-        goto end;
857
-    }
858
-    ext_opencl_env->command_queue = clCreateCommandQueue(ext_opencl_env->context,
859
-                                                         ext_opencl_env->device_id, 0, &status);
860
-    if (status != CL_SUCCESS || !ext_opencl_env->command_queue) {
861
-        ret = AVERROR_EXTERNAL;
862
-        goto end;
863
-    }
864
-    ret = benchmark(ext_opencl_env);
865
-    if (ret < 0)
866
-        av_log(&opencl_ctx, AV_LOG_ERROR, "Benchmark failed with OpenCL device %s\n",
867
-               device_node->device_name);
868
-end:
869
-    if (ext_opencl_env->command_queue)
870
-        clReleaseCommandQueue(ext_opencl_env->command_queue);
871
-    if (ext_opencl_env->context)
872
-        clReleaseContext(ext_opencl_env->context);
873
-    av_opencl_free_external_env(&ext_opencl_env);
874
-    return ret;
875
-}
876 1
deleted file mode 100644
... ...
@@ -1,292 +0,0 @@
1
-/*
2
- * Copyright (C) 2012 Peng  Gao     <peng@multicorewareinc.com>
3
- * Copyright (C) 2012 Li    Cao     <li@multicorewareinc.com>
4
- * Copyright (C) 2012 Wei   Gao     <weigao@multicorewareinc.com>
5
- * Copyright (C) 2013 Lenny Wang    <lwanghpc@gmail.com>
6
- *
7
- * This file is part of FFmpeg.
8
- *
9
- * FFmpeg is free software; you can redistribute it and/or
10
- * modify it under the terms of the GNU Lesser General Public
11
- * License as published by the Free Software Foundation; either
12
- * version 2.1 of the License, or (at your option) any later version.
13
- *
14
- * FFmpeg is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
- * Lesser General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU Lesser General Public
20
- * License along with FFmpeg; if not, write to the Free Software
21
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
- */
23
-
24
-/**
25
- * @file
26
- * OpenCL wrapper
27
- *
28
- * This interface is considered still experimental and its API and ABI may
29
- * change without prior notice.
30
- */
31
-
32
-#ifndef AVUTIL_OPENCL_H
33
-#define AVUTIL_OPENCL_H
34
-
35
-#define CL_USE_DEPRECATED_OPENCL_1_2_APIS 1
36
-#ifdef __APPLE__
37
-#include <OpenCL/cl.h>
38
-#else
39
-#include <CL/cl.h>
40
-#endif
41
-#include <stdint.h>
42
-#include "dict.h"
43
-
44
-#include "libavutil/version.h"
45
-
46
-#define AV_OPENCL_KERNEL( ... )# __VA_ARGS__
47
-
48
-typedef struct {
49
-    int device_type;
50
-    char *device_name;
51
-    cl_device_id device_id;
52
-} AVOpenCLDeviceNode;
53
-
54
-typedef struct {
55
-    cl_platform_id platform_id;
56
-    char *platform_name;
57
-    int device_num;
58
-    AVOpenCLDeviceNode **device_node;
59
-} AVOpenCLPlatformNode;
60
-
61
-typedef struct {
62
-    int platform_num;
63
-    AVOpenCLPlatformNode **platform_node;
64
-} AVOpenCLDeviceList;
65
-
66
-typedef struct {
67
-    cl_platform_id platform_id;
68
-    cl_device_type device_type;
69
-    cl_context context;
70
-    cl_device_id  device_id;
71
-    cl_command_queue command_queue;
72
-    char *platform_name;
73
-} AVOpenCLExternalEnv;
74
-
75
-/**
76
- * Get OpenCL device list.
77
- *
78
- * It must be freed with av_opencl_free_device_list().
79
- *
80
- * @param device_list pointer to OpenCL environment device list,
81
- *                    should be released by av_opencl_free_device_list()
82
- *
83
- * @return  >=0 on success, a negative error code in case of failure
84
- */
85
-int av_opencl_get_device_list(AVOpenCLDeviceList **device_list);
86
-
87
-/**
88
-  * Free OpenCL device list.
89
-  *
90
-  * @param device_list pointer to OpenCL environment device list
91
-  *                       created by av_opencl_get_device_list()
92
-  */
93
-void av_opencl_free_device_list(AVOpenCLDeviceList **device_list);
94
-
95
-/**
96
- * Set option in the global OpenCL context.
97
- *
98
- * This options affect the operation performed by the next
99
- * av_opencl_init() operation.
100
- *
101
- * The currently accepted options are:
102
- * - platform: set index of platform in device list
103
- * - device: set index of device in device list
104
- *
105
- * See reference "OpenCL Specification Version: 1.2 chapter 5.6.4".
106
- *
107
- * @param key                 option key
108
- * @param val                 option value
109
- * @return >=0 on success, a negative error code in case of failure
110
- * @see av_opencl_get_option()
111
- */
112
-int av_opencl_set_option(const char *key, const char *val);
113
-
114
-/**
115
- * Get option value from the global OpenCL context.
116
- *
117
- * @param key        option key
118
- * @param out_val  pointer to location where option value will be
119
- *                         written, must be freed with av_freep()
120
- * @return  >=0 on success, a negative error code in case of failure
121
- * @see av_opencl_set_option()
122
- */
123
-int av_opencl_get_option(const char *key, uint8_t **out_val);
124
-
125
-/**
126
- * Free option values of the global OpenCL context.
127
- *
128
- */
129
-void av_opencl_free_option(void);
130
-
131
-/**
132
- * Allocate OpenCL external environment.
133
- *
134
- * It must be freed with av_opencl_free_external_env().
135
- *
136
- * @return pointer to allocated OpenCL external environment
137
- */
138
-AVOpenCLExternalEnv *av_opencl_alloc_external_env(void);
139
-
140
-/**
141
- * Free OpenCL external environment.
142
- *
143
- * @param ext_opencl_env pointer to OpenCL external environment
144
- *                       created by av_opencl_alloc_external_env()
145
- */
146
-void av_opencl_free_external_env(AVOpenCLExternalEnv **ext_opencl_env);
147
-
148
-/**
149
- * Get OpenCL error string.
150
- *
151
- * @param status    OpenCL error code
152
- * @return OpenCL error string
153
- */
154
-const char *av_opencl_errstr(cl_int status);
155
-
156
-/**
157
- * Register kernel code.
158
- *
159
- *  The registered kernel code is stored in a global context, and compiled
160
- *  in the runtime environment when av_opencl_init() is called.
161
- *
162
- * @param kernel_code    kernel code to be compiled in the OpenCL runtime environment
163
- * @return  >=0 on success, a negative error code in case of failure
164
- */
165
-int av_opencl_register_kernel_code(const char *kernel_code);
166
-
167
-/**
168
- * Initialize the run time OpenCL environment
169
- *
170
- * @param ext_opencl_env external OpenCL environment, created by an
171
- *                       application program, ignored if set to NULL
172
- * @return >=0 on success, a negative error code in case of failure
173
- */
174
-int av_opencl_init(AVOpenCLExternalEnv *ext_opencl_env);
175
-
176
-/**
177
- * compile specific OpenCL kernel source
178
- *
179
- * @param program_name  pointer to a program name used for identification
180
- * @param build_opts    pointer to a string that describes the preprocessor
181
- *                      build options to be used for building the program
182
- * @return a cl_program object
183
- */
184
-cl_program av_opencl_compile(const char *program_name, const char* build_opts);
185
-
186
-/**
187
- * get OpenCL command queue
188
- *
189
- * @return a cl_command_queue object
190
- */
191
-cl_command_queue av_opencl_get_command_queue(void);
192
-
193
-/**
194
- * Create OpenCL buffer.
195
- *
196
- * The buffer is used to save the data used or created by an OpenCL
197
- * kernel.
198
- * The created buffer must be released with av_opencl_buffer_release().
199
- *
200
- * See clCreateBuffer() function reference for more information about
201
- * the parameters.
202
- *
203
- * @param cl_buf       pointer to OpenCL buffer
204
- * @param cl_buf_size  size in bytes of the OpenCL buffer to create
205
- * @param flags        flags used to control buffer attributes
206
- * @param host_ptr     host pointer of the OpenCL buffer
207
- * @return >=0 on success, a negative error code in case of failure
208
- */
209
-int av_opencl_buffer_create(cl_mem *cl_buf, size_t cl_buf_size, int flags, void *host_ptr);
210
-
211
-/**
212
- * Write OpenCL buffer with data from src_buf.
213
- *
214
- * @param dst_cl_buf        pointer to OpenCL destination buffer
215
- * @param src_buf           pointer to source buffer
216
- * @param buf_size          size in bytes of the source and destination buffers
217
- * @return >=0 on success, a negative error code in case of failure
218
- */
219
-int av_opencl_buffer_write(cl_mem dst_cl_buf, uint8_t *src_buf, size_t buf_size);
220
-
221
-/**
222
- * Read data from OpenCL buffer to memory buffer.
223
- *
224
- * @param dst_buf           pointer to destination buffer (CPU memory)
225
- * @param src_cl_buf        pointer to source OpenCL buffer
226
- * @param buf_size          size in bytes of the source and destination buffers
227
- * @return >=0 on success, a negative error code in case of failure
228
- */
229
-int av_opencl_buffer_read(uint8_t *dst_buf, cl_mem src_cl_buf, size_t buf_size);
230
-
231
-/**
232
- * Write image data from memory to OpenCL buffer.
233
- *
234
- * The source must be an array of pointers to image plane buffers.
235
- *
236
- * @param dst_cl_buf         pointer to destination OpenCL buffer
237
- * @param dst_cl_buf_size    size in bytes of OpenCL buffer
238
- * @param dst_cl_buf_offset  the offset of the OpenCL buffer start position
239
- * @param src_data           array of pointers to source plane buffers
240
- * @param src_plane_sizes    array of sizes in bytes of the source plane buffers
241
- * @param src_plane_num      number of source image planes
242
- * @return >=0 on success, a negative error code in case of failure
243
- */
244
-int av_opencl_buffer_write_image(cl_mem dst_cl_buf, size_t cl_buffer_size, int dst_cl_offset,
245
-                                 uint8_t **src_data, int *plane_size, int plane_num);
246
-
247
-/**
248
- * Read image data from OpenCL buffer.
249
- *
250
- * @param dst_data           array of pointers to destination plane buffers
251
- * @param dst_plane_sizes    array of pointers to destination plane buffers
252
- * @param dst_plane_num      number of destination image planes
253
- * @param src_cl_buf         pointer to source OpenCL buffer
254
- * @param src_cl_buf_size    size in bytes of OpenCL buffer
255
- * @return >=0 on success, a negative error code in case of failure
256
- */
257
-int av_opencl_buffer_read_image(uint8_t **dst_data, int *plane_size, int plane_num,
258
-                                cl_mem src_cl_buf, size_t cl_buffer_size);
259
-
260
-/**
261
- * Release OpenCL buffer.
262
- *
263
- * @param cl_buf pointer to OpenCL buffer to release, which was
264
- *               previously filled with av_opencl_buffer_create()
265
- */
266
-void av_opencl_buffer_release(cl_mem *cl_buf);
267
-
268
-/**
269
- * Release OpenCL environment.
270
- *
271
- * The OpenCL environment is effectively released only if all the created
272
- * kernels had been released with av_opencl_release_kernel().
273
- */
274
-void av_opencl_uninit(void);
275
-
276
-/**
277
- * Benchmark an OpenCL device with a user defined callback function.  This function
278
- * sets up an external OpenCL environment including context and command queue on
279
- * the device then tears it down in the end.  The callback function should perform
280
- * the rest of the work.
281
- *
282
- * @param device            pointer to the OpenCL device to be used
283
- * @param platform          cl_platform_id handle to which the device belongs to
284
- * @param benchmark         callback function to perform the benchmark, return a
285
- *                          negative value in case of failure
286
- * @return the score passed from the callback function, a negative error code in case
287
- * of failure
288
- */
289
-int64_t av_opencl_benchmark(AVOpenCLDeviceNode *device, cl_platform_id platform,
290
-                            int64_t (*benchmark)(AVOpenCLExternalEnv *ext_opencl_env));
291
-
292
-#endif /* AVUTIL_OPENCL_H */
293 1
deleted file mode 100644
... ...
@@ -1,59 +0,0 @@
1
-/*
2
- * Copyright (C) 2012 Peng Gao <peng@multicorewareinc.com>
3
- * Copyright (C) 2012 Li   Cao <li@multicorewareinc.com>
4
- * Copyright (C) 2012 Wei  Gao <weigao@multicorewareinc.com>
5
- *
6
- * This file is part of FFmpeg.
7
- *
8
- * FFmpeg is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU Lesser General Public
10
- * License as published by the Free Software Foundation; either
11
- * version 2.1 of the License, or (at your option) any later version.
12
- *
13
- * FFmpeg is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
- * Lesser General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU Lesser General Public
19
- * License along with FFmpeg; if not, write to the Free Software
20
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
- */
22
-
23
-#include "opencl_internal.h"
24
-#include "libavutil/log.h"
25
-
26
-int avpriv_opencl_set_parameter(FFOpenclParam *opencl_param, ...)
27
-{
28
-    int ret = 0;
29
-    va_list arg_ptr;
30
-    void *param;
31
-    size_t param_size;
32
-    cl_int status;
33
-    if (!opencl_param->kernel) {
34
-        av_log(opencl_param->ctx, AV_LOG_ERROR, "OpenCL kernel must be set\n");
35
-        return AVERROR(EINVAL);
36
-    }
37
-    va_start(arg_ptr, opencl_param);
38
-    do {
39
-        param = va_arg(arg_ptr, void *);
40
-        if (!param)
41
-            break;
42
-        param_size = va_arg(arg_ptr, size_t);
43
-        if (!param_size) {
44
-            av_log(opencl_param->ctx, AV_LOG_ERROR, "Parameter size must not be 0\n");
45
-            ret = AVERROR(EINVAL);
46
-            goto end;
47
-        }
48
-        status = clSetKernelArg(opencl_param->kernel, opencl_param->param_num, param_size, param);
49
-        if (status != CL_SUCCESS) {
50
-            av_log(opencl_param->ctx, AV_LOG_ERROR, "Cannot set kernel argument: %s\n", av_opencl_errstr(status));
51
-            ret = AVERROR_EXTERNAL;
52
-            goto end;
53
-        }
54
-        opencl_param->param_num++;
55
-    } while (param && param_size);
56
-end:
57
-    va_end(arg_ptr);
58
-    return ret;
59
-}
60 1
deleted file mode 100644
... ...
@@ -1,40 +0,0 @@
1
-/*
2
- * Copyright (C) 2012 Peng Gao <peng@multicorewareinc.com>
3
- * Copyright (C) 2012 Li   Cao <li@multicorewareinc.com>
4
- * Copyright (C) 2012 Wei  Gao <weigao@multicorewareinc.com>
5
- *
6
- * This file is part of FFmpeg.
7
- *
8
- * FFmpeg is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU Lesser General Public
10
- * License as published by the Free Software Foundation; either
11
- * version 2.1 of the License, or (at your option) any later version.
12
- *
13
- * FFmpeg is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
- * Lesser General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU Lesser General Public
19
- * License along with FFmpeg; if not, write to the Free Software
20
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
- */
22
-
23
-#ifndef AVUTIL_OPENCL_INTERNAL_H
24
-#define AVUTIL_OPENCL_INTERNAL_H
25
-
26
-#include "attributes.h"
27
-#include "opencl.h"
28
-
29
-#define FF_OPENCL_PARAM_INFO(a) ((void*)(&(a))), (sizeof(a))
30
-
31
-typedef struct {
32
-    cl_kernel kernel;
33
-    int param_num;
34
-    void *ctx;
35
-} FFOpenclParam;
36
-
37
-av_warn_unused_result
38
-int avpriv_opencl_set_parameter(FFOpenclParam *opencl_param, ...);
39
-
40
-#endif /* AVUTIL_OPENCL_INTERNAL_H */