[FFmpeg-devel] patch 1. Correction of loop behaviour in ffpeg.c

ffmpeg at a.legko.ru ffmpeg at a.legko.ru
Wed Jun 28 15:02:42 EEST 2017


subject: when input sample stops, input thread stops too (withous 
restart), thus, breaking the streaming and loop mode does not affect this. touches 
only multistream (multiprog) mode, when threads are used.

-------------- next part --------------
From d8310311a3c1a1828eacd4b45b31f9a723b5ee2b Mon Sep 17 00:00:00 2001
From: root <ffmpeg at scil.sinp.msu.ru>
Date: Wed, 28 Jun 2017 14:53:40 +0300
Subject: [PATCH 1/3] add support for samples looping (threaded mode; thread
 stops after decoding input)

---
 ffmpeg.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/ffmpeg.c b/ffmpeg.c
index a783e6e..2866754 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -4013,6 +4013,29 @@ static void free_input_threads(void)
     }
 }
 
+static int init_input_thread(int i)
+{
+    int ret;
+  
+    if (nb_input_files == 1)
+       return 0;
+
+    InputFile *f = input_files[i];
+    if (f->ctx->pb ? !f->ctx->pb->seekable :
+       strcmp(f->ctx->iformat->name, "lavfi"))
+           f->non_blocking = 1;
+    ret = av_thread_message_queue_alloc(&f->in_thread_queue,
+           f->thread_queue_size, sizeof(AVPacket));
+    if (ret < 0)
+       return ret;
+    if ((ret = pthread_create(&f->thread, NULL, input_thread, f))) {
+       av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret));
+       av_thread_message_queue_free(&f->in_thread_queue);
+       return AVERROR(ret);
+    }
+return 0;
+}
+ 
 static int init_input_threads(void)
 {
     int i, ret;
@@ -4191,9 +4214,13 @@ static int process_input(int file_index)
         ifile->eagain = 1;
         return ret;
     }
+
     if (ret < 0 && ifile->loop) {
         if ((ret = seek_to_start(ifile, is)) < 0)
             return ret;
+#if HAVE_PTHREADS
+        init_input_thread(file_index);
+#endif
         ret = get_input_packet(ifile, &pkt);
         if (ret == AVERROR(EAGAIN)) {
             ifile->eagain = 1;
-- 
2.7.4



More information about the ffmpeg-devel mailing list