[FFmpeg-cvslog] avformat/avio{,buf}: introduce public AVIOContext::bytes_{read,written}

Jan Ekström git at videolan.org
Sun Oct 24 13:08:14 EEST 2021


ffmpeg | branch: master | Jan Ekström <jeebjp at gmail.com> | Mon Oct 18 00:35:48 2021 +0300| [682bafdb12507ec8b049ecbbe2e48bf814927002] | committer: Jan Ekström

avformat/avio{,buf}: introduce public AVIOContext::bytes_{read,written}

Such fields can be seen as generally useful in cases where the
API user is not implementing custom AVIO callbacks, but still would
like to know if data is being read or written out, such as in case
data is being read from input but no AVPacket has been received yet.

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

 doc/APIchanges              |  3 +++
 libavformat/avio.h          | 14 +++++++++++++-
 libavformat/avio_internal.h |  5 +++++
 libavformat/aviobuf.c       | 10 ++++++++--
 libavformat/version.h       |  2 +-
 5 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 4731e14cb1..99e185ee4e 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,9 @@ libavutil:     2021-04-27
 
 API changes, most recent first:
 
+2021-10-18 - xxxxxxxxxx - lavf 59.8.100 - avio.h
+  Introduce public bytes_{read,written} statistic fields to AVIOContext.
+
 2021-10-13 - xxxxxxxxxx - lavf 59.7.100 - avio.h
   Deprecate AVIOContext.written. Originally added as a private entry in
   commit 3f75e5116b900f1428aa13041fc7d6301bf1988a, its grouping with
diff --git a/libavformat/avio.h b/libavformat/avio.h
index 5e60c2e35c..cd63322a62 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -292,7 +292,9 @@ typedef struct AVIOContext {
 
 #if FF_API_AVIOCONTEXT_WRITTEN
     /**
-     * @deprecated field utilized privately by libavformat.
+     * @deprecated field utilized privately by libavformat. For a public
+     *             statistic of how many bytes were written out, see
+     *             AVIOContext::bytes_written.
      */
     attribute_deprecated
     int64_t written;
@@ -303,6 +305,16 @@ typedef struct AVIOContext {
      * used keeping track of already written data for a later flush.
      */
     unsigned char *buf_ptr_max;
+
+    /**
+     * Read-only statistic of bytes read for this AVIOContext.
+     */
+    int64_t bytes_read;
+
+    /**
+     * Read-only statistic of bytes written for this AVIOContext.
+     */
+    int64_t bytes_written;
 } AVIOContext;
 
 /**
diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h
index 467e80701f..187433f283 100644
--- a/libavformat/avio_internal.h
+++ b/libavformat/avio_internal.h
@@ -51,6 +51,11 @@ typedef struct FFIOContext {
      */
     int64_t bytes_read;
 
+    /**
+     * Bytes written statistic
+     */
+    int64_t bytes_written;
+
     /**
      * seek statistic
      */
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index f21f1c89df..5da4dea7b6 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -169,6 +169,9 @@ static void writeout(AVIOContext *s, const uint8_t *data, int len)
         if (ret < 0) {
             s->error = ret;
         } else {
+            ctx->bytes_written += len;
+            s->bytes_written = ctx->bytes_written;
+
             if (s->pos + len > ctx->written_output_size) {
                 ctx->written_output_size = s->pos + len;
 #if FF_API_AVIOCONTEXT_WRITTEN
@@ -584,6 +587,7 @@ static void fill_buffer(AVIOContext *s)
         s->buf_ptr = dst;
         s->buf_end = dst + len;
         ffiocontext(s)->bytes_read += len;
+        s->bytes_read = ffiocontext(s)->bytes_read;
     }
 }
 
@@ -657,6 +661,7 @@ int avio_read(AVIOContext *s, unsigned char *buf, int size)
                 } else {
                     s->pos += len;
                     ffiocontext(s)->bytes_read += len;
+                    s->bytes_read = ffiocontext(s)->bytes_read;
                     size -= len;
                     buf += len;
                     // reset the buffer
@@ -1236,8 +1241,9 @@ int avio_close(AVIOContext *s)
 
     av_freep(&s->buffer);
     if (s->write_flag)
-        av_log(s, AV_LOG_VERBOSE, "Statistics: %d seeks, %d writeouts\n",
-               ctx->seek_count, ctx->writeout_count);
+        av_log(s, AV_LOG_VERBOSE,
+               "Statistics: %"PRId64" bytes written, %d seeks, %d writeouts\n",
+               ctx->bytes_written, ctx->seek_count, ctx->writeout_count);
     else
         av_log(s, AV_LOG_VERBOSE, "Statistics: %"PRId64" bytes read, %d seeks\n",
                ctx->bytes_read, ctx->seek_count);
diff --git a/libavformat/version.h b/libavformat/version.h
index de780124c7..81ed517609 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -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  59
-#define LIBAVFORMAT_VERSION_MINOR   7
+#define LIBAVFORMAT_VERSION_MINOR   8
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list