* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
+#include "libavutil/crc.h"
+#include "libavutil/intreadwrite.h"
#include "avformat.h"
#include "avio.h"
+#include "internal.h"
#include <stdarg.h>
#define IO_BUFFER_SIZE 32768
+/**
+ * Do seeks within this distance ahead of the current buffer by skipping
+ * data instead of calling the protocol seek function, for seekable
+ * protocols.
+ */
+#define SHORT_SEEK_THRESHOLD 4096
+
static void fill_buffer(ByteIOContext *s);
+#if !FF_API_URL_RESETBUF
+static int url_resetbuf(ByteIOContext *s, int flags);
+#endif
int init_put_byte(ByteIOContext *s,
unsigned char *buffer,
void *opaque,
int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
- offset_t (*seek)(void *opaque, offset_t offset, int whence))
+ int64_t (*seek)(void *opaque, int64_t offset, int whence))
{
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;
s->opaque = opaque;
+ url_resetbuf(s, write_flag ? URL_WRONLY : URL_RDONLY);
s->write_packet = write_packet;
s->read_packet = read_packet;
s->seek = seek;
s->pos = buffer_size;
s->buf_end = s->buffer + buffer_size;
}
+ s->read_pause = NULL;
+ s->read_seek = NULL;
return 0;
}
+ByteIOContext *av_alloc_put_byte(
+ unsigned char *buffer,
+ int buffer_size,
+ int write_flag,
+ void *opaque,
+ int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
+ int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
+ int64_t (*seek)(void *opaque, int64_t offset, int whence))
+{
+ ByteIOContext *s = av_mallocz(sizeof(ByteIOContext));
+ init_put_byte(s, buffer, buffer_size, write_flag, opaque,
+ read_packet, write_packet, seek);
+ return s;
+}
+
static void flush_buffer(ByteIOContext *s)
{
if (s->buf_ptr > s->buffer) {
void put_buffer(ByteIOContext *s, const unsigned char *buf, int size)
{
- int len;
-
while (size > 0) {
- len = (s->buf_end - s->buf_ptr);
- if (len > size)
- len = size;
+ int len = FFMIN(s->buf_end - s->buf_ptr, size);
memcpy(s->buf_ptr, buf, len);
s->buf_ptr += len;
s->must_flush = 0;
}
-offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence)
+int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence)
{
- offset_t offset1;
- offset_t pos= s->pos - (s->write_flag ? 0 : (s->buf_end - s->buffer));
+ int64_t offset1;
+ int64_t pos;
+ int force = whence & AVSEEK_FORCE;
+ whence &= ~AVSEEK_FORCE;
+
+ if(!s)
+ return AVERROR(EINVAL);
+
+ pos = s->pos - (s->write_flag ? 0 : (s->buf_end - s->buffer));
if (whence != SEEK_CUR && whence != SEEK_SET)
- return -EINVAL;
+ return AVERROR(EINVAL);
if (whence == SEEK_CUR) {
offset1 = pos + (s->buf_ptr - s->buffer);
}
offset1 = offset - pos;
if (!s->must_flush &&
- offset1 >= 0 && offset1 < (s->buf_end - s->buffer)) {
+ offset1 >= 0 && offset1 <= (s->buf_end - s->buffer)) {
/* can do the seek inside the buffer */
s->buf_ptr = s->buffer + offset1;
- } else if(s->is_streamed && !s->write_flag &&
- offset1 >= 0 && offset1 < (s->buf_end - s->buffer) + (1<<16)){
+ } else if ((s->is_streamed ||
+ offset1 <= s->buf_end + SHORT_SEEK_THRESHOLD - s->buffer) &&
+ !s->write_flag && offset1 >= 0 &&
+ (whence != SEEK_END || force)) {
while(s->pos < offset && !s->eof_reached)
fill_buffer(s);
+ if (s->eof_reached)
+ return AVERROR_EOF;
s->buf_ptr = s->buf_end + offset - s->pos;
} else {
-#ifdef CONFIG_MUXERS
+ int64_t res;
+
+#if CONFIG_MUXERS || CONFIG_NETWORK
if (s->write_flag) {
flush_buffer(s);
s->must_flush = 1;
- } else
-#endif //CONFIG_MUXERS
- {
- s->buf_end = s->buffer;
}
+#endif /* CONFIG_MUXERS || CONFIG_NETWORK */
+ if (!s->seek)
+ return AVERROR(EPIPE);
+ if ((res = s->seek(s->opaque, offset, SEEK_SET)) < 0)
+ return res;
+ if (!s->write_flag)
+ s->buf_end = s->buffer;
s->buf_ptr = s->buffer;
- if (!s->seek || s->seek(s->opaque, offset, SEEK_SET) == (offset_t)-EPIPE)
- return -EPIPE;
s->pos = offset;
}
s->eof_reached = 0;
return offset;
}
-void url_fskip(ByteIOContext *s, offset_t offset)
+int url_fskip(ByteIOContext *s, int64_t offset)
{
- url_fseek(s, offset, SEEK_CUR);
+ int64_t ret = url_fseek(s, offset, SEEK_CUR);
+ return ret < 0 ? ret : 0;
}
-offset_t url_ftell(ByteIOContext *s)
+int64_t url_ftell(ByteIOContext *s)
{
return url_fseek(s, 0, SEEK_CUR);
}
-offset_t url_fsize(ByteIOContext *s)
+int64_t url_fsize(ByteIOContext *s)
{
- offset_t size;
+ int64_t size;
+
+ if(!s)
+ return AVERROR(EINVAL);
if (!s->seek)
- return -EPIPE;
- size = s->seek(s->opaque, -1, SEEK_END) + 1;
- s->seek(s->opaque, s->pos, SEEK_SET);
+ return AVERROR(ENOSYS);
+ size = s->seek(s->opaque, 0, AVSEEK_SIZE);
+ if(size<0){
+ if ((size = s->seek(s->opaque, -1, SEEK_END)) < 0)
+ return size;
+ size++;
+ s->seek(s->opaque, s->pos, SEEK_SET);
+ }
return size;
}
int url_feof(ByteIOContext *s)
{
+ if(!s)
+ return 0;
return s->eof_reached;
}
int url_ferror(ByteIOContext *s)
{
+ if(!s)
+ return 0;
return s->error;
}
-#if defined(CONFIG_MUXERS) || defined(CONFIG_PROTOCOLS)
void put_le32(ByteIOContext *s, unsigned int val)
{
put_byte(s, val);
put_byte(s, 0);
}
+int ff_get_v_length(uint64_t val){
+ int i=1;
+
+ while(val>>=7)
+ i++;
+
+ return i;
+}
+
+void ff_put_v(ByteIOContext *bc, uint64_t val){
+ int i= ff_get_v_length(val);
+
+ while(--i>0)
+ put_byte(bc, 128 | (val>>(7*i)));
+
+ put_byte(bc, val&127);
+}
+
void put_le64(ByteIOContext *s, uint64_t val)
{
put_le32(s, (uint32_t)(val & 0xffffffff));
put_byte(s, *tag++);
}
}
-#endif //CONFIG_MUXERS || CONFIG_PROTOCOLS
/* Input stream */
static void fill_buffer(ByteIOContext *s)
{
- int len;
+ uint8_t *dst= !s->max_packet_size && s->buf_end - s->buffer < s->buffer_size ? s->buf_ptr : s->buffer;
+ int len= s->buffer_size - (dst - s->buffer);
+ int max_buffer_size = s->max_packet_size ? s->max_packet_size : IO_BUFFER_SIZE;
/* no need to do anything if EOF already reached */
if (s->eof_reached)
return;
- if(s->update_checksum){
+ if(s->update_checksum && dst == s->buffer){
if(s->buf_end > s->checksum_ptr)
s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_end - s->checksum_ptr);
s->checksum_ptr= s->buffer;
}
- len = s->read_packet(s->opaque, s->buffer, s->buffer_size);
+ /* make buffer smaller in case it ended up large after probing */
+ if (s->buffer_size > max_buffer_size) {
+ url_setbufsize(s, max_buffer_size);
+
+ s->checksum_ptr = dst = s->buffer;
+ len = s->buffer_size;
+ }
+
+ if(s->read_packet)
+ len = s->read_packet(s->opaque, dst, len);
+ else
+ len = 0;
if (len <= 0) {
/* do not modify buffer if EOF reached so that a seek back can
be done without rereading data */
s->eof_reached = 1;
- if(len<0)
- s->error= len;
+ if(len<0)
+ s->error= len;
} else {
s->pos += len;
- s->buf_ptr = s->buffer;
- s->buf_end = s->buffer + len;
+ s->buf_ptr = dst;
+ s->buf_end = dst + len;
}
}
-unsigned long get_checksum(ByteIOContext *s){
+unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
+ unsigned int len)
+{
+ return av_crc(av_crc_get_table(AV_CRC_32_IEEE), checksum, buf, len);
+}
+
+unsigned long get_checksum(ByteIOContext *s)
+{
s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr - s->checksum_ptr);
s->update_checksum= NULL;
return s->checksum;
}
-void init_checksum(ByteIOContext *s, unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum){
+void init_checksum(ByteIOContext *s,
+ unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
+ unsigned long checksum)
+{
s->update_checksum= update_checksum;
if(s->update_checksum){
s->checksum= checksum;
}
}
-/* NOTE: return 0 if EOF, so you cannot use it if EOF handling is
- necessary */
/* XXX: put an inline version */
int get_byte(ByteIOContext *s)
{
- if (s->buf_ptr < s->buf_end) {
- return *s->buf_ptr++;
- } else {
+ if (s->buf_ptr >= s->buf_end)
fill_buffer(s);
- if (s->buf_ptr < s->buf_end)
- return *s->buf_ptr++;
- else
- return 0;
- }
+ if (s->buf_ptr < s->buf_end)
+ return *s->buf_ptr++;
+ return 0;
}
-/* NOTE: return URL_EOF (-1) if EOF */
int url_fgetc(ByteIOContext *s)
{
- if (s->buf_ptr < s->buf_end) {
- return *s->buf_ptr++;
- } else {
+ if (s->buf_ptr >= s->buf_end)
fill_buffer(s);
- if (s->buf_ptr < s->buf_end)
- return *s->buf_ptr++;
- else
- return URL_EOF;
- }
+ if (s->buf_ptr < s->buf_end)
+ return *s->buf_ptr++;
+ return URL_EOF;
}
int get_buffer(ByteIOContext *s, unsigned char *buf, int size)
len = size;
if (len == 0) {
if(size > s->buffer_size && !s->update_checksum){
- len = s->read_packet(s->opaque, buf, size);
+ if(s->read_packet)
+ len = s->read_packet(s->opaque, buf, size);
if (len <= 0) {
/* do not modify buffer if EOF reached so that a seek back can
be done without rereading data */
size -= len;
}
}
+ if (size1 == size) {
+ if (url_ferror(s)) return url_ferror(s);
+ if (url_feof(s)) return AVERROR_EOF;
+ }
return size1 - size;
}
len = size;
memcpy(buf, s->buf_ptr, len);
s->buf_ptr += len;
+ if (!len) {
+ if (url_ferror(s)) return url_ferror(s);
+ if (url_feof(s)) return AVERROR_EOF;
+ }
return len;
}
return buf;
}
+int ff_get_line(ByteIOContext *s, char *buf, int maxlen)
+{
+ int i = 0;
+ char c;
+
+ do {
+ c = get_byte(s);
+ if (c && i < maxlen-1)
+ buf[i++] = c;
+ } while (c != '\n' && c);
+
+ buf[i] = 0;
+ return i;
+}
+
uint64_t get_be64(ByteIOContext *s)
{
uint64_t val;
return val;
}
-/* link with avio functions */
+uint64_t ff_get_v(ByteIOContext *bc){
+ uint64_t val = 0;
+ int tmp;
-#ifdef CONFIG_MUXERS
-static int url_write_packet(void *opaque, uint8_t *buf, int buf_size)
-{
- URLContext *h = opaque;
- return url_write(h, buf, buf_size);
-}
-#else
-#define url_write_packet NULL
-#endif //CONFIG_MUXERS
-
-static int url_read_packet(void *opaque, uint8_t *buf, int buf_size)
-{
- URLContext *h = opaque;
- return url_read(h, buf, buf_size);
-}
-
-static offset_t url_seek_packet(void *opaque, offset_t offset, int whence)
-{
- URLContext *h = opaque;
- return url_seek(h, offset, whence);
- //return 0;
+ do{
+ tmp = get_byte(bc);
+ val= (val<<7) + (tmp&127);
+ }while(tmp&128);
+ return val;
}
-int url_fdopen(ByteIOContext *s, URLContext *h)
+int url_fdopen(ByteIOContext **s, URLContext *h)
{
uint8_t *buffer;
int buffer_size, max_packet_size;
-
max_packet_size = url_get_max_packet_size(h);
if (max_packet_size) {
buffer_size = max_packet_size; /* no need to bufferize more than one packet */
}
buffer = av_malloc(buffer_size);
if (!buffer)
- return -ENOMEM;
+ return AVERROR(ENOMEM);
+
+ *s = av_mallocz(sizeof(ByteIOContext));
+ if(!*s) {
+ av_free(buffer);
+ return AVERROR(ENOMEM);
+ }
- if (init_put_byte(s, buffer, buffer_size,
+ if (init_put_byte(*s, buffer, buffer_size,
(h->flags & URL_WRONLY || h->flags & URL_RDWR), h,
- url_read_packet, url_write_packet, url_seek_packet) < 0) {
+ url_read, url_write, url_seek) < 0) {
av_free(buffer);
- return AVERROR_IO;
+ av_freep(s);
+ return AVERROR(EIO);
+ }
+ (*s)->is_streamed = h->is_streamed;
+ (*s)->max_packet_size = max_packet_size;
+ if(h->prot) {
+ (*s)->read_pause = (int (*)(void *, int))h->prot->url_read_pause;
+ (*s)->read_seek = (int64_t (*)(void *, int, int64_t, int))h->prot->url_read_seek;
}
- s->is_streamed = h->is_streamed;
- s->max_packet_size = max_packet_size;
return 0;
}
-/* XXX: must be called before any I/O */
int url_setbufsize(ByteIOContext *s, int buf_size)
{
uint8_t *buffer;
buffer = av_malloc(buf_size);
if (!buffer)
- return -ENOMEM;
+ return AVERROR(ENOMEM);
av_free(s->buffer);
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;
+}
+
+#if FF_API_URL_RESETBUF
+int url_resetbuf(ByteIOContext *s, int flags)
+#else
+static int url_resetbuf(ByteIOContext *s, int flags)
+#endif
+{
+#if FF_API_URL_RESETBUF
+ if (flags & URL_RDWR)
+ return AVERROR(EINVAL);
+#else
+ assert(flags == URL_WRONLY || flags == URL_RDONLY);
+#endif
+
+ 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;
+}
+
+int ff_rewind_with_probe_data(ByteIOContext *s, unsigned char *buf, int buf_size)
+{
+ int64_t buffer_start;
+ int buffer_size;
+ int overlap, new_size, alloc_size;
+
+ if (s->write_flag)
+ return AVERROR(EINVAL);
+
+ buffer_size = s->buf_end - s->buffer;
+
+ /* the buffers must touch or overlap */
+ if ((buffer_start = s->pos - buffer_size) > buf_size)
+ return AVERROR(EINVAL);
+
+ overlap = buf_size - buffer_start;
+ new_size = buf_size + buffer_size - overlap;
+
+ alloc_size = FFMAX(s->buffer_size, new_size);
+ if (alloc_size > buf_size)
+ if (!(buf = av_realloc(buf, alloc_size)))
+ return AVERROR(ENOMEM);
+
+ if (new_size > buf_size) {
+ memcpy(buf + buf_size, s->buffer + overlap, buffer_size - overlap);
+ buf_size = new_size;
+ }
+
+ av_free(s->buffer);
+ s->buf_ptr = s->buffer = buf;
+ s->buffer_size = alloc_size;
+ s->pos = buf_size;
+ s->buf_end = s->buf_ptr + buf_size;
+ s->eof_reached = 0;
+ s->must_flush = 0;
+
return 0;
}
-/* NOTE: when opened as read/write, the buffers are only used for
- reading */
-int url_fopen(ByteIOContext *s, const char *filename, int flags)
+int url_fopen(ByteIOContext **s, const char *filename, int flags)
{
URLContext *h;
int err;
URLContext *h = s->opaque;
av_free(s->buffer);
- memset(s, 0, sizeof(ByteIOContext));
+ av_free(s);
return url_close(h);
}
return s->opaque;
}
-#ifdef CONFIG_MUXERS
-/* XXX: currently size is limited */
+#if CONFIG_MUXERS
int url_fprintf(ByteIOContext *s, const char *fmt, ...)
{
va_list ap;
}
#endif //CONFIG_MUXERS
-/* note: unlike fgets, the EOL character is not returned and a whole
- line is parsed. return NULL if first char read was EOF */
char *url_fgets(ByteIOContext *s, char *buf, int buf_size)
{
int c;
return buf;
}
-/*
- * Return the maximum packet size associated to packetized buffered file
- * handle. If the file is not packetized (stream like http or file on
- * disk), then 0 is returned.
- *
- * @param h buffered file handle
- * @return maximum packet size in bytes
- */
int url_fget_max_packet_size(ByteIOContext *s)
{
return s->max_packet_size;
}
-#ifdef CONFIG_MUXERS
+int av_url_read_fpause(ByteIOContext *s, int pause)
+{
+ if (!s->read_pause)
+ return AVERROR(ENOSYS);
+ return s->read_pause(s->opaque, pause);
+}
+
+int64_t av_url_read_fseek(ByteIOContext *s, int stream_index,
+ int64_t timestamp, int flags)
+{
+ URLContext *h = s->opaque;
+ int64_t ret;
+ if (!s->read_seek)
+ return AVERROR(ENOSYS);
+ ret = s->read_seek(h, stream_index, timestamp, flags);
+ if(ret >= 0) {
+ int64_t pos;
+ s->buf_ptr = s->buf_end; // Flush buffer
+ pos = s->seek(h, 0, SEEK_CUR);
+ if (pos >= 0)
+ s->pos = pos;
+ else if (pos != AVERROR(ENOSYS))
+ ret = pos;
+ }
+ return ret;
+}
+
+/* url_open_dyn_buf and url_close_dyn_buf are used in rtp.c to send a response
+ * back to the server even if CONFIG_MUXERS is false. */
+#if CONFIG_MUXERS || CONFIG_NETWORK
/* buffer handling */
-int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags)
+int url_open_buf(ByteIOContext **s, uint8_t *buf, int buf_size, int flags)
{
- return init_put_byte(s, buf, buf_size,
- (flags & URL_WRONLY || flags & URL_RDWR),
- NULL, NULL, NULL, NULL);
+ int ret;
+ *s = av_mallocz(sizeof(ByteIOContext));
+ if(!*s)
+ return AVERROR(ENOMEM);
+ ret = init_put_byte(*s, buf, buf_size,
+ (flags & URL_WRONLY || flags & URL_RDWR),
+ NULL, NULL, NULL, NULL);
+ if(ret != 0)
+ av_freep(s);
+ return ret;
}
-/* return the written or read size */
int url_close_buf(ByteIOContext *s)
{
put_flush_packet(s);
static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
{
DynBuffer *d = opaque;
- int new_size, new_allocated_size;
+ unsigned new_size, new_allocated_size;
/* reallocate buffer if needed */
new_size = d->pos + buf_size;
if (new_allocated_size > d->allocated_size) {
d->buffer = av_realloc(d->buffer, new_allocated_size);
if(d->buffer == NULL)
- return -1234;
+ return AVERROR(ENOMEM);
d->allocated_size = new_allocated_size;
}
memcpy(d->buffer + d->pos, buf, buf_size);
int ret;
/* packetized write: output the header */
- buf1[0] = (buf_size >> 24);
- buf1[1] = (buf_size >> 16);
- buf1[2] = (buf_size >> 8);
- buf1[3] = (buf_size);
+ AV_WB32(buf1, buf_size);
ret= dyn_buf_write(opaque, buf1, 4);
if(ret < 0)
return ret;
return dyn_buf_write(opaque, buf, buf_size);
}
-static offset_t dyn_buf_seek(void *opaque, offset_t offset, int whence)
+static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
{
DynBuffer *d = opaque;
return 0;
}
-static int url_open_dyn_buf_internal(ByteIOContext *s, int max_packet_size)
+static int url_open_dyn_buf_internal(ByteIOContext **s, int max_packet_size)
{
DynBuffer *d;
- int io_buffer_size, ret;
-
- if (max_packet_size)
- io_buffer_size = max_packet_size;
- else
- io_buffer_size = 1024;
+ int ret;
+ unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
if(sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
return -1;
- d = av_malloc(sizeof(DynBuffer) + io_buffer_size);
+ d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
if (!d)
- return -1;
+ return AVERROR(ENOMEM);
+ *s = av_mallocz(sizeof(ByteIOContext));
+ if(!*s) {
+ av_free(d);
+ return AVERROR(ENOMEM);
+ }
d->io_buffer_size = io_buffer_size;
- d->buffer = NULL;
- d->pos = 0;
- d->size = 0;
- d->allocated_size = 0;
- ret = init_put_byte(s, d->io_buffer, io_buffer_size,
+ ret = init_put_byte(*s, d->io_buffer, io_buffer_size,
1, d, NULL,
max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
max_packet_size ? NULL : dyn_buf_seek);
if (ret == 0) {
- s->max_packet_size = max_packet_size;
+ (*s)->max_packet_size = max_packet_size;
+ } else {
+ av_free(d);
+ av_freep(s);
}
return ret;
}
-/*
- * Open a write only memory stream.
- *
- * @param s new IO context
- * @return zero if no error.
- */
-int url_open_dyn_buf(ByteIOContext *s)
+int url_open_dyn_buf(ByteIOContext **s)
{
return url_open_dyn_buf_internal(s, 0);
}
-/*
- * Open a write only packetized memory stream with a maximum packet
- * size of 'max_packet_size'. The stream is stored in a memory buffer
- * with a big endian 4 byte header giving the packet size in bytes.
- *
- * @param s new IO context
- * @param max_packet_size maximum packet size (must be > 0)
- * @return zero if no error.
- */
-int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size)
+int url_open_dyn_packet_buf(ByteIOContext **s, int max_packet_size)
{
if (max_packet_size <= 0)
return -1;
return url_open_dyn_buf_internal(s, max_packet_size);
}
-/*
- * Return the written size and a pointer to the buffer. The buffer
- * must be freed with av_free().
- * @param s IO context
- * @param pointer to a byte buffer
- * @return the length of the byte buffer
- */
int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer)
{
DynBuffer *d = s->opaque;
int size;
+ static const char padbuf[FF_INPUT_BUFFER_PADDING_SIZE] = {0};
+ int padding = 0;
+
+ /* don't attempt to pad fixed-size packet buffers */
+ if (!s->max_packet_size) {
+ put_buffer(s, padbuf, sizeof(padbuf));
+ padding = FF_INPUT_BUFFER_PADDING_SIZE;
+ }
put_flush_packet(s);
*pbuffer = d->buffer;
size = d->size;
av_free(d);
- return size;
+ av_free(s);
+ return size - padding;
}
-#endif //CONFIG_MUXERS
+#endif /* CONFIG_MUXERS || CONFIG_NETWORK */