[FFmpeg-devel] [PATCH 1/3] avcodec/utils: av_register_codec & hwaccel() that work in O(1) time
Michael Niedermayer
michaelni at gmx.at
Tue Dec 17 01:07:36 CET 2013
On Mon, Dec 16, 2013 at 05:01:47PM +0100, Stefano Sabatini wrote:
> On date Sunday 2013-12-08 03:55:21 +0100, Michael Niedermayer encoded:
> > Its possible to implement this with a few lines less code but it then
> > would flip the order of the list and require registration of external
> > codecs to be done first, also it could break user applications due to
> > this. Thus to maintain ABI this slighty more complex solution is
> > used.
> >
> > Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> > ---
> > libavcodec/utils.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> > index 102a049..8d96bd0 100644
> > --- a/libavcodec/utils.c
> > +++ b/libavcodec/utils.c
> > @@ -169,6 +169,7 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
> >
> > /* encoder management */
> > static AVCodec *first_avcodec = NULL;
> > +static AVCodec **last_avcodec = &first_avcodec;
> >
> > AVCodec *av_codec_next(const AVCodec *c)
> > {
> > @@ -204,11 +205,12 @@ av_cold void avcodec_register(AVCodec *codec)
> > {
> > AVCodec **p;
> > avcodec_init();
> > - p = &first_avcodec;
> > + p = last_avcodec;
> > codec->next = NULL;
> >
> > while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, codec))
> > p = &(*p)->next;
> > + last_avcodec = &codec->next;
> >
> > if (codec->init_static_data)
> > codec->init_static_data(codec);
> > @@ -3187,13 +3189,15 @@ FF_ENABLE_DEPRECATION_WARNINGS
> > #endif /* FF_API_MISSING_SAMPLE */
> >
> > static AVHWAccel *first_hwaccel = NULL;
> > +static AVHWAccel **last_hwaccel = &first_hwaccel;
> >
> > void av_register_hwaccel(AVHWAccel *hwaccel)
> > {
> > - AVHWAccel **p = &first_hwaccel;
> > + AVHWAccel **p = last_hwaccel;
> > hwaccel->next = NULL;
> > while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, hwaccel))
> > p = &(*p)->next;
> > + last_hwaccel = &hwaccel->next;
> > }
>
> LGTM.
applied
thanks
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
The misfortune of the wise is better than the prosperity of the fool.
-- Epicurus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20131217/45e45a73/attachment.asc>
More information about the ffmpeg-devel
mailing list