# HG changeset patch # User benoit # Date 1192114667 0 # Node ID fc7f8ee4700b5dccaec1caedd9a37c7ac8e54928 # Parent eb7808a9d3618e9761bb2d6a295497d4b8d4d0a5 Add functionality to set the direction of a ByteIOContext buffer. Patch by Bj«Órn Axelsson bjorn axelsson intinor se Original thread: [FFmpeg-devel] [PATCH] MMS protocol support patch 1 Date: 09/19/2007 05:51 PM diff -r eb7808a9d361 -r fc7f8ee4700b avio.h --- a/avio.h Wed Oct 10 22:59:36 2007 +0000 +++ b/avio.h Thu Oct 11 14:57:47 2007 +0000 @@ -203,6 +203,11 @@ /** @warning must be called before any I/O */ int url_setbufsize(ByteIOContext *s, int buf_size); +/** Reset the buffer for reading or writing. + * @note Will drop any data currently in the buffer without transmitting it. + * @param flags URL_RDONLY to set up the buffer for reading, or URL_WRONLY + * to set up the buffer for writing. */ +int url_resetbuf(ByteIOContext *s, int flags); /** @note when opened as read/write, the buffers are only used for writing */ diff -r eb7808a9d361 -r fc7f8ee4700b aviobuf.c --- a/aviobuf.c Wed Oct 10 22:59:36 2007 +0000 +++ b/aviobuf.c Thu Oct 11 14:57:47 2007 +0000 @@ -38,11 +38,7 @@ s->buffer = buffer; s->buffer_size = buffer_size; s->buf_ptr = buffer; - s->write_flag = write_flag; - if (!s->write_flag) - s->buf_end = buffer; - else - s->buf_end = buffer + buffer_size; + url_resetbuf(s, write_flag ? URL_WRONLY : URL_RDONLY); s->opaque = opaque; s->write_packet = write_packet; s->read_packet = read_packet; @@ -534,10 +530,23 @@ s->buffer = buffer; s->buffer_size = buf_size; s->buf_ptr = buffer; - if (!s->write_flag) - s->buf_end = buffer; - else - s->buf_end = buffer + buf_size; + url_resetbuf(s, s->write_flag ? URL_WRONLY : URL_RDONLY); + return 0; +} + +int url_resetbuf(ByteIOContext *s, int flags) +{ + URLContext *h = s->opaque; + if ((flags & URL_RDWR) || (h && h->flags != flags && !h->flags & URL_RDWR)) + return AVERROR(EINVAL); + + if (flags & URL_WRONLY) { + s->buf_end = s->buffer + s->buffer_size; + s->write_flag = 1; + } else { + s->buf_end = s->buffer; + s->write_flag = 0; + } return 0; }