[FFmpeg-cvslog] libavformat: Add a flag for muxers that support write_packet(NULL) for flushing

Martin Storsjö git at videolan.org
Thu Jan 26 03:20:19 CET 2012


ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Fri Jan 20 19:27:33 2012 +0200| [f1caf01d5e2913a96c5689e6570fd10e25d1c76b] | committer: Martin Storsjö

libavformat: Add a flag for muxers that support write_packet(NULL) for flushing

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f1caf01d5e2913a96c5689e6570fd10e25d1c76b
---

 libavformat/avformat.h |   18 +++++++++++++++---
 libavformat/utils.c    |   10 +++++++++-
 libavformat/version.h  |    2 +-
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 71aed80..18a80ac 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -380,6 +380,7 @@ typedef struct AVFormatParameters {
 #define AVFMT_NOBINSEARCH   0x2000 /**< Format does not allow to fallback to binary search via read_timestamp */
 #define AVFMT_NOGENSEARCH   0x4000 /**< Format does not allow to fallback to generic search */
 #define AVFMT_NO_BYTE_SEEK  0x8000 /**< Format does not allow seeking by bytes */
+#define AVFMT_ALLOW_FLUSH  0x10000 /**< Format allows flushing. If not set, the muxer will not receive a NULL packet in the write_packet function. */
 
 /**
  * @addtogroup lavf_encoding
@@ -403,12 +404,19 @@ typedef struct AVOutputFormat {
     enum CodecID audio_codec; /**< default audio codec */
     enum CodecID video_codec; /**< default video codec */
     int (*write_header)(struct AVFormatContext *);
+    /**
+     * Write a packet. If AVFMT_ALLOW_FLUSH is set in flags,
+     * pkt can be NULL in order to flush data buffered in the muxer.
+     * When flushing, return 0 if there still is more data to flush,
+     * or 1 if everything was flushed and there is no more buffered
+     * data.
+     */
     int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
     int (*write_trailer)(struct AVFormatContext *);
     /**
      * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE,
      * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS,
-     * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS
+     * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH
      */
     int flags;
     /**
@@ -1685,8 +1693,12 @@ attribute_deprecated int av_write_header(AVFormatContext *s);
  *
  * @param s media file handle
  * @param pkt The packet, which contains the stream_index, buf/buf_size,
-              dts/pts, ...
- * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
+ *            dts/pts, ...
+ *            This can be NULL (at any time, not just at the end), in
+ *            order to immediately flush data buffered within the muxer,
+ *            for muxers that buffer up data internally before writing it
+ *            to the output.
+ * @return < 0 on error, = 0 if OK, 1 if flushed and there is no more data to flush
  */
 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
 
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 22ee13b..093389b 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3135,7 +3135,15 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt){
 
 int av_write_frame(AVFormatContext *s, AVPacket *pkt)
 {
-    int ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt);
+    int ret;
+
+    if (!pkt) {
+        if (s->oformat->flags & AVFMT_ALLOW_FLUSH)
+            return s->oformat->write_packet(s, pkt);
+        return 1;
+    }
+
+    ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt);
 
     if(ret<0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
         return ret;
diff --git a/libavformat/version.h b/libavformat/version.h
index b283592..5cdf1c8 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,7 +30,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFORMAT_VERSION_MAJOR 53
-#define LIBAVFORMAT_VERSION_MINOR 21
+#define LIBAVFORMAT_VERSION_MINOR 22
 #define LIBAVFORMAT_VERSION_MICRO  0
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list