LibAv/FFMpeg的线程安全性? [英] Thread Safety of LibAv/FFMpeg?

查看:149
本文介绍了LibAv/FFMpeg的线程安全性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

LibAV/FFMpeg线程安全吗?例如.我可以在一个线程中使用AVFormatContext *从文件中读取文件,然后通过简单地添加互斥锁在另一个线程中对读取的数据包进行解码,或者该库的线程安全性是无关紧要"类型的交易吗?我知道libav对编码器线程具有基本的支持,但是我正在尝试更多的黑盒类型方法,将其分解为多个线程(源->解码器->过滤器->编码器->接收器),并试图理解其复杂性.这样的.

Is LibAV/FFMpeg thread safe? For example. Could i read from a file using AVFormatContext* in one thread and decode the read packet it in another with simple additions of mutexes or is the thread safetyness of the library a "don't know don't care" type deal? I know that libav has basic support for encoder threads but i'm trying more of a blackbox type approach where i break it up into multiple threads (Source -> Decoder -> Filter -> Encoder -> Sink) and trying to understand the complications of such.

任何对ffmpeg和线程有经验并希望了解与此相关的其他信息的人,也将不胜感激.

Anyone with any experience with ffmpeg and threads and would like to chime in with any other info pertinent to this would also be greatly appreciated.

推荐答案

您可以注册自己的锁管理器.ffmpeg库将控制线程安全.

You can register your own lock manager. The ffmpeg library will control thread safety.

示例:

 ::av_lockmgr_register(&my_lockmgr_cb);


 //// ..........

 int my_lockmgr_cb(void **mutex, enum AVLockOp op)
 {
  if (NULL == mutex)
   return -1;

   switch(op)
   {
   case AV_LOCK_CREATE:
   {
    *mutex = NULL;
    boost::mutex * m = new boost::mutex();
    *mutex = static_cast<void*>(m);
    break;
   }
   case AV_LOCK_OBTAIN:
   {
    boost::mutex * m =  static_cast<boost::mutex*>(*mutex);
    m->lock();
    break;
   }
   case AV_LOCK_RELEASE:
   {
    boost::mutex * m = static_cast<boost::mutex*>(*mutex);
    m->unlock();
    break;
   }
   case AV_LOCK_DESTROY:
   {
    boost::mutex * m = static_cast<boost::mutex*>(*mutex);
    delete m;
    break;
   }
   default:
   break;
}
return 0;

}

这篇关于LibAv/FFMpeg的线程安全性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