forked from FFmpeg/FFmpeg
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.
This commit is contained in:
parent
009ef35d38
commit
6a23be92d2
3 changed files with 32 additions and 6 deletions
|
@ -583,9 +583,12 @@ typedef struct OutputStream {
|
||||||
int64_t error[4];
|
int64_t error[4];
|
||||||
} OutputStream;
|
} OutputStream;
|
||||||
|
|
||||||
|
typedef struct Muxer Muxer;
|
||||||
|
|
||||||
typedef struct OutputFile {
|
typedef struct OutputFile {
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
|
Muxer *mux;
|
||||||
const AVOutputFormat *format;
|
const AVOutputFormat *format;
|
||||||
|
|
||||||
AVFormatContext *ctx;
|
AVFormatContext *ctx;
|
||||||
|
@ -596,8 +599,6 @@ typedef struct OutputFile {
|
||||||
uint64_t limit_filesize; /* filesize limit expressed in bytes */
|
uint64_t limit_filesize; /* filesize limit expressed in bytes */
|
||||||
|
|
||||||
int shortest;
|
int shortest;
|
||||||
|
|
||||||
int header_written;
|
|
||||||
} OutputFile;
|
} OutputFile;
|
||||||
|
|
||||||
extern InputStream **input_streams;
|
extern InputStream **input_streams;
|
||||||
|
@ -696,6 +697,7 @@ int hw_device_setup_for_filter(FilterGraph *fg);
|
||||||
|
|
||||||
int hwaccel_decode_init(AVCodecContext *avctx);
|
int hwaccel_decode_init(AVCodecContext *avctx);
|
||||||
|
|
||||||
|
int of_muxer_init(OutputFile *of);
|
||||||
/* open the muxer when all the streams are initialized */
|
/* open the muxer when all the streams are initialized */
|
||||||
int of_check_init(OutputFile *of);
|
int of_check_init(OutputFile *of);
|
||||||
int of_write_trailer(OutputFile *of);
|
int of_write_trailer(OutputFile *of);
|
||||||
|
|
|
@ -32,6 +32,10 @@
|
||||||
#include "libavformat/avformat.h"
|
#include "libavformat/avformat.h"
|
||||||
#include "libavformat/avio.h"
|
#include "libavformat/avio.h"
|
||||||
|
|
||||||
|
struct Muxer {
|
||||||
|
int header_written;
|
||||||
|
};
|
||||||
|
|
||||||
static void close_all_output_streams(OutputStream *ost, OSTFinished this_stream, OSTFinished others)
|
static void close_all_output_streams(OutputStream *ost, OSTFinished this_stream, OSTFinished others)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -64,7 +68,7 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost,
|
||||||
ost->frame_number++;
|
ost->frame_number++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!of->header_written) {
|
if (!of->mux->header_written) {
|
||||||
AVPacket *tmp_pkt;
|
AVPacket *tmp_pkt;
|
||||||
/* the muxer is not initialized yet, buffer the packet */
|
/* the muxer is not initialized yet, buffer the packet */
|
||||||
if (!av_fifo_can_write(ost->muxing_queue)) {
|
if (!av_fifo_can_write(ost->muxing_queue)) {
|
||||||
|
@ -182,7 +186,7 @@ static int print_sdp(void)
|
||||||
AVFormatContext **avc;
|
AVFormatContext **avc;
|
||||||
|
|
||||||
for (i = 0; i < nb_output_files; i++) {
|
for (i = 0; i < nb_output_files; i++) {
|
||||||
if (!output_files[i]->header_written)
|
if (!output_files[i]->mux->header_written)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +250,7 @@ int of_check_init(OutputFile *of)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
//assert_avoptions(of->opts);
|
//assert_avoptions(of->opts);
|
||||||
of->header_written = 1;
|
of->mux->header_written = 1;
|
||||||
|
|
||||||
av_dump_format(of->ctx, of->index, of->ctx->url, 1);
|
av_dump_format(of->ctx, of->index, of->ctx->url, 1);
|
||||||
nb_output_dumped++;
|
nb_output_dumped++;
|
||||||
|
@ -282,7 +286,7 @@ int of_write_trailer(OutputFile *of)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!of->header_written) {
|
if (!of->mux->header_written) {
|
||||||
av_log(NULL, AV_LOG_ERROR,
|
av_log(NULL, AV_LOG_ERROR,
|
||||||
"Nothing was written into output file %d (%s), because "
|
"Nothing was written into output file %d (%s), because "
|
||||||
"at least one of its streams received no packets.\n",
|
"at least one of its streams received no packets.\n",
|
||||||
|
@ -313,5 +317,19 @@ void of_close(OutputFile **pof)
|
||||||
avformat_free_context(s);
|
avformat_free_context(s);
|
||||||
av_dict_free(&of->opts);
|
av_dict_free(&of->opts);
|
||||||
|
|
||||||
|
av_freep(&of->mux);
|
||||||
|
|
||||||
av_freep(pof);
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -3006,6 +3006,12 @@ loop_end:
|
||||||
exit_program(1);
|
exit_program(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = of_muxer_init(of);
|
||||||
|
if (err < 0) {
|
||||||
|
av_log(NULL, AV_LOG_FATAL, "Error initializing internal muxing state\n");
|
||||||
|
exit_program(1);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue