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
153 */153 */
154 154
155#define LIBAVUTIL_VERSION_MAJOR 51155#define LIBAVUTIL_VERSION_MAJOR 51
156#define LIBAVUTIL_VERSION_MINOR 51156#define LIBAVUTIL_VERSION_MINOR 52
157#define LIBAVUTIL_VERSION_MICRO 100157#define LIBAVUTIL_VERSION_MICRO 100
158 158
159#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \159#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
79 return 0;79 return 0;
80}80}
81 81
82int 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
82// src must NOT be const as it can be a context for func that may need updating (like a pointer or byte counter)95// src must NOT be const as it can be a context for func that may need updating (like a pointer or byte counter)
83int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int))96int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int))
84{97{
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
102 */102 */
103int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);103int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
104 104
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 */
114int av_fifo_grow(AVFifoBuffer *f, unsigned int additional_space);
115
105/**116/**
106 * Read and discard the specified amount of data from an AVFifoBuffer.117 * Read and discard the specified amount of data from an AVFifoBuffer.
107 * @param f AVFifoBuffer to read from118 * @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