avcodec: add avcodec_get_supported_config()

This replaces the myriad of existing lists in AVCodec by a unified API
call, allowing us to (ultimately) trim down the sizeof(AVCodec) quite
substantially, while also making this more trivially extensible.

In addition to the already covered lists, add two new entries for color
space and color range, mirroring the newly added negotiable fields in
libavfilter.

Once the deprecation period passes for the existing public fields, the
rough plan is to move the commonly used fields (such as
pix_fmt/sample_fmt) into FFCodec, possibly as a union of audio and video
configuration types, and then implement the rarely used fields with
custom callbacks.
This commit is contained in:
Niklas Haas 2024-04-03 22:19:28 +02:00
parent 703288cec6
commit 3305767560
6 changed files with 172 additions and 5 deletions

View file

@ -22,6 +22,7 @@
#include <stdint.h>
#include "libavutil/attributes.h"
#include "avcodec.h"
#include "codec.h"
#include "config.h"
@ -269,8 +270,34 @@ typedef struct FFCodec {
* List of supported codec_tags, terminated by FF_CODEC_TAGS_END.
*/
const uint32_t *codec_tags;
/**
* Custom callback for avcodec_get_supported_config(). If absent,
* ff_default_get_supported_config() will be used. `out_num_configs` will
* always be set to a valid pointer.
*/
int (*get_supported_config)(const AVCodecContext *avctx,
const AVCodec *codec,
enum AVCodecConfig config,
unsigned flags,
const void **out_configs,
int *out_num_configs);
} FFCodec;
/**
* Default implementation for avcodec_get_supported_config(). Will return the
* relevant fields from AVCodec if present, or NULL otherwise.
*
* For AVCODEC_CONFIG_COLOR_RANGE, the output will depend on the bitmask in
* FFCodec.color_ranges, with a value of 0 returning NULL.
*/
int ff_default_get_supported_config(const AVCodecContext *avctx,
const AVCodec *codec,
enum AVCodecConfig config,
unsigned flags,
const void **out_configs,
int *out_num_configs);
#if CONFIG_SMALL
#define CODEC_LONG_NAME(str) .p.long_name = NULL
#else