]> git.sesse.net Git - ffmpeg/commitdiff
avformat/aviobuf: add support for specifying minimum packet size and marking flush...
authorMarton Balint <cus@passwd.hu>
Sun, 18 Jun 2017 12:38:39 +0000 (14:38 +0200)
committerMarton Balint <cus@passwd.hu>
Sat, 24 Jun 2017 16:51:29 +0000 (18:51 +0200)
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Marton Balint <cus@passwd.hu>
doc/APIchanges
libavformat/avio.h
libavformat/aviobuf.c
libavformat/url.h
libavformat/version.h

index 5dca6b3e51d4c4acdf47aed6f0d66d75e3feffd0..fc013fd5139b014e0f80fbcc419bf0adf32af686 100644 (file)
@@ -15,6 +15,9 @@ libavutil:     2015-08-28
 
 API changes, most recent first:
 
+2017-06-24 - xxxxxxx - lavf 57.75.100 - avio.h
+  Add AVIO_DATA_MARKER_FLUSH_POINT to signal preferred flush points to aviobuf.
+
 2017-06-14 - xxxxxxx - lavu 55.66.100 - hwcontext.h
   av_hwframe_ctx_create_derived() now takes some AV_HWFRAME_MAP_* combination
   as its flags argument (which was previously unused).
index 844a5723d3d28ec5753beb17fc6a8a88d298d01d..f14b003ba5d7569983f6f70608d9db44e355f038 100644 (file)
@@ -137,7 +137,13 @@ enum AVIODataMarkerType {
      * Trailer data, which doesn't contain actual content, but only for
      * finalizing the output file.
      */
-    AVIO_DATA_MARKER_TRAILER
+    AVIO_DATA_MARKER_TRAILER,
+    /**
+     * A point in the output bytestream where the underlying AVIOContext might
+     * flush the buffer depending on latency or buffering requirements. Typically
+     * means the end of a packet.
+     */
+    AVIO_DATA_MARKER_FLUSH_POINT,
 };
 
 /**
@@ -339,6 +345,11 @@ typedef struct AVIOContext {
      * used keeping track of already written data for a later flush.
      */
     unsigned char *buf_ptr_max;
+
+    /**
+     * Try to buffer at least this amount of data before flushing it
+     */
+    int min_packet_size;
 } AVIOContext;
 
 /**
index dcb91570d88c2bba7777e7850aaa37ad04034d97..7f4e740a334828c62d005a913d30a3dead6eb41e 100644 (file)
@@ -104,6 +104,7 @@ int ffio_init_context(AVIOContext *s,
     s->eof_reached     = 0;
     s->error           = 0;
     s->seekable        = seek ? AVIO_SEEKABLE_NORMAL : 0;
+    s->min_packet_size = 0;
     s->max_packet_size = 0;
     s->update_checksum = NULL;
     s->short_seek_threshold = SHORT_SEEK_THRESHOLD;
@@ -489,6 +490,11 @@ void avio_wb24(AVIOContext *s, unsigned int val)
 
 void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
 {
+    if (type == AVIO_DATA_MARKER_FLUSH_POINT) {
+        if (s->buf_ptr - s->buffer >= s->min_packet_size)
+            avio_flush(s);
+        return;
+    }
     if (!s->write_data_type)
         return;
     // If ignoring boundary points, just treat it as unknown
@@ -941,6 +947,7 @@ int ffio_fdopen(AVIOContext **s, URLContext *h)
 
     (*s)->seekable = h->is_streamed ? 0 : AVIO_SEEKABLE_NORMAL;
     (*s)->max_packet_size = max_packet_size;
+    (*s)->min_packet_size = h->min_packet_size;
     if(h->prot) {
         (*s)->read_pause = io_read_pause;
         (*s)->read_seek  = io_read_seek;
index 910f1e00b389455c7806914d30f7992a0a37fbe7..4750bfff825b54527b54b4a8dc978110dc34ffc9 100644 (file)
@@ -48,6 +48,7 @@ typedef struct URLContext {
     int64_t rw_timeout;         /**< maximum time to wait for (network) read/write operation completion, in mcs */
     const char *protocol_whitelist;
     const char *protocol_blacklist;
+    int min_packet_size;        /**< if non zero, the stream is packetized with this min packet size */
 } URLContext;
 
 typedef struct URLProtocol {
index 1fb8ffb2b96ff27ac0f1d79c7cc7c3a02f6f9484..44c16ac75ad45b5968b67e3ca1f4cc64445d7a25 100644 (file)
@@ -32,7 +32,7 @@
 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  57
-#define LIBAVFORMAT_VERSION_MINOR  74
+#define LIBAVFORMAT_VERSION_MINOR  75
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \