[Libav-user] synchronize initialization

Zanelli Franco fzanelli at tecnosens.it
Wed Apr 11 10:39:27 CEST 2012


I play streams simultaneously in different threads calling this group of 
methods for each thread:

{
     av_register_all();
     avformat_network_init();
     AVFormatContext *fc = avformat_alloc_context();
     AVDictionary *opts = 0;
     // set the options
         ....
     int res;
     res = avformat_open_input(&fc, url, 0, &opts);
     res = avformat_find_stream_info(fc, NULL);
     while(true){
         av_read_frame(fc, &packet);
         ...
     }
     avformat_close_input(&fc);
}

which method should I synchronize in order to avoid conflicts between 
threads?
what about the docoding  part following?

{
         av_register_all();
         AVCodec *avCodec = avcodec_find_decoder_by_name(c_string);
         AVCodecContext *codecCtx = avcodec_alloc_context3(avCodec);
         AVFrame *avFrame = avcodec_alloc_frame();
         AVPacket *avPacket = new AVPacket();
         SwsContext *sc;
         while (true){
             int len = avcodec_decode_video2(codecCtx, avFrame, 
&got_picture, avPacket);
             if (sc != null)
                 sc = sws_getContext(...);
             sws_scale(..)
         }

          avcodec_close(codecCtx);
          av_free(codecCtx);
          av_free(avFrame);
          sws_freeContext(sc);
}


thank you in advance

Franco


More information about the Libav-user mailing list