[FFmpeg-trac] #1981(avformat:new): mpegtsraw open of multicast stream may hang

FFmpeg trac at avcodec.org
Fri Nov 30 21:07:16 CET 2012


#1981: mpegtsraw open of multicast stream may hang
-----------------------------------+--------------------------------------
             Reporter:  Krieger    |                     Type:  defect
               Status:  new        |                 Priority:  normal
            Component:  avformat   |                  Version:  git-master
             Keywords:  mpegtsraw  |               Blocked By:
             Blocking:             |  Reproduced by developer:  0
Analyzed by developer:  0          |
-----------------------------------+--------------------------------------
 Summary of the bug:
 When opening many multicast UDP streams using avformat_open_input(), some
 instances may loop infinitely in mpegts_read_header() in lines 2016-2030.
 Inspecting with gdb shows that nb_packets number is big, so it does not
 hang inside avio-stuff.
 How to reproduce:
 {{{
 1. Have a lot of multicast MPEGTS streams. I had my on
 udp://239.195.0.1-50:1234
 2. Code snippet:

 #include <assert.h>
 #include <stdio.h>
 #include <pthread.h>
 #include <libavformat/avformat.h>

 #define THREADS_NUM 50

 void *thread_work(void* dummy) {
   int ret;
   int i;
   char *url = dummy;
   printf("'%s' thread starts\n", url);
   AVFormatContext *ctx = avformat_alloc_context();
   assert(ctx);
   AVDictionary *avio_opts = NULL;
   av_dict_set(&avio_opts, "timeout", "2000000", 0);
   av_dict_set(&avio_opts, "fifo_size", "0", 0);  // bug happens both with
 and without separate UDP-fetching thread
   ret = avio_open2(&ctx->pb, url, AVIO_FLAG_READ, NULL, &avio_opts);
   assert(!ret);
   ret = avformat_open_input(&ctx, url, av_find_input_format("mpegtsraw"),
 NULL);
   if (!ret) {
     // read a bit, to add networking load
     for (i = 0; i < 1000; i++) {
       AVPacket pkt;
       ret = av_read_frame(ctx, &pkt);
     }
   }
   printf("'%s' thread exits\n", url);
   return NULL;
 }

 int main() {
   int ret;
   int i;
   pthread_t tids[THREADS_NUM];

   av_register_all();
   avformat_network_init();

   for (i = 0; i < THREADS_NUM; i++) {
     char *url = NULL;
     ret = asprintf(&url, "udp://239.195.0.%d:1234", i+1);
     assert(ret != -1);
     ret = pthread_create(&tids[i], NULL, thread_work, url);
     printf("created %d-th thread\n", i);
     assert(!ret);
   }
   for (i = 0; i < THREADS_NUM; i++) {
     pthread_join(tids[i], NULL);
     printf("joined %d-th thread\n", i);
   }
   return 0;
 }

 The defective result is that the application does not terminate. This
 happens not in 100% of launch cases, but happens most of times.
 I could not replicate this bug on local UDP streams, sorry.
 The same problem affects libav.org fork.
 }}}

-- 
Ticket URL: <https://ffmpeg.org/trac/ffmpeg/ticket/1981>
FFmpeg <http://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list