[libav-api] multi-threading context

Luca Barbato lu_zero at gentoo.org
Sat Jun 21 13:50:08 CEST 2014


On 20/06/14 15:08, Florian Iragne wrote:
> Hi,
> 
> i'm using libav in a multithreading context and i'm facing the problem
> of concurrent access to a few libav functions.
> 
> I'm programming in c++ and i'm using OpenMP for multithreading.
> 
> I have an AudioConverter class. In its init, i do:
>   static class Once {
>             public:
>                 Once() {
> #ifdef OPENMP_IN_USE
>                     av_lockmgr_register(&lockMgr);
> #endif
>                     avcodec_register_all();
>                     av_register_all();
>                     avformat_network_init();
>                 }
>         } Once_;
> 
> and lockMgr is defined as:
> 
> #ifdef OPENMP_IN_USE
>     static int lockMgr(void **mutex, enum AVLockOp op) {
>         // returns are 0 success
>         omp_lock_t** m = (omp_lock_t**) mutex;
>         if (op == AV_LOCK_CREATE) {
>             *m = new omp_lock_t();
>             omp_init_lock(*m);
>             return 0;
>         }
>         else if (op == AV_LOCK_DESTROY) {
>             omp_destroy_lock(*m);
>             return 0;
>         }
>         else if (op == AV_LOCK_OBTAIN) {
>             omp_set_lock(*m);
>             return 0;
>         }
>         else if (op == AV_LOCK_RELEASE) {
>             omp_unset_lock(*m);
>             return 0;
>         }
>         else {
>             return -1;
>         }
>     }
> #endif
> 
> As i understand, this would be enough to protect any libav function that
> needs to be protected against concurrent access. Is that true?
> 

Should. Given it isn't the case you may check that the lock manager is
really in use first, then would be useful to see why avcodec_open is
having that problem.



More information about the libav-api mailing list