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.
Showing the changes to libavfilter (14 of 14 files). Show all
Unified · Split
| @@ -452,7 +452,7 @@ AVFilterFormats *ff_all_formats(enum AVMediaType type) · 451 unmodified lines | ||
| 452 | 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 | 457 | unsigned nb_formats, fmt, flags; |
| 458 | 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 | 477 | if (formats) { |
| 478 | 478 | av_assert0(formats->nb_formats == nb_formats); |
| 479 | − *rfmts = formats; | |
| 480 | − return 0; | |
| 479 | + return formats; | |
| 481 | 480 | } |
| 482 | 481 | formats = av_mallocz(sizeof(*formats)); |
| 483 | 482 | if (!formats) |
| 484 | − return AVERROR(ENOMEM); | |
| 483 | + return NULL; | |
| 485 | 484 | formats->nb_formats = nb_formats; |
| 486 | 485 | if (nb_formats) { |
| 487 | 486 | formats->formats = av_malloc_array(nb_formats, sizeof(*formats->formats)); |
| 488 | 487 | if (!formats->formats) { |
| 489 | 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 | 230 | * properties |
| 231 | 231 | */ |
| 232 | 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 | 235 | //* format is software, non-planar with sub-sampling |
| 236 | 236 | #define FF_PIX_FMT_FLAG_SW_FLAT_SUB (1 << 24) |
| @@ -29,14 +29,7 @@ · 28 unmodified lines | ||
| 29 | 29 | |
| 30 | 30 | static int query_formats(AVFilterContext *ctx) |
| 31 | 31 | { |
| 32 | − AVFilterFormats *formats = NULL; | |
| 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); | |
| 32 | + return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, AV_PIX_FMT_FLAG_HWACCEL)); | |
| 40 | 33 | } |
| 41 | 34 | |
| 42 | 35 | static int filter_frame(AVFilterLink *inlink, AVFrame *in) |
| @@ -93,13 +93,9 @@ typedef struct CropContext { · 92 unmodified lines | ||
| 93 | 93 | |
| 94 | 94 | static int query_formats(AVFilterContext *ctx) |
| 95 | 95 | { |
| 96 | − AVFilterFormats *formats = NULL; | |
| 97 | − int ret; | |
| 96 | + int reject_flags = AV_PIX_FMT_FLAG_BITSTREAM | FF_PIX_FMT_FLAG_SW_FLAT_SUB; | |
| 98 | 97 | |
| 99 | − ret = ff_formats_pixdesc_filter(&formats, 0, AV_PIX_FMT_FLAG_BITSTREAM | FF_PIX_FMT_FLAG_SW_FLAT_SUB); | |
| 100 | − if (ret < 0) | |
| 101 | − return ret; | |
| 102 | − return ff_set_common_formats(ctx, formats); | |
| 98 | + return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); | |
| 103 | 99 | } |
| 104 | 100 | |
| 105 | 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 | 125 | static int query_formats(AVFilterContext *ctx) |
| 126 | 126 | { |
| 127 | − AVFilterFormats *formats = NULL; | |
| 128 | − int ret; | |
| 127 | + int reject_flags = AV_PIX_FMT_FLAG_BITSTREAM | | |
| 128 | + AV_PIX_FMT_FLAG_PAL | | |
| 129 | + AV_PIX_FMT_FLAG_HWACCEL; | |
| 129 | 130 | |
| 130 | − ret = ff_formats_pixdesc_filter(&formats, 0, | |
| 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); | |
| 131 | + return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); | |
| 137 | 132 | } |
| 138 | 133 | |
| 139 | 134 | static int config_input(AVFilterLink *inlink) |
| @@ -77,16 +77,11 @@ static av_cold int init(AVFilterContext *ctx) · 76 unmodified lines | ||
| 77 | 77 | |
| 78 | 78 | static int query_formats(AVFilterContext *ctx) |
| 79 | 79 | { |
| 80 | − AVFilterFormats *formats = NULL; | |
| 81 | − int ret; | |
| 80 | + int reject_flags = AV_PIX_FMT_FLAG_BITSTREAM | | |
| 81 | + AV_PIX_FMT_FLAG_HWACCEL | | |
| 82 | + AV_PIX_FMT_FLAG_PAL; | |
| 82 | 83 | |
| 83 | − ret = ff_formats_pixdesc_filter(&formats, 0, | |
| 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); | |
| 84 | + return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); | |
| 90 | 85 | } |
| 91 | 86 | |
| 92 | 87 | static int config_input(AVFilterLink *inlink) |
| @@ -37,13 +37,12 @@ typedef struct HWDownloadContext { · 36 unmodified lines | ||
| 37 | 37 | |
| 38 | 38 | static int hwdownload_query_formats(AVFilterContext *avctx) |
| 39 | 39 | { |
| 40 | − AVFilterFormats *fmts; | |
| 41 | 40 | int err; |
| 42 | 41 | |
| 43 | − if ((err = ff_formats_pixdesc_filter(&fmts, AV_PIX_FMT_FLAG_HWACCEL, 0)) || | |
| 44 | − (err = ff_formats_ref(fmts, &avctx->inputs[0]->outcfg.formats)) || | |
| 45 | − (err = ff_formats_pixdesc_filter(&fmts, 0, AV_PIX_FMT_FLAG_HWACCEL)) || | |
| 46 | − (err = ff_formats_ref(fmts, &avctx->outputs[0]->incfg.formats))) | |
| 42 | + if ((err = ff_formats_ref(ff_formats_pixdesc_filter(AV_PIX_FMT_FLAG_HWACCEL, 0), | |
| 43 | + &avctx->inputs[0]->outcfg.formats)) || | |
| 44 | + (err = ff_formats_ref(ff_formats_pixdesc_filter(0, AV_PIX_FMT_FLAG_HWACCEL), | |
| 45 | + &avctx->outputs[0]->incfg.formats))) | |
| 47 | 46 | return err; |
| 48 | 47 | |
| 49 | 48 | return 0; |
| @@ -83,15 +83,9 @@ AVFILTER_DEFINE_CLASS(il); · 82 unmodified lines | ||
| 83 | 83 | |
| 84 | 84 | static int query_formats(AVFilterContext *ctx) |
| 85 | 85 | { |
| 86 | − AVFilterFormats *formats = NULL; | |
| 87 | − int ret; | |
| 86 | + int reject_flags = AV_PIX_FMT_FLAG_PAL | AV_PIX_FMT_FLAG_HWACCEL; | |
| 88 | 87 | |
| 89 | − ret = ff_formats_pixdesc_filter(&formats, 0, | |
| 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); | |
| 88 | + return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); | |
| 95 | 89 | } |
| 96 | 90 | |
| 97 | 91 | static int config_input(AVFilterLink *inlink) |
| @@ -55,16 +55,11 @@ typedef struct MixContext { · 54 unmodified lines | ||
| 55 | 55 | |
| 56 | 56 | static int query_formats(AVFilterContext *ctx) |
| 57 | 57 | { |
| 58 | − AVFilterFormats *formats = NULL; | |
| 59 | − int ret; | |
| 58 | + int reject_flags = AV_PIX_FMT_FLAG_BITSTREAM | | |
| 59 | + AV_PIX_FMT_FLAG_HWACCEL | | |
| 60 | + AV_PIX_FMT_FLAG_PAL; | |
| 60 | 61 | |
| 61 | − ret = ff_formats_pixdesc_filter(&formats, 0, | |
| 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); | |
| 62 | + return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); | |
| 68 | 63 | } |
| 69 | 64 | |
| 70 | 65 | static int parse_weights(AVFilterContext *ctx) |
| @@ -60,21 +60,16 @@ typedef struct StackContext { · 59 unmodified lines | ||
| 60 | 60 | |
| 61 | 61 | static int query_formats(AVFilterContext *ctx) |
| 62 | 62 | { |
| 63 | − AVFilterFormats *formats = NULL; | |
| 64 | 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 | 68 | if (s->fillcolor_enable) { |
| 68 | 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 | − 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); | |
| 72 | + return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); | |
| 78 | 73 | } |
| 79 | 74 | |
| 80 | 75 | static av_cold int init(AVFilterContext *ctx) |
| @@ -57,16 +57,11 @@ AVFILTER_DEFINE_CLASS(swaprect); · 56 unmodified lines | ||
| 57 | 57 | |
| 58 | 58 | static int query_formats(AVFilterContext *ctx) |
| 59 | 59 | { |
| 60 | − AVFilterFormats *pix_fmts = NULL; | |
| 61 | − int ret; | |
| 60 | + int reject_flags = AV_PIX_FMT_FLAG_PAL | | |
| 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 | − 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); | |
| 64 | + return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); | |
| 70 | 65 | } |
| 71 | 66 | |
| 72 | 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 | 102 | static int query_formats(AVFilterContext *ctx) |
| 103 | 103 | { |
| 104 | − AVFilterFormats *formats = NULL; | |
| 105 | − int ret; | |
| 106 | − | |
| 107 | − ret = ff_formats_pixdesc_filter(&formats, 0, | |
| 108 | − AV_PIX_FMT_FLAG_BITSTREAM | | |
| 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); | |
| 104 | + int reject_flags = AV_PIX_FMT_FLAG_BITSTREAM | | |
| 105 | + AV_PIX_FMT_FLAG_HWACCEL | | |
| 106 | + AV_PIX_FMT_FLAG_PAL; | |
| 107 | + | |
| 108 | + return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); | |
| 114 | 109 | } |
| 115 | 110 | |
| 116 | 111 | static int config_input(AVFilterLink *inlink) |
| @@ -62,16 +62,11 @@ static av_cold int init(AVFilterContext *ctx) · 61 unmodified lines | ||
| 62 | 62 | |
| 63 | 63 | static int query_formats(AVFilterContext *ctx) |
| 64 | 64 | { |
| 65 | − AVFilterFormats *formats = NULL; | |
| 66 | − int ret; | |
| 67 | − | |
| 68 | − ret = ff_formats_pixdesc_filter(&formats, 0, | |
| 69 | − AV_PIX_FMT_FLAG_HWACCEL | | |
| 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); | |
| 65 | + int reject_flags = AV_PIX_FMT_FLAG_HWACCEL | | |
| 66 | + AV_PIX_FMT_FLAG_BITSTREAM | | |
| 67 | + FF_PIX_FMT_FLAG_SW_FLAT_SUB; | |
| 68 | + | |
| 69 | + return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); | |
| 75 | 70 | } |
| 76 | 71 | |
| 77 | 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 | 52 | static int query_formats(AVFilterContext *ctx) |
| 53 | 53 | { |
| 54 | − AVFilterFormats *formats = NULL; | |
| 55 | − int ret; | |
| 54 | + int reject_flags = AV_PIX_FMT_FLAG_PAL | AV_PIX_FMT_FLAG_HWACCEL; | |
| 56 | 55 | |
| 57 | − ret = ff_formats_pixdesc_filter(&formats, 0, | |
| 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); | |
| 56 | + return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, reject_flags)); | |
| 63 | 57 | } |
| 64 | 58 | |
| 65 | 59 | static int config_props_output(AVFilterLink *outlink) |