Commit eeeb595c authored by Marton Balint's avatar Marton Balint

avformat: make flush_packets a tri-state and set it to -1 (auto) by default

If flushing is not disabled, then mux.c will signal the end of the packets with
an AVIO_DATA_MARKER_FLUSH_POINT, and aviobuf will be able to decide to flush or
not based on the preferred minimum packet size set by the used protocol.
Reviewed-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
Signed-off-by: 's avatarMarton Balint <cus@passwd.hu>
parent 09891c53
...@@ -182,9 +182,10 @@ Default is 0. ...@@ -182,9 +182,10 @@ Default is 0.
Correct single timestamp overflows if set to 1. Default is 1. Correct single timestamp overflows if set to 1. Default is 1.
@item flush_packets @var{integer} (@emph{output}) @item flush_packets @var{integer} (@emph{output})
Flush the underlying I/O stream after each packet. Default 1 enables it, and Flush the underlying I/O stream after each packet. Default is -1 (auto), which
has the effect of reducing the latency; 0 disables it and may slightly means that the underlying protocol will decide, 1 enables it, and has the
increase performance in some cases. effect of reducing the latency, 0 disables it and may increase IO throughput in
some cases.
@item output_ts_offset @var{offset} (@emph{output}) @item output_ts_offset @var{offset} (@emph{output})
Set the output time offset. Set the output time offset.
......
...@@ -468,6 +468,16 @@ static int init_pts(AVFormatContext *s) ...@@ -468,6 +468,16 @@ static int init_pts(AVFormatContext *s)
return 0; return 0;
} }
static void flush_if_needed(AVFormatContext *s)
{
if (s->pb && s->pb->error >= 0) {
if (s->flush_packets == 1 || s->flags & AVFMT_FLAG_FLUSH_PACKETS)
avio_flush(s->pb);
else if (s->flush_packets && !(s->oformat->flags & AVFMT_NOFILE))
avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT);
}
}
static int write_header_internal(AVFormatContext *s) static int write_header_internal(AVFormatContext *s)
{ {
if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb) if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
...@@ -479,8 +489,7 @@ static int write_header_internal(AVFormatContext *s) ...@@ -479,8 +489,7 @@ static int write_header_internal(AVFormatContext *s)
s->internal->write_header_ret = ret; s->internal->write_header_ret = ret;
if (ret < 0) if (ret < 0)
return ret; return ret;
if (s->flush_packets && s->pb && s->pb->error >= 0 && s->flags & AVFMT_FLAG_FLUSH_PACKETS) flush_if_needed(s);
avio_flush(s->pb);
} }
s->internal->header_written = 1; s->internal->header_written = 1;
if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb) if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
...@@ -772,8 +781,7 @@ FF_ENABLE_DEPRECATION_WARNINGS ...@@ -772,8 +781,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
} }
if (s->pb && ret >= 0) { if (s->pb && ret >= 0) {
if (s->flush_packets && s->flags & AVFMT_FLAG_FLUSH_PACKETS) flush_if_needed(s);
avio_flush(s->pb);
if (s->pb->error < 0) if (s->pb->error < 0)
ret = s->pb->error; ret = s->pb->error;
} }
...@@ -932,8 +940,7 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt) ...@@ -932,8 +940,7 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt)
return ret; return ret;
} }
ret = s->oformat->write_packet(s, NULL); ret = s->oformat->write_packet(s, NULL);
if (s->flush_packets && s->pb && s->pb->error >= 0 && s->flags & AVFMT_FLAG_FLUSH_PACKETS) flush_if_needed(s);
avio_flush(s->pb);
if (ret >= 0 && s->pb && s->pb->error < 0) if (ret >= 0 && s->pb && s->pb->error < 0)
ret = s->pb->error; ret = s->pb->error;
return ret; return ret;
......
...@@ -39,7 +39,7 @@ static const AVOption avformat_options[] = { ...@@ -39,7 +39,7 @@ static const AVOption avformat_options[] = {
{"probesize", "set probing size", OFFSET(probesize), AV_OPT_TYPE_INT64, {.i64 = 5000000 }, 32, INT64_MAX, D}, {"probesize", "set probing size", OFFSET(probesize), AV_OPT_TYPE_INT64, {.i64 = 5000000 }, 32, INT64_MAX, D},
{"formatprobesize", "number of bytes to probe file format", OFFSET(format_probesize), AV_OPT_TYPE_INT, {.i64 = PROBE_BUF_MAX}, 0, INT_MAX-1, D}, {"formatprobesize", "number of bytes to probe file format", OFFSET(format_probesize), AV_OPT_TYPE_INT, {.i64 = PROBE_BUF_MAX}, 0, INT_MAX-1, D},
{"packetsize", "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, E}, {"packetsize", "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, E},
{"fflags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = AVFMT_FLAG_FLUSH_PACKETS | AVFMT_FLAG_AUTO_BSF }, INT_MIN, INT_MAX, D|E, "fflags"}, {"fflags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = AVFMT_FLAG_AUTO_BSF }, INT_MIN, INT_MAX, D|E, "fflags"},
{"flush_packets", "reduce the latency by flushing out packets immediately", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_FLUSH_PACKETS }, INT_MIN, INT_MAX, E, "fflags"}, {"flush_packets", "reduce the latency by flushing out packets immediately", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_FLUSH_PACKETS }, INT_MIN, INT_MAX, E, "fflags"},
{"ignidx", "ignore index", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_IGNIDX }, INT_MIN, INT_MAX, D, "fflags"}, {"ignidx", "ignore index", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_IGNIDX }, INT_MIN, INT_MAX, D, "fflags"},
{"genpts", "generate pts", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_GENPTS }, INT_MIN, INT_MAX, D, "fflags"}, {"genpts", "generate pts", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_GENPTS }, INT_MIN, INT_MAX, D, "fflags"},
...@@ -85,7 +85,7 @@ static const AVOption avformat_options[] = { ...@@ -85,7 +85,7 @@ static const AVOption avformat_options[] = {
{"use_wallclock_as_timestamps", "use wallclock as timestamps", OFFSET(use_wallclock_as_timestamps), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, D}, {"use_wallclock_as_timestamps", "use wallclock as timestamps", OFFSET(use_wallclock_as_timestamps), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, D},
{"skip_initial_bytes", "set number of bytes to skip before reading header and frames", OFFSET(skip_initial_bytes), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX-1, D}, {"skip_initial_bytes", "set number of bytes to skip before reading header and frames", OFFSET(skip_initial_bytes), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX-1, D},
{"correct_ts_overflow", "correct single timestamp overflows", OFFSET(correct_ts_overflow), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, D}, {"correct_ts_overflow", "correct single timestamp overflows", OFFSET(correct_ts_overflow), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, D},
{"flush_packets", "enable flushing of the I/O context after each packet", OFFSET(flush_packets), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, E}, {"flush_packets", "enable flushing of the I/O context after each packet", OFFSET(flush_packets), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, E},
{"metadata_header_padding", "set number of bytes to be written as padding in a metadata header", OFFSET(metadata_header_padding), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, E}, {"metadata_header_padding", "set number of bytes to be written as padding in a metadata header", OFFSET(metadata_header_padding), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, E},
{"output_ts_offset", "set output timestamp offset", OFFSET(output_ts_offset), AV_OPT_TYPE_DURATION, {.i64 = 0}, -INT64_MAX, INT64_MAX, E}, {"output_ts_offset", "set output timestamp offset", OFFSET(output_ts_offset), AV_OPT_TYPE_DURATION, {.i64 = 0}, -INT64_MAX, INT64_MAX, E},
{"max_interleave_delta", "maximum buffering duration for interleaving", OFFSET(max_interleave_delta), AV_OPT_TYPE_INT64, { .i64 = 10000000 }, 0, INT64_MAX, E }, {"max_interleave_delta", "maximum buffering duration for interleaving", OFFSET(max_interleave_delta), AV_OPT_TYPE_INT64, { .i64 = 10000000 }, 0, INT64_MAX, E },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment