[FFmpeg-devel] [PATCH 2/3] avfilter/avfilter: avfilter_register() that works in O(1) time

Michael Niedermayer michaelni at gmx.at
Thu Jan 9 00:39:56 CET 2014


On Wed, Dec 18, 2013 at 02:25:10AM +0100, Michael Niedermayer wrote:
> On Tue, Dec 17, 2013 at 08:18:14PM +0100, Stefano Sabatini wrote:
> > On date Tuesday 2013-12-17 01:05:21 +0100, Michael Niedermayer encoded:
> > > On Mon, Dec 16, 2013 at 05:16:37PM +0100, Stefano Sabatini wrote:
> > > > On date Sunday 2013-12-08 03:55:22 +0100, Michael Niedermayer encoded:
> > > > > This also flips the order of the list
> > > > > avfilters should be unique and thus the order should not matter
> > > > > 
> > > > > Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> > > > > ---
> > > > >  libavfilter/avfilter.c |    8 +++-----
> > > > >  1 file changed, 3 insertions(+), 5 deletions(-)
> > > > > 
> > > > > diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> > > > > index 2567ce9..c564b45 100644
> > > > > --- a/libavfilter/avfilter.c
> > > > > +++ b/libavfilter/avfilter.c
> > > > > @@ -476,7 +476,6 @@ AVFilter *avfilter_get_by_name(const char *name)
> > > > >  
> > > > >  int avfilter_register(AVFilter *filter)
> > > > >  {
> > > > > -    AVFilter **f = &first_filter;
> > > > >      int i;
> > > > >  
> > > > >      /* the filter must select generic or internal exclusively */
> > > > > @@ -488,10 +487,9 @@ int avfilter_register(AVFilter *filter)
> > > > >                      || (!input->start_frame && !input->end_frame));
> > > > >      }
> > > > >  
> > > > > -    filter->next = NULL;
> > > > > -
> > > > > -    while(*f || avpriv_atomic_ptr_cas((void * volatile *)f, NULL, filter))
> > > > > -        f = &(*f)->next;
> > > > 
> > > > > +    do {
> > > > > +        filter->next = first_filter;
> > > > > +    } while (filter->next != avpriv_atomic_ptr_cas((void * volatile *)&first_filter, filter->next, filter));
> > > > 
> > > > why do you need a loop for this?
> > > 
> > 
> > > consider 2 libs or an app and a lib try to use avfilter_register() at
> > > the same time
> > > we need to insert our filter atomically but its 2 operations so if
> > > something else inserted something after we did the first step but
> > > before the second then we have to retry
> > 
> > Isn't a mutex a cleaner solution?
> 
> where would it be created & destroyed ?
> 
> 
> > 
> > Anyway feel free to push it. OTOH I don't like very much the idea of
> > having filters listed in order inverted to that of registration, as it
> > messes up output of ffmpeg -filters for example.
> 
> i can implement it so its not inverted?

implemented it that way and applied

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Frequently ignored answer#1 FFmpeg bugs should be sent to our bugtracker. User
questions about the command line tools should be sent to the ffmpeg-user ML.
And questions about how to use libav* should be sent to the libav-user ML.
-------------- 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/20140109/85d5d2c3/attachment.asc>


More information about the ffmpeg-devel mailing list