History

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.

Jan Ekström committed 5 years ago

Commit 682bafd1 parent a5622ed5 files · +30 −4Browse files

Unified · Split

5 files
  1. doc/APIchanges +3 −0
  2. libavformat/avio.h +13 −1
  3. libavformat/avio_internal.h +5 −0
  4. libavformat/aviobuf.c +8 −2
  5. libavformat/version.h +1 −1
doc/APIchanges+3−0
@@ -14,6 +14,9 @@ libavutil: 2021-04-27 · 13 unmodified lines
1414
1515 API changes, most recent first:
1616
17+2021-10-18 - xxxxxxxxxx - lavf 59.8.100 - avio.h
18+ Introduce public bytes_{read,written} statistic fields to AVIOContext.
19+
1720 2021-10-13 - xxxxxxxxxx - lavf 59.7.100 - avio.h
1821 Deprecate AVIOContext.written. Originally added as a private entry in
1922 commit 3f75e5116b900f1428aa13041fc7d6301bf1988a, its grouping with
libavformat/avio.h+13−1
@@ -292,7 +292,9 @@ typedef struct AVIOContext { · 291 unmodified lines
292292
293293 #if FF_API_AVIOCONTEXT_WRITTEN
294294 /**
295− * @deprecated field utilized privately by libavformat.
295+ * @deprecated field utilized privately by libavformat. For a public
296+ * statistic of how many bytes were written out, see
297+ * AVIOContext::bytes_written.
296298 */
297299 attribute_deprecated
298300 int64_t written;
@@ -303,6 +305,16 @@ typedef struct AVIOContext { · 4 unmodified lines
303305 * used keeping track of already written data for a later flush.
304306 */
305307 unsigned char *buf_ptr_max;
308+
309+ /**
310+ * Read-only statistic of bytes read for this AVIOContext.
311+ */
312+ int64_t bytes_read;
313+
314+ /**
315+ * Read-only statistic of bytes written for this AVIOContext.
316+ */
317+ int64_t bytes_written;
306318 } AVIOContext;
307319
308320 /**
libavformat/avio_internal.h+5−0
@@ -51,6 +51,11 @@ typedef struct FFIOContext { · 50 unmodified lines
5151 */
5252 int64_t bytes_read;
5353
54+ /**
55+ * Bytes written statistic
56+ */
57+ int64_t bytes_written;
58+
5459 /**
5560 * seek statistic
5661 */
libavformat/aviobuf.c+8−2
@@ -169,6 +169,9 @@ static void writeout(AVIOContext *s, const uint8_t *data, int len) · 168 unmodified lines
169169 if (ret < 0) {
170170 s->error = ret;
171171 } else {
172+ ctx->bytes_written += len;
173+ s->bytes_written = ctx->bytes_written;
174+
172175 if (s->pos + len > ctx->written_output_size) {
173176 ctx->written_output_size = s->pos + len;
174177 #if FF_API_AVIOCONTEXT_WRITTEN
@@ -584,6 +587,7 @@ static void fill_buffer(AVIOContext *s) · 409 unmodified lines
584587 s->buf_ptr = dst;
585588 s->buf_end = dst + len;
586589 ffiocontext(s)->bytes_read += len;
590+ s->bytes_read = ffiocontext(s)->bytes_read;
587591 }
588592 }
589593
@@ -657,6 +661,7 @@ int avio_read(AVIOContext *s, unsigned char *buf, int size) · 67 unmodified lines
657661 } else {
658662 s->pos += len;
659663 ffiocontext(s)->bytes_read += len;
664+ s->bytes_read = ffiocontext(s)->bytes_read;
660665 size -= len;
661666 buf += len;
662667 // reset the buffer
@@ -1236,8 +1241,9 @@ int avio_close(AVIOContext *s) · 573 unmodified lines
12361241
12371242 av_freep(&s->buffer);
12381243 if (s->write_flag)
1239− av_log(s, AV_LOG_VERBOSE, "Statistics: %d seeks, %d writeouts\n",
1240− ctx->seek_count, ctx->writeout_count);
1244+ av_log(s, AV_LOG_VERBOSE,
1245+ "Statistics: %"PRId64" bytes written, %d seeks, %d writeouts\n",
1246+ ctx->bytes_written, ctx->seek_count, ctx->writeout_count);
12411247 else
12421248 av_log(s, AV_LOG_VERBOSE, "Statistics: %"PRId64" bytes read, %d seeks\n",
12431249 ctx->bytes_read, ctx->seek_count);
libavformat/version.h+1−1
@@ -32,7 +32,7 @@ · 31 unmodified lines
3232 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
3333 // Also please add any ticket numbers that you believe might be affected here
3434 #define LIBAVFORMAT_VERSION_MAJOR 59
35−#define LIBAVFORMAT_VERSION_MINOR 7
35+#define LIBAVFORMAT_VERSION_MINOR 8
3636 #define LIBAVFORMAT_VERSION_MICRO 100
3737
3838 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t