History

lavfi/buffersink: move the option sanity check to init

Options are set before init, so that is the appropriate place to validate them.

Anton Khirnov committed 2 years ago

Commit 2aad37f1 parent eff9ed71 file · +35 −25Browse files

Unified · Split

libavfilter/buffersink.c+35−25
@@ -155,6 +155,41 @@ static av_cold int common_init(AVFilterContext *ctx) · 154 unmodified lines
155{155{
156 BufferSinkContext *buf = ctx->priv;156 BufferSinkContext *buf = ctx->priv;
157 157
158#if FF_API_BUFFERSINK_OPTS
159
160#define CHECK_LIST_SIZE(field) \
161 if (buf->field ## _size % sizeof(*buf->field)) { \
162 av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \
163 "should be multiple of %d\n", \
164 buf->field ## _size, (int)sizeof(*buf->field)); \
165 return AVERROR(EINVAL); \
166 }
167
168 if (ctx->input_pads[0].type == AVMEDIA_TYPE_VIDEO) {
169 if ((buf->pixel_fmts_size || buf->color_spaces_size || buf->color_ranges_size) &&
170 (buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges)) {
171 av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n");
172 return AVERROR(EINVAL);
173 }
174
175 CHECK_LIST_SIZE(pixel_fmts)
176 CHECK_LIST_SIZE(color_spaces)
177 CHECK_LIST_SIZE(color_ranges)
178 } else {
179 if ((buf->sample_fmts_size || buf->channel_layouts_str || buf->sample_rates_size) &&
180 (buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts)) {
181 av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n");
182 return AVERROR(EINVAL);
183 }
184
185 CHECK_LIST_SIZE(sample_fmts)
186 CHECK_LIST_SIZE(sample_rates)
187 }
188
189#undef CHECK_LIST_SIZE
190
191#endif
192
158 buf->warning_limit = 100;193 buf->warning_limit = 100;
159 return 0;194 return 0;
160}195}
@@ -291,14 +326,6 @@ int av_buffersink_get_ch_layout(const AVFilterContext *ctx, AVChannelLayout *out · 130 unmodified lines
291 326
292#if FF_API_BUFFERSINK_OPTS327#if FF_API_BUFFERSINK_OPTS
293#define NB_ITEMS(list) (list ## _size / sizeof(*list))328#define NB_ITEMS(list) (list ## _size / sizeof(*list))
294
295#define CHECK_LIST_SIZE(field) \
296 if (buf->field ## _size % sizeof(*buf->field)) { \
297 av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \
298 "should be multiple of %d\n", \
299 buf->field ## _size, (int)sizeof(*buf->field)); \
300 return AVERROR(EINVAL); \
301 }
302#endif329#endif
303 330
304static int vsink_query_formats(AVFilterContext *ctx)331static int vsink_query_formats(AVFilterContext *ctx)
@@ -307,12 +334,6 @@ static int vsink_query_formats(AVFilterContext *ctx) · 2 unmodified lines
307 int ret;334 int ret;
308 335
309#if FF_API_BUFFERSINK_OPTS336#if FF_API_BUFFERSINK_OPTS
310 if ((buf->pixel_fmts_size || buf->color_spaces_size || buf->color_ranges_size) &&
311 (buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges)) {
312 av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n");
313 return AVERROR(EINVAL);
314 }
315
316 if (buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges) {337 if (buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges) {
317#endif338#endif
318 if (buf->nb_pixel_formats) {339 if (buf->nb_pixel_formats) {
@@ -333,9 +354,6 @@ static int vsink_query_formats(AVFilterContext *ctx) · 14 unmodified lines
333#if FF_API_BUFFERSINK_OPTS354#if FF_API_BUFFERSINK_OPTS
334 } else {355 } else {
335 unsigned i;356 unsigned i;
336 CHECK_LIST_SIZE(pixel_fmts)
337 CHECK_LIST_SIZE(color_spaces)
338 CHECK_LIST_SIZE(color_ranges)
339 if (buf->pixel_fmts_size) {357 if (buf->pixel_fmts_size) {
340 AVFilterFormats *formats = NULL;358 AVFilterFormats *formats = NULL;
341 for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++)359 for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++)
@@ -374,12 +392,6 @@ static int asink_query_formats(AVFilterContext *ctx) · 32 unmodified lines
374 int ret;392 int ret;
375 393
376#if FF_API_BUFFERSINK_OPTS394#if FF_API_BUFFERSINK_OPTS
377 if ((buf->sample_fmts_size || buf->channel_layouts_str || buf->sample_rates_size) &&
378 (buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts)) {
379 av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n");
380 return AVERROR(EINVAL);
381 }
382
383 if (buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts) {395 if (buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts) {
384#endif396#endif
385 if (buf->nb_sample_formats) {397 if (buf->nb_sample_formats) {
@@ -403,8 +415,6 @@ static int asink_query_formats(AVFilterContext *ctx) · 17 unmodified lines
403 AVChannelLayout layout = { 0 };415 AVChannelLayout layout = { 0 };
404 AVFilterChannelLayouts *layouts = NULL;416 AVFilterChannelLayouts *layouts = NULL;
405 unsigned i;417 unsigned i;
406 CHECK_LIST_SIZE(sample_fmts)
407 CHECK_LIST_SIZE(sample_rates)
408 418
409 if (buf->sample_fmts_size) {419 if (buf->sample_fmts_size) {
410 for (i = 0; i < NB_ITEMS(buf->sample_fmts); i++)420 for (i = 0; i < NB_ITEMS(buf->sample_fmts); i++)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t