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: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
@@ -468,6 +468,16 @@ static int init_pts(AVFormatContext *s)
|
||||
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)
|
||||
{
|
||||
if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
|
||||
@@ -479,8 +489,7 @@ static int write_header_internal(AVFormatContext *s)
|
||||
s->internal->write_header_ret = ret;
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if (s->flush_packets && s->pb && s->pb->error >= 0 && s->flags & AVFMT_FLAG_FLUSH_PACKETS)
|
||||
avio_flush(s->pb);
|
||||
flush_if_needed(s);
|
||||
}
|
||||
s->internal->header_written = 1;
|
||||
if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
|
||||
@@ -772,8 +781,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
||||
}
|
||||
|
||||
if (s->pb && ret >= 0) {
|
||||
if (s->flush_packets && s->flags & AVFMT_FLAG_FLUSH_PACKETS)
|
||||
avio_flush(s->pb);
|
||||
flush_if_needed(s);
|
||||
if (s->pb->error < 0)
|
||||
ret = s->pb->error;
|
||||
}
|
||||
@@ -932,8 +940,7 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt)
|
||||
return ret;
|
||||
}
|
||||
ret = s->oformat->write_packet(s, NULL);
|
||||
if (s->flush_packets && s->pb && s->pb->error >= 0 && s->flags & AVFMT_FLAG_FLUSH_PACKETS)
|
||||
avio_flush(s->pb);
|
||||
flush_if_needed(s);
|
||||
if (ret >= 0 && s->pb && s->pb->error < 0)
|
||||
ret = s->pb->error;
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user