Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 06/20] fftools/ffmpeg: move threading fields from InputFile to Demuxer
Date: Tue, 18 Oct 2022 14:36:47 +0200
Message-ID: <20221018123701.25002-6-anton@khirnov.net> (raw)
In-Reply-To: <20221018123701.25002-1-anton@khirnov.net>

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

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2022-10-18 12:40 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-18 12:36 [FFmpeg-devel] [PATCH 01/20] fftools/ffmpeg_opt: move opening input files to ffmpeg_demux.c Anton Khirnov
2022-10-18 12:36 ` [FFmpeg-devel] [PATCH 02/20] fftools/ffmpeg_demux: add demuxer private data Anton Khirnov
2022-10-18 12:36 ` [FFmpeg-devel] [PATCH 03/20] fftools/ffmpeg: drop init_input_threads() Anton Khirnov
2022-10-18 12:36 ` [FFmpeg-devel] [PATCH 04/20] fftools/ffmpeg: move closing the input file into a separate function Anton Khirnov
2022-10-18 12:36 ` [FFmpeg-devel] [PATCH 05/20] fftools/ffmpeg: drop free_input_threads() Anton Khirnov
2022-10-18 12:36 ` Anton Khirnov [this message]
2022-10-18 12:36 ` [FFmpeg-devel] [PATCH 07/20] fftools/ffmpeg: move duration/time_base from InputFile to Demuxer Anton Khirnov
2022-10-18 12:36 ` [FFmpeg-devel] [PATCH 08/20] fftools/ffmpeg_demux: do not log to the demuxer context Anton Khirnov
2022-10-18 12:36 ` [FFmpeg-devel] [PATCH 09/20] fftools/ffmpeg: move nb_streams_warn from InputFile to Demuxer Anton Khirnov
2022-10-18 12:36 ` [FFmpeg-devel] [PATCH 10/20] fftools/ffmpeg_demux: log when the demuxer thread terminates Anton Khirnov
2022-10-18 12:36 ` [FFmpeg-devel] [PATCH 11/20] fftools/ffmpeg: factor out copying metadata/chapters from of_open() Anton Khirnov
2022-10-18 12:36 ` [FFmpeg-devel] [PATCH 12/20] fftools/ffmpeg_mux_init: avoid modifying OptionsContext.chapters_input_file Anton Khirnov
2022-10-18 12:36 ` [FFmpeg-devel] [PATCH 13/20] fftools/ffmpeg_mux_init: constify metadata specifier arguments Anton Khirnov
2022-10-18 12:36 ` [FFmpeg-devel] [PATCH 14/20] fftools/ffmpeg_mux_init: drop a duplicated block in copy_metadata() Anton Khirnov
2022-10-18 21:51   ` Michael Niedermayer
2022-11-08 12:46     ` Anton Khirnov
2022-11-14  9:24       ` Anton Khirnov
2022-11-14 22:21       ` Michael Niedermayer
2022-10-18 12:36 ` [FFmpeg-devel] [PATCH 15/20] fftools/ffmpeg_mux_init: stop using OptionsContext as storage " Anton Khirnov
2022-10-18 12:36 ` [FFmpeg-devel] [PATCH 16/20] fftools/ffmpeg_mux_init: stop modifying some OptionsContext fields Anton Khirnov
2022-10-18 12:36 ` [FFmpeg-devel] [PATCH 17/20] fftools/ffmpeg_mux_init: move code creating streams into a new function Anton Khirnov
2022-10-18 12:36 ` [FFmpeg-devel] [PATCH 18/20] fftools/ffmpeg_mux_init: stop modifying OptionsContext.*_disable Anton Khirnov
2022-10-18 12:37 ` [FFmpeg-devel] [PATCH 19/20] fftools/ffmpeg_demux: stop modifying OptionsContext Anton Khirnov
2022-10-18 12:37 ` [FFmpeg-devel] [PATCH 20/20] fftools/ffmpeg_[de]mux: constify all uses of OptionsContext Anton Khirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221018123701.25002-6-anton@khirnov.net \
    --to=anton@khirnov.net \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git