1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <stdio.h>
20 #include <string.h>
21
25
27
30 {
32
34
38
40 ctx->hwctx =
ctx->device->hwctx;
41
42 return 0;
43 }
44
46 {
50 int err;
51
52 if (!
inlink->hw_frames_ctx) {
54 "hardware frames context on the input.\n");
56 }
57
58 // Extract the device and default output format from the first input.
60 return 0;
61
65
67 if (err < 0)
68 return err;
69
70 // Default output parameters match input parameters.
73 if (!
ctx->output_width)
75 if (!
ctx->output_height)
77
78 return 0;
79 }
80
82 {
87 int err;
88
90
91 if (!
ctx->device_ref) {
94 "OpenCL device.\n");
96 }
97
99 if (err < 0)
100 return err;
101 }
102
104 if (!output_frames_ref) {
107 }
109
112 output_frames->
width =
ctx->output_width;
113 output_frames->
height =
ctx->output_height;
114
116 if (err < 0) {
118 "frames: %d.\n", err);
120 }
121
123 outlink->
w =
ctx->output_width;
124 outlink->
h =
ctx->output_height;
125
126 return 0;
129 return err;
130 }
131
133 {
135
137
138 return 0;
139 }
140
142 {
144 cl_int cle;
145
147 cle = clReleaseProgram(
ctx->program);
148 if (cle != CL_SUCCESS)
150 "program: %d.\n", cle);
151 }
152
154 }
155
157 const char **program_source_array,
158 int nb_strings)
159 {
161 cl_int cle;
162
163 ctx->program = clCreateProgramWithSource(
ctx->hwctx->context, nb_strings,
164 program_source_array,
169 }
170
171 cle = clBuildProgram(
ctx->program, 1, &
ctx->hwctx->device_id,
173 if (cle != CL_SUCCESS) {
175
176 if (cle == CL_BUILD_PROGRAM_FAILURE) {
178 size_t log_length;
179
180 clGetProgramBuildInfo(
ctx->program,
ctx->hwctx->device_id,
181 CL_PROGRAM_BUILD_LOG, 0,
NULL, &log_length);
182
185 cle = clGetProgramBuildInfo(
ctx->program,
186 ctx->hwctx->device_id,
187 CL_PROGRAM_BUILD_LOG,
189 if (cle == CL_SUCCESS)
191 }
192
194 }
195
196 clReleaseProgram(
ctx->program);
199 }
200
201 return 0;
202 }
203
205 const char *filename)
206 {
207 FILE *file;
210 const char *src_const;
211 int err;
212
214 if (!file) {
216 "source file \"%s\".\n", filename);
218 }
219
222
224 if (err < 0)
226
228 if (err < 0) {
231 }
235 }
237
238 while (1) {
240 if (rb == 0 && ferror(file)) {
243 }
246 break;
249 if (err < 0)
251 }
253
255
258 fclose(file);
260 return err;
261 }
262
264 size_t *work_size,
266 int block_alignment)
267 {
268 cl_mem image;
269 cl_mem_object_type
type;
271 cl_int cle;
272
277 }
278
282 plane);
284 }
285
286 cle = clGetMemObjectInfo(image, CL_MEM_TYPE,
sizeof(
type),
288 if (cle != CL_SUCCESS) {
290 "plane %d: %d.\n", plane, cle);
292 }
293 if (
type != CL_MEM_OBJECT_IMAGE2D) {
295 plane);
297 }
298
299 cle = clGetImageInfo(image, CL_IMAGE_WIDTH, sizeof(size_t),
301 if (cle != CL_SUCCESS) {
303 plane, cle);
305 }
306
307 cle = clGetImageInfo(image, CL_IMAGE_HEIGHT, sizeof(size_t),
309 if (cle != CL_SUCCESS) {
311 plane, cle);
313 }
314
315 if (block_alignment) {
318 }
319
320 work_size[0] =
width;
322
323 return 0;
324 }
325
327 double mat[3][3])
328 {
330 av_bprintf(buf,
"__constant float %s[9] = {\n", name_str);
331 for (
i = 0;
i < 3;
i++) {
332 for (j = 0; j < 3; j++)
335 }
337 }
338
340 cl_ulong time_start;
341 cl_ulong time_end;
342
343 clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_START,
sizeof(time_start), &time_start,
NULL);
344 clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_END,
sizeof(time_end), &time_end,
NULL);
345
346 return time_end - time_start;
347 }