[FFmpeg-cvslog] ffmpeg: factorize input thread creation and destruction
Marton Balint
git at videolan.org
Sun Jul 8 14:40:00 EEST 2018
ffmpeg | branch: release/4.0 | Marton Balint <cus at passwd.hu> | Wed Jun 27 21:55:38 2018 +0200| [2c138c2d8c343219bd7a10151039ca8a53ca8cae] | committer: Marton Balint
ffmpeg: factorize input thread creation and destruction
Signed-off-by: Marton Balint <cus at passwd.hu>
(cherry picked from commit b181cd359b872283d5fcaf7c553bbad88517c78b)
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2c138c2d8c343219bd7a10151039ca8a53ca8cae
---
fftools/ffmpeg.c | 66 ++++++++++++++++++++++++++++++++++----------------------
1 file changed, 40 insertions(+), 26 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 16ce07c3ab..be1680dac3 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -4015,49 +4015,63 @@ static void *input_thread(void *arg)
return NULL;
}
+static void free_input_thread(int i)
+{
+ InputFile *f = input_files[i];
+ AVPacket pkt;
+
+ if (!f || !f->in_thread_queue)
+ return;
+ av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF);
+ while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0)
+ av_packet_unref(&pkt);
+
+ pthread_join(f->thread, NULL);
+ f->joined = 1;
+ av_thread_message_queue_free(&f->in_thread_queue);
+}
+
static void free_input_threads(void)
{
int i;
- for (i = 0; i < nb_input_files; i++) {
- InputFile *f = input_files[i];
- AVPacket pkt;
+ for (i = 0; i < nb_input_files; i++)
+ free_input_thread(i);
+}
- if (!f || !f->in_thread_queue)
- continue;
- av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF);
- while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0)
- av_packet_unref(&pkt);
+static int init_input_thread(int i)
+{
+ int ret;
+ InputFile *f = input_files[i];
- pthread_join(f->thread, NULL);
- f->joined = 1;
+ if (nb_input_files == 1)
+ return 0;
+
+ 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;
- if (nb_input_files == 1)
- return 0;
-
for (i = 0; i < nb_input_files; i++) {
- 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));
+ ret = init_input_thread(i);
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;
}
More information about the ffmpeg-cvslog
mailing list