Commit 54bac7d8 authored by Laurent Aimar's avatar Laurent Aimar

Made vlc_memalign public.

parent 7f42234c
......@@ -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 );
......
......@@ -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 \
......
......@@ -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
......
......@@ -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
}
......@@ -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"
......
......@@ -41,7 +41,6 @@
#include <vlc_picture_fifo.h>
#include <vlc_picture_pool.h>
#include "vout_pictures.h"
#include "vout_internal.h"
/**
......
/*****************************************************************************
* vout_pictures.h : picture management definitions
*****************************************************************************
* Copyright (C) 2002-2004 the VideoLAN team
* $Id$
*
* Authors: Samuel Hocevar <sam@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
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment