1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-06-25 14:23:15 +02:00

lavc: add new API for iterating codecs and codec parsers

Based on an unfinished patch by atomnuker.
This commit is contained in:
Josh de Kock
2017-12-22 22:17:00 +00:00
parent caa4bd7a9f
commit 7e8eba2d87
9 changed files with 963 additions and 735 deletions

View File

@ -46,7 +46,6 @@
#include "decode.h"
#include "hwaccel.h"
#include "libavutil/opt.h"
#include "me_cmp.h"
#include "mpegvideo.h"
#include "thread.h"
#include "frame_thread_encoder.h"
@ -92,18 +91,6 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
memset(*p, 0, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
}
/* encoder management */
static AVCodec *first_avcodec = NULL;
static AVCodec **last_avcodec = &first_avcodec;
AVCodec *av_codec_next(const AVCodec *c)
{
if (c)
return c->next;
else
return first_avcodec;
}
int av_codec_is_encoder(const AVCodec *codec)
{
return codec && (codec->encode_sub || codec->encode2 ||codec->send_frame);
@ -114,27 +101,6 @@ int av_codec_is_decoder(const AVCodec *codec)
return codec && (codec->decode || codec->receive_frame);
}
static AVMutex codec_register_mutex = AV_MUTEX_INITIALIZER;
av_cold void avcodec_register(AVCodec *codec)
{
AVCodec **p;
ff_mutex_lock(&codec_register_mutex);
p = last_avcodec;
while (*p)
p = &(*p)->next;
*p = codec;
codec->next = NULL;
last_avcodec = &codec->next;
ff_mutex_unlock(&codec_register_mutex);
if (codec->init_static_data)
codec->init_static_data(codec);
}
int ff_set_dimensions(AVCodecContext *s, int width, int height)
{
int ret = av_image_check_size2(width, height, s->max_pixels, AV_PIX_FMT_NONE, 0, s);
@ -1155,71 +1121,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
return 0;
}
static enum AVCodecID remap_deprecated_codec_id(enum AVCodecID id)
{
switch(id){
//This is for future deprecatec codec ids, its empty since
//last major bump but will fill up again over time, please don't remove it
default : return id;
}
}
static AVCodec *find_encdec(enum AVCodecID id, int encoder)
{
AVCodec *p, *experimental = NULL;
p = first_avcodec;
id= remap_deprecated_codec_id(id);
while (p) {
if ((encoder ? av_codec_is_encoder(p) : av_codec_is_decoder(p)) &&
p->id == id) {
if (p->capabilities & AV_CODEC_CAP_EXPERIMENTAL && !experimental) {
experimental = p;
} else
return p;
}
p = p->next;
}
return experimental;
}
AVCodec *avcodec_find_encoder(enum AVCodecID id)
{
return find_encdec(id, 1);
}
AVCodec *avcodec_find_encoder_by_name(const char *name)
{
AVCodec *p;
if (!name)
return NULL;
p = first_avcodec;
while (p) {
if (av_codec_is_encoder(p) && strcmp(name, p->name) == 0)
return p;
p = p->next;
}
return NULL;
}
AVCodec *avcodec_find_decoder(enum AVCodecID id)
{
return find_encdec(id, 0);
}
AVCodec *avcodec_find_decoder_by_name(const char *name)
{
AVCodec *p;
if (!name)
return NULL;
p = first_avcodec;
while (p) {
if (av_codec_is_decoder(p) && strcmp(name, p->name) == 0)
return p;
p = p->next;
}
return NULL;
}
const char *avcodec_get_name(enum AVCodecID id)
{
const AVCodecDescriptor *cd;