Browse code

Implement av_fifo_realloc2().

Originally committed as revision 14846 to svn://svn.ffmpeg.org/ffmpeg/trunk

Stefano Sabatini authored on 2008/08/20 03:43:34
Showing 3 changed files
... ...
@@ -35,7 +35,7 @@
35 35
 #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
36 36
 
37 37
 #define LIBAVUTIL_VERSION_MAJOR 49
38
-#define LIBAVUTIL_VERSION_MINOR  9
38
+#define LIBAVUTIL_VERSION_MINOR 10
39 39
 #define LIBAVUTIL_VERSION_MICRO  0
40 40
 
41 41
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
... ...
@@ -55,18 +55,24 @@ int av_fifo_read(AVFifoBuffer *f, uint8_t *buf, int buf_size)
55 55
  * Resizes a FIFO.
56 56
  */
57 57
 void av_fifo_realloc(AVFifoBuffer *f, unsigned int new_size) {
58
+    av_fifo_realloc2(f, new_size);
59
+}
60
+
61
+int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) {
58 62
     unsigned int old_size= f->end - f->buffer;
59 63
 
60 64
     if(old_size <= new_size){
61 65
         int len= av_fifo_size(f);
62 66
         AVFifoBuffer f2;
63 67
 
64
-        av_fifo_init(&f2, new_size);
68
+        if (av_fifo_init(&f2, new_size) < 0)
69
+            return -1;
65 70
         av_fifo_read(f, f2.buffer, len);
66 71
         f2.wptr += len;
67 72
         av_free(f->buffer);
68 73
         *f= f2;
69 74
     }
75
+    return 0;
70 76
 }
71 77
 
72 78
 void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size)
... ...
@@ -97,10 +97,19 @@ int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void
97 97
  * Resizes an AVFifoBuffer.
98 98
  * @param *f AVFifoBuffer to resize
99 99
  * @param size new AVFifoBuffer size in bytes
100
+ * @see av_fifo_realloc2()
100 101
  */
101 102
 void av_fifo_realloc(AVFifoBuffer *f, unsigned int size);
102 103
 
103 104
 /**
105
+ * Resizes an AVFifoBuffer.
106
+ * @param *f AVFifoBuffer to resize
107
+ * @param size new AVFifoBuffer size in bytes
108
+ * @return <0 for failure >=0 otherwise
109
+ */
110
+int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
111
+
112
+/**
104 113
  * Reads and discards the specified amount of data from an AVFifoBuffer.
105 114
  * @param *f AVFifoBuffer to read from
106 115
  * @param size amount of data to read in bytes