diff mbox series

[FFmpeg-devel,v3,1/3] avformat/avio: privatize point of truth for AVIOContext::written

Message ID 20211018124723.11497-2-jeebjp@gmail.com
State Accepted
Commit d39b58dc32b5fc7b480eeb9ef00a610732f02c2c
Headers show
Series introduce public AVIOContext::bytes_{read, written}
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Jan Ekström Oct. 18, 2021, 12:47 p.m. UTC
Looking at 3f75e5116b900f1428aa13041fc7d6301bf1988a, the field
was supposed to be private, but during merging the field and the
group that had the comment about it got separated.

Thus, move the actual privately utilized state of this variable
into the private FFIOContext. Additionally, name the private field
somewhat better, so that it does not get confused with the amount
of bytes written out.
---
 libavformat/avio_internal.h |  6 ++++++
 libavformat/aviobuf.c       | 11 +++++++----
 2 files changed, 13 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h
index eded38759b..467e80701f 100644
--- a/libavformat/avio_internal.h
+++ b/libavformat/avio_internal.h
@@ -66,6 +66,12 @@  typedef struct FFIOContext {
      * used after probing to ensure seekback and to reset the buffer size
      */
     int orig_buffer_size;
+
+    /**
+     * Written output size
+     * is updated each time a successful writeout ends up further position-wise
+     */
+    int64_t written_output_size;
 } FFIOContext;
 
 static av_always_inline FFIOContext *ffiocontext(AVIOContext *ctx)
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 3d87d66091..b18a56ef19 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -164,8 +164,10 @@  static void writeout(AVIOContext *s, const uint8_t *data, int len)
         if (ret < 0) {
             s->error = ret;
         } else {
-            if (s->pos + len > s->written)
-                s->written = s->pos + len;
+            if (s->pos + len > ctx->written_output_size) {
+                ctx->written_output_size = s->pos + len;
+                s->written = ctx->written_output_size;
+            }
         }
     }
     if (ctx->current_type == AVIO_DATA_MARKER_SYNC_POINT ||
@@ -337,13 +339,14 @@  int64_t avio_skip(AVIOContext *s, int64_t offset)
 
 int64_t avio_size(AVIOContext *s)
 {
+    FFIOContext *const ctx = ffiocontext(s);
     int64_t size;
 
     if (!s)
         return AVERROR(EINVAL);
 
-    if (s->written)
-        return s->written;
+    if (ctx->written_output_size)
+        return ctx->written_output_size;
 
     if (!s->seek)
         return AVERROR(ENOSYS);