[FFmpeg-devel] [PATCH 06/20] fftools/ffmpeg: move threading fields from InputFile to Demuxer
Anton Khirnov
anton at khirnov.net
Tue Oct 18 15:36:47 EEST 2022
They are private to the demuxer and do not need to be visible outside of
it.
---
fftools/ffmpeg.h | 5 -----
fftools/ffmpeg_demux.c | 49 +++++++++++++++++++++++-------------------
2 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 823347f670..8c3effdb05 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -455,11 +455,6 @@ typedef struct InputFile {
float readrate;
int accurate_seek;
- AVThreadMessageQueue *in_thread_queue;
- pthread_t thread; /* thread reading from this file */
- int non_blocking; /* reading packets from the thread should not block */
- int thread_queue_size; /* maximum number of queued packets */
-
/* when looping the input file, this queue is used by decoders to report
* the last frame duration back to the demuxer thread */
AVThreadMessageQueue *audio_duration_queue;
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 5c75dd5b23..90868de7aa 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -50,6 +50,11 @@ typedef struct Demuxer {
/* number of times input stream should be looped */
int loop;
+
+ AVThreadMessageQueue *in_thread_queue;
+ int thread_queue_size;
+ pthread_t thread;
+ int non_blocking;
} Demuxer;
typedef struct DemuxMsg {
@@ -211,7 +216,7 @@ static void *input_thread(void *arg)
Demuxer *d = arg;
InputFile *f = &d->f;
AVPacket *pkt;
- unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0;
+ unsigned flags = d->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0;
int ret = 0;
pkt = av_packet_alloc();
@@ -233,7 +238,7 @@ static void *input_thread(void *arg)
if (d->loop) {
/* signal looping to the consumer thread */
msg.looping = 1;
- ret = av_thread_message_queue_send(f->in_thread_queue, &msg, 0);
+ ret = av_thread_message_queue_send(d->in_thread_queue, &msg, 0);
if (ret >= 0)
ret = seek_to_start(d);
if (ret >= 0)
@@ -278,14 +283,14 @@ static void *input_thread(void *arg)
break;
}
av_packet_move_ref(msg.pkt, pkt);
- ret = av_thread_message_queue_send(f->in_thread_queue, &msg, flags);
+ ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags);
if (flags && ret == AVERROR(EAGAIN)) {
flags = 0;
- ret = av_thread_message_queue_send(f->in_thread_queue, &msg, flags);
+ ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags);
av_log(f->ctx, AV_LOG_WARNING,
"Thread message queue blocking; consider raising the "
"thread_queue_size option (current value: %d)\n",
- f->thread_queue_size);
+ d->thread_queue_size);
}
if (ret < 0) {
if (ret != AVERROR_EOF)
@@ -299,7 +304,7 @@ static void *input_thread(void *arg)
finish:
av_assert0(ret < 0);
- av_thread_message_queue_set_err_recv(f->in_thread_queue, ret);
+ av_thread_message_queue_set_err_recv(d->in_thread_queue, ret);
av_packet_free(&pkt);
@@ -311,14 +316,14 @@ static void thread_stop(Demuxer *d)
InputFile *f = &d->f;
DemuxMsg msg;
- if (!f->in_thread_queue)
+ if (!d->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, &msg, 0) >= 0)
+ av_thread_message_queue_set_err_send(d->in_thread_queue, AVERROR_EOF);
+ while (av_thread_message_queue_recv(d->in_thread_queue, &msg, 0) >= 0)
av_packet_free(&msg.pkt);
- pthread_join(f->thread, NULL);
- av_thread_message_queue_free(&f->in_thread_queue);
+ pthread_join(d->thread, NULL);
+ av_thread_message_queue_free(&d->in_thread_queue);
av_thread_message_queue_free(&f->audio_duration_queue);
}
@@ -327,14 +332,14 @@ static int thread_start(Demuxer *d)
int ret;
InputFile *f = &d->f;
- if (f->thread_queue_size <= 0)
- f->thread_queue_size = (nb_input_files > 1 ? 8 : 1);
+ if (d->thread_queue_size <= 0)
+ d->thread_queue_size = (nb_input_files > 1 ? 8 : 1);
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(DemuxMsg));
+ d->non_blocking = 1;
+ ret = av_thread_message_queue_alloc(&d->in_thread_queue,
+ d->thread_queue_size, sizeof(DemuxMsg));
if (ret < 0)
return ret;
@@ -356,7 +361,7 @@ static int thread_start(Demuxer *d)
}
}
- if ((ret = pthread_create(&f->thread, NULL, input_thread, d))) {
+ if ((ret = pthread_create(&d->thread, NULL, input_thread, d))) {
av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret));
ret = AVERROR(ret);
goto fail;
@@ -364,7 +369,7 @@ static int thread_start(Demuxer *d)
return 0;
fail:
- av_thread_message_queue_free(&f->in_thread_queue);
+ av_thread_message_queue_free(&d->in_thread_queue);
return ret;
}
@@ -375,7 +380,7 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt)
DemuxMsg msg;
int ret;
- if (!f->in_thread_queue) {
+ if (!d->in_thread_queue) {
ret = thread_start(d);
if (ret < 0)
return ret;
@@ -400,8 +405,8 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt)
}
}
- ret = av_thread_message_queue_recv(f->in_thread_queue, &msg,
- f->non_blocking ?
+ ret = av_thread_message_queue_recv(d->in_thread_queue, &msg,
+ d->non_blocking ?
AV_THREAD_MESSAGE_NONBLOCK : 0);
if (ret < 0)
return ret;
@@ -968,7 +973,7 @@ int ifile_open(OptionsContext *o, const char *filename)
f->rate_emu = 0;
}
- f->thread_queue_size = o->thread_queue_size;
+ d->thread_queue_size = o->thread_queue_size;
/* check if all codec options have been used */
unused_opts = strip_specifiers(o->g->codec_opts);
--
2.35.1
More information about the ffmpeg-devel
mailing list