Re: [FFmpeg-devel] [PATCH v2 1/6] lavc: add new API for iterating codecs and codec parsers

2018-01-03 Thread Michael Niedermayer
On Wed, Jan 03, 2018 at 12:42:36AM +, Josh de Kock wrote:
> Also replace linked list with an array.
> ---
>  configure  |   12 +-
>  doc/APIchanges |4 +
>  libavcodec/allcodecs.c | 1473 
> 
>  libavcodec/avcodec.h   |   31 +
>  libavcodec/parser.c|   87 ++-
>  libavcodec/utils.c |  105 
>  libavcodec/version.h   |3 +
>  7 files changed, 974 insertions(+), 741 deletions(-)

Fails to build
make distclean ; ../configure && make 

LD  ffmpeg_g
libavcodec/libavcodec.a(allcodecs.o):(.rodata+0x10): undefined reference to 
`ff_apng_encoder'
libavcodec/libavcodec.a(allcodecs.o):(.rodata+0x50): undefined reference to 
`ff_flashsv_encoder'
libavcodec/libavcodec.a(allcodecs.o):(.rodata+0x54): undefined reference to 
`ff_flashsv2_encoder'
libavcodec/libavcodec.a(allcodecs.o):(.rodata+0x6c): undefined reference to 
`ff_hap_encoder'
libavcodec/libavcodec.a(allcodecs.o):(.rodata+0xb4): undefined reference to 
`ff_png_encoder'
libavcodec/libavcodec.a(allcodecs.o):(.rodata+0x138): undefined reference to 
`ff_zlib_encoder'
libavcodec/libavcodec.a(allcodecs.o):(.rodata+0x13c): undefined reference to 
`ff_zmbv_encoder'
libavcodec/libavcodec.a(allcodecs.o):(.rodata+0x25c): undefined reference to 
`ff_libfdk_aac_encoder'
libavcodec/libavcodec.a(allcodecs.o):(.rodata+0x260): undefined reference to 
`ff_libgsm_encoder'
libavcodec/libavcodec.a(allcodecs.o):(.rodata+0x264): undefined reference to 
`ff_libgsm_ms_encoder'
libavcodec/libavcodec.a(allcodecs.o):(.rodata+0x268): undefined reference to 
`ff_libilbc_encoder'
libavcodec/libavcodec.a(allcodecs.o):(.rodata+0x26c): undefined reference to 
`ff_libmp3lame_encoder'

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Modern terrorism, a quick summary: Need oil, start war with country that
has oil, kill hundread thousand in war. Let country fall into chaos,
be surprised about raise of fundamantalists. Drop more bombs, kill more
people, be surprised about them taking revenge and drop even more bombs
and strip your own citizens of their rights and freedoms. to be continued


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v2 1/6] lavc: add new API for iterating codecs and codec parsers

2018-01-03 Thread Muhammad Faiz
On Thu, Jan 4, 2018 at 2:59 AM, Rostislav Pehlivanov
 wrote:
> On 3 January 2018 at 19:16, Muhammad Faiz  wrote:
>
>> On Wed, Jan 3, 2018 at 7:42 AM, Josh de Kock  wrote:
>> > Also replace linked list with an array.
>> > ---
>> >  configure  |   12 +-
>> >  doc/APIchanges |4 +
>> >  libavcodec/allcodecs.c | 1473 --
>> --
>> >  libavcodec/avcodec.h   |   31 +
>> >  libavcodec/parser.c|   87 ++-
>> >  libavcodec/utils.c |  105 
>> >  libavcodec/version.h   |3 +
>> >  7 files changed, 974 insertions(+), 741 deletions(-)
>> >
>>
>> > +
>> > +#include "codec_list.c"
>>
>> Won't work when building outside source directory. Use
>> "libavcodec/codec_list.c"
>>
>
> It pretty much will, this is exactly how hwaccels and bitstream filters
> currently work.

At bitstream_filters.c:
#include "libavcodec/bsf_list.c"

