summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorJan Ekström <jeebjp@gmail.com>2021-10-18 00:35:48 +0300
committerJan Ekström <jeebjp@gmail.com>2021-10-24 13:04:39 +0300
commit682bafdb12507ec8b049ecbbe2e48bf814927002 (patch)
treec2e7df981e2c02d9f5013d8f2d2242f131bfad77 /libavformat
parenta5622ed16f8e22a80cecd8936799e61f61a74cd5 (diff)
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.
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/avio.h14
-rw-r--r--libavformat/avio_internal.h5
-rw-r--r--libavformat/aviobuf.c10
-rw-r--r--libavformat/version.h2
4 files changed, 27 insertions, 4 deletions
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
@@ -52,6 +52,11 @@ typedef struct FFIOContext {
int64_t bytes_read;
/**
+ * Bytes written statistic
+ */
+ int64_t bytes_written;
+
+ /**
* seek statistic
*/
int seek_count;
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, \