diff mbox series

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

Message ID 20211013211038.13391-2-jeebjp@gmail.com
State New
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. 13, 2021, 9:10 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.
---
 libavformat/avio_internal.h |  5 +++++
 libavformat/aviobuf.c       | 11 +++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)

Comments

Michael Niedermayer Oct. 15, 2021, 1:07 p.m. UTC | #1
On Thu, Oct 14, 2021 at 12:10:36AM +0300, Jan Ekström wrote:
> 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.
> ---
>  libavformat/avio_internal.h |  5 +++++
>  libavformat/aviobuf.c       | 11 +++++++----
>  2 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h
> index eded38759b..28ea38079d 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 3d87d66091..7afbff0266 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->bytes_written) {
> +                ctx->bytes_written = s->pos + len;
> +                s->written = ctx->bytes_written;
> +            }
>          }
>      }
>      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->bytes_written)
> +        return ctx->bytes_written;

looking at this again, it doesnt look like "written" is what "bytes_written" is
if s->written represents the file size as avio_size() returns then
thats different from the number of bytes written statistic as soon as any
seeking has happened

[...]
diff mbox series

Patch

diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h
index eded38759b..28ea38079d 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 3d87d66091..7afbff0266 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->bytes_written) {
+                ctx->bytes_written = s->pos + len;
+                s->written = ctx->bytes_written;
+            }
         }
     }
     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->bytes_written)
+        return ctx->bytes_written;
 
     if (!s->seek)
         return AVERROR(ENOSYS);