[FFmpeg-devel] [PATCH 2/3] avformat/aviobuf: Add ffio_ensure_seekback()
Michael Niedermayer
michaelni at gmx.at
Sun Jun 30 18:30:30 CEST 2013
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
libavformat/avio_internal.h | 9 +++++++++
libavformat/aviobuf.c | 25 +++++++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h
index cf36764..311e297 100644
--- a/libavformat/avio_internal.h
+++ b/libavformat/avio_internal.h
@@ -71,6 +71,15 @@ uint64_t ffio_read_varlen(AVIOContext *bc);
/** @warning must be called before any I/O */
int ffio_set_buf_size(AVIOContext *s, int buf_size);
+/**
+ * Ensures that the requested seekback buffer size will be available
+ *
+ * Will ensure that when reading sequentially up to buf_size, seeking
+ * within the current pos and pos+buf_size is possible.
+ * Once the stream position moves outside this window this gurantee is lost.
+ */
+int ffio_ensure_seekback(AVIOContext *s, int buf_size);
+
int ffio_limit(AVIOContext *s, int size);
void ffio_init_checksum(AVIOContext *s,
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 790c261..93a187b 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -725,6 +725,31 @@ int ffio_fdopen(AVIOContext **s, URLContext *h)
return 0;
}
+int ffio_ensure_seekback(AVIOContext *s, int buf_size)
+{
+ uint8_t *buffer;
+ int max_buffer_size = s->max_packet_size ?
+ s->max_packet_size : IO_BUFFER_SIZE;
+
+ buf_size += s->buf_ptr - s->buffer + max_buffer_size;
+
+ if (buf_size < s->buffer_size || s->seekable)
+ return 0;
+ av_assert0(!s->write_flag);
+
+ buffer = av_malloc(buf_size);
+ if (!buffer)
+ return AVERROR(ENOMEM);
+
+ memcpy(buffer, s->buffer, s->buffer_size);
+ av_free(s->buffer);
+ s->buf_ptr = buffer + (s->buf_ptr - s->buffer);
+ s->buf_end = buffer + (s->buf_end - s->buffer);
+ s->buffer = buffer;
+ s->buffer_size = buf_size;
+ return 0;
+}
+
int ffio_set_buf_size(AVIOContext *s, int buf_size)
{
uint8_t *buffer;
--
1.7.9.5
More information about the ffmpeg-devel
mailing list