[FFmpeg-devel] [PATCH 1/5] lavu: add av_dynarray_alloc_elem().
Clément Bœsch
ubitux at gmail.com
Sun Apr 14 03:07:54 CEST 2013
---
libavutil/mem.c | 19 +++++++++++++++++++
libavutil/mem.h | 13 +++++++++++++
libavutil/version.h | 2 +-
3 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 860c011..835c73a 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -250,6 +250,25 @@ void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
*nb_ptr = nb;
}
+void *av_dynarray_alloc_elem(void **tab_ptr, int *nb_ptr, size_t elem_size)
+{
+ int nb = *nb_ptr;
+ uint8_t *tab = *tab_ptr;
+
+ if ((nb & (nb - 1)) == 0) {
+ int nb_alloc = nb == 0 ? 1 : nb * 2;
+ tab = av_realloc_f(tab, nb_alloc, elem_size);
+ if (!tab)
+ return NULL;
+ *tab_ptr = tab;
+ }
+ *nb_ptr = nb + 1;
+#if CONFIG_MEMORY_POISONING
+ memset(tab + nb*elem_size, 0x2a, elem_size);
+#endif
+ return tab + nb*elem_size;
+}
+
static void fill16(uint8_t *dst, int len)
{
uint32_t v = AV_RN16(dst - 2);
diff --git a/libavutil/mem.h b/libavutil/mem.h
index ced9453..64d86ff 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -198,6 +198,19 @@ void av_freep(void *ptr);
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
/**
+ * Allocate an element of size elem_size to a dynamic array.
+ *
+ * @param tab_ptr Pointer to the array.
+ * @param nb_ptr Pointer to the number of elements in the array.
+ * @param elem_size Size of the elements in the array.
+ * @return Pointer to the elem_size allocated space at the end of the
+ * array, or NULL in case of memory error
+ *
+ * @note this function is not compatible with av_dynarray_add
+ */
+void *av_dynarray_alloc_elem(void **tab_ptr, int *nb_ptr, size_t elem_size);
+
+/**
* Multiply two size_t values checking for overflow.
* @return 0 if success, AVERROR(EINVAL) if overflow.
*/
diff --git a/libavutil/version.h b/libavutil/version.h
index 6531397..e46e97c 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -75,7 +75,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 52
-#define LIBAVUTIL_VERSION_MINOR 26
+#define LIBAVUTIL_VERSION_MINOR 27
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
--
1.8.2.1
More information about the ffmpeg-devel
mailing list