Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Copyright (c) 2011 Stefano Sabatini | ||
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 | /** | ||
22 | * @file | ||
23 | * buffer sink | ||
24 | */ | ||
25 | |||
26 | #include "libavutil/avassert.h" | ||
27 | #include "libavutil/avstring.h" | ||
28 | #include "libavutil/channel_layout.h" | ||
29 | #include "libavutil/common.h" | ||
30 | #include "libavutil/internal.h" | ||
31 | #include "libavutil/mem.h" | ||
32 | #include "libavutil/opt.h" | ||
33 | |||
34 | #include "audio.h" | ||
35 | #include "avfilter.h" | ||
36 | #include "avfilter_internal.h" | ||
37 | #include "buffersink.h" | ||
38 | #include "filters.h" | ||
39 | #include "formats.h" | ||
40 | #include "framequeue.h" | ||
41 | #include "video.h" | ||
42 | |||
43 | typedef struct BufferSinkContext { | ||
44 | const AVClass *class; | ||
45 | unsigned warning_limit; | ||
46 | unsigned frame_size; | ||
47 | |||
48 | /* only used for video */ | ||
49 | #if FF_API_BUFFERSINK_OPTS | ||
50 | enum AVPixelFormat *pixel_fmts; ///< list of accepted pixel formats | ||
51 | int pixel_fmts_size; | ||
52 | enum AVColorSpace *color_spaces; ///< list of accepted color spaces | ||
53 | int color_spaces_size; | ||
54 | enum AVColorRange *color_ranges; ///< list of accepted color ranges | ||
55 | int color_ranges_size; | ||
56 | enum AVColorRange *alpha_modes; ///< list of accepted alpha modes | ||
57 | int alpha_modes_size; | ||
58 | #endif | ||
59 | |||
60 | enum AVPixelFormat *pixel_formats; | ||
61 | unsigned nb_pixel_formats; | ||
62 | |||
63 | int *colorspaces; | ||
64 | unsigned nb_colorspaces; | ||
65 | |||
66 | int *colorranges; | ||
67 | unsigned nb_colorranges; | ||
68 | |||
69 | int *alphamodes; | ||
70 | unsigned nb_alphamodes; | ||
71 | |||
72 | /* only used for audio */ | ||
73 | #if FF_API_BUFFERSINK_OPTS | ||
74 | enum AVSampleFormat *sample_fmts; ///< list of accepted sample formats | ||
75 | int sample_fmts_size; | ||
76 | char *channel_layouts_str; ///< list of accepted channel layouts | ||
77 | int all_channel_counts; | ||
78 | int *sample_rates; ///< list of accepted sample rates | ||
79 | int sample_rates_size; | ||
80 | #endif | ||
81 | |||
82 | enum AVSampleFormat *sample_formats; | ||
83 | unsigned nb_sample_formats; | ||
84 | |||
85 | int *samplerates; | ||
86 | unsigned nb_samplerates; | ||
87 | |||
88 | AVChannelLayout *channel_layouts; | ||
89 | unsigned nb_channel_layouts; | ||
90 | |||
91 | AVFrame *peeked_frame; | ||
92 | } BufferSinkContext; | ||
93 | |||
94 | ✗ | int attribute_align_arg av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame) | |
95 | { | ||
96 | ✗ | return av_buffersink_get_frame_flags(ctx, frame, 0); | |
97 | } | ||
98 | |||
99 | 458139 | static int return_or_keep_frame(BufferSinkContext *buf, AVFrame *out, AVFrame *in, int flags) | |
100 | { | ||
101 |
2/2✓ Branch 0 taken 43068 times.
✓ Branch 1 taken 415071 times.
|
458139 | if ((flags & AV_BUFFERSINK_FLAG_PEEK)) { |
102 | 43068 | buf->peeked_frame = in; | |
103 |
2/2✓ Branch 0 taken 12687 times.
✓ Branch 1 taken 30381 times.
|
43068 | return out ? av_frame_ref(out, in) : 0; |
104 | } else { | ||
105 | av_assert1(out); | ||
106 | 415071 | buf->peeked_frame = NULL; | |
107 | 415071 | av_frame_move_ref(out, in); | |
108 | 415071 | av_frame_free(&in); | |
109 | 415071 | return 0; | |
110 | } | ||
111 | } | ||
112 | |||
113 | 1287970 | static int get_frame_internal(AVFilterContext *ctx, AVFrame *frame, int flags, int samples) | |
114 | { | ||
115 | 1287970 | BufferSinkContext *buf = ctx->priv; | |
116 | 1287970 | AVFilterLink *inlink = ctx->inputs[0]; | |
117 | 1287970 | FilterLinkInternal *li = ff_link_internal(inlink); | |
118 | int status, ret; | ||
119 | AVFrame *cur_frame; | ||
120 | int64_t pts; | ||
121 | 1287970 | int buffersrc_empty = 0; | |
122 | |||
123 |
2/2✓ Branch 0 taken 1244904 times.
✓ Branch 1 taken 43066 times.
|
1287970 | if (buf->peeked_frame) |
124 | 43066 | return return_or_keep_frame(buf, frame, buf->peeked_frame, flags); | |
125 | |||
126 | while (1) { | ||
127 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3508612 times.
|
3508612 | ret = samples ? ff_inlink_consume_samples(inlink, samples, samples, &cur_frame) : |
128 | 3508612 | ff_inlink_consume_frame(inlink, &cur_frame); | |
129 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3508612 times.
|
3508612 | if (ret < 0) { |
130 | ✗ | return ret; | |
131 |
2/2✓ Branch 0 taken 415073 times.
✓ Branch 1 taken 3093539 times.
|
3508612 | } else if (ret) { |
132 | /* TODO return the frame instead of copying it */ | ||
133 | 415073 | return return_or_keep_frame(buf, frame, cur_frame, flags); | |
134 |
2/2✓ Branch 1 taken 9288 times.
✓ Branch 2 taken 3084251 times.
|
3093539 | } else if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { |
135 | 9288 | return status; | |
136 |
2/2✓ Branch 0 taken 446086 times.
✓ Branch 1 taken 2638165 times.
|
3084251 | } else if ((flags & AV_BUFFERSINK_FLAG_NO_REQUEST)) { |
137 | 446086 | return AVERROR(EAGAIN); | |
138 |
2/2✓ Branch 0 taken 2223572 times.
✓ Branch 1 taken 414593 times.
|
2638165 | } else if (li->frame_wanted_out) { |
139 | 2223572 | ret = ff_filter_graph_run_once(ctx->graph); | |
140 |
2/2✓ Branch 0 taken 374888 times.
✓ Branch 1 taken 1848684 times.
|
2223572 | if (ret == FFERROR_BUFFERSRC_EMPTY) { |
141 | 374888 | buffersrc_empty = 1; | |
142 |
2/2✓ Branch 0 taken 378906 times.
✓ Branch 1 taken 1469778 times.
|
1848684 | } else if (ret == AVERROR(EAGAIN)) { |
143 |
2/2✓ Branch 0 taken 374457 times.
✓ Branch 1 taken 4449 times.
|
378906 | if (buffersrc_empty) |
144 | 374457 | return ret; | |
145 | 4449 | ff_inlink_request_frame(inlink); | |
146 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1469778 times.
|
1469778 | } else if (ret < 0) { |
147 | ✗ | return ret; | |
148 | } | ||
149 | } else { | ||
150 | 414593 | ff_inlink_request_frame(inlink); | |
151 | } | ||
152 | } | ||
153 | } | ||
154 | |||
155 | 1287970 | int attribute_align_arg av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags) | |
156 | { | ||
157 | 1287970 | return get_frame_internal(ctx, frame, flags, | |
158 | 1287970 | ff_filter_link(ctx->inputs[0])->min_samples); | |
159 | } | ||
160 | |||
161 | ✗ | int attribute_align_arg av_buffersink_get_samples(AVFilterContext *ctx, | |
162 | AVFrame *frame, int nb_samples) | ||
163 | { | ||
164 | ✗ | return get_frame_internal(ctx, frame, 0, nb_samples); | |
165 | } | ||
166 | |||
167 | 8230 | static av_cold int common_init(AVFilterContext *ctx) | |
168 | { | ||
169 | 8230 | BufferSinkContext *buf = ctx->priv; | |
170 | 8230 | int ret = 0; | |
171 | |||
172 | #if FF_API_BUFFERSINK_OPTS | ||
173 | |||
174 | #define CHECK_LIST_SIZE(field) \ | ||
175 | if (buf->field ## _size % sizeof(*buf->field)) { \ | ||
176 | av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \ | ||
177 | "should be multiple of %d\n", \ | ||
178 | buf->field ## _size, (int)sizeof(*buf->field)); \ | ||
179 | return AVERROR(EINVAL); \ | ||
180 | } | ||
181 | |||
182 |
2/2✓ Branch 0 taken 6866 times.
✓ Branch 1 taken 1364 times.
|
8230 | if (ctx->input_pads[0].type == AVMEDIA_TYPE_VIDEO) { |
183 |
4/8✓ Branch 0 taken 6866 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6866 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6866 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6866 times.
|
6866 | if ((buf->pixel_fmts_size || buf->color_spaces_size || buf->color_ranges_size || buf->alpha_modes_size) && |
184 | ✗ | (buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges || buf->nb_alphamodes)) { | |
185 | ✗ | av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n"); | |
186 | ✗ | return AVERROR(EINVAL); | |
187 | } | ||
188 | |||
189 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6866 times.
|
6866 | CHECK_LIST_SIZE(pixel_fmts) |
190 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6866 times.
|
6866 | CHECK_LIST_SIZE(color_spaces) |
191 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6866 times.
|
6866 | CHECK_LIST_SIZE(color_ranges) |
192 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6866 times.
|
6866 | CHECK_LIST_SIZE(alpha_modes) |
193 | } else { | ||
194 |
4/6✓ Branch 0 taken 1338 times.
✓ Branch 1 taken 26 times.
✓ Branch 2 taken 1338 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1338 times.
|
1364 | if ((buf->sample_fmts_size || buf->channel_layouts_str || buf->sample_rates_size) && |
195 |
3/6✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 26 times.
|
26 | (buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts)) { |
196 | ✗ | av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n"); | |
197 | ✗ | return AVERROR(EINVAL); | |
198 | } | ||
199 | |||
200 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1364 times.
|
1364 | CHECK_LIST_SIZE(sample_fmts) |
201 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1364 times.
|
1364 | CHECK_LIST_SIZE(sample_rates) |
202 | |||
203 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1364 times.
|
1364 | if (buf->channel_layouts_str) { |
204 | ✗ | const char *cur = buf->channel_layouts_str; | |
205 | |||
206 | ✗ | if (buf->all_channel_counts) | |
207 | ✗ | av_log(ctx, AV_LOG_WARNING, | |
208 | "Conflicting all_channel_counts and list in options\n"); | ||
209 | |||
210 | ✗ | while (cur) { | |
211 | void *tmp; | ||
212 | ✗ | char *next = strchr(cur, '|'); | |
213 | ✗ | if (next) | |
214 | ✗ | *next++ = 0; | |
215 | |||
216 | // +2 for the new element and terminator | ||
217 | ✗ | tmp = av_realloc_array(buf->channel_layouts, buf->nb_channel_layouts + 2, | |
218 | sizeof(*buf->channel_layouts)); | ||
219 | ✗ | if (!tmp) | |
220 | ✗ | return AVERROR(ENOMEM); | |
221 | |||
222 | ✗ | buf->channel_layouts = tmp; | |
223 | ✗ | memset(&buf->channel_layouts[buf->nb_channel_layouts], 0, | |
224 | sizeof(*buf->channel_layouts) * 2); | ||
225 | ✗ | buf->nb_channel_layouts++; | |
226 | |||
227 | ✗ | ret = av_channel_layout_from_string(&buf->channel_layouts[buf->nb_channel_layouts - 1], cur); | |
228 | ✗ | if (ret < 0) { | |
229 | ✗ | av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: %s.\n", cur); | |
230 | ✗ | return ret; | |
231 | } | ||
232 | ✗ | if (ret < 0) | |
233 | ✗ | return ret; | |
234 | |||
235 | ✗ | cur = next; | |
236 | } | ||
237 | |||
238 | ✗ | if (buf->nb_channel_layouts) | |
239 | ✗ | buf->channel_layouts[buf->nb_channel_layouts] = (AVChannelLayout){ 0 }; | |
240 | } | ||
241 | } | ||
242 | |||
243 | #undef CHECK_LIST_SIZE | ||
244 | |||
245 | #endif | ||
246 | |||
247 | 8230 | buf->warning_limit = 100; | |
248 | 8230 | return 0; | |
249 | } | ||
250 | |||
251 | #define TERMINATE_ARRAY(arr, val) \ | ||
252 | if (s->arr) { \ | ||
253 | void *tmp = av_realloc_array(s->arr, s->nb_ ## arr + 1, sizeof(*s->arr)); \ | ||
254 | if (!tmp) \ | ||
255 | return AVERROR(ENOMEM); \ | ||
256 | s->arr = tmp; \ | ||
257 | s->arr[s->nb_ ## arr] = val; \ | ||
258 | } | ||
259 | |||
260 | 6866 | static int init_video(AVFilterContext *ctx) | |
261 | { | ||
262 | 6866 | BufferSinkContext *s = ctx->priv; | |
263 | |||
264 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 6866 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
6866 | TERMINATE_ARRAY(pixel_formats, AV_PIX_FMT_NONE); |
265 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 6866 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
6866 | TERMINATE_ARRAY(colorranges, -1); |
266 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 6866 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
6866 | TERMINATE_ARRAY(colorspaces, -1); |
267 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 6866 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
6866 | TERMINATE_ARRAY(alphamodes, -1); |
268 | |||
269 | 6866 | return common_init(ctx); | |
270 | } | ||
271 | |||
272 | 1364 | static int init_audio(AVFilterContext *ctx) | |
273 | { | ||
274 | 1364 | BufferSinkContext *s = ctx->priv; | |
275 | |||
276 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1364 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1364 | TERMINATE_ARRAY(sample_formats, AV_SAMPLE_FMT_NONE); |
277 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1364 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1364 | TERMINATE_ARRAY(samplerates, -1); |
278 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1364 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1364 | TERMINATE_ARRAY(channel_layouts, (AVChannelLayout){ .nb_channels = 0 }); |
279 | |||
280 | 1364 | return common_init(ctx); | |
281 | } | ||
282 | |||
283 | #undef TERMINATE_ARRAY | ||
284 | |||
285 | 8230 | static void uninit(AVFilterContext *ctx) | |
286 | { | ||
287 | 8230 | BufferSinkContext *buf = ctx->priv; | |
288 | |||
289 | 8230 | av_frame_free(&buf->peeked_frame); | |
290 | 8230 | } | |
291 | |||
292 | 421282 | static int activate(AVFilterContext *ctx) | |
293 | { | ||
294 | 421282 | BufferSinkContext *buf = ctx->priv; | |
295 | 421282 | FilterLinkInternal * const li = ff_link_internal(ctx->inputs[0]); | |
296 | |||
297 |
1/2✓ Branch 0 taken 421282 times.
✗ Branch 1 not taken.
|
421282 | if (buf->warning_limit && |
298 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 421282 times.
|
421282 | ff_framequeue_queued_frames(&li->fifo) >= buf->warning_limit) { |
299 | ✗ | av_log(ctx, AV_LOG_WARNING, | |
300 | "%d buffers queued in %s, something may be wrong.\n", | ||
301 | buf->warning_limit, | ||
302 | ✗ | (char *)av_x_if_null(ctx->name, ctx->filter->name)); | |
303 | ✗ | buf->warning_limit *= 10; | |
304 | } | ||
305 | |||
306 | /* The frame is queued, the rest is up to get_frame_internal */ | ||
307 | 421282 | return 0; | |
308 | } | ||
309 | |||
310 | 1364 | static int config_input_audio(AVFilterLink *inlink) | |
311 | { | ||
312 | 1364 | BufferSinkContext *buf = inlink->dst->priv; | |
313 | 1364 | FilterLink *l = ff_filter_link(inlink); | |
314 | |||
315 | 1364 | l->min_samples = l->max_samples = buf->frame_size; | |
316 | |||
317 | 1364 | return 0; | |
318 | } | ||
319 | |||
320 | ✗ | void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size) | |
321 | { | ||
322 | ✗ | BufferSinkContext *buf = ctx->priv; | |
323 | ✗ | buf->frame_size = frame_size; | |
324 | |||
325 | ✗ | if (ctx->inputs && ctx->inputs[0]) { | |
326 | ✗ | FilterLink *l = ff_filter_link(ctx->inputs[0]); | |
327 | ✗ | l->min_samples = l->max_samples = buf->frame_size; | |
328 | } | ||
329 | ✗ | } | |
330 | |||
331 | #define MAKE_AVFILTERLINK_ACCESSOR(type, field) \ | ||
332 | type av_buffersink_get_##field(const AVFilterContext *ctx) { \ | ||
333 | av_assert0(fffilter(ctx->filter)->activate == activate); \ | ||
334 | return ctx->inputs[0]->field; \ | ||
335 | } | ||
336 | |||
337 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
|
54 | MAKE_AVFILTERLINK_ACCESSOR(enum AVMediaType , type ) |
338 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 423357 times.
|
423357 | MAKE_AVFILTERLINK_ACCESSOR(AVRational , time_base ) |
339 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8230 times.
|
8230 | MAKE_AVFILTERLINK_ACCESSOR(int , format ) |
340 | |||
341 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8204 times.
|
8204 | MAKE_AVFILTERLINK_ACCESSOR(int , w ) |
342 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8204 times.
|
8204 | MAKE_AVFILTERLINK_ACCESSOR(int , h ) |
343 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8204 times.
|
8204 | MAKE_AVFILTERLINK_ACCESSOR(AVRational , sample_aspect_ratio) |
344 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8176 times.
|
8176 | MAKE_AVFILTERLINK_ACCESSOR(enum AVColorSpace, colorspace) |
345 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8176 times.
|
8176 | MAKE_AVFILTERLINK_ACCESSOR(enum AVColorRange, color_range) |
346 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8176 times.
|
8176 | MAKE_AVFILTERLINK_ACCESSOR(enum AVAlphaMode , alpha_mode) |
347 | |||
348 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8202 times.
|
8202 | MAKE_AVFILTERLINK_ACCESSOR(int , sample_rate ) |
349 | |||
350 | 10617 | AVRational av_buffersink_get_frame_rate(const AVFilterContext *ctx) | |
351 | { | ||
352 | 10617 | FilterLink *l = ff_filter_link(ctx->inputs[0]); | |
353 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10617 times.
|
10617 | av_assert0(fffilter(ctx->filter)->activate == activate); |
354 | 10617 | return l->frame_rate; | |
355 | } | ||
356 | |||
357 | ✗ | AVBufferRef* av_buffersink_get_hw_frames_ctx(const AVFilterContext *ctx) | |
358 | { | ||
359 | ✗ | FilterLink *l = ff_filter_link(ctx->inputs[0]); | |
360 | ✗ | av_assert0(fffilter(ctx->filter)->activate == activate); | |
361 | ✗ | return l->hw_frames_ctx; | |
362 | } | ||
363 | |||
364 | ✗ | int av_buffersink_get_channels(const AVFilterContext *ctx) | |
365 | { | ||
366 | ✗ | av_assert0(fffilter(ctx->filter)->activate == activate); | |
367 | ✗ | return ctx->inputs[0]->ch_layout.nb_channels; | |
368 | } | ||
369 | |||
370 | 8202 | int av_buffersink_get_ch_layout(const AVFilterContext *ctx, AVChannelLayout *out) | |
371 | { | ||
372 | 8202 | AVChannelLayout ch_layout = { 0 }; | |
373 | int ret; | ||
374 | |||
375 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8202 times.
|
8202 | av_assert0(fffilter(ctx->filter)->activate == activate); |
376 | 8202 | ret = av_channel_layout_copy(&ch_layout, &ctx->inputs[0]->ch_layout); | |
377 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8202 times.
|
8202 | if (ret < 0) |
378 | ✗ | return ret; | |
379 | 8202 | *out = ch_layout; | |
380 | 8202 | return 0; | |
381 | } | ||
382 | |||
383 | 8176 | const AVFrameSideData *const *av_buffersink_get_side_data(const AVFilterContext *ctx, | |
384 | int *nb_side_data) | ||
385 | { | ||
386 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8176 times.
|
8176 | av_assert0(fffilter(ctx->filter)->activate == activate); |
387 | 8176 | *nb_side_data = ctx->inputs[0]->nb_side_data; | |
388 | 8176 | return (const AVFrameSideData *const *)ctx->inputs[0]->side_data; | |
389 | } | ||
390 | |||
391 | #if FF_API_BUFFERSINK_OPTS | ||
392 | #define NB_ITEMS(list) (list ## _size / sizeof(*list)) | ||
393 | #endif | ||
394 | |||
395 | 6866 | static int vsink_query_formats(const AVFilterContext *ctx, | |
396 | AVFilterFormatsConfig **cfg_in, | ||
397 | AVFilterFormatsConfig **cfg_out) | ||
398 | { | ||
399 | 6866 | const BufferSinkContext *buf = ctx->priv; | |
400 | int ret; | ||
401 | |||
402 | #if FF_API_BUFFERSINK_OPTS | ||
403 |
4/8✓ Branch 0 taken 6866 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6866 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6866 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6866 times.
|
6866 | if (buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges || buf->nb_alphamodes) { |
404 | #endif | ||
405 | ✗ | if (buf->nb_pixel_formats) { | |
406 | ✗ | ret = ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out, buf->pixel_formats); | |
407 | ✗ | if (ret < 0) | |
408 | ✗ | return ret; | |
409 | } | ||
410 | ✗ | if (buf->nb_colorspaces) { | |
411 | ✗ | ret = ff_set_common_color_spaces_from_list2(ctx, cfg_in, cfg_out, buf->colorspaces); | |
412 | ✗ | if (ret < 0) | |
413 | ✗ | return ret; | |
414 | } | ||
415 | ✗ | if (buf->nb_colorranges) { | |
416 | ✗ | ret = ff_set_common_color_ranges_from_list2(ctx, cfg_in, cfg_out, buf->colorranges); | |
417 | ✗ | if (ret < 0) | |
418 | ✗ | return ret; | |
419 | } | ||
420 | ✗ | if (buf->nb_alphamodes) { | |
421 | ✗ | ret = ff_set_common_alpha_modes_from_list2(ctx, cfg_in, cfg_out, buf->alphamodes); | |
422 | ✗ | if (ret < 0) | |
423 | ✗ | return ret; | |
424 | } | ||
425 | #if FF_API_BUFFERSINK_OPTS | ||
426 | } else { | ||
427 | unsigned i; | ||
428 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6866 times.
|
6866 | if (buf->pixel_fmts_size) { |
429 | ✗ | AVFilterFormats *formats = NULL; | |
430 | ✗ | for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++) | |
431 | ✗ | if ((ret = ff_add_format(&formats, buf->pixel_fmts[i])) < 0) | |
432 | ✗ | return ret; | |
433 | ✗ | if ((ret = ff_set_common_formats2(ctx, cfg_in, cfg_out, formats)) < 0) | |
434 | ✗ | return ret; | |
435 | } | ||
436 | |||
437 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6866 times.
|
6866 | if (buf->color_spaces_size) { |
438 | ✗ | AVFilterFormats *formats = NULL; | |
439 | ✗ | for (i = 0; i < NB_ITEMS(buf->color_spaces); i++) | |
440 | ✗ | if ((ret = ff_add_format(&formats, buf->color_spaces[i])) < 0) | |
441 | ✗ | return ret; | |
442 | ✗ | if ((ret = ff_set_common_color_spaces2(ctx, cfg_in, cfg_out, formats)) < 0) | |
443 | ✗ | return ret; | |
444 | } | ||
445 | |||
446 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6866 times.
|
6866 | if (buf->color_ranges_size) { |
447 | ✗ | AVFilterFormats *formats = NULL; | |
448 | ✗ | for (i = 0; i < NB_ITEMS(buf->color_ranges); i++) | |
449 | ✗ | if ((ret = ff_add_format(&formats, buf->color_ranges[i])) < 0) | |
450 | ✗ | return ret; | |
451 | ✗ | if ((ret = ff_set_common_color_ranges2(ctx, cfg_in, cfg_out, formats)) < 0) | |
452 | ✗ | return ret; | |
453 | } | ||
454 | |||
455 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6866 times.
|
6866 | if (buf->alpha_modes_size) { |
456 | ✗ | AVFilterFormats *formats = NULL; | |
457 | ✗ | for (i = 0; i < NB_ITEMS(buf->alpha_modes); i++) | |
458 | ✗ | if ((ret = ff_add_format(&formats, buf->alpha_modes[i])) < 0) | |
459 | ✗ | return ret; | |
460 | ✗ | if ((ret = ff_set_common_alpha_modes2(ctx, cfg_in, cfg_out, formats)) < 0) | |
461 | ✗ | return ret; | |
462 | } | ||
463 | } | ||
464 | #endif | ||
465 | |||
466 | 6866 | return 0; | |
467 | } | ||
468 | |||
469 | 1364 | static int asink_query_formats(const AVFilterContext *ctx, | |
470 | AVFilterFormatsConfig **cfg_in, | ||
471 | AVFilterFormatsConfig **cfg_out) | ||
472 | { | ||
473 | 1364 | const BufferSinkContext *buf = ctx->priv; | |
474 | int ret; | ||
475 | |||
476 | #if FF_API_BUFFERSINK_OPTS | ||
477 |
3/6✓ Branch 0 taken 1364 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1364 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1364 times.
|
1364 | if (buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts) { |
478 | #endif | ||
479 | ✗ | if (buf->nb_sample_formats) { | |
480 | ✗ | ret = ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out, buf->sample_formats); | |
481 | ✗ | if (ret < 0) | |
482 | ✗ | return ret; | |
483 | } | ||
484 | ✗ | if (buf->nb_samplerates) { | |
485 | ✗ | ret = ff_set_common_samplerates_from_list2(ctx, cfg_in, cfg_out, buf->samplerates); | |
486 | ✗ | if (ret < 0) | |
487 | ✗ | return ret; | |
488 | } | ||
489 | ✗ | if (buf->nb_channel_layouts) { | |
490 | ✗ | ret = ff_set_common_channel_layouts_from_list2(ctx, cfg_in, cfg_out, buf->channel_layouts); | |
491 | ✗ | if (ret < 0) | |
492 | ✗ | return ret; | |
493 | } | ||
494 | #if FF_API_BUFFERSINK_OPTS | ||
495 | } else { | ||
496 | 1364 | AVFilterFormats *formats = NULL; | |
497 | unsigned i; | ||
498 | |||
499 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 1338 times.
|
1364 | if (buf->sample_fmts_size) { |
500 |
2/2✓ Branch 0 taken 130 times.
✓ Branch 1 taken 26 times.
|
156 | for (i = 0; i < NB_ITEMS(buf->sample_fmts); i++) |
501 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 130 times.
|
130 | if ((ret = ff_add_format(&formats, buf->sample_fmts[i])) < 0) |
502 | ✗ | return ret; | |
503 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
|
26 | if ((ret = ff_set_common_formats2(ctx, cfg_in, cfg_out, formats)) < 0) |
504 | ✗ | return ret; | |
505 | } | ||
506 | |||
507 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1364 times.
|
1364 | if (buf->nb_channel_layouts) { |
508 | ✗ | ret = ff_set_common_channel_layouts_from_list2(ctx, cfg_in, cfg_out, buf->channel_layouts); | |
509 | ✗ | if (ret < 0) | |
510 | ✗ | return ret; | |
511 | } | ||
512 | |||
513 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1364 times.
|
1364 | if (buf->sample_rates_size) { |
514 | ✗ | formats = NULL; | |
515 | ✗ | for (i = 0; i < NB_ITEMS(buf->sample_rates); i++) | |
516 | ✗ | if ((ret = ff_add_format(&formats, buf->sample_rates[i])) < 0) | |
517 | ✗ | return ret; | |
518 | ✗ | if ((ret = ff_set_common_samplerates2(ctx, cfg_in, cfg_out, formats)) < 0) | |
519 | ✗ | return ret; | |
520 | } | ||
521 | } | ||
522 | #endif | ||
523 | |||
524 | 1364 | return 0; | |
525 | } | ||
526 | |||
527 | #define OFFSET(x) offsetof(BufferSinkContext, x) | ||
528 | #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM | ||
529 | static const AVOption buffersink_options[] = { | ||
530 | #if FF_API_BUFFERSINK_OPTS | ||
531 | { "pix_fmts", "set the supported pixel formats", OFFSET(pixel_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED }, | ||
532 | { "color_spaces", "set the supported color spaces", OFFSET(color_spaces), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED }, | ||
533 | { "color_ranges", "set the supported color ranges", OFFSET(color_ranges), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED }, | ||
534 | #endif | ||
535 | |||
536 | { "pixel_formats", "array of supported pixel formats", OFFSET(pixel_formats), | ||
537 | AV_OPT_TYPE_PIXEL_FMT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS }, | ||
538 | { "colorspaces", "array of supported color spaces", OFFSET(colorspaces), | ||
539 | AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS }, | ||
540 | { "colorranges", "array of supported color ranges", OFFSET(colorranges), | ||
541 | AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS }, | ||
542 | { "alphamodes", "array of supported color ranges", OFFSET(alphamodes), | ||
543 | AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS }, | ||
544 | |||
545 | { NULL }, | ||
546 | }; | ||
547 | #undef FLAGS | ||
548 | #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM | ||
549 | static const AVOption abuffersink_options[] = { | ||
550 | #if FF_API_BUFFERSINK_OPTS | ||
551 | { "sample_fmts", "set the supported sample formats", OFFSET(sample_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED }, | ||
552 | { "sample_rates", "set the supported sample rates", OFFSET(sample_rates), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED }, | ||
553 | { "ch_layouts", "set a '|'-separated list of supported channel layouts", | ||
554 | OFFSET(channel_layouts_str), AV_OPT_TYPE_STRING, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED }, | ||
555 | { "all_channel_counts", "accept all channel counts", OFFSET(all_channel_counts), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS | AV_OPT_FLAG_DEPRECATED }, | ||
556 | #endif | ||
557 | |||
558 | { "sample_formats", "array of supported sample formats", OFFSET(sample_formats), | ||
559 | AV_OPT_TYPE_SAMPLE_FMT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS }, | ||
560 | { "samplerates", "array of supported sample formats", OFFSET(samplerates), | ||
561 | AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS }, | ||
562 | { "channel_layouts", "array of supported channel layouts", OFFSET(channel_layouts), | ||
563 | AV_OPT_TYPE_CHLAYOUT | AV_OPT_TYPE_FLAG_ARRAY, .flags = FLAGS }, | ||
564 | { NULL }, | ||
565 | }; | ||
566 | #undef FLAGS | ||
567 | |||
568 | AVFILTER_DEFINE_CLASS(buffersink); | ||
569 | AVFILTER_DEFINE_CLASS(abuffersink); | ||
570 | |||
571 | const FFFilter ff_vsink_buffer = { | ||
572 | .p.name = "buffersink", | ||
573 | .p.description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."), | ||
574 | .p.priv_class = &buffersink_class, | ||
575 | .p.outputs = NULL, | ||
576 | .priv_size = sizeof(BufferSinkContext), | ||
577 | .init = init_video, | ||
578 | .uninit = uninit, | ||
579 | .activate = activate, | ||
580 | FILTER_INPUTS(ff_video_default_filterpad), | ||
581 | FILTER_QUERY_FUNC2(vsink_query_formats), | ||
582 | }; | ||
583 | |||
584 | static const AVFilterPad inputs_audio[] = { | ||
585 | { | ||
586 | .name = "default", | ||
587 | .type = AVMEDIA_TYPE_AUDIO, | ||
588 | .config_props = config_input_audio, | ||
589 | }, | ||
590 | }; | ||
591 | |||
592 | const FFFilter ff_asink_abuffer = { | ||
593 | .p.name = "abuffersink", | ||
594 | .p.description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."), | ||
595 | .p.priv_class = &abuffersink_class, | ||
596 | .p.outputs = NULL, | ||
597 | .priv_size = sizeof(BufferSinkContext), | ||
598 | .init = init_audio, | ||
599 | .uninit = uninit, | ||
600 | .activate = activate, | ||
601 | FILTER_INPUTS(inputs_audio), | ||
602 | FILTER_QUERY_FUNC2(asink_query_formats), | ||
603 | }; | ||
604 |