>
>
>
>>
>> > +static void av_codec_init_next(void)
>> > +{
>> > +AVCodec *prev = NULL, *p;
>> > +void *i = 0;
>> > +while ((p = (AVCodec*)av_codec_iterate(&i))) {
>>
>> Better use: for (i = 0; codec_list[i]; i++)
>>
>>
>> > diff --git a/libavcodec/parser.c b/libavcodec/parser.c
>> > index 670680e..76532e2 100644
>> > --- a/libavcodec/parser.c
>> > +++ b/libavcodec/parser.c
>> > @@ -32,33 +32,104 @@
>> >  #include "internal.h"
>> >  #include "parser.h"
>> >
>> > -static AVCodecParser *av_first_parser = NULL;
>> > +#include "pthread.h"
>> > +
>> > +/* Parsers */
>> > +extern AVCodecParser ff_aac_parser;
>> > +extern AVCodecParser ff_aac_latm_parser;
>> > +extern AVCodecParser ff_ac3_parser;
>> > +extern AVCodecParser ff_adx_parser;
>> > +extern AVCodecParser ff_bmp_parser;
>> > +extern AVCodecParser ff_cavsvideo_parser;
>> > +extern AVCodecParser ff_cook_parser;
>> > +extern AVCodecParser ff_dca_parser;
>> > +extern AVCodecParser ff_dirac_parser;
>> > +extern AVCodecParser ff_dnxhd_parser;
>> > +extern AVCodecParser ff_dpx_parser;
>> > +extern AVCodecParser ff_dvaudio_parser;
>> > +extern AVCodecParser ff_dvbsub_parser;
>> > +extern AVCodecParser ff_dvdsub_parser;
>> > +extern AVCodecParser ff_dvd_nav_parser;
>> > +extern AVCodecParser ff_flac_parser;
>> > +extern AVCodecParser ff_g729_parser;
>> > +extern AVCodecParser ff_gsm_parser;
>> > +extern AVCodecParser ff_h261_parser;
>> > +extern AVCodecParser ff_h263_parser;
>> > +extern AVCodecParser ff_h264_parser;
>> > +extern AVCodecParser ff_hevc_parser;
>> > +extern AVCodecParser ff_mjpeg_parser;
>> > +extern AVCodecParser ff_mlp_parser;
>> > +extern AVCodecParser ff_mpeg4video_parser;
>> > +extern AVCodecParser ff_mpegaudio_parser;
>> > +extern AVCodecParser ff_mpegvideo_parser;
>> > +extern AVCodecParser ff_opus_parser;
>> > +extern AVCodecParser ff_png_parser;
>> > +extern AVCodecParser ff_pnm_parser;
>> > +extern AVCodecParser ff_rv30_parser;
>> > +extern AVCodecParser ff_rv40_parser;
>> > +extern AVCodecParser ff_sipr_parser;
>> > +extern AVCodecParser ff_tak_parser;
>> > +extern AVCodecParser ff_vc1_parser;
>> > +extern AVCodecParser ff_vorbis_parser;
>> > +extern AVCodecParser ff_vp3_parser;
>> > +extern AVCodecParser ff_vp8_parser;
>> > +extern AVCodecParser ff_vp9_parser;
>> > +extern AVCodecParser ff_xma_parser;
>>
>> Why these are not in allcodecs.c?
>>
>
> Because they're parsers.
>

They still need initialize next pointer. So better to initialize it on
avcodec_register_all().
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v2 1/6] lavc: add new API for iterating codecs and codec parsers

2018-01-03 Thread Rostislav Pehlivanov
On 3 January 2018 at 19:16, Muhammad Faiz  wrote:

> On Wed, Jan 3, 2018 at 7:42 AM, Josh de Kock  wrote:
> > Also replace linked list with an array.
> > ---
> >  configure  |   12 +-
> >  doc/APIchanges |4 +
> >  libavcodec/allcodecs.c | 1473 --
> --
> >  libavcodec/avcodec.h   |   31 +
> >  libavcodec/parser.c|   87 ++-
> >  libavcodec/utils.c |  105 
> >  libavcodec/version.h   |3 +
> >  7 files changed, 974 insertions(+), 741 deletions(-)
> >
>
> > +
> > +#include "codec_list.c"
>
> Won't work when building outside source directory. Use
> "libavcodec/codec_list.c"
>

It pretty much will, this is exactly how hwaccels and bitstream filters
currently work.



>
> > +static void av_codec_init_next(void)
> > +{
> > +AVCodec *prev = NULL, *p;
> > +void *i = 0;
> > +while ((p = (AVCodec*)av_codec_iterate(&i))) {
>
> Better use: for (i = 0; codec_list[i]; i++)
>
>
> > diff --git a/libavcodec/parser.c b/libavcodec/parser.c
> > index 670680e..76532e2 100644
> > --- a/libavcodec/parser.c
> > +++ b/libavcodec/parser.c
> > @@ -32,33 +32,104 @@
> >  #include "internal.h"
> >  #include "parser.h"
> >
> > -static AVCodecParser *av_first_parser = NULL;
> > +#include "pthread.h"
> > +
> > +/* Parsers */
> > +extern AVCodecParser ff_aac_parser;
> > +extern AVCodecParser ff_aac_latm_parser;
> > +extern AVCodecParser ff_ac3_parser;
> > +extern AVCodecParser ff_adx_parser;
> > +extern AVCodecParser ff_bmp_parser;
> > +extern AVCodecParser ff_cavsvideo_parser;
> > +extern AVCodecParser ff_cook_parser;
> > +extern AVCodecParser ff_dca_parser;
> > +extern AVCodecParser ff_dirac_parser;
> > +extern AVCodecParser ff_dnxhd_parser;
> > +extern AVCodecParser ff_dpx_parser;
> > +extern AVCodecParser ff_dvaudio_parser;
> > +extern AVCodecParser ff_dvbsub_parser;
> > +extern AVCodecParser ff_dvdsub_parser;
> > +extern AVCodecParser ff_dvd_nav_parser;
> > +extern AVCodecParser ff_flac_parser;
> > +extern AVCodecParser ff_g729_parser;
> > +extern AVCodecParser ff_gsm_parser;
> > +extern AVCodecParser ff_h261_parser;
> > +extern AVCodecParser ff_h263_parser;
> > +extern AVCodecParser ff_h264_parser;
> > +extern AVCodecParser ff_hevc_parser;
> > +extern AVCodecParser ff_mjpeg_parser;
> > +extern AVCodecParser ff_mlp_parser;
> > +extern AVCodecParser ff_mpeg4video_parser;
> > +extern AVCodecParser ff_mpegaudio_parser;
> > +extern AVCodecParser ff_mpegvideo_parser;
> > +extern AVCodecParser ff_opus_parser;
> > +extern AVCodecParser ff_png_parser;
> > +extern AVCodecParser ff_pnm_parser;
> > +extern AVCodecParser ff_rv30_parser;
> > +extern AVCodecParser ff_rv40_parser;
> > +extern AVCodecParser ff_sipr_parser;
> > +extern AVCodecParser ff_tak_parser;
> > +extern AVCodecParser ff_vc1_parser;
> > +extern AVCodecParser ff_vorbis_parser;
> > +extern AVCodecParser ff_vp3_parser;
> > +extern AVCodecParser ff_vp8_parser;
> > +extern AVCodecParser ff_vp9_parser;
> > +extern AVCodecParser ff_xma_parser;
>
> Why these are not in allcodecs.c?
>

Because they're parsers.


> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v2 1/6] lavc: add new API for iterating codecs and codec parsers

2018-01-03 Thread Muhammad Faiz
On Wed, Jan 3, 2018 at 7:42 AM, Josh de Kock  wrote:
> Also replace linked list with an array.
> ---
>  configure  |   12 +-
>  doc/APIchanges |4 +
>  libavcodec/allcodecs.c | 1473 
> 
>  libavcodec/avcodec.h   |   31 +
>  libavcodec/parser.c|   87 ++-
>  libavcodec/utils.c |  105 
>  libavcodec/version.h   |3 +
>  7 files changed, 974 insertions(+), 741 deletions(-)
>

> +
> +#include "codec_list.c"

Won't work when building outside source directory. Use "libavcodec/codec_list.c"


> +static void av_codec_init_next(void)
> +{
> +AVCodec *prev = NULL, *p;
> +void *i = 0;
> +while ((p = (AVCodec*)av_codec_iterate(&i))) {

Better use: for (i = 0; codec_list[i]; i++)


> diff --git a/libavcodec/parser.c b/libavcodec/parser.c
> index 670680e..76532e2 100644
> --- a/libavcodec/parser.c
> +++ b/libavcodec/parser.c
> @@ -32,33 +32,104 @@
>  #include "internal.h"
>  #include "parser.h"
>
> -static AVCodecParser *av_first_parser = NULL;
> +#include "pthread.h"
> +
> +/* Parsers */
> +extern AVCodecParser ff_aac_parser;
> +extern AVCodecParser ff_aac_latm_parser;
> +extern AVCodecParser ff_ac3_parser;
> +extern AVCodecParser ff_adx_parser;
> +extern AVCodecParser ff_bmp_parser;
> +extern AVCodecParser ff_cavsvideo_parser;
> +extern AVCodecParser ff_cook_parser;
> +extern AVCodecParser ff_dca_parser;
> +extern AVCodecParser ff_dirac_parser;
> +extern AVCodecParser ff_dnxhd_parser;
> +extern AVCodecParser ff_dpx_parser;
> +extern AVCodecParser ff_dvaudio_parser;
> +extern AVCodecParser ff_dvbsub_parser;
> +extern AVCodecParser ff_dvdsub_parser;
> +extern AVCodecParser ff_dvd_nav_parser;
> +extern AVCodecParser ff_flac_parser;
> +extern AVCodecParser ff_g729_parser;
> +extern AVCodecParser ff_gsm_parser;
> +extern AVCodecParser ff_h261_parser;
> +extern AVCodecParser ff_h263_parser;
> +extern AVCodecParser ff_h264_parser;
> +extern AVCodecParser ff_hevc_parser;
> +extern AVCodecParser ff_mjpeg_parser;
> +extern AVCodecParser ff_mlp_parser;
> +extern AVCodecParser ff_mpeg4video_parser;
> +extern AVCodecParser ff_mpegaudio_parser;
> +extern AVCodecParser ff_mpegvideo_parser;
> +extern AVCodecParser ff_opus_parser;
> +extern AVCodecParser ff_png_parser;
> +extern AVCodecParser ff_pnm_parser;
> +extern AVCodecParser ff_rv30_parser;
> +extern AVCodecParser ff_rv40_parser;
> +extern AVCodecParser ff_sipr_parser;
> +extern AVCodecParser ff_tak_parser;
> +extern AVCodecParser ff_vc1_parser;
> +extern AVCodecParser ff_vorbis_parser;
> +extern AVCodecParser ff_vp3_parser;
> +extern AVCodecParser ff_vp8_parser;
> +extern AVCodecParser ff_vp9_parser;
> +extern AVCodecParser ff_xma_parser;

Why these are not in allcodecs.c?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v2 1/6] lavc: add new API for iterating codecs and codec parsers

2018-01-03 Thread wm4
On Wed, 3 Jan 2018 16:50:00 +
Rostislav Pehlivanov  wrote:

> On 3 January 2018 at 15:25, wm4  wrote:
> 
> > On Wed, 3 Jan 2018 00:42:36 +
> > Josh de Kock  wrote:
> >  

> > > +static AVCodec *find_codec_by_name(const char *name, int (*x)(const  
> > AVCodec *))  
> > > +{
> > > +void *i = 0;
> > > +const AVCodec *p;
> > > +
> > > +if (!name)
> > > +return NULL;
> > > +
> > > +while ((p = av_codec_iterate(&i))) {
> > > +if (!x(p))
> > > +continue;
> > > +if (strcmp(name, p->name) == 0)
> > > +return (AVCodec*)p;
> > > +}
> > > +
> > > +return NULL;
> > > +}
> > > +
> > > +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)
> > > +{
> > > +return find_codec_by_name(name, av_codec_is_decoder);
> > >  }  
> >
> > Personally I'd argue a bool parameter or so to select encoders vs.
> > decoders would be less roudnabout (like it was before), but I have no
> > strong opinion. Could be considered an improvement as well.
> >
> >  
> I think separate functions would be better in this case.

My comment was just about how find_codec_by_name() is called. Certainly
we don't want to duplicate the actual code.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v2 1/6] lavc: add new API for iterating codecs and codec parsers

2018-01-03 Thread Rostislav Pehlivanov
On 3 January 2018 at 15:25, wm4  wrote:

> On Wed, 3 Jan 2018 00:42:36 +
> Josh de Kock  wrote:
>
> > Also replace linked list with an array.
> > ---
> >  configure  |   12 +-
> >  doc/APIchanges |4 +
> >  libavcodec/allcodecs.c | 1473 --
> --
> >  libavcodec/avcodec.h   |   31 +
> >  libavcodec/parser.c|   87 ++-
> >  libavcodec/utils.c |  105 
> >  libavcodec/version.h   |3 +
> >  7 files changed, 974 insertions(+), 741 deletions(-)
> >
>
> > +#if CONFIG_ME_CMP
> > +#include "me_cmp.h"
> > +#endif
> > +
> > +pthread_once_t av_codec_static_init = PTHREAD_ONCE_INIT;
> > +static void av_codec_init_static(void)
> > +{
> > +#if CONFIG_ME_CMP
> > +ff_me_cmp_init_static();
> > +#endif
>
> (This should probably be moved away, since it doesn't really have to do
> with any of this - it's just a global init in the wrong place. But I
> won't insist that this gets cleaned up now. Someone else can do it
> later.)
>
> > +for (int i = 0; codec_list[i]; i++) {
> > +if (codec_list[i]->init_static_data)
> > +codec_list[i]->init_static_data((AVCodec*)codec_list[i]);
> >  }
> > +}
> > +
> > +const AVCodec *av_codec_iterate(void **opaque)
> > +{
> > +uintptr_t i = (uintptr_t)*opaque;
> > +const AVCodec *c = codec_list[i];
> > +
> > +pthread_once(&av_codec_static_init, av_codec_init_static);
>
> One issue: you need to use ff_thread_once() everywhere (it uses a
> different initializer type too). The reason is because if it's built
> without threads, pthread_once() will not be defined.
>
> Same for all other uses of this.
>
> >
> > -#define REGISTER_ENCDEC(X, x) REGISTER_ENCODER(X, x);
> REGISTER_DECODER(X, x)
> > +if (c)
> > +*opaque = (void*)(i + 1);
> >
> > -#define REGISTER_PARSER(X, x)
>  \
> > -{
>  \
> > -extern AVCodecParser ff_##x##_parser;
>  \
> > -if (CONFIG_##X##_PARSER)
> \
> > -av_register_codec_parser(&ff_##x##_parser);
>  \
> > +return c;
> > +}
> > +
> > +#if FF_API_NEXT
> > +pthread_once_t av_codec_next_init = PTHREAD_ONCE_INIT;
> > +
> > +static void av_codec_init_next(void)
> > +{
> > +AVCodec *prev = NULL, *p;
> > +void *i = 0;
> > +while ((p = (AVCodec*)av_codec_iterate(&i))) {
> > +if (prev)
> > +prev->next = p;
> > +prev = p;
> >  }
>
> > +if (prev)
> > +prev->next = NULL;
>
> What's this for? Isn't it already initialized to NULL?
>
> > +}
> > +
> >
> > -static void register_all(void)
> > +
> > +av_cold void avcodec_register(AVCodec *codec)
> >  {
> > -/* video codecs */
> > -REGISTER_ENCODER(A64MULTI,  a64multi);
>
> > +pthread_once(&av_codec_next_init, av_codec_init_next);
> > +}
>
> I don't see much of a point in this call. Could be dropped, so the body
> is empty.
>
> > +AVCodec *av_codec_next(const AVCodec *c)
> > +{
> > +pthread_once(&av_codec_next_init, av_codec_init_next);
> > +
> > +if (c)
> > +return c->next;
> > +else
> > +return (AVCodec*)codec_list[0];
> >  }
> >
> >  void avcodec_register_all(void)
> >  {
> > -static AVOnce control = AV_ONCE_INIT;
> > +pthread_once(&av_codec_next_init, av_codec_init_next);
> > +}
>
> So that means if you use the legacy API, you still need to call
> the register function. Strange choice, but I'm fine with it.
>
> > +#endif
> > +
> > +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_codec(enum AVCodecID id, int (*x)(const AVCodec *))
> > +{
> > +const AVCodec *p, *experimental = NULL;
> > +void *i = 0;
> > +
> > +id = remap_deprecated_codec_id(id);
> > +
> > +while ((p = av_codec_iterate(&i))) {
> > +if (!x(p))
> > +continue;
> > +if (p->id == id) {
> > +if (p->capabilities & AV_CODEC_CAP_EXPERIMENTAL &&
> !experimental) {
> > +experimental = p;
> > +} else
> > +return (AVCodec*)p;
> > +}
> > +}
> >
> > -ff_thread_once(&control, register_all);
> > +return (AVCodec*)experimental;
> > +}
> > +
> > +AVCodec *avcodec_find_encoder(enum AVCodecID id)
> > +{
> > +return find_codec(id, av_codec_is_encoder);
> > +}
> > +
> > +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 *))
> > +{
> > +void *i = 0;
> > +const AVCodec *p;
> > +
> > +if (!name)
> > +return NULL;
> > +
> > +while ((p = av_codec_iterate(&i))) {
> > +if (!x(p))
> > +contin

Re: [FFmpeg-devel] [PATCH v2 1/6] lavc: add new API for iterating codecs and codec parsers

2018-01-03 Thread wm4
On Wed, 3 Jan 2018 00:42:36 +
Josh de Kock  wrote:

> Also replace linked list with an array.
> ---

> diff --git a/doc/APIchanges b/doc/APIchanges
> index 3c9f237..3d28d85 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,10 @@ libavutil: 2017-10-21
>  
>  API changes, most recent first:
>  
> +2018-xx-xx - xxx - lavc 58.9.100 - avcodec.h
> +  Deprecate use of avcodec_register(), avcodec_register_all(), and
> +  av_codec_next(). Add av_codec_iterate().
> +

PS: oh, sorry, APIchanges entry was present. Never mind.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v2 1/6] lavc: add new API for iterating codecs and codec parsers

2018-01-03 Thread wm4
On Wed, 3 Jan 2018 00:42:36 +
Josh de Kock  wrote:

> Also replace linked list with an array.
> ---
>  configure  |   12 +-
>  doc/APIchanges |4 +
>  libavcodec/allcodecs.c | 1473 
> 
>  libavcodec/avcodec.h   |   31 +
>  libavcodec/parser.c|   87 ++-
>  libavcodec/utils.c |  105 
>  libavcodec/version.h   |3 +
>  7 files changed, 974 insertions(+), 741 deletions(-)
> 

> +#if CONFIG_ME_CMP
> +#include "me_cmp.h"
> +#endif
> +
> +pthread_once_t av_codec_static_init = PTHREAD_ONCE_INIT;
> +static void av_codec_init_static(void)
> +{
> +#if CONFIG_ME_CMP
> +ff_me_cmp_init_static();
> +#endif

(This should probably be moved away, since it doesn't really have to do
with any of this - it's just a global init in the wrong place. But I
won't insist that this gets cleaned up now. Someone else can do it
later.)

> +for (int i = 0; codec_list[i]; i++) {
> +if (codec_list[i]->init_static_data)
> +codec_list[i]->init_static_data((AVCodec*)codec_list[i]);
>  }
> +}
> +
> +const AVCodec *av_codec_iterate(void **opaque)
> +{
> +uintptr_t i = (uintptr_t)*opaque;
> +const AVCodec *c = codec_list[i];
> +
> +pthread_once(&av_codec_static_init, av_codec_init_static);

One issue: you need to use ff_thread_once() everywhere (it uses a
different initializer type too). The reason is because if it's built
without threads, pthread_once() will not be defined.

Same for all other uses of this.

>  
> -#define REGISTER_ENCDEC(X, x) REGISTER_ENCODER(X, x); REGISTER_DECODER(X, x)
> +if (c)
> +*opaque = (void*)(i + 1);
>  
> -#define REGISTER_PARSER(X, x)   \
> -{   \
> -extern AVCodecParser ff_##x##_parser;   \
> -if (CONFIG_##X##_PARSER)\
> -av_register_codec_parser(&ff_##x##_parser); \
> +return c;
> +}
> +
> +#if FF_API_NEXT
> +pthread_once_t av_codec_next_init = PTHREAD_ONCE_INIT;
> +
> +static void av_codec_init_next(void)
> +{
> +AVCodec *prev = NULL, *p;
> +void *i = 0;
> +while ((p = (AVCodec*)av_codec_iterate(&i))) {
> +if (prev)
> +prev->next = p;
> +prev = p;
>  }

> +if (prev)
> +prev->next = NULL;

What's this for? Isn't it already initialized to NULL?

> +}
> +
>  
> -static void register_all(void)
> +
> +av_cold void avcodec_register(AVCodec *codec)
>  {
> -/* video codecs */
> -REGISTER_ENCODER(A64MULTI,  a64multi);

> +pthread_once(&av_codec_next_init, av_codec_init_next);
> +}

I don't see much of a point in this call. Could be dropped, so the body
is empty.

> +AVCodec *av_codec_next(const AVCodec *c)
> +{
> +pthread_once(&av_codec_next_init, av_codec_init_next);
> +
> +if (c)
> +return c->next;
> +else
> +return (AVCodec*)codec_list[0];
>  }
>  
>  void avcodec_register_all(void)
>  {
> -static AVOnce control = AV_ONCE_INIT;
> +pthread_once(&av_codec_next_init, av_codec_init_next);
> +}

So that means if you use the legacy API, you still need to call
the register function. Strange choice, but I'm fine with it.

> +#endif
> +
> +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_codec(enum AVCodecID id, int (*x)(const AVCodec *))
> +{
> +const AVCodec *p, *experimental = NULL;
> +void *i = 0;
> +
> +id = remap_deprecated_codec_id(id);
> +
> +while ((p = av_codec_iterate(&i))) {
> +if (!x(p))
> +continue;
> +if (p->id == id) {
> +if (p->capabilities & AV_CODEC_CAP_EXPERIMENTAL && 
> !experimental) {
> +experimental = p;
> +} else
> +return (AVCodec*)p;
> +}
> +}
>  
> -ff_thread_once(&control, register_all);
> +return (AVCodec*)experimental;
> +}
> +
> +AVCodec *avcodec_find_encoder(enum AVCodecID id)
> +{
> +return find_codec(id, av_codec_is_encoder);
> +}
> +
> +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 
> *))
> +{
> +void *i = 0;
> +const AVCodec *p;
> +
> +if (!name)
> +return NULL;
> +
> +while ((p = av_codec_iterate(&i))) {
> +if (!x(p))
> +continue;
> +if (strcmp(name, p->name) == 0)
> +return (AVCodec*)p;
> +}
> +
> +return NULL;
> +}
> +
> +AVCodec *avcodec_find_encoder_by_name(const char *na

[FFmpeg-devel] [PATCH v2 1/6] lavc: add new API for iterating codecs and codec parsers

2018-01-02 Thread Josh de Kock
Also replace linked list with an array.
---
 configure  |   12 +-
 doc/APIchanges |4 +
 libavcodec/allcodecs.c | 1473 
 libavcodec/avcodec.h   |   31 +
 libavcodec/parser.c|   87 ++-
 libavcodec/utils.c |  105 
 libavcodec/version.h   |3 +
 7 files changed, 974 insertions(+), 741 deletions(-)

diff --git a/configure b/configure
index 606cdd0..bfe4bdf 100755
--- a/configure
+++ b/configure
@@ -3525,9 +3525,6 @@ find_things(){
 sed -n "s/^[^#]*$pattern.*([^,]*, *\([^,]*\)\(,.*\)*).*/\1_$thing/p" 
"$file"
 }
 
-ENCODER_LIST=$(find_things  encoder  ENC  libavcodec/allcodecs.c)
-DECODER_LIST=$(find_things  decoder  DEC  libavcodec/allcodecs.c)
-PARSER_LIST=$(find_things   parser   PARSER   libavcodec/allcodecs.c)
 MUXER_LIST=$(find_thingsmuxer_MUX libavformat/allformats.c)
 DEMUXER_LIST=$(find_things  demuxer  DEMUXlibavformat/allformats.c)
 OUTDEV_LIST=$(find_things   outdev   OUTDEV   libavdevice/alldevices.c)
@@ -3541,6 +3538,13 @@ find_things_extern(){
 sed -n "s/^[^#]*extern.*$pattern *ff_\([^ ]*\)_$thing;/\1_$thing/p" "$file"
 }
 
+ENCODER_LIST=$(find_things_extern encoder AVCodec libavcodec/allcodecs.c)
+DECODER_LIST=$(find_things_extern decoder AVCodec libavcodec/allcodecs.c)
+CODEC_LIST="
+$ENCODER_LIST
+$DECODER_LIST
+"
+PARSER_LIST=$(find_things_extern parser AVCodecParser libavcodec/parser.c)
 BSF_LIST=$(find_things_extern bsf AVBitStreamFilter 
libavcodec/bitstream_filters.c)
 HWACCEL_LIST=$(find_things_extern hwaccel AVHWAccel libavcodec/hwaccels.h)
 PROTOCOL_LIST=$(find_things_extern protocol URLProtocol 
libavformat/protocols.c)
@@ -7034,6 +7038,8 @@ print_enabled_components(){
 cp_if_changed $TMPH $file
 }
 
+print_enabled_components libavcodec/codec_list.c AVCodec codec_list $CODEC_LIST
+print_enabled_components libavcodec/parser_list.c AVCodecParser parser_list 
$PARSER_LIST
 print_enabled_components libavcodec/bsf_list.c AVBitStreamFilter 
bitstream_filters $BSF_LIST
 print_enabled_components libavformat/protocol_list.c URLProtocol url_protocols 
$PROTOCOL_LIST
 
diff --git a/doc/APIchanges b/doc/APIchanges
index 3c9f237..3d28d85 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,10 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2018-xx-xx - xxx - lavc 58.9.100 - avcodec.h
+  Deprecate use of avcodec_register(), avcodec_register_all(), and
+  av_codec_next(). Add av_codec_iterate().
+
 2017-xx-xx - xxx - lavc 58.9.100 - avcodec.h
   Deprecate av_lockmgr_register(). You need to build FFmpeg with threading
   support enabled to get basic thread-safety (which is the default build
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index ed1e7ab..a7ea772 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -29,641 +29,864 @@
 #include "avcodec.h"
 #include "version.h"
 
-#define REGISTER_ENCODER(X, x)  \
-{   \
-extern AVCodec ff_##x##_encoder;\
-if (CONFIG_##X##_ENCODER)   \
-avcodec_register(&ff_##x##_encoder);\
-}
+extern AVCodec ff_a64multi_encoder;
+extern AVCodec ff_a64multi5_encoder;
+extern AVCodec ff_aasc_decoder;
+extern AVCodec ff_aic_decoder;
+extern AVCodec ff_alias_pix_encoder;
+extern AVCodec ff_alias_pix_decoder;
+extern AVCodec ff_amv_encoder;
+extern AVCodec ff_amv_decoder;
+extern AVCodec ff_anm_decoder;
+extern AVCodec ff_ansi_decoder;
+extern AVCodec ff_apng_encoder;
+extern AVCodec ff_apng_decoder;
+extern AVCodec ff_asv1_encoder;
+extern AVCodec ff_asv1_decoder;
+extern AVCodec ff_asv2_encoder;
+extern AVCodec ff_asv2_decoder;
+extern AVCodec ff_aura_decoder;
+extern AVCodec ff_aura2_decoder;
+extern AVCodec ff_avrp_encoder;
+extern AVCodec ff_avrp_decoder;
+extern AVCodec ff_avrn_decoder;
+extern AVCodec ff_avs_decoder;
+extern AVCodec ff_avui_encoder;
+extern AVCodec ff_avui_decoder;
+extern AVCodec ff_ayuv_encoder;
+extern AVCodec ff_ayuv_decoder;
+extern AVCodec ff_bethsoftvid_decoder;
+extern AVCodec ff_bfi_decoder;
+extern AVCodec ff_bink_decoder;
+extern AVCodec ff_bmp_encoder;
+extern AVCodec ff_bmp_decoder;
+extern AVCodec ff_bmv_video_decoder;
+extern AVCodec ff_brender_pix_decoder;
+extern AVCodec ff_c93_decoder;
+extern AVCodec ff_cavs_decoder;
+extern AVCodec ff_cdgraphics_decoder;
+extern AVCodec ff_cdxl_decoder;
+extern AVCodec ff_cfhd_decoder;
+extern AVCodec ff_cinepak_encoder;
+extern AVCodec ff_cinepak_decoder;
+extern AVCodec ff_clearvideo_decoder;
+extern AVCodec ff_cljr_encoder;
+extern AVCodec ff_cljr_decoder;
+extern AVCodec ff_cllc_decoder;
+extern AVCodec ff_comfortnoise_encoder;
+extern AVCodec ff_comfortnoise_decoder;
+extern AVCodec ff_cpia_decoder;
+extern AVCodec ff_cscd_decoder;
+extern AVCodec ff_cyuv_decoder;
+extern AVC