History

Move av_fast_{m,re}alloc from lavc to lavu.

Anton Khirnov committed 13 years ago

Commit cce3e0a1 parent aa241227 files · +71 −48Browse files

Unified · Split

7 files
  1. doc/APIchanges +3 −0
  2. libavcodec/avcodec.h +4 −21
  3. libavcodec/utils.c +6 −26
  4. libavcodec/version.h +3 −0
  5. libavutil/mem.c +33 −0
  6. libavutil/mem.h +21 −0
  7. libavutil/version.h +1 −1
doc/APIchanges+3−0
@@ -13,6 +13,9 @@ libavutil: 2012-10-22 · 12 unmodified lines
1313
1414 API changes, most recent first:
1515
16+2013-11-xx - xxxxxxx - lavu 52.18.0 - mem.h
17+ Move av_fast_malloc() and av_fast_realloc() for libavcodec to libavutil.
18+
1619 2013-10-xx - xxxxxxx - lavc 55.27.0 - avcodec.h
1720 Deprecate AVCodecContext.error_rate, it is replaced by the 'error_rate'
1821 private option of the mpegvideo encoder family.
libavcodec/avcodec.h+4−21
@@ -36,6 +36,10 @@ · 35 unmodified lines
3636 #include "libavutil/dict.h"
3737 #include "libavutil/frame.h"
3838 #include "libavutil/log.h"
39+#if FF_API_FAST_MALLOC
40+// to provide fast_*alloc
41+#include "libavutil/mem.h"
42+#endif
3943 #include "libavutil/pixfmt.h"
4044 #include "libavutil/rational.h"
4145
@@ -4197,27 +4201,6 @@ AVBitStreamFilter *av_bitstream_filter_next(AVBitStreamFilter *f); · 4155 unmodified lines
41974201
41984202 /* memory */
41994203
4200−/**
4201− * Reallocate the given block if it is not large enough, otherwise do nothing.
4202− *
4203− * @see av_realloc
4204− */
4205−void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
4206−
4207−/**
4208− * Allocate a buffer, reusing the given one if large enough.
4209− *
4210− * Contrary to av_fast_realloc the current buffer contents might not be
4211− * preserved and on error the old buffer is freed, thus no special
4212− * handling to avoid memleaks is necessary.
4213− *
4214− * @param ptr pointer to pointer to already allocated buffer, overwritten with pointer to new buffer
4215− * @param size size of the buffer *ptr points to
4216− * @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and
4217− * *size 0 if an error occurred.
4218− */
4219−void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
4220−
42214204 /**
42224205 * Allocate a buffer with padding, reusing the given one if large enough.
42234206 *
libavcodec/utils.c+6−26
@@ -55,37 +55,17 @@ static int (*lockmgr_cb)(void **mutex, enum AVLockOp op); · 54 unmodified lines
5555 static void *codec_mutex;
5656 static void *avformat_mutex;
5757
58−void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
58+#if FF_API_FAST_MALLOC && CONFIG_SHARED && HAVE_SYMVER
59+FF_SYMVER(void*, av_fast_realloc, (void *ptr, unsigned int *size, size_t min_size), "LIBAVCODEC_55")
5960 {
60− if (min_size < *size)
61− return ptr;
62−
63− min_size = FFMAX(17 * min_size / 16 + 32, min_size);
64−
65− ptr = av_realloc(ptr, min_size);
66− /* we could set this to the unmodified min_size but this is safer
67− * if the user lost the ptr and uses NULL now
68− */
69− if (!ptr)
70− min_size = 0;
71−
72− *size = min_size;
73−
74− return ptr;
61+ return av_fast_realloc(ptr, size, min_size);
7562 }
7663
77−void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
64+FF_SYMVER(void, av_fast_malloc, (void *ptr, unsigned int *size, size_t min_size), "LIBAVCODEC_55")
7865 {
79− void **p = ptr;
80− if (min_size < *size)
81− return;
82− min_size = FFMAX(17 * min_size / 16 + 32, min_size);
83− av_free(*p);
84− *p = av_malloc(min_size);
85− if (!*p)
86− min_size = 0;
87− *size = min_size;
66+ av_fast_malloc(ptr, size, min_size);
8867 }
68+#endif
8969
9070 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
9171 {
libavcodec/version.h+3−0
@@ -112,5 +112,8 @@ · 111 unmodified lines
112112 #ifndef FF_API_MAX_BFRAMES
113113 #define FF_API_MAX_BFRAMES (LIBAVCODEC_VERSION_MAJOR < 56)
114114 #endif
115+#ifndef FF_API_FAST_MALLOC
116+#define FF_API_FAST_MALLOC (LIBAVCODEC_VERSION_MAJOR < 56)
117+#endif
115118
116119 #endif /* AVCODEC_VERSION_H */
libavutil/mem.c+33−0
@@ -35,6 +35,7 @@ · 34 unmodified lines
3535 #endif
3636
3737 #include "avutil.h"
38+#include "common.h"
3839 #include "intreadwrite.h"
3940 #include "mem.h"
4041
@@ -344,3 +345,35 @@ void av_memcpy_backptr(uint8_t *dst, int back, int cnt) · 303 unmodified lines
344345 *dst = *src;
345346 }
346347 }
348+
349+void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
350+{
351+ if (min_size < *size)
352+ return ptr;
353+
354+ min_size = FFMAX(17 * min_size / 16 + 32, min_size);
355+
356+ ptr = av_realloc(ptr, min_size);
357+ /* we could set this to the unmodified min_size but this is safer
358+ * if the user lost the ptr and uses NULL now
359+ */
360+ if (!ptr)
361+ min_size = 0;
362+
363+ *size = min_size;
364+
365+ return ptr;
366+}
367+
368+void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
369+{
370+ void **p = ptr;
371+ if (min_size < *size)
372+ return;
373+ min_size = FFMAX(17 * min_size / 16 + 32, min_size);
374+ av_free(*p);
375+ *p = av_malloc(min_size);
376+ if (!*p)
377+ min_size = 0;
378+ *size = min_size;
379+}
libavutil/mem.h+21−0
@@ -237,6 +237,27 @@ void av_freep(void *ptr); · 236 unmodified lines
237237 */
238238 void av_memcpy_backptr(uint8_t *dst, int back, int cnt);
239239
240+/**
241+ * Reallocate the given block if it is not large enough, otherwise do nothing.
242+ *
243+ * @see av_realloc
244+ */
245+void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
246+
247+/**
248+ * Allocate a buffer, reusing the given one if large enough.
249+ *
250+ * Contrary to av_fast_realloc the current buffer contents might not be
251+ * preserved and on error the old buffer is freed, thus no special
252+ * handling to avoid memleaks is necessary.
253+ *
254+ * @param ptr pointer to pointer to already allocated buffer, overwritten with pointer to new buffer
255+ * @param size size of the buffer *ptr points to
256+ * @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and
257+ * *size 0 if an error occurred.
258+ */
259+void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
260+
240261 /**
241262 * @}
242263 */
libavutil/version.h+1−1
@@ -37,7 +37,7 @@ · 36 unmodified lines
3737 */
3838
3939 #define LIBAVUTIL_VERSION_MAJOR 52
40−#define LIBAVUTIL_VERSION_MINOR 17
40+#define LIBAVUTIL_VERSION_MINOR 18
4141 #define LIBAVUTIL_VERSION_MICRO 0
4242
4343 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

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