diff options
author | Martin Storsjö <martin@martin.st> | 2013-09-18 22:50:50 +0400 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2013-09-19 23:42:37 +0400 |
commit | 3627ce2f1dab1d33b7f99d78907a3e4d86b7d847 (patch) | |
tree | bb6eef3471870fd73cfeb23b4a8c482d75cdf2cb /libavformat/aviobuf.c | |
parent | bb461370e34b1fa1637f34ce7d37b934ddb472d5 (diff) |
aviobuf: Add functions for null buffers
Null buffers are useful for simulating writing to a real buffer
for the sake of measuring how many bytes are written.
Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/aviobuf.c')
-rw-r--r-- | libavformat/aviobuf.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 7d76e0b1b0..3f27d6976c 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -975,3 +975,36 @@ int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer) av_free(s); return size - padding; } + +static int null_buf_write(void *opaque, uint8_t *buf, int buf_size) +{ + DynBuffer *d = opaque; + + d->pos += buf_size; + if (d->pos > d->size) + d->size = d->pos; + return buf_size; +} + +int ffio_open_null_buf(AVIOContext **s) +{ + int ret = url_open_dyn_buf_internal(s, 0); + if (ret >= 0) { + AVIOContext *pb = *s; + pb->write_packet = null_buf_write; + } + return ret; +} + +int ffio_close_null_buf(AVIOContext *s) +{ + DynBuffer *d = s->opaque; + int size; + + avio_flush(s); + + size = d->size; + av_free(d); + av_free(s); + return size; +} |