summaryrefslogtreecommitdiff
path: root/fftools/ffmpeg_mux.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-12-11 14:03:18 +0100
committerAnton Khirnov <anton@khirnov.net>2022-07-23 11:53:19 +0200
commit6a23be92d2a0b1f5100afa0fd3ff33e8510b6eb3 (patch)
tree247f8268be9dd85eab4235c1075c762c0d15f4e4 /fftools/ffmpeg_mux.c
parent009ef35d384c3df22d8a8be7416dc9d532e91c52 (diff)
fftools/ffmpeg_mux: add private muxer context
Move header_written into it, which is not (and should not be) used by any code outside of ffmpeg_mux. In the future this context will contain more muxer-private state that should not be visible to other code.
Diffstat (limited to 'fftools/ffmpeg_mux.c')
-rw-r--r--fftools/ffmpeg_mux.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index a55fd18f8f..e47a55c4e9 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -32,6 +32,10 @@
#include "libavformat/avformat.h"
#include "libavformat/avio.h"
+struct Muxer {
+ int header_written;
+};
+
static void close_all_output_streams(OutputStream *ost, OSTFinished this_stream, OSTFinished others)
{
int i;
@@ -64,7 +68,7 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost,
ost->frame_number++;
}
- if (!of->header_written) {
+ if (!of->mux->header_written) {
AVPacket *tmp_pkt;
/* the muxer is not initialized yet, buffer the packet */
if (!av_fifo_can_write(ost->muxing_queue)) {
@@ -182,7 +186,7 @@ static int print_sdp(void)
AVFormatContext **avc;
for (i = 0; i < nb_output_files; i++) {
- if (!output_files[i]->header_written)
+ if (!output_files[i]->mux->header_written)
return 0;
}
@@ -246,7 +250,7 @@ int of_check_init(OutputFile *of)
return ret;
}
//assert_avoptions(of->opts);
- of->header_written = 1;
+ of->mux->header_written = 1;
av_dump_format(of->ctx, of->index, of->ctx->url, 1);
nb_output_dumped++;
@@ -282,7 +286,7 @@ int of_write_trailer(OutputFile *of)
{
int ret;
- if (!of->header_written) {
+ if (!of->mux->header_written) {
av_log(NULL, AV_LOG_ERROR,
"Nothing was written into output file %d (%s), because "
"at least one of its streams received no packets.\n",
@@ -313,5 +317,19 @@ void of_close(OutputFile **pof)
avformat_free_context(s);
av_dict_free(&of->opts);
+ av_freep(&of->mux);
+
av_freep(pof);
}
+
+int of_muxer_init(OutputFile *of)
+{
+ Muxer *mux = av_mallocz(sizeof(*mux));
+
+ if (!mux)
+ return AVERROR(ENOMEM);
+
+ of->mux = mux;
+
+ return 0;
+}