Browse code

lavfi/buffersink: factor checks for lists sizes.

Nicolas George authored on 2013/04/13 18:27:52
Showing 1 changed files
... ...
@@ -384,6 +384,13 @@ static av_cold int vsink_init(AVFilterContext *ctx, void *opaque)
384 384
     return common_init(ctx);
385 385
 }
386 386
 
387
+#define CHECK_LIST_SIZE(field) \
388
+        if (buf->field ## _size % sizeof(*buf->field)) { \
389
+            av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \
390
+                   "should be multiple of %d\n", \
391
+                   buf->field ## _size, (int)sizeof(*buf->field)); \
392
+            return AVERROR(EINVAL); \
393
+        }
387 394
 static int vsink_query_formats(AVFilterContext *ctx)
388 395
 {
389 396
     BufferSinkContext *buf = ctx->priv;
... ...
@@ -391,11 +398,7 @@ static int vsink_query_formats(AVFilterContext *ctx)
391 391
     unsigned i;
392 392
     int ret;
393 393
 
394
-    if (buf->pixel_fmts_size % sizeof(*buf->pixel_fmts)) {
395
-        av_log(ctx, AV_LOG_ERROR, "Invalid size for format list\n");
396
-        return AVERROR(EINVAL);
397
-    }
398
-
394
+    CHECK_LIST_SIZE(pixel_fmts)
399 395
     if (buf->pixel_fmts_size) {
400 396
         for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++)
401 397
             if ((ret = ff_add_format(&formats, buf->pixel_fmts[i])) < 0)
... ...
@@ -433,23 +436,10 @@ static int asink_query_formats(AVFilterContext *ctx)
433 433
     unsigned i;
434 434
     int ret;
435 435
 
436
-    if (buf->sample_fmts_size     % sizeof(*buf->sample_fmts)     ||
437
-        buf->sample_rates_size    % sizeof(*buf->sample_rates)    ||
438
-        buf->channel_layouts_size % sizeof(*buf->channel_layouts) ||
439
-        buf->channel_counts_size  % sizeof(*buf->channel_counts)) {
440
-        av_log(ctx, AV_LOG_ERROR, "Invalid size for format lists\n");
441
-#define LOG_ERROR(field) \
442
-        if (buf->field ## _size % sizeof(*buf->field)) \
443
-            av_log(ctx, AV_LOG_ERROR, "  " #field " is %d, should be " \
444
-                   "multiple of %d\n", \
445
-                   buf->field ## _size, (int)sizeof(*buf->field));
446
-        LOG_ERROR(sample_fmts);
447
-        LOG_ERROR(sample_rates);
448
-        LOG_ERROR(channel_layouts);
449
-        LOG_ERROR(channel_counts);
450
-#undef LOG_ERROR
451
-        return AVERROR(EINVAL);
452
-    }
436
+    CHECK_LIST_SIZE(sample_fmts)
437
+    CHECK_LIST_SIZE(sample_rates)
438
+    CHECK_LIST_SIZE(channel_layouts)
439
+    CHECK_LIST_SIZE(channel_counts)
453 440
 
454 441
     if (buf->sample_fmts_size) {
455 442
         for (i = 0; i < NB_ITEMS(buf->sample_fmts); i++)