[vlc-commits] commit: Made vlc_memalign public. (Laurent Aimar )

git at videolan.org git at videolan.org
Sun May 9 16:18:59 CEST 2010


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Sun May  9 15:54:30 2010 +0200| [54bac7d87af582675d09464790731a38dd86582a] | committer: Laurent Aimar 

Made vlc_memalign public.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=54bac7d87af582675d09464790731a38dd86582a
---

 include/vlc_common.h             |    2 +
 src/Makefile.am                  |    1 -
 src/libvlccore.sym               |    1 +
 src/misc/cpu.c                   |   30 ++++++++++++++++++++
 src/video_output/video_output.c  |    1 -
 src/video_output/vout_pictures.c |    1 -
 src/video_output/vout_pictures.h |   57 --------------------------------------
 7 files changed, 33 insertions(+), 60 deletions(-)

diff --git a/include/vlc_common.h b/include/vlc_common.h
index e42bba6..9cb0273 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -829,6 +829,8 @@ static inline uint64_t ntoh64 (uint64_t ll)
 
 VLC_EXPORT( bool, vlc_ureduce, ( unsigned *, unsigned *, uint64_t, uint64_t, uint64_t ) );
 
+VLC_EXPORT( void *, vlc_memalign, ( void **base, size_t alignment, size_t size ) );
+
 /* iconv wrappers (defined in src/extras/libc.c) */
 typedef void *vlc_iconv_t;
 VLC_EXPORT( vlc_iconv_t, vlc_iconv_open, ( const char *, const char * ) LIBVLC_USED );
diff --git a/src/Makefile.am b/src/Makefile.am
index bd81fe4..25748c2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -375,7 +375,6 @@ SOURCES_libvlc_common = \
 	video_output/postprocessing.h \
 	video_output/video_output.c \
 	video_output/vout_pictures.c \
-	video_output/vout_pictures.h \
 	video_output/video_text.c \
 	video_output/video_epg.c \
 	video_output/video_widgets.c \
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 9bc39d3..fa8d962 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -530,6 +530,7 @@ vlc_list_children
 vlc_list_release
 vlc_memcpy
 vlc_memset
+vlc_memalign
 vlc_meta_AddExtra
 vlc_meta_CopyExtraNames
 vlc_meta_Delete
diff --git a/src/misc/cpu.c b/src/misc/cpu.c
index a2db2c2..83b9560 100644
--- a/src/misc/cpu.c
+++ b/src/misc/cpu.c
@@ -41,6 +41,7 @@
 #else
 #include <errno.h>
 #endif
+#include <assert.h>
 
 #include "libvlc.h"
 
@@ -405,3 +406,32 @@ void *vlc_memset (void *tgt, int c, size_t n)
 {
     return pf_vlc_memset (tgt, c, n);
 }
+
+/**
+ * Returned an aligned pointer on newly allocated memory.
+ * \param alignment must be a power of 2 and a multiple of sizeof(void*)
+ * \param size is the size of the usable memory returned.
+ *
+ * It must not be freed directly, *base must.
+ */
+void *vlc_memalign(void **base, size_t alignment, size_t size)
+{
+    assert(alignment >= sizeof(void*));
+    for (size_t t = alignment; t > 1; t >>= 1)
+        assert((t&1) == 0);
+#if defined(HAVE_POSIX_MEMALIGN)
+    if (posix_memalign(base, alignment, size)) {
+        *base = NULL;
+        return NULL;
+    }
+    return *base;
+#elif defined(HAVE_MEMALIGN)
+    return *base = memalign(alignment, size);
+#else
+    unsigned char *p = *base = malloc(size + alignment - 1);
+    if (!p)
+        return NULL;
+    return (void*)((uintptr_t)(p + alignment - 1) & ~(alignment - 1));
+#endif
+}
+
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 79c4ad3..362e9e3 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -47,7 +47,6 @@
 
 #include <libvlc.h>
 #include <vlc_input.h>
-#include "vout_pictures.h"
 #include "vout_internal.h"
 #include "interlacing.h"
 #include "postprocessing.h"
diff --git a/src/video_output/vout_pictures.c b/src/video_output/vout_pictures.c
index 3519caa..8d0b9d3 100644
--- a/src/video_output/vout_pictures.c
+++ b/src/video_output/vout_pictures.c
@@ -41,7 +41,6 @@
 #include <vlc_picture_fifo.h>
 #include <vlc_picture_pool.h>
 
-#include "vout_pictures.h"
 #include "vout_internal.h"
 
 /**
diff --git a/src/video_output/vout_pictures.h b/src/video_output/vout_pictures.h
deleted file mode 100644
index 8d41545..0000000
--- a/src/video_output/vout_pictures.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*****************************************************************************
- * vout_pictures.h : picture management definitions
- *****************************************************************************
- * Copyright (C) 2002-2004 the VideoLAN team
- * $Id$
- *
- * Authors: Samuel Hocevar <sam at zoy.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-/*****************************************************************************
- * Fourcc definitions that we can handle internally
- *****************************************************************************/
-
-/* Alignment of critical dynamic data structure
- *
- * Not all platforms support memalign so we provide a vlc_memalign wrapper
- * void *vlc_memalign( size_t align, size_t size, void **pp_orig )
- * *pp_orig is the pointer that has to be freed afterwards.
- */
-static inline
-void *vlc_memalign (void **pp, size_t align, size_t size)
-{
-#if defined (HAVE_POSIX_MEMALIGN)
-    return posix_memalign (pp, align, size) ? NULL : *pp;
-#elif defined (HAVE_MEMALIGN)
-    return *pp = memalign (align, size);
-#else
-    unsigned char *ptr;
-
-    if (align < 1)
-        return NULL;
-
-    align--;
-    ptr = malloc (size + align);
-    if (ptr == NULL)
-        return NULL;
-
-    *pp = ptr;
-    ptr += align;
-    return (void *)(((uintptr_t)ptr) & ~align);
-#endif
-}
-



More information about the vlc-commits mailing list