[libav-api] multi-threading context

Florian Iragne florian at iragne.fr
Fri Jun 20 15:08:03 CEST 2014


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?

I stil get:
[aac @ 0x7f1d0c004020] insufficient thread locking around 
avcodec_open/close()

and sometimes:
what():  Cannot open audio codec for myUrl (the exception i throw when 
avcodec_open2 fails)

Have i missed something ?

thanks for your help

Florian



More information about the libav-api mailing list