avcodec/codec, allcodecs: Constify the AVCodec API

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
Andreas Rheinhardt 2021-02-25 07:45:51 +01:00 committed by James Almer
parent 14fa0a4efb
commit 626535f6a1
15 changed files with 45 additions and 38 deletions

View File

@ -14,6 +14,11 @@ libavutil: 2017-10-21
API changes, most recent first:
2021-04-27 - xxxxxxxxxx - lavc yyyyyyyyy - codec.h
avcodec_find_encoder_by_name(), avcodec_find_encoder(),
avcodec_find_decoder_by_name() and avcodec_find_decoder()
now return a pointer to const AVCodec.
2021-04-27 - xxxxxxxxxx - lavf yyyyyyyyy - avformat.h
Constified AVFormatContext.*_codec.

View File

@ -149,7 +149,7 @@ static int open_codec_context(int *stream_idx,
{
int ret, stream_index;
AVStream *st;
AVCodec *dec = NULL;
const AVCodec *dec = NULL;
AVDictionary *opts = NULL;
ret = av_find_best_stream(fmt_ctx, type, -1, -1, NULL, 0);

View File

@ -121,7 +121,7 @@ static int write_frame(AVFormatContext *fmt_ctx, AVCodecContext *c,
/* Add an output stream. */
static void add_stream(OutputStream *ost, AVFormatContext *oc,
AVCodec **codec,
const AVCodec **codec,
enum AVCodecID codec_id)
{
AVCodecContext *c;
@ -242,7 +242,8 @@ static AVFrame *alloc_audio_frame(enum AVSampleFormat sample_fmt,
return frame;
}
static void open_audio(AVFormatContext *oc, AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg)
static void open_audio(AVFormatContext *oc, const AVCodec *codec,
OutputStream *ost, AVDictionary *opt_arg)
{
AVCodecContext *c;
int nb_samples;
@ -405,7 +406,8 @@ static AVFrame *alloc_picture(enum AVPixelFormat pix_fmt, int width, int height)
return picture;
}
static void open_video(AVFormatContext *oc, AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg)
static void open_video(AVFormatContext *oc, const AVCodec *codec,
OutputStream *ost, AVDictionary *opt_arg)
{
int ret;
AVCodecContext *c = ost->enc;
@ -539,7 +541,7 @@ int main(int argc, char **argv)
const AVOutputFormat *fmt;
const char *filename;
AVFormatContext *oc;
AVCodec *audio_codec, *video_codec;
const AVCodec *audio_codec, *video_codec;
int ret;
int have_video = 0, have_audio = 0;
int encode_video = 0, encode_audio = 0;

View File

@ -60,7 +60,7 @@ static int open_input_file(const char *filename,
AVCodecContext **input_codec_context)
{
AVCodecContext *avctx;
AVCodec *input_codec;
const AVCodec *input_codec;
int error;
/* Open the input file to read from it. */
@ -144,7 +144,7 @@ static int open_output_file(const char *filename,
AVCodecContext *avctx = NULL;
AVIOContext *output_io_context = NULL;
AVStream *stream = NULL;
AVCodec *output_codec = NULL;
const AVCodec *output_codec = NULL;
int error;
/* Open the output file to write to it. */

View File

@ -77,7 +77,7 @@ static int open_input_file(const char *filename)
for (i = 0; i < ifmt_ctx->nb_streams; i++) {
AVStream *stream = ifmt_ctx->streams[i];
AVCodec *dec = avcodec_find_decoder(stream->codecpar->codec_id);
const AVCodec *dec = avcodec_find_decoder(stream->codecpar->codec_id);
AVCodecContext *codec_ctx;
if (!dec) {
av_log(NULL, AV_LOG_ERROR, "Failed to find decoder for stream #%u\n", i);
@ -122,7 +122,7 @@ static int open_output_file(const char *filename)
AVStream *out_stream;
AVStream *in_stream;
AVCodecContext *dec_ctx, *enc_ctx;
AVCodec *encoder;
const AVCodec *encoder;
int ret;
unsigned int i;

View File

@ -105,7 +105,7 @@ int main(int argc, char *argv[])
FILE *fin = NULL, *fout = NULL;
AVFrame *sw_frame = NULL, *hw_frame = NULL;
AVCodecContext *avctx = NULL;
AVCodec *codec = NULL;
const AVCodec *codec = NULL;
const char *enc_name = "h264_vaapi";
if (argc < 5) {

View File

@ -142,7 +142,7 @@ end:
return ret;
}
static int dec_enc(AVPacket *pkt, AVCodec *enc_codec)
static int dec_enc(AVPacket *pkt, const AVCodec *enc_codec)
{
AVFrame *frame;
int ret = 0;
@ -226,9 +226,9 @@ fail:
int main(int argc, char **argv)
{
const AVCodec *enc_codec;
int ret = 0;
AVPacket *dec_pkt;
AVCodec *enc_codec;
if (argc != 4) {
fprintf(stderr, "Usage: %s <input file> <encode codec> <output file>\n"

View File

@ -873,7 +873,7 @@ static enum AVCodecID remap_deprecated_codec_id(enum AVCodecID id)
}
}
static AVCodec *find_codec(enum AVCodecID id, int (*x)(const AVCodec *))
static const AVCodec *find_codec(enum AVCodecID id, int (*x)(const AVCodec *))
{
const AVCodec *p, *experimental = NULL;
void *i = 0;
@ -887,24 +887,24 @@ static AVCodec *find_codec(enum AVCodecID id, int (*x)(const AVCodec *))
if (p->capabilities & AV_CODEC_CAP_EXPERIMENTAL && !experimental) {
experimental = p;
} else
return (AVCodec*)p;
return p;
}
}
return (AVCodec*)experimental;
return experimental;
}
AVCodec *avcodec_find_encoder(enum AVCodecID id)
const AVCodec *avcodec_find_encoder(enum AVCodecID id)
{
return find_codec(id, av_codec_is_encoder);
}
AVCodec *avcodec_find_decoder(enum AVCodecID id)
const AVCodec *avcodec_find_decoder(enum AVCodecID id)
{
return find_codec(id, av_codec_is_decoder);
}
static AVCodec *find_codec_by_name(const char *name, int (*x)(const AVCodec *))
static const AVCodec *find_codec_by_name(const char *name, int (*x)(const AVCodec *))
{
void *i = 0;
const AVCodec *p;
@ -916,18 +916,18 @@ static AVCodec *find_codec_by_name(const char *name, int (*x)(const AVCodec *))
if (!x(p))
continue;
if (strcmp(name, p->name) == 0)
return (AVCodec*)p;
return p;
}
return NULL;
}
AVCodec *avcodec_find_encoder_by_name(const char *name)
const AVCodec *avcodec_find_encoder_by_name(const char *name)
{
return find_codec_by_name(name, av_codec_is_encoder);
}
AVCodec *avcodec_find_decoder_by_name(const char *name)
const AVCodec *avcodec_find_decoder_by_name(const char *name)
{
return find_codec_by_name(name, av_codec_is_decoder);
}

View File

@ -367,7 +367,7 @@ const AVCodec *av_codec_iterate(void **opaque);
* @param id AVCodecID of the requested decoder
* @return A decoder if one was found, NULL otherwise.
*/
AVCodec *avcodec_find_decoder(enum AVCodecID id);
const AVCodec *avcodec_find_decoder(enum AVCodecID id);
/**
* Find a registered decoder with the specified name.
@ -375,7 +375,7 @@ AVCodec *avcodec_find_decoder(enum AVCodecID id);
* @param name name of the requested decoder
* @return A decoder if one was found, NULL otherwise.
*/
AVCodec *avcodec_find_decoder_by_name(const char *name);
const AVCodec *avcodec_find_decoder_by_name(const char *name);
/**
* Find a registered encoder with a matching codec ID.
@ -383,7 +383,7 @@ AVCodec *avcodec_find_decoder_by_name(const char *name);
* @param id AVCodecID of the requested encoder
* @return An encoder if one was found, NULL otherwise.
*/
AVCodec *avcodec_find_encoder(enum AVCodecID id);
const AVCodec *avcodec_find_encoder(enum AVCodecID id);
/**
* Find a registered encoder with the specified name.
@ -391,7 +391,7 @@ AVCodec *avcodec_find_encoder(enum AVCodecID id);
* @param name name of the requested encoder
* @return An encoder if one was found, NULL otherwise.
*/
AVCodec *avcodec_find_encoder_by_name(const char *name);
const AVCodec *avcodec_find_encoder_by_name(const char *name);
/**
* @return a non-zero number if codec is an encoder, zero otherwise
*/

View File

@ -369,7 +369,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
enum AVPixelFormat pix_fmt = dshow_pixfmt(bih->biCompression, bih->biBitCount);
if (pix_fmt == AV_PIX_FMT_NONE) {
enum AVCodecID codec_id = av_codec_get_id(tags, bih->biCompression);
AVCodec *codec = avcodec_find_decoder(codec_id);
const AVCodec *codec = avcodec_find_decoder(codec_id);
if (codec_id == AV_CODEC_ID_NONE || !codec) {
av_log(avctx, AV_LOG_INFO, " unknown compression type 0x%X", (int) bih->biCompression);
} else {

View File

@ -66,7 +66,7 @@ static void draw_horiz_band(AVCodecContext *ctx, const AVFrame *fr, int offset[4
static int video_decode(const char *input_filename)
{
AVCodec *codec = NULL;
const AVCodec *codec = NULL;
AVCodecContext *ctx= NULL;
AVCodecParameters *origin_par = NULL;
uint8_t *byte_buffer = NULL;

View File

@ -48,7 +48,7 @@ static int generate_raw_frame(uint16_t *frame_data, int i, int sample_rate,
return 0;
}
static int init_encoder(AVCodec *enc, AVCodecContext **enc_ctx,
static int init_encoder(const AVCodec *enc, AVCodecContext **enc_ctx,
int64_t ch_layout, int sample_rate)
{
AVCodecContext *ctx;
@ -78,7 +78,7 @@ static int init_encoder(AVCodec *enc, AVCodecContext **enc_ctx,
return 0;
}
static int init_decoder(AVCodec *dec, AVCodecContext **dec_ctx,
static int init_decoder(const AVCodec *dec, AVCodecContext **dec_ctx,
int64_t ch_layout)
{
AVCodecContext *ctx;
@ -105,8 +105,8 @@ static int init_decoder(AVCodec *dec, AVCodecContext **dec_ctx,
return 0;
}
static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx,
AVCodecContext *dec_ctx)
static int run_test(const AVCodec *enc, const AVCodec *dec,
AVCodecContext *enc_ctx, AVCodecContext *dec_ctx)
{
AVPacket *enc_pkt;
AVFrame *in_frame, *out_frame;
@ -244,7 +244,7 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx,
int main(void)
{
AVCodec *enc = NULL, *dec = NULL;
const AVCodec *enc = NULL, *dec = NULL;
AVCodecContext *enc_ctx = NULL, *dec_ctx = NULL;
uint64_t channel_layouts[] = {AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_5POINT1_BACK, AV_CH_LAYOUT_SURROUND, AV_CH_LAYOUT_STEREO_DOWNMIX};
int sample_rates[] = {8000, 44100, 48000, 192000};

View File

@ -32,7 +32,7 @@
static int video_decode_example(const char *input_filename)
{
AVCodec *codec = NULL;
const AVCodec *codec = NULL;
AVCodecContext *ctx= NULL;
AVCodecParameters *origin_par = NULL;
AVFrame *fr = NULL;

View File

@ -184,7 +184,7 @@ static long int read_seek_range(const char *string_with_number)
static int seek_test(const char *input_filename, const char *start, const char *end)
{
AVCodec *codec = NULL;
const AVCodec *codec = NULL;
AVCodecContext *ctx= NULL;
AVCodecParameters *origin_par = NULL;
AVPacket *pkt = NULL;

View File

@ -59,7 +59,7 @@
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
extern AVCodec * codec_list[];
extern const AVCodec * codec_list[];
static void error(const char *err)
{
@ -67,10 +67,10 @@ static void error(const char *err)
exit(1);
}
static AVCodec *c = NULL;
static AVCodec *AVCodecInitialize(enum AVCodecID codec_id)
static const AVCodec *c = NULL;
static const AVCodec *AVCodecInitialize(enum AVCodecID codec_id)
{
AVCodec *res;
const AVCodec *res;
res = avcodec_find_decoder(codec_id);
if (!res)