Up until now, it has returned the AVFilterFormats list via an AVFilterFormats** parameter; the actual return value was an int that was always AVERROR(ENOMEM) on error. The AVFilterFormats** argument was a pure output parameter which was only documented by naming the parameter rfmts. Yet nevertheless all callers initialized the underlying AVFilterFormats* to NULL. This commit changes this to return a pointer to AVFilterFormats directly. This is more in line with the API in general, as it allows to avoid checks for intermediate values.
Unified · Split
| @@ -452,7 +452,7 @@ AVFilterFormats *ff_all_formats(enum AVMediaType type) · 451 unmodified lines | |||
| 452 | return ret; | 452 | return ret; |
| 453 | } | 453 | } |
| 454 | 454 | ||
| 455 | int ff_formats_pixdesc_filter(AVFilterFormats **rfmts, unsigned want, unsigned rej) | 455 | AVFilterFormats *ff_formats_pixdesc_filter(unsigned want, unsigned rej) |
| 456 | { | 456 | { |
| 457 | unsigned nb_formats, fmt, flags; | 457 | unsigned nb_formats, fmt, flags; |
| 458 | AVFilterFormats *formats = NULL; | 458 | AVFilterFormats *formats = NULL; |
| @@ -476,18 +476,17 @@ int ff_formats_pixdesc_filter(AVFilterFormats **rfmts, unsigned want, unsigned r · 17 unmodified lines | |||
| 476 | } | 476 | } |
| 477 | if (formats) { | 477 | if (formats) { |
| 478 | av_assert0(formats->nb_formats == nb_formats); | 478 | av_assert0(formats->nb_formats == nb_formats); |
| 479 | *rfmts = formats; | 479 | return formats; |
| 480 | return 0; | ||
| 481 | } | 480 | } |
| 482 | formats = av_mallocz(sizeof(*formats)); | 481 | formats = av_mallocz(sizeof(*formats)); |
| 483 | if (!formats) | 482 | if (!formats) |
| 484 | return AVERROR(ENOMEM); | 483 | return NULL; |
| 485 | formats->nb_formats = nb_formats; | 484 | formats->nb_formats = nb_formats; |
| 486 | if (nb_formats) { | 485 | if (nb_formats) { |
| 487 | formats->formats = av_malloc_array(nb_formats, sizeof(*formats->formats)); | 486 | formats->formats = av_malloc_array(nb_formats, sizeof(*formats->formats)); |
| 488 | if (!formats->formats) { | 487 | if (!formats->formats) { |
| 489 | av_freep(&formats); | 488 | av_freep(&formats); |
| 490 | return AVERROR(ENOMEM); | 489 | return NULL; |
| 491 | } | 490 | } |
| 492 | } | 491 | } |
| 493 | } | 492 | } |
| @@ -230,7 +230,7 @@ AVFilterFormats *ff_all_formats(enum AVMediaType type); · 229 unmodified lines | |||
| 230 | * properties | 230 | * properties |
| 231 | */ | 231 | */ |
| 232 | av_warn_unused_result | 232 | av_warn_unused_result |
| 233 | int ff_formats_pixdesc_filter(AVFilterFormats **rfmts, unsigned want, unsigned rej); | 233 | AVFilterFormats *ff_formats_pixdesc_filter(unsigned want, unsigned rej); |
| 234 | 234 | ||
| 235 | //* format is software, non-planar with sub-sampling | 235 | //* format is software, non-planar with sub-sampling |
| 236 | #define FF_PIX_FMT_FLAG_SW_FLAT_SUB (1 << 24) | 236 | #define FF_PIX_FMT_FLAG_SW_FLAT_SUB (1 << 24) |
| @@ -29,14 +29,7 @@ · 28 unmodified lines | |||
| 29 | 29 | ||
| 30 | static int query_formats(AVFilterContext *ctx) | 30 | static int query_formats(AVFilterContext *ctx) |
| 31 | { | 31 | { |
| 32 | AVFilterFormats *formats = NULL; | 32 | return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, AV_PIX_FMT_FLAG_HWACCEL)); |
| 33 | int ret; | ||
| 34 | |||
| 35 | ret = ff_formats_pixdesc_filter(&formats, 0, | ||
| 36 | AV_PIX_FMT_FLAG_HWACCEL); | ||
| 37 | if (ret < 0) | ||
| 38 | return ret; | ||
| 39 | return ff_set_common_formats(ctx, formats); | ||
| 40 | } | 33 | } |
| 41 | 34 | ||
| 42 | static int filter_frame(AVFilterLink *inlink, AVFrame *in) | 35 | static int filter_frame(AVFilterLink *inlink, AVFrame *in) |
| @@ -93,13 +93,9 @@ typedef struct CropContext { · 92 unmodified lines | |||
| 93 | 93 | ||
| 94 | static int query_formats(AVFilterContext *ctx) | 94 | static int query_formats(AVFilterContext *ctx) |
| 95 | { | 95 | { |
| 96 | AVFilterFormats *formats = NULL; | 96 | int reject_flags = AV_PIX_FMT_FLAG_BITSTREAM | FF_PIX_FMT_FLAG_SW_FLAT_SUB; |
| 97 | int ret; | ||
| 98 | 97 | ||
| 99 | ret = ff_formats_pixdesc_filter(&formats, 0, AV_PIX_FMT_FLAG_BITSTREAM | FF_PIX_FMT_FLAG_SW_FLAT_SUB); | 98 | return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); |
| 100 | if (ret < 0) | ||
| 101 | return ret; | ||
| 102 | return ff_set_common_formats(ctx, formats); | ||
| 103 | } | 99 | } |
| 104 | 100 | ||
| 105 | static av_cold void uninit(AVFilterContext *ctx) | 101 | static av_cold void uninit(AVFilterContext *ctx) |
| @@ -124,16 +124,11 @@ static av_cold int init(AVFilterContext *ctx) · 123 unmodified lines | |||
| 124 | 124 | ||
| 125 | static int query_formats(AVFilterContext *ctx) | 125 | static int query_formats(AVFilterContext *ctx) |
| 126 | { | 126 | { |
| 127 | AVFilterFormats *formats = NULL; | 127 | int reject_flags = AV_PIX_FMT_FLAG_BITSTREAM | |
| 128 | int ret; | 128 | AV_PIX_FMT_FLAG_PAL | |
| 129 | AV_PIX_FMT_FLAG_HWACCEL; | ||
| 129 | 130 | ||
| 130 | ret = ff_formats_pixdesc_filter(&formats, 0, | 131 | return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); |
| 131 | AV_PIX_FMT_FLAG_BITSTREAM | | ||
| 132 | AV_PIX_FMT_FLAG_PAL | | ||
| 133 | AV_PIX_FMT_FLAG_HWACCEL); | ||
| 134 | if (ret < 0) | ||
| 135 | return ret; | ||
| 136 | return ff_set_common_formats(ctx, formats); | ||
| 137 | } | 132 | } |
| 138 | 133 | ||
| 139 | static int config_input(AVFilterLink *inlink) | 134 | static int config_input(AVFilterLink *inlink) |
| @@ -77,16 +77,11 @@ static av_cold int init(AVFilterContext *ctx) · 76 unmodified lines | |||
| 77 | 77 | ||
| 78 | static int query_formats(AVFilterContext *ctx) | 78 | static int query_formats(AVFilterContext *ctx) |
| 79 | { | 79 | { |
| 80 | AVFilterFormats *formats = NULL; | 80 | int reject_flags = AV_PIX_FMT_FLAG_BITSTREAM | |
| 81 | int ret; | 81 | AV_PIX_FMT_FLAG_HWACCEL | |
| 82 | AV_PIX_FMT_FLAG_PAL; | ||
| 82 | 83 | ||
| 83 | ret = ff_formats_pixdesc_filter(&formats, 0, | 84 | return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); |
| 84 | AV_PIX_FMT_FLAG_HWACCEL | | ||
| 85 | AV_PIX_FMT_FLAG_BITSTREAM | | ||
| 86 | AV_PIX_FMT_FLAG_PAL); | ||
| 87 | if (ret < 0) | ||
| 88 | return ret; | ||
| 89 | return ff_set_common_formats(ctx, formats); | ||
| 90 | } | 85 | } |
| 91 | 86 | ||
| 92 | static int config_input(AVFilterLink *inlink) | 87 | static int config_input(AVFilterLink *inlink) |
| @@ -37,13 +37,12 @@ typedef struct HWDownloadContext { · 36 unmodified lines | |||
| 37 | 37 | ||
| 38 | static int hwdownload_query_formats(AVFilterContext *avctx) | 38 | static int hwdownload_query_formats(AVFilterContext *avctx) |
| 39 | { | 39 | { |
| 40 | AVFilterFormats *fmts; | ||
| 41 | int err; | 40 | int err; |
| 42 | 41 | ||
| 43 | if ((err = ff_formats_pixdesc_filter(&fmts, AV_PIX_FMT_FLAG_HWACCEL, 0)) || | 42 | if ((err = ff_formats_ref(ff_formats_pixdesc_filter(AV_PIX_FMT_FLAG_HWACCEL, 0), |
| 44 | (err = ff_formats_ref(fmts, &avctx->inputs[0]->outcfg.formats)) || | 43 | &avctx->inputs[0]->outcfg.formats)) || |
| 45 | (err = ff_formats_pixdesc_filter(&fmts, 0, AV_PIX_FMT_FLAG_HWACCEL)) || | 44 | (err = ff_formats_ref(ff_formats_pixdesc_filter(0, AV_PIX_FMT_FLAG_HWACCEL), |
| 46 | (err = ff_formats_ref(fmts, &avctx->outputs[0]->incfg.formats))) | 45 | &avctx->outputs[0]->incfg.formats))) |
| 47 | return err; | 46 | return err; |
| 48 | 47 | ||
| 49 | return 0; | 48 | return 0; |
| @@ -83,15 +83,9 @@ AVFILTER_DEFINE_CLASS(il); · 82 unmodified lines | |||
| 83 | 83 | ||
| 84 | static int query_formats(AVFilterContext *ctx) | 84 | static int query_formats(AVFilterContext *ctx) |
| 85 | { | 85 | { |
| 86 | AVFilterFormats *formats = NULL; | 86 | int reject_flags = AV_PIX_FMT_FLAG_PAL | AV_PIX_FMT_FLAG_HWACCEL; |
| 87 | int ret; | ||
| 88 | 87 | ||
| 89 | ret = ff_formats_pixdesc_filter(&formats, 0, | 88 | return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); |
| 90 | AV_PIX_FMT_FLAG_PAL | | ||
| 91 | AV_PIX_FMT_FLAG_HWACCEL); | ||
| 92 | if (ret < 0) | ||
| 93 | return ret; | ||
| 94 | return ff_set_common_formats(ctx, formats); | ||
| 95 | } | 89 | } |
| 96 | 90 | ||
| 97 | static int config_input(AVFilterLink *inlink) | 91 | static int config_input(AVFilterLink *inlink) |
| @@ -55,16 +55,11 @@ typedef struct MixContext { · 54 unmodified lines | |||
| 55 | 55 | ||
| 56 | static int query_formats(AVFilterContext *ctx) | 56 | static int query_formats(AVFilterContext *ctx) |
| 57 | { | 57 | { |
| 58 | AVFilterFormats *formats = NULL; | 58 | int reject_flags = AV_PIX_FMT_FLAG_BITSTREAM | |
| 59 | int ret; | 59 | AV_PIX_FMT_FLAG_HWACCEL | |
| 60 | AV_PIX_FMT_FLAG_PAL; | ||
| 60 | 61 | ||
| 61 | ret = ff_formats_pixdesc_filter(&formats, 0, | 62 | return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); |
| 62 | AV_PIX_FMT_FLAG_BITSTREAM | | ||
| 63 | AV_PIX_FMT_FLAG_PAL | | ||
| 64 | AV_PIX_FMT_FLAG_HWACCEL); | ||
| 65 | if (ret < 0) | ||
| 66 | return ret; | ||
| 67 | return ff_set_common_formats(ctx, formats); | ||
| 68 | } | 63 | } |
| 69 | 64 | ||
| 70 | static int parse_weights(AVFilterContext *ctx) | 65 | static int parse_weights(AVFilterContext *ctx) |
| @@ -60,21 +60,16 @@ typedef struct StackContext { · 59 unmodified lines | |||
| 60 | 60 | ||
| 61 | static int query_formats(AVFilterContext *ctx) | 61 | static int query_formats(AVFilterContext *ctx) |
| 62 | { | 62 | { |
| 63 | AVFilterFormats *formats = NULL; | ||
| 64 | StackContext *s = ctx->priv; | 63 | StackContext *s = ctx->priv; |
| 65 | int ret; | 64 | int reject_flags = AV_PIX_FMT_FLAG_BITSTREAM | |
| 65 | AV_PIX_FMT_FLAG_HWACCEL | | ||
| 66 | AV_PIX_FMT_FLAG_PAL; | ||
| 66 | 67 | ||
| 67 | if (s->fillcolor_enable) { | 68 | if (s->fillcolor_enable) { |
| 68 | return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0)); | 69 | return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0)); |
| 69 | } | 70 | } |
| 70 | 71 | ||
| 71 | ret = ff_formats_pixdesc_filter(&formats, 0, | 72 | return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); |
| 72 | AV_PIX_FMT_FLAG_HWACCEL | | ||
| 73 | AV_PIX_FMT_FLAG_BITSTREAM | | ||
| 74 | AV_PIX_FMT_FLAG_PAL); | ||
| 75 | if (ret < 0) | ||
| 76 | return ret; | ||
| 77 | return ff_set_common_formats(ctx, formats); | ||
| 78 | } | 73 | } |
| 79 | 74 | ||
| 80 | static av_cold int init(AVFilterContext *ctx) | 75 | static av_cold int init(AVFilterContext *ctx) |
| @@ -57,16 +57,11 @@ AVFILTER_DEFINE_CLASS(swaprect); · 56 unmodified lines | |||
| 57 | 57 | ||
| 58 | static int query_formats(AVFilterContext *ctx) | 58 | static int query_formats(AVFilterContext *ctx) |
| 59 | { | 59 | { |
| 60 | AVFilterFormats *pix_fmts = NULL; | 60 | int reject_flags = AV_PIX_FMT_FLAG_PAL | |
| 61 | int ret; | 61 | AV_PIX_FMT_FLAG_HWACCEL | |
| 62 | AV_PIX_FMT_FLAG_BITSTREAM; | ||
| 62 | 63 | ||
| 63 | ret = ff_formats_pixdesc_filter(&pix_fmts, 0, AV_PIX_FMT_FLAG_PAL | | 64 | return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); |
| 64 | AV_PIX_FMT_FLAG_HWACCEL | | ||
| 65 | AV_PIX_FMT_FLAG_BITSTREAM); | ||
| 66 | if (ret < 0) | ||
| 67 | return ret; | ||
| 68 | |||
| 69 | return ff_set_common_formats(ctx, pix_fmts); | ||
| 70 | } | 65 | } |
| 71 | 66 | ||
| 72 | static const char *const var_names[] = { "w", "h", "a", "n", "t", "pos", "sar", "dar", NULL }; | 67 | static const char *const var_names[] = { "w", "h", "a", "n", "t", "pos", "sar", "dar", NULL }; |
| @@ -101,16 +101,11 @@ static av_cold int init(AVFilterContext *ctx) · 100 unmodified lines | |||
| 101 | 101 | ||
| 102 | static int query_formats(AVFilterContext *ctx) | 102 | static int query_formats(AVFilterContext *ctx) |
| 103 | { | 103 | { |
| 104 | AVFilterFormats *formats = NULL; | 104 | int reject_flags = AV_PIX_FMT_FLAG_BITSTREAM | |
| 105 | int ret; | 105 | AV_PIX_FMT_FLAG_HWACCEL | |
| 106 | 106 | AV_PIX_FMT_FLAG_PAL; | |
| 107 | ret = ff_formats_pixdesc_filter(&formats, 0, | 107 | |
| 108 | AV_PIX_FMT_FLAG_BITSTREAM | | 108 | return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); |
| 109 | AV_PIX_FMT_FLAG_PAL | | ||
| 110 | AV_PIX_FMT_FLAG_HWACCEL); | ||
| 111 | if (ret < 0) | ||
| 112 | return ret; | ||
| 113 | return ff_set_common_formats(ctx, formats); | ||
| 114 | } | 109 | } |
| 115 | 110 | ||
| 116 | static int config_input(AVFilterLink *inlink) | 111 | static int config_input(AVFilterLink *inlink) |
| @@ -62,16 +62,11 @@ static av_cold int init(AVFilterContext *ctx) · 61 unmodified lines | |||
| 62 | 62 | ||
| 63 | static int query_formats(AVFilterContext *ctx) | 63 | static int query_formats(AVFilterContext *ctx) |
| 64 | { | 64 | { |
| 65 | AVFilterFormats *formats = NULL; | 65 | int reject_flags = AV_PIX_FMT_FLAG_HWACCEL | |
| 66 | int ret; | 66 | AV_PIX_FMT_FLAG_BITSTREAM | |
| 67 | 67 | FF_PIX_FMT_FLAG_SW_FLAT_SUB; | |
| 68 | ret = ff_formats_pixdesc_filter(&formats, 0, | 68 | |
| 69 | AV_PIX_FMT_FLAG_HWACCEL | | 69 | return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); |
| 70 | AV_PIX_FMT_FLAG_BITSTREAM | | ||
| 71 | FF_PIX_FMT_FLAG_SW_FLAT_SUB); | ||
| 72 | if (ret < 0) | ||
| 73 | return ret; | ||
| 74 | return ff_set_common_formats(ctx, formats); | ||
| 75 | } | 70 | } |
| 76 | 71 | ||
| 77 | static int config_output(AVFilterLink *outlink) | 72 | static int config_output(AVFilterLink *outlink) |
| @@ -51,15 +51,9 @@ AVFILTER_DEFINE_CLASS_EXT(weave, "(double)weave", weave_options); · 50 unmodified lines | |||
| 51 | 51 | ||
| 52 | static int query_formats(AVFilterContext *ctx) | 52 | static int query_formats(AVFilterContext *ctx) |
| 53 | { | 53 | { |
| 54 | AVFilterFormats *formats = NULL; | 54 | int reject_flags = AV_PIX_FMT_FLAG_PAL | AV_PIX_FMT_FLAG_HWACCEL; |
| 55 | int ret; | ||
| 56 | 55 | ||
| 57 | ret = ff_formats_pixdesc_filter(&formats, 0, | 56 | return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); |
| 58 | AV_PIX_FMT_FLAG_PAL | | ||
| 59 | AV_PIX_FMT_FLAG_HWACCEL); | ||
| 60 | if (ret < 0) | ||
| 61 | return ret; | ||
| 62 | return ff_set_common_formats(ctx, formats); | ||
| 63 | } | 57 | } |
| 64 | 58 | ||
| 65 | static int config_props_output(AVFilterLink *outlink) | 59 | static int config_props_output(AVFilterLink *outlink) |