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
28
31 {
33
35
39
41 ctx->hwctx =
ctx->device->hwctx;
42
43 return 0;
44 }
45
47 {
52 int err;
53
56 "hardware frames context on the input.\n");
58 }
59
60 // Extract the device and default output format from the first input.
62 return 0;
63
67
69 if (err < 0)
70 return err;
71
72 // Default output parameters match input parameters.
75 if (!
ctx->output_width)
77 if (!
ctx->output_height)
79
80 return 0;
81 }
82
84 {
90 int err;
91
93
94 if (!
ctx->device_ref) {
97 "OpenCL device.\n");
99 }
100
102 if (err < 0)
103 return err;
104 }
105
107 if (!output_frames_ref) {
110 }
112
115 output_frames->
width =
ctx->output_width;
116 output_frames->
height =
ctx->output_height;
117
119 if (err < 0) {
121 "frames: %d.\n", err);
123 }
124
126 outlink->
w =
ctx->output_width;
127 outlink->
h =
ctx->output_height;
128
129 return 0;
132 return err;
133 }
134
136 {
138
140
141 return 0;
142 }
143
145 {
147 cl_int cle;
148
150 cle = clReleaseProgram(
ctx->program);
151 if (cle != CL_SUCCESS)
153 "program: %d.\n", cle);
154 }
155
157 }
158
160 const char **program_source_array,
161 int nb_strings)
162 {
164 cl_int cle;
165
166 ctx->program = clCreateProgramWithSource(
ctx->hwctx->context, nb_strings,
167 program_source_array,
172 }
173
174 cle = clBuildProgram(
ctx->program, 1, &
ctx->hwctx->device_id,
176 if (cle != CL_SUCCESS) {
178
179 if (cle == CL_BUILD_PROGRAM_FAILURE) {
181 size_t log_length;
182
183 clGetProgramBuildInfo(
ctx->program,
ctx->hwctx->device_id,
184 CL_PROGRAM_BUILD_LOG, 0,
NULL, &log_length);
185
188 cle = clGetProgramBuildInfo(
ctx->program,
189 ctx->hwctx->device_id,
190 CL_PROGRAM_BUILD_LOG,
192 if (cle == CL_SUCCESS)
194 }
195
197 }
198
199 clReleaseProgram(
ctx->program);
202 }
203
204 return 0;
205 }
206
208 const char *filename)
209 {
210 FILE *file;
213 const char *src_const;
214 int err;
215
217 if (!file) {
219 "source file \"%s\".\n", filename);
221 }
222
225
227 if (err < 0)
229
231 if (err < 0) {
234 }
238 }
240
241 while (1) {
243 if (rb == 0 && ferror(file)) {
246 }
249 break;
252 if (err < 0)
254 }
256
258
261 fclose(file);
263 return err;
264 }
265
267 size_t *work_size,
269 int block_alignment)
270 {
271 cl_mem image;
272 cl_mem_object_type
type;
274 cl_int cle;
275
280 }
281
282 image = (cl_mem)
frame->data[plane];
285 plane);
287 }
288
289 cle = clGetMemObjectInfo(image, CL_MEM_TYPE,
sizeof(
type),
291 if (cle != CL_SUCCESS) {
293 "plane %d: %d.\n", plane, cle);
295 }
296 if (
type != CL_MEM_OBJECT_IMAGE2D) {
298 plane);
300 }
301
302 cle = clGetImageInfo(image, CL_IMAGE_WIDTH, sizeof(size_t),
304 if (cle != CL_SUCCESS) {
306 plane, cle);
308 }
309
310 cle = clGetImageInfo(image, CL_IMAGE_HEIGHT, sizeof(size_t),
312 if (cle != CL_SUCCESS) {
314 plane, cle);
316 }
317
318 if (block_alignment) {
321 }
322
323 work_size[0] =
width;
325
326 return 0;
327 }
328
330 double mat[3][3])
331 {
333 av_bprintf(buf,
"__constant float %s[9] = {\n", name_str);
334 for (
i = 0;
i < 3;
i++) {
335 for (j = 0; j < 3; j++)
338 }
340 }
341
343 cl_ulong time_start;
344 cl_ulong time_end;
345
346 clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_START,
sizeof(time_start), &time_start,
NULL);
347 clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_END,
sizeof(time_end), &time_end,
NULL);
348
349 return time_end - time_start;
350 }