[libav-api] Thread-safe: (avio_open avformat_open_input)

Evgeny Yakimov john.yakimov at gmail.com
Tue Nov 8 23:10:24 CET 2011


Hello

I've been getting a lot of issues when attempting to open/close input
files/streams in a multi threaded application, mostly resulting in memory
problems and segfaults.
I've found a small reference to thread-safety in the post here:
http://lists.libav.org/pipermail/libav-api/2011-June/000126.html but I'm
using a lot more calls than the ones referenced here.


My application has one input thread opened with avformat_open_input
followed by multiple output threads which use avio_open to send the stream
over rtmp,
I've noticed that if all my output threads try to open the output stream at
the same time that I experience the problems, where as if I do this
sequentially, one after the other, they work fine.

Are these functions thread-safe? if not which functions should I mutex/lock
?


My application currently runs in this order,

Input (Thread 1)

avformat_open_input
avformat_find_stream_info
av_find_best_stream
avcodec_open2

while(av_read_frame){
  avcodec_decode_audio3
  avcodec_decode_video2
  av_free_packet
}


/* Some encoder threads in the middle */


Output (Thread 2,3....)
av_guess_format
avformat_alloc_context
av_new_stream
avio_open
avformat_write_header
while (/*packets to send */){
  av_write_frame
}


(I'm working under the assumption that ANY of the calls mentioned above can
occur at the same time.)

Can you please advise which of these calls need to be protected with mutex
locks?

Regard
Evgeny
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libav.org/pipermail/libav-api/attachments/20111108/4aa426f2/attachment.html>


More information about the libav-api mailing list