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

Michael Niedermayer michael at niedermayer.cc
Fri Oct 15 16:07:02 EEST 2021


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

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I am the wisest man alive, for I know one thing, and that is that I know
nothing. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20211015/63f1257c/attachment.sig>


More information about the ffmpeg-devel mailing list