fftools/ffmpeg_mux: inline of_muxer_init() into of_open()

A separate muxer init is no longer necessary, now that of_open() has
access to Muxer.
This commit is contained in:
Anton Khirnov 2022-10-13 15:24:33 +02:00
parent a55ca682e2
commit 36ce335d46
4 changed files with 40 additions and 64 deletions

View File

@ -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.

View File

@ -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);

View File

@ -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 */

View File

@ -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;