avio: Keep track of the amount of data written
authorLuca Barbato <lu_zero@gentoo.org>
Tue, 6 Dec 2016 01:56:24 +0000 (02:56 +0100)
committerVittorio Giovara <vittorio.giovara@gmail.com>
Thu, 8 Dec 2016 20:58:28 +0000 (15:58 -0500)
Make avio_size() work with any write AVIOContext.

libavformat/avio.h
libavformat/aviobuf.c
libavformat/version.h

index 49721aa..7bf7985 100644 (file)
@@ -176,6 +176,7 @@ typedef struct AVIOContext {
      */
     enum AVIODataMarkerType current_type;
     int64_t last_time;
      */
     enum AVIODataMarkerType current_type;
     int64_t last_time;
+    int64_t written;
 } AVIOContext;
 
 /**
 } AVIOContext;
 
 /**
index 5cb733d..6d83a96 100644 (file)
@@ -168,18 +168,22 @@ AVIOContext *avio_alloc_context(
 static void flush_buffer(AVIOContext *s)
 {
     if (s->buf_ptr > s->buffer) {
 static void flush_buffer(AVIOContext *s)
 {
     if (s->buf_ptr > s->buffer) {
+        int size = s->buf_ptr - s->buffer;
         if (!s->error) {
             int ret = 0;
             if (s->write_data_type)
                 ret = s->write_data_type(s->opaque, s->buffer,
         if (!s->error) {
             int ret = 0;
             if (s->write_data_type)
                 ret = s->write_data_type(s->opaque, s->buffer,
-                                         s->buf_ptr - s->buffer,
+                                         size,
                                          s->current_type,
                                          s->last_time);
             else if (s->write_packet)
                 ret = s->write_packet(s->opaque, s->buffer,
                                          s->current_type,
                                          s->last_time);
             else if (s->write_packet)
                 ret = s->write_packet(s->opaque, s->buffer,
-                                      s->buf_ptr - s->buffer);
+                                      size);
             if (ret < 0) {
                 s->error = ret;
             if (ret < 0) {
                 s->error = ret;
+            } else {
+                if (s->pos + size > s->written)
+                    s->written = s->pos + size;
             }
         }
         if (s->current_type == AVIO_DATA_MARKER_SYNC_POINT ||
             }
         }
         if (s->current_type == AVIO_DATA_MARKER_SYNC_POINT ||
@@ -192,7 +196,7 @@ static void flush_buffer(AVIOContext *s)
                                                  s->buf_ptr - s->checksum_ptr);
             s->checksum_ptr = s->buffer;
         }
                                                  s->buf_ptr - s->checksum_ptr);
             s->checksum_ptr = s->buffer;
         }
-        s->pos += s->buf_ptr - s->buffer;
+        s->pos += size;
     }
     s->buf_ptr = s->buffer;
 }
     }
     s->buf_ptr = s->buffer;
 }
@@ -301,6 +305,9 @@ int64_t avio_size(AVIOContext *s)
     if (!s)
         return AVERROR(EINVAL);
 
     if (!s)
         return AVERROR(EINVAL);
 
+    if (s->written)
+        return s->written;
+
     if (!s->seek)
         return AVERROR(ENOSYS);
     size = s->seek(s->opaque, 0, AVSEEK_SIZE);
     if (!s->seek)
         return AVERROR(ENOSYS);
     size = s->seek(s->opaque, 0, AVSEEK_SIZE);
index ad7997e..3fa2c44 100644 (file)
@@ -31,7 +31,7 @@
 
 #define LIBAVFORMAT_VERSION_MAJOR 57
 #define LIBAVFORMAT_VERSION_MINOR 10
 
 #define LIBAVFORMAT_VERSION_MAJOR 57
 #define LIBAVFORMAT_VERSION_MINOR 10
-#define LIBAVFORMAT_VERSION_MICRO  1
+#define LIBAVFORMAT_VERSION_MICRO  2
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \