[FFmpeg-cvslog] Move av_fast_{m,re}alloc from lavc to lavu.

Anton Khirnov git at videolan.org
Thu Nov 14 15:23:18 CET 2013


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sun Oct 27 22:21:59 2013 +0100| [cce3e0a49f0dd030262c28d9c53de0bd2fd909c4] | committer: Anton Khirnov

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

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cce3e0a49f0dd030262c28d9c53de0bd2fd909c4
---

 doc/APIchanges       |    3 +++
 libavcodec/avcodec.h |   25 ++++---------------------
 libavcodec/utils.c   |   32 ++++++--------------------------
 libavcodec/version.h |    3 +++
 libavutil/mem.c      |   33 +++++++++++++++++++++++++++++++++
 libavutil/mem.h      |   21 +++++++++++++++++++++
 libavutil/version.h  |    2 +-
 7 files changed, 71 insertions(+), 48 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 2fca8fb..1882fb8 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil:     2012-10-22
 
 API changes, most recent first:
 
+2013-11-xx - xxxxxxx - lavu 52.18.0 - mem.h
+  Move av_fast_malloc() and av_fast_realloc() for libavcodec to libavutil.
+
 2013-10-xx - xxxxxxx - lavc 55.27.0 - avcodec.h
   Deprecate AVCodecContext.error_rate, it is replaced by the 'error_rate'
   private option of the mpegvideo encoder family.
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 294783b..79c6efc 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -36,6 +36,10 @@
 #include "libavutil/dict.h"
 #include "libavutil/frame.h"
 #include "libavutil/log.h"
+#if FF_API_FAST_MALLOC
+// to provide fast_*alloc
+#include "libavutil/mem.h"
+#endif
 #include "libavutil/pixfmt.h"
 #include "libavutil/rational.h"
 
@@ -4198,27 +4202,6 @@ AVBitStreamFilter *av_bitstream_filter_next(AVBitStreamFilter *f);
 /* memory */
 
 /**
- * Reallocate the given block if it is not large enough, otherwise do nothing.
- *
- * @see av_realloc
- */
-void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
-
-/**
- * Allocate a buffer, reusing the given one if large enough.
- *
- * Contrary to av_fast_realloc the current buffer contents might not be
- * preserved and on error the old buffer is freed, thus no special
- * handling to avoid memleaks is necessary.
- *
- * @param ptr pointer to pointer to already allocated buffer, overwritten with pointer to new buffer
- * @param size size of the buffer *ptr points to
- * @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and
- *                 *size 0 if an error occurred.
- */
-void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
-
-/**
  * Allocate a buffer with padding, reusing the given one if large enough.
  *
  * Same behaviour av_fast_malloc but the buffer has additional
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 2f5c170..23165f4 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -55,37 +55,17 @@ static int (*lockmgr_cb)(void **mutex, enum AVLockOp op);
 static void *codec_mutex;
 static void *avformat_mutex;
 
-void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
+#if FF_API_FAST_MALLOC && CONFIG_SHARED && HAVE_SYMVER
+FF_SYMVER(void*, av_fast_realloc, (void *ptr, unsigned int *size, size_t min_size), "LIBAVCODEC_55")
 {
-    if (min_size < *size)
-        return ptr;
-
-    min_size = FFMAX(17 * min_size / 16 + 32, min_size);
-
-    ptr = av_realloc(ptr, min_size);
-    /* we could set this to the unmodified min_size but this is safer
-     * if the user lost the ptr and uses NULL now
-     */
-    if (!ptr)
-        min_size = 0;
-
-    *size = min_size;
-
-    return ptr;
+    return av_fast_realloc(ptr, size, min_size);
 }
 
-void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
+FF_SYMVER(void, av_fast_malloc, (void *ptr, unsigned int *size, size_t min_size), "LIBAVCODEC_55")
 {
-    void **p = ptr;
-    if (min_size < *size)
-        return;
-    min_size = FFMAX(17 * min_size / 16 + 32, min_size);
-    av_free(*p);
-    *p = av_malloc(min_size);
-    if (!*p)
-        min_size = 0;
-    *size = min_size;
+    av_fast_malloc(ptr, size, min_size);
 }
+#endif
 
 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
 {
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 5f86245..38a6064 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -112,5 +112,8 @@
 #ifndef FF_API_MAX_BFRAMES
 #define FF_API_MAX_BFRAMES       (LIBAVCODEC_VERSION_MAJOR < 56)
 #endif
+#ifndef FF_API_FAST_MALLOC
+#define FF_API_FAST_MALLOC       (LIBAVCODEC_VERSION_MAJOR < 56)
+#endif
 
 #endif /* AVCODEC_VERSION_H */
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 15a8c07..be42342 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -35,6 +35,7 @@
 #endif
 
 #include "avutil.h"
+#include "common.h"
 #include "intreadwrite.h"
 #include "mem.h"
 
@@ -344,3 +345,35 @@ void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
             *dst = *src;
     }
 }
+
+void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
+{
+    if (min_size < *size)
+        return ptr;
+
+    min_size = FFMAX(17 * min_size / 16 + 32, min_size);
+
+    ptr = av_realloc(ptr, min_size);
+    /* we could set this to the unmodified min_size but this is safer
+     * if the user lost the ptr and uses NULL now
+     */
+    if (!ptr)
+        min_size = 0;
+
+    *size = min_size;
+
+    return ptr;
+}
+
+void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
+{
+    void **p = ptr;
+    if (min_size < *size)
+        return;
+    min_size = FFMAX(17 * min_size / 16 + 32, min_size);
+    av_free(*p);
+    *p = av_malloc(min_size);
+    if (!*p)
+        min_size = 0;
+    *size = min_size;
+}
diff --git a/libavutil/mem.h b/libavutil/mem.h
index 99dc4cc..4a5e362 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -238,6 +238,27 @@ void av_freep(void *ptr);
 void av_memcpy_backptr(uint8_t *dst, int back, int cnt);
 
 /**
+ * Reallocate the given block if it is not large enough, otherwise do nothing.
+ *
+ * @see av_realloc
+ */
+void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
+
+/**
+ * Allocate a buffer, reusing the given one if large enough.
+ *
+ * Contrary to av_fast_realloc the current buffer contents might not be
+ * preserved and on error the old buffer is freed, thus no special
+ * handling to avoid memleaks is necessary.
+ *
+ * @param ptr pointer to pointer to already allocated buffer, overwritten with pointer to new buffer
+ * @param size size of the buffer *ptr points to
+ * @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and
+ *                 *size 0 if an error occurred.
+ */
+void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
+
+/**
  * @}
  */
 
diff --git a/libavutil/version.h b/libavutil/version.h
index 4fabb1b..4f0f469 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -37,7 +37,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 52
-#define LIBAVUTIL_VERSION_MINOR 17
+#define LIBAVUTIL_VERSION_MINOR 18
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list