History

fifo: add av_fifo_grow()

Michael Niedermayer committed 14 years ago

Commit f8196751 parent b9777793 files · +25 −1Browse files

Unified · Split

3 files
  1. libavutil/avutil.h +1 −1
  2. libavutil/fifo.c +13 −0
  3. libavutil/fifo.h +11 −0
libavutil/avutil.h+1−1
@@ -153,7 +153,7 @@ · 152 unmodified lines
153153 */
154154
155155 #define LIBAVUTIL_VERSION_MAJOR 51
156−#define LIBAVUTIL_VERSION_MINOR 51
156+#define LIBAVUTIL_VERSION_MINOR 52
157157 #define LIBAVUTIL_VERSION_MICRO 100
158158
159159 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
libavutil/fifo.c+13−0
@@ -79,6 +79,19 @@ int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) · 78 unmodified lines
7979 return 0;
8080 }
8181
82+int av_fifo_grow(AVFifoBuffer *f, unsigned int size)
83+{
84+ unsigned int old_size = f->end - f->buffer;
85+ if(size + (unsigned)av_fifo_size(f) < size)
86+ return AVERROR(EINVAL);
87+
88+ size += av_fifo_size(f);
89+
90+ if (old_size < size)
91+ return av_fifo_realloc2(f, FFMAX(size, 2*size));
92+ return 0;
93+}
94+
8295 // src must NOT be const as it can be a context for func that may need updating (like a pointer or byte counter)
8396 int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int))
8497 {
libavutil/fifo.h+11−0
@@ -102,6 +102,17 @@ int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void · 101 unmodified lines
102102 */
103103 int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
104104
105+/**
106+ * Enlarge an AVFifoBuffer.
107+ * In case of reallocation failure, the old FIFO is kept unchanged.
108+ * The new fifo size may be larger than the requested size.
109+ *
110+ * @param f AVFifoBuffer to resize
111+ * @param additional_space the amount of space in bytes to allocate in addition to av_fifo_size()
112+ * @return <0 for failure, >=0 otherwise
113+ */
114+int av_fifo_grow(AVFifoBuffer *f, unsigned int additional_space);
115+
105116 /**
106117 * Read and discard the specified amount of data from an AVFifoBuffer.
107118 * @param f AVFifoBuffer to read from

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