Unified · Split
| @@ -13,6 +13,9 @@ libavutil: 2012-10-22 · 12 unmodified lines | ||
| 13 | 13 | |
| 14 | 14 | API changes, most recent first: |
| 15 | 15 | |
| 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 | + | |
| 16 | 19 | 2013-10-xx - xxxxxxx - lavc 55.27.0 - avcodec.h |
| 17 | 20 | Deprecate AVCodecContext.error_rate, it is replaced by the 'error_rate' |
| 18 | 21 | private option of the mpegvideo encoder family. |
| @@ -36,6 +36,10 @@ · 35 unmodified lines | ||
| 36 | 36 | #include "libavutil/dict.h" |
| 37 | 37 | #include "libavutil/frame.h" |
| 38 | 38 | #include "libavutil/log.h" |
| 39 | +#if FF_API_FAST_MALLOC | |
| 40 | +// to provide fast_*alloc | |
| 41 | +#include "libavutil/mem.h" | |
| 42 | +#endif | |
| 39 | 43 | #include "libavutil/pixfmt.h" |
| 40 | 44 | #include "libavutil/rational.h" |
| 41 | 45 | |
| @@ -4197,27 +4201,6 @@ AVBitStreamFilter *av_bitstream_filter_next(AVBitStreamFilter *f); · 4155 unmodified lines | ||
| 4197 | 4201 | |
| 4198 | 4202 | /* memory */ |
| 4199 | 4203 | |
| 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 | − | |
| 4221 | 4204 | /** |
| 4222 | 4205 | * Allocate a buffer with padding, reusing the given one if large enough. |
| 4223 | 4206 | * |
| @@ -55,37 +55,17 @@ static int (*lockmgr_cb)(void **mutex, enum AVLockOp op); · 54 unmodified lines | ||
| 55 | 55 | static void *codec_mutex; |
| 56 | 56 | static void *avformat_mutex; |
| 57 | 57 | |
| 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") | |
| 59 | 60 | { |
| 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); | |
| 75 | 62 | } |
| 76 | 63 | |
| 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") | |
| 78 | 65 | { |
| 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); | |
| 88 | 67 | } |
| 68 | +#endif | |
| 89 | 69 | |
| 90 | 70 | void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size) |
| 91 | 71 | { |
| @@ -112,5 +112,8 @@ · 111 unmodified lines | ||
| 112 | 112 | #ifndef FF_API_MAX_BFRAMES |
| 113 | 113 | #define FF_API_MAX_BFRAMES (LIBAVCODEC_VERSION_MAJOR < 56) |
| 114 | 114 | #endif |
| 115 | +#ifndef FF_API_FAST_MALLOC | |
| 116 | +#define FF_API_FAST_MALLOC (LIBAVCODEC_VERSION_MAJOR < 56) | |
| 117 | +#endif | |
| 115 | 118 | |
| 116 | 119 | #endif /* AVCODEC_VERSION_H */ |
| @@ -35,6 +35,7 @@ · 34 unmodified lines | ||
| 35 | 35 | #endif |
| 36 | 36 | |
| 37 | 37 | #include "avutil.h" |
| 38 | +#include "common.h" | |
| 38 | 39 | #include "intreadwrite.h" |
| 39 | 40 | #include "mem.h" |
| 40 | 41 | |
| @@ -344,3 +345,35 @@ void av_memcpy_backptr(uint8_t *dst, int back, int cnt) · 303 unmodified lines | ||
| 344 | 345 | *dst = *src; |
| 345 | 346 | } |
| 346 | 347 | } |
| 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 | +} | |
| @@ -237,6 +237,27 @@ void av_freep(void *ptr); · 236 unmodified lines | ||
| 237 | 237 | */ |
| 238 | 238 | void av_memcpy_backptr(uint8_t *dst, int back, int cnt); |
| 239 | 239 | |
| 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 | + | |
| 240 | 261 | /** |
| 241 | 262 | * @} |
| 242 | 263 | */ |
| @@ -37,7 +37,7 @@ · 36 unmodified lines | ||
| 37 | 37 | */ |
| 38 | 38 | |
| 39 | 39 | #define LIBAVUTIL_VERSION_MAJOR 52 |
| 40 | −#define LIBAVUTIL_VERSION_MINOR 17 | |
| 40 | +#define LIBAVUTIL_VERSION_MINOR 18 | |
| 41 | 41 | #define LIBAVUTIL_VERSION_MICRO 0 |
| 42 | 42 | |
| 43 | 43 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |