Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] fftools/ffmpeg: use an int for nb_threads
@ 2025-02-14 16:33 James Almer
  2025-02-15  1:28 ` Andreas Rheinhardt
  0 siblings, 1 reply; 4+ messages in thread
From: James Almer @ 2025-02-14 16:33 UTC (permalink / raw)
  To: ffmpeg-devel

Removes unnecessary allocations.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 fftools/ffmpeg.h          |  2 +-
 fftools/ffmpeg_filter.c   | 16 ++++++----------
 fftools/ffmpeg_mux_init.c |  5 ++---
 3 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 9439be0f41..6cc0da05a0 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -316,7 +316,7 @@ typedef struct OutputFilterOptions {
     AVDictionary       *sws_opts;
     AVDictionary       *swr_opts;
 
-    const char         *nb_threads;
+    int64_t             nb_threads;
 
     // A combination of OFilterFlags.
     unsigned            flags;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index a0d04fd76f..800e2a3f06 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -60,7 +60,7 @@ typedef struct FilterGraphPriv {
 
     const char      *graph_desc;
 
-    char            *nb_threads;
+    int              nb_threads;
 
     // frame for temporarily holding output from the filtergraph
     AVFrame         *frame;
@@ -1042,7 +1042,6 @@ void fg_free(FilterGraph **pfg)
     }
     av_freep(&fg->outputs);
     av_freep(&fgp->graph_desc);
-    av_freep(&fgp->nb_threads);
 
     av_frame_free(&fgp->frame);
     av_frame_free(&fgp->frame_enc);
@@ -1097,6 +1096,7 @@ int fg_create(FilterGraph **pfg, char *graph_desc, Scheduler *sch)
     fg->class       = &fg_class;
     fgp->graph_desc = graph_desc;
     fgp->disable_conversions = !auto_conversion_filters;
+    fgp->nb_threads          = -1;
     fgp->sch                 = sch;
 
     snprintf(fgp->log_name, sizeof(fgp->log_name), "fc#%d", fg->index);
@@ -1247,12 +1247,8 @@ int fg_create_simple(FilterGraph **pfg,
     if (ret < 0)
         return ret;
 
-    if (opts->nb_threads) {
-        av_freep(&fgp->nb_threads);
-        fgp->nb_threads = av_strdup(opts->nb_threads);
-        if (!fgp->nb_threads)
-            return AVERROR(ENOMEM);
-    }
+    if (opts->nb_threads >= 0)
+        fgp->nb_threads = opts->nb_threads;
 
     return 0;
 }
@@ -1936,8 +1932,8 @@ static int configure_filtergraph(FilterGraph *fg, FilterGraphThread *fgt)
             ret = av_opt_set(fgt->graph, "threads", filter_nbthreads, 0);
             if (ret < 0)
                 goto fail;
-        } else if (fgp->nb_threads) {
-            ret = av_opt_set(fgt->graph, "threads", fgp->nb_threads, 0);
+        } else if (fgp->nb_threads >= 0) {
+            ret = av_opt_set_int(fgt->graph, "threads", fgp->nb_threads, 0);
             if (ret < 0)
                 return ret;
         }
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 944176ca5d..d212a1f326 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -930,7 +930,7 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter,
         .ts_offset        = mux->of.start_time == AV_NOPTS_VALUE ?
                             0 : mux->of.start_time,
         .vs               = vs,
-
+        .nb_threads       = -1,
         .flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt |
                  OFILTER_FLAG_AUTOSCALE       * !!autoscale    |
                  OFILTER_FLAG_AUDIO_24BIT * !!(av_get_exact_bits_per_sample(enc_ctx->codec_id) == 24),
@@ -982,7 +982,7 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter,
     }
 
     if (threads_manual) {
-        ret = av_opt_get(enc_ctx, "threads", 0, (uint8_t**)&opts.nb_threads);
+        ret = av_opt_get_int(enc_ctx, "threads", 0, &opts.nb_threads);
         if (ret < 0)
             return ret;
     }
@@ -1002,7 +1002,6 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter,
             ost->filter = ost->fg_simple->outputs[0];
 
     }
-    av_freep(&opts.nb_threads);
     if (ret < 0)
         return ret;
 
-- 
2.48.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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-02-15 15:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-14 16:33 [FFmpeg-devel] [PATCH] fftools/ffmpeg: use an int for nb_threads James Almer
2025-02-15  1:28 ` Andreas Rheinhardt
2025-02-15  3:42   ` James Almer
2025-02-15 15:26     ` James Almer

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