Module: libav
Branch: master
Commit: 596e5d4783ca951258a7c580951fd161f1785ec1

Author:    Luca Barbato <[email protected]>
Committer: Martin Storsjö <[email protected]>
Date:      Wed Sep 11 14:02:06 2013 +0200

lavf: Add a flag to enable/disable per-packet flushing

This is enabled by default and can be disabled with
"-fflags -flush_packets".

Inspired by a patch from Nicolas George <[email protected]>.

Signed-off-by: Martin Storsjö <[email protected]>

---

 libavformat/avformat.h      |    1 +
 libavformat/mux.c           |    8 +++++++-
 libavformat/options_table.h |    3 ++-
 libavformat/version.h       |    2 +-
 4 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 12462c8..ce7a2f8 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -894,6 +894,7 @@ typedef struct AVFormatContext {
 #define AVFMT_FLAG_NOBUFFER     0x0040 ///< Do not buffer frames when possible
 #define AVFMT_FLAG_CUSTOM_IO    0x0080 ///< The caller has supplied a custom 
AVIOContext, don't avio_close() it.
 #define AVFMT_FLAG_DISCARD_CORRUPT  0x0100 ///< Discard frames marked corrupted
+#define AVFMT_FLAG_FLUSH_PACKETS    0x0200 ///< Flush the AVIOContext every 
packet.
 
     /**
      * decoding: size of data to probe; encoding: unused.
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 5a08dd6..505ed2e 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -404,6 +404,7 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream 
*st, AVPacket *pkt)
 
 static int write_packet(AVFormatContext *s, AVPacket *pkt)
 {
+    int ret;
     if (!(s->oformat->flags & (AVFMT_TS_NEGATIVE | AVFMT_NOTIMESTAMPS))) {
         AVRational time_base = s->streams[pkt->stream_index]->time_base;
         int64_t offset = 0;
@@ -420,7 +421,12 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
         if (pkt->pts != AV_NOPTS_VALUE)
             pkt->pts += offset;
     }
-    return s->oformat->write_packet(s, pkt);
+    ret = s->oformat->write_packet(s, pkt);
+
+    if (s->pb && ret >= 0 && s->flags & AVFMT_FLAG_FLUSH_PACKETS)
+        avio_flush(s->pb);
+
+    return ret;
 }
 
 int av_write_frame(AVFormatContext *s, AVPacket *pkt)
diff --git a/libavformat/options_table.h b/libavformat/options_table.h
index 273c589..54bf25f 100644
--- a/libavformat/options_table.h
+++ b/libavformat/options_table.h
@@ -33,7 +33,8 @@
 static const AVOption avformat_options[] = {
 {"probesize", "set probing size", OFFSET(probesize), AV_OPT_TYPE_INT, {.i64 = 
5000000 }, 32, INT_MAX, D},
 {"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 = DEFAULT }, INT_MIN, 
INT_MAX, D|E, "fflags"},
+{"fflags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 
AVFMT_FLAG_FLUSH_PACKETS }, 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, 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"},
 {"nofillin", "do not fill in missing values that can be exactly calculated", 
0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_NOFILLIN }, INT_MIN, INT_MAX, D, 
"fflags"},
diff --git a/libavformat/version.h b/libavformat/version.h
index ac675ce..38c959f 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,7 +30,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFORMAT_VERSION_MAJOR 55
-#define LIBAVFORMAT_VERSION_MINOR  3
+#define LIBAVFORMAT_VERSION_MINOR  4
 #define LIBAVFORMAT_VERSION_MICRO  0
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \

_______________________________________________
libav-commits mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-commits

Reply via email to