From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 10/13] fftools/ffmpeg_mux: inline of_muxer_init() into of_open()
Date: Thu, 13 Oct 2022 15:49:01 +0200
Message-ID: <20221013134904.10104-10-anton@khirnov.net> (raw)
In-Reply-To: <20221013134904.10104-1-anton@khirnov.net>
A separate muxer init is no longer necessary, now that of_open() has
access to Muxer.
---
fftools/ffmpeg.h | 4 ---
fftools/ffmpeg_mux.c | 56 ++++-----------------------------------
fftools/ffmpeg_mux.h | 5 ++++
fftools/ffmpeg_mux_init.c | 39 ++++++++++++++++++++-------
4 files changed, 40 insertions(+), 64 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index fb409c22ad..9ccd158e4b 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -727,10 +727,6 @@ int hw_device_setup_for_filter(FilterGraph *fg);
int hwaccel_decode_init(AVCodecContext *avctx);
-int of_muxer_init(OutputFile *of, AVFormatContext *fc,
- AVDictionary *opts, int64_t limit_filesize,
- int thread_queue_size);
-
/*
* Initialize muxing state for the given stream, should be called
* after the codec/streamcopy setup has been done.
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 4c56f4ba96..2f71e03144 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -38,7 +38,7 @@
#include "libavformat/avformat.h"
#include "libavformat/avio.h"
-static int want_sdp = 1;
+int want_sdp = 1;
static Muxer *mux_from_of(OutputFile *of)
{
@@ -487,9 +487,9 @@ fail:
return ret;
}
-static int mux_check_init(OutputFile *of)
+int mux_check_init(Muxer *mux)
{
- Muxer *mux = mux_from_of(of);
+ OutputFile *of = &mux->of;
AVFormatContext *fc = mux->fc;
int ret, i;
@@ -538,12 +538,13 @@ static int mux_check_init(OutputFile *of)
int of_stream_init(OutputFile *of, OutputStream *ost)
{
+ Muxer *mux = mux_from_of(of);
if (ost->sq_idx_mux >= 0)
sq_set_tb(of->sq_mux, ost->sq_idx_mux, ost->mux_timebase);
ost->initialized = 1;
- return mux_check_init(of);
+ return mux_check_init(mux);
}
int of_write_trailer(OutputFile *of)
@@ -638,53 +639,6 @@ void of_close(OutputFile **pof)
av_freep(pof);
}
-int of_muxer_init(OutputFile *of, AVFormatContext *fc,
- AVDictionary *opts, int64_t limit_filesize,
- int thread_queue_size)
-{
- Muxer *mux = mux_from_of(of);
- int ret = 0;
-
- mux->streams = av_calloc(fc->nb_streams, sizeof(*mux->streams));
- if (!mux->streams) {
- fc_close(&fc);
- return AVERROR(ENOMEM);
- }
- of->nb_streams = fc->nb_streams;
-
- mux->fc = fc;
-
- for (int i = 0; i < fc->nb_streams; i++) {
- MuxStream *ms = &mux->streams[i];
- ms->muxing_queue = av_fifo_alloc2(8, sizeof(AVPacket*), 0);
- if (!ms->muxing_queue) {
- ret = AVERROR(ENOMEM);
- goto fail;
- }
- ms->last_mux_dts = AV_NOPTS_VALUE;
- }
-
- mux->thread_queue_size = thread_queue_size > 0 ? thread_queue_size : 8;
- mux->limit_filesize = limit_filesize;
- mux->opts = opts;
-
- if (strcmp(of->format->name, "rtp"))
- want_sdp = 0;
-
- /* write the header for files with no streams */
- if (of->format->flags & AVFMT_NOSTREAMS && fc->nb_streams == 0) {
- ret = mux_check_init(of);
- if (ret < 0)
- goto fail;
- }
-
-fail:
- if (ret < 0)
- mux_free(mux);
-
- return ret;
-}
-
int64_t of_filesize(OutputFile *of)
{
Muxer *mux = mux_from_of(of);
diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h
index 90ff979ec1..d9c4dce750 100644
--- a/fftools/ffmpeg_mux.h
+++ b/fftools/ffmpeg_mux.h
@@ -71,4 +71,9 @@ typedef struct Muxer {
AVPacket *sq_pkt;
} Muxer;
+/* whether we want to print an SDP, set in of_open() */
+extern int want_sdp;
+
+int mux_check_init(Muxer *mux);
+
#endif /* FFTOOLS_FFMPEG_MUX_H */
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 6c4d9bad1e..be7286c26d 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1582,7 +1582,7 @@ int of_open(OptionsContext *o, const char *filename)
AVFormatContext *oc;
int i, j, err;
OutputFile *of;
- AVDictionary *unused_opts = NULL, *format_opts = NULL;
+ AVDictionary *unused_opts = NULL;
const AVDictionaryEntry *e = NULL;
if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) {
@@ -1608,7 +1608,10 @@ int of_open(OptionsContext *o, const char *filename)
of->recording_time = o->recording_time;
of->start_time = o->start_time;
of->shortest = o->shortest;
- av_dict_copy(&format_opts, o->g->format_opts, 0);
+
+ mux->thread_queue_size = o->thread_queue_size > 0 ? o->thread_queue_size : 8;
+ mux->limit_filesize = o->limit_filesize;
+ av_dict_copy(&mux->opts, o->g->format_opts, 0);
if (!strcmp(filename, "-"))
filename = "pipe:";
@@ -1618,6 +1621,10 @@ int of_open(OptionsContext *o, const char *filename)
print_error(filename, err);
exit_program(1);
}
+ mux->fc = oc;
+
+ if (strcmp(oc->oformat->name, "rtp"))
+ want_sdp = 0;
of->format = oc->oformat;
if (o->recording_time != INT64_MAX)
@@ -1629,7 +1636,7 @@ int of_open(OptionsContext *o, const char *filename)
oc->flags |= AVFMT_FLAG_BITEXACT;
of->bitexact = 1;
} else {
- of->bitexact = check_opt_bitexact(oc, format_opts, "fflags",
+ of->bitexact = check_opt_bitexact(oc, mux->opts, "fflags",
AVFMT_FLAG_BITEXACT);
}
@@ -1798,7 +1805,7 @@ int of_open(OptionsContext *o, const char *filename)
/* open the file */
if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
&oc->interrupt_callback,
- &format_opts)) < 0) {
+ &mux->opts)) < 0) {
print_error(filename, err);
exit_program(1);
}
@@ -1806,7 +1813,7 @@ int of_open(OptionsContext *o, const char *filename)
assert_file_overwrite(filename);
if (o->mux_preload) {
- av_dict_set_int(&format_opts, "preload", o->mux_preload*AV_TIME_BASE, 0);
+ av_dict_set_int(&mux->opts, "preload", o->mux_preload*AV_TIME_BASE, 0);
}
oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
@@ -1884,10 +1891,24 @@ int of_open(OptionsContext *o, const char *filename)
of->url = filename;
- err = of_muxer_init(of, oc, format_opts, o->limit_filesize, o->thread_queue_size);
- if (err < 0) {
- av_log(NULL, AV_LOG_FATAL, "Error initializing internal muxing state\n");
- exit_program(1);
+ mux->streams = av_calloc(oc->nb_streams, sizeof(*mux->streams));
+ if (!mux->streams)
+ return AVERROR(ENOMEM);
+ of->nb_streams = oc->nb_streams;
+
+ for (int i = 0; i < oc->nb_streams; i++) {
+ MuxStream *ms = &mux->streams[i];
+ ms->muxing_queue = av_fifo_alloc2(8, sizeof(AVPacket*), 0);
+ if (!ms->muxing_queue)
+ return AVERROR(ENOMEM);
+ ms->last_mux_dts = AV_NOPTS_VALUE;
+ }
+
+ /* write the header for files with no streams */
+ if (of->format->flags & AVFMT_NOSTREAMS && oc->nb_streams == 0) {
+ int ret = mux_check_init(mux);
+ if (ret < 0)
+ return ret;
}
return 0;
--
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".
next prev parent reply other threads:[~2022-10-13 13:50 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-13 13:48 [FFmpeg-devel] [PATCH 01/13] fftools/ffmpeg_mux: do not unref a NULL packet Anton Khirnov
2022-10-13 13:48 ` [FFmpeg-devel] [PATCH 02/13] fftools/ffmpeg: move output_packet() to ffmpeg_mux Anton Khirnov
2022-10-13 13:48 ` [FFmpeg-devel] [PATCH 03/13] fftools/ffmpeg_mux: rename submit_packet() to thread_submit_packet() Anton Khirnov
2022-10-13 13:48 ` [FFmpeg-devel] [PATCH 04/13] fftools/ffmpeg_mux: drop the of_ prefix from of_submit_packet() Anton Khirnov
2022-10-13 13:48 ` [FFmpeg-devel] [PATCH 05/13] fftools/ffmpeg: move some stream initialization code to ffmpeg_mux Anton Khirnov
2022-10-13 13:48 ` [FFmpeg-devel] [PATCH 06/13] fftools/ffmpeg_opt: move opening output files into a new file Anton Khirnov
2022-10-13 13:48 ` [FFmpeg-devel] [PATCH 07/13] fftools/ffmpeg_mux: move Muxer and MuxStream to a new header Anton Khirnov
2022-10-13 13:48 ` [FFmpeg-devel] [PATCH 08/13] fftools/ffmpeg_mux: embed OutputFile in a Muxer Anton Khirnov
2022-10-13 13:49 ` [FFmpeg-devel] [PATCH 09/13] fftools/ffmpeg_mux: allocate sq_pkt in setup_sync_queues() Anton Khirnov
2022-10-13 13:49 ` Anton Khirnov [this message]
2022-10-13 13:49 ` [FFmpeg-devel] [PATCH 11/13] fftools/ffmpeg_mux: inline mux_free() into of_close() Anton Khirnov
2022-10-13 13:49 ` [FFmpeg-devel] [PATCH 12/13] fftools/ffmpeg_mux: move sq_mux from OutputFile to Muxer Anton Khirnov
2022-10-13 13:49 ` [FFmpeg-devel] [PATCH 13/13] fftools/ffmpeg: move init_output_bsfs() to ffmpeg_mux Anton Khirnov
2022-10-14 10:15 ` [FFmpeg-devel] [PATCH 14/22] fftools/ffmpeg: move freeing an output stream into a separate function Anton Khirnov
2022-10-14 10:15 ` [FFmpeg-devel] [PATCH 15/22] fftools/ffmpeg: reindent after previous commit Anton Khirnov
2022-10-14 10:15 ` [FFmpeg-devel] [PATCH 16/22] fftools/ffmpeg_mux_init: pass Muxer to new_output_stream() Anton Khirnov
2022-10-14 10:15 ` [FFmpeg-devel] [PATCH 17/22] fftools/ffmpeg: remove the output_streams global Anton Khirnov
2022-10-14 10:15 ` [FFmpeg-devel] [PATCH 18/22] fftools/ffmpeg: remove a cleanup block at the end of transcode() Anton Khirnov
2022-10-14 10:15 ` [FFmpeg-devel] [PATCH 19/22] fftools/ffmpeg: free output streams in of_close() Anton Khirnov
2022-10-14 10:15 ` [FFmpeg-devel] [PATCH 20/22] fftools/ffmpeg_mux: embed OutputStream in a MuxStream Anton Khirnov
2022-10-14 10:15 ` [FFmpeg-devel] [PATCH 21/22] fftools/ffmpeg_mux: move bsf_ctx from OutputStream to MuxStream Anton Khirnov
2022-10-14 10:15 ` [FFmpeg-devel] [PATCH 22/22] fftools/ffmpeg_mux: move muxing queue fields " Anton Khirnov
2022-10-17 8:49 ` [FFmpeg-devel] [PATCH 01/13] fftools/ffmpeg_mux: do not unref a NULL packet 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=20221013134904.10104-10-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