On Tue, Apr 14, 2009 at 11:12 AM, Stefano Sabatini <
[email protected]> wrote:

> On date Saturday 2009-04-11 20:45:20 -0400, AliReza Khoshgoftar Monfared
> encoded:
> > Dear All,
> >
> > I have written a wrapper function around ffmpeg.c's main to use it for
> some
> > decoding/encoding function.
> > As I am using it in  MultiThreaded environment, I have done these changes
> to
> > make ffmpeg.c threadsafe:
> >
> > 1) I have made all global variables, local by putting them inside a big
> > structure, and passing it to all functions
> > 2) I have put mutexes around these functions:
> > *
> > *
> > >
> > > *    avcodec_register_all();
> > >     avdevice_register_all();
> > >     av_register_all();
> > >     avcodec_open();
> > >     avcodec_close();*
> > >
> >
> > though doing this, If I use my wrapper function in two threads, I get the
> > following error:
> >
> > *[NULL @ 0x20ef360]insufficient thread locking around
> avcodec_open/close()*
> > >
> >
> > So, does anybody have an idea what is wrong with my actions that I still
> > have these errors.
> >
> > Just for your reference, I have built ffmpeg under MinGW (in Windows).
> > And I have put the mutexes using pthreads, here is an example of how I
> put a
> > mutex around avcodec_open()
> >
> >             *pthread_mutex_lock (&mutex_avcodec_open1);*
> > >             if (avcodec_open(ost->st->codec, codec) < 0) {
> > >                 fprintf(stderr, "Error while opening codec for output
> > > stream #%d.%d - maybe incorrect parameters such as bit_rate, rate,
> width or
> > > height\n",
> > >                         ost->file_index, ost->index);
> > >                 av_exit(1,global_var);
> > >             }
> > >             *pthread_mutex_unlock (&mutex_avcodec_open1);*
>
> This is not sufficient. You need a *unique* lock for both
> avcodec_open() and avcodec_close().
>
> Regards.
> _______________________________________________
> libav-user mailing list
> [email protected]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user


Right,
You seem to be absolutely correct.I have not that error anymore.

I have the locks now, but it still seems that my version of ffmpeg.c is not
completely threadsafe, as it fails in some of the tests.
Right now, I have locks around the functions mentioned in the previous post.
Do I still need to put locks around all avcodec_find_*()'s and allocation
functions?(I saw in an old post somebody told they are also non-safe)And if
yes, do they need to be the same mutex as the previous one?



Alireza
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to