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
22
27
29 "in_h", "ih",
30 "in_w", "iw",
31 "x",
32 "y",
33 "h",
34 "w",
35 "t",
36 "fill",
38 };
39
50 };
51
53
57
58 /* The hardware frame context containing the frames for outer_rect. */
62
68
74
76
78
80 {
85 double var_values[
VARS_NB], res;
87 char *expr;
88
96
98 /* evaluate expressions, fail on last iteration */
105
112
119
126
132 ctx->thickness = var_values[
VAR_T] = res;
133 }
134
135 /* Sanity check */
142
143 ctx->outer_rect.x =
ctx->x;
144 ctx->outer_rect.y =
ctx->y;
145 ctx->outer_rect.width =
ctx->w;
146 ctx->outer_rect.height =
ctx->h;
147
148 if (
ctx->outer_rect.width <=
ctx->thickness * 2 ||
149 ctx->outer_rect.height <=
ctx->thickness * 2) {
151 } else {
153 ctx->inner_rect.x =
ctx->outer_rect.x +
ctx->thickness;
154 ctx->inner_rect.y =
ctx->outer_rect.y +
ctx->thickness;
155 ctx->inner_rect.width =
ctx->outer_rect.width -
ctx->thickness * 2;
156 ctx->inner_rect.height =
ctx->outer_rect.height -
ctx->thickness * 2;
157 }
158
161
165
167 if (!
ctx->outer_frames_ref) {
169 }
170
172
175 ctx->outer_frames->width =
ctx->outer_rect.width;
176 ctx->outer_frames->height =
ctx->outer_rect.height;
177
179
182 "Error when evaluating the expression '%s'.\n",
183 expr);
185 }
186
188 {
194 VAProcPipelineParameterBuffer box_params;
195 VAProcPipelineParameterBuffer params[3];
196 VABlendState blend_state = {
197 .flags = VA_BLEND_GLOBAL_ALPHA,
198 };
199 VARectangle box[4];
200 int err, nb_params = 0;
201
206 }
207
213 }
214
216 if (err < 0) {
219 }
220
221 /* Create image for the outer rect */
224 if (err < 0)
226
227 blend_state.global_alpha = 0.0f;
228 box_params.surface_region = &drawbox_ctx->
outer_rect;
229 box_params.blend_state = &blend_state;
230 box_params.output_background_color = (drawbox_ctx->
drawbox_rgba[3] << 24 |
234
236 if (err < 0)
238 }
239
240 /* Draw outer & inner rects on the input video, then we can get a box*/
245 }
246
248 if (err < 0)
250
253 if (err < 0)
255
256 box[0].x = 0;
257 box[0].y = 0;
258 box[0].width =
link->w;
260 params[nb_params].surface_region = &box[0];
261 params[nb_params].output_background_color = 0;
262 nb_params++;
263
266 if (err < 0)
268
272 params[nb_params].blend_state = &blend_state;
273 }
274 params[nb_params].output_region = &box[1];
275 params[nb_params].output_background_color = 0;
276 nb_params++;
277
278 if (!drawbox_ctx->
fill) {
280 params[nb_params] = params[0];
281 params[nb_params].surface_region = &box[2];
282 params[nb_params].output_region = &box[3];
283 params[nb_params].output_background_color = 0;
284 nb_params++;
285 }
286
288 if (err < 0)
290
292
294
298 return err;
299 }
300
302 {
304
308
309 return 0;
310 }
311
313 {
315
319 }
320
321 #define OFFSET(x) offsetof(DrawboxVAAPIContext, x)
322 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
323
337 };
338
340
342 {
347 },
348 };
349
351 {
355 },
356 };
357
359 .
name =
"drawbox_vaapi",
362 .priv_class = &drawbox_vaapi_class,
369 };