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.
pull/373/head
Jan Ekström 3 years ago
parent a5622ed16f
commit 682bafdb12
  1. 3
      doc/APIchanges
  2. 14
      libavformat/avio.h
  3. 5
      libavformat/avio_internal.h
  4. 10
      libavformat/aviobuf.c
  5. 2
      libavformat/version.h

@ -14,6 +14,9 @@ libavutil: 2021-04-27
API changes, most recent first: 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 2021-10-13 - xxxxxxxxxx - lavf 59.7.100 - avio.h
Deprecate AVIOContext.written. Originally added as a private entry in Deprecate AVIOContext.written. Originally added as a private entry in
commit 3f75e5116b900f1428aa13041fc7d6301bf1988a, its grouping with commit 3f75e5116b900f1428aa13041fc7d6301bf1988a, its grouping with

@ -292,7 +292,9 @@ typedef struct AVIOContext {
#if FF_API_AVIOCONTEXT_WRITTEN #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 attribute_deprecated
int64_t written; int64_t written;
@ -303,6 +305,16 @@ typedef struct AVIOContext {
* used keeping track of already written data for a later flush. * used keeping track of already written data for a later flush.
*/ */
unsigned char *buf_ptr_max; 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; } AVIOContext;
/** /**

@ -51,6 +51,11 @@ typedef struct FFIOContext {
*/ */
int64_t bytes_read; int64_t bytes_read;
/**
* Bytes written statistic
*/
int64_t bytes_written;
/** /**
* seek statistic * seek statistic
*/ */

@ -169,6 +169,9 @@ static void writeout(AVIOContext *s, const uint8_t *data, int len)
if (ret < 0) { if (ret < 0) {
s->error = ret; s->error = ret;
} else { } else {
ctx->bytes_written += len;
s->bytes_written = ctx->bytes_written;
if (s->pos + len > ctx->written_output_size) { if (s->pos + len > ctx->written_output_size) {
ctx->written_output_size = s->pos + len; ctx->written_output_size = s->pos + len;
#if FF_API_AVIOCONTEXT_WRITTEN #if FF_API_AVIOCONTEXT_WRITTEN
@ -584,6 +587,7 @@ static void fill_buffer(AVIOContext *s)
s->buf_ptr = dst; s->buf_ptr = dst;
s->buf_end = dst + len; s->buf_end = dst + len;
ffiocontext(s)->bytes_read += 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 { } else {
s->pos += len; s->pos += len;
ffiocontext(s)->bytes_read += len; ffiocontext(s)->bytes_read += len;
s->bytes_read = ffiocontext(s)->bytes_read;
size -= len; size -= len;
buf += len; buf += len;
// reset the buffer // reset the buffer
@ -1236,8 +1241,9 @@ int avio_close(AVIOContext *s)
av_freep(&s->buffer); av_freep(&s->buffer);
if (s->write_flag) if (s->write_flag)
av_log(s, AV_LOG_VERBOSE, "Statistics: %d seeks, %d writeouts\n", av_log(s, AV_LOG_VERBOSE,
ctx->seek_count, ctx->writeout_count); "Statistics: %"PRId64" bytes written, %d seeks, %d writeouts\n",
ctx->bytes_written, ctx->seek_count, ctx->writeout_count);
else else
av_log(s, AV_LOG_VERBOSE, "Statistics: %"PRId64" bytes read, %d seeks\n", av_log(s, AV_LOG_VERBOSE, "Statistics: %"PRId64" bytes read, %d seeks\n",
ctx->bytes_read, ctx->seek_count); ctx->bytes_read, ctx->seek_count);

@ -32,7 +32,7 @@
// Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium) // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
// Also please add any ticket numbers that you believe might be affected here // Also please add any ticket numbers that you believe might be affected here
#define LIBAVFORMAT_VERSION_MAJOR 59 #define LIBAVFORMAT_VERSION_MAJOR 59
#define LIBAVFORMAT_VERSION_MINOR 7 #define LIBAVFORMAT_VERSION_MINOR 8
#define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \

Loading…
Cancel
Save