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
32
34 #define ROUND_TO_16(a) (((((a) - 1)/16)+1)*16)
35
38 const float *matrix_y, const float *matrix_uv,
41 {
43 cl_int status;
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]};
49 size_t local_worksize[2] = {16, 16};
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
59 }
71 if (ret < 0)
88 if (ret < 0)
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) {
99 }
101 deshake->opencl_ctx.plane_num, deshake->opencl_ctx.cl_outbuf,
102 deshake->opencl_ctx.cl_outbuf_size);
103 if (ret < 0)
106 }
107
109 {
110 int ret = 0;
113 if (ret < 0)
115 deshake->opencl_ctx.plane_num =
PLANE_NUM;
117 if (!deshake->opencl_ctx.command_queue) {
118 av_log(ctx,
AV_LOG_ERROR,
"Unable to get OpenCL command queue in filter 'deshake'\n");
120 }
122 if (!deshake->opencl_ctx.program) {
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");
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");
140 }
141 }
143 }
144
146 {
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;
155 }
156
158 {
159 int ret = 0;
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) {
180 deshake->opencl_ctx.cl_inbuf_size,
181 CL_MEM_READ_ONLY,
NULL);
182 if (ret < 0)
184 }
185 if (!deshake->opencl_ctx.cl_outbuf) {
187 deshake->opencl_ctx.cl_outbuf_size,
188 CL_MEM_READ_WRITE,
NULL);
189 if (ret < 0)
191 }
192 }
194 deshake->opencl_ctx.cl_inbuf_size,
195 0, in->
data,deshake->opencl_ctx.in_plane_size,
196 deshake->opencl_ctx.plane_num);
197 if(ret < 0)
200 }