dnl Check for usual libc functions
AC_CHECK_DECLS([nanosleep],,,[#include <time.h>])
-AC_CHECK_FUNCS([daemon fcntl fstatvfs fork getenv getpwuid_r if_nameindex if_nametoindex isatty lstat memalign mmap openat pread posix_fadvise posix_madvise posix_memalign setlocale stricmp strnicmp uselocale])
+AC_CHECK_FUNCS([daemon fcntl fstatvfs fork getenv getpwuid_r if_nameindex if_nametoindex isatty lstat memalign mmap openat pread posix_fadvise posix_madvise setlocale stricmp strnicmp uselocale])
AC_REPLACE_FUNCS([asprintf atof atoll dirfd fdopendir flockfile fsync getdelim getpid gmtime_r lldiv localtime_r nrand48 rewind setenv strcasecmp strcasestr strdup strlcpy strncasecmp strndup strnlen strsep strtof strtok_r strtoll swab tdestroy vasprintf])
AC_CHECK_FUNCS(fdatasync,,
[AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])
VLC_API bool vlc_ureduce( unsigned *, unsigned *, uint64_t, uint64_t, uint64_t );
-VLC_API void * vlc_memalign( void **base, size_t alignment, size_t size ) VLC_USED;
+/* Aligned memory allocator */
+#ifdef WIN32
+# include <malloc.h>
+# define vlc_memalign(align, size) (__mingw_aligned_malloc(size, align))
+# define vlc_free(base) (__mingw_aligned_free(base))
+#else
+static inline void *vlc_memalign(size_t align, size_t size)
+{
+ void *base;
+ if (unlikely(posix_memalign(&base, align, size)))
+ base = NULL;
+ return base;
+}
+# define vlc_free(base) free(base)
+#endif
VLC_API void vlc_tdestroy( void *, void (*)(void *) );
int CopyInitCache(copy_cache_t *cache, unsigned width)
{
cache->size = __MAX((width + 0x0f) & ~ 0x0f, 4096);
- cache->buffer = vlc_memalign(&cache->base, 16, cache->size);
- if (!cache->base)
+ cache->buffer = vlc_memalign(16, cache->size);
+ if (!cache->buffer)
return VLC_EGENERIC;
return VLC_SUCCESS;
}
void CopyCleanCache(copy_cache_t *cache)
{
- free(cache->base);
-
- cache->base = NULL;
+ vlc_free(cache->buffer);
cache->buffer = NULL;
cache->size = 0;
}
#define _VLC_AVCODEC_COPY_H 1
typedef struct {
- void *base;
uint8_t *buffer;
size_t size;
} copy_cache_t;
float strength;
int radius;
const vlc_chroma_description_t *chroma;
- void *base_buf;
struct vf_priv_s cfg;
};
sys->radius = var_CreateGetIntegerCommand(filter, CFG_PREFIX "radius");
var_AddCallback(filter, CFG_PREFIX "strength", Callback, NULL);
var_AddCallback(filter, CFG_PREFIX "radius", Callback, NULL);
- sys->base_buf = NULL;
+ sys->cfg.buf = NULL;
struct vf_priv_s *cfg = &sys->cfg;
cfg->thresh = 0.0;
var_DelCallback(filter, CFG_PREFIX "radius", Callback, NULL);
var_DelCallback(filter, CFG_PREFIX "strength", Callback, NULL);
- free(sys->base_buf);
+ free(sys->cfg.buf);
vlc_mutex_destroy(&sys->lock);
free(sys);
}
cfg->thresh = (1 << 15) / strength;
if (cfg->radius != radius) {
cfg->radius = radius;
- cfg->buf = vlc_memalign(&sys->base_buf, 16,
+ cfg->buf = vlc_memalign(16,
(((fmt->i_width + 15) & ~15) * (cfg->radius + 1) / 2 + 32) * sizeof(*cfg->buf));
}
vlc_list_children
vlc_list_release
vlc_memcpy
-vlc_memalign
vlc_meta_AddExtra
vlc_meta_CopyExtraNames
vlc_meta_Delete
{
return pf_vlc_memcpy (tgt, src, 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
-}
i_bytes += p->i_pitch * p->i_lines;
}
- uint8_t *p_data = vlc_memalign( &p_pic->p_data_orig, 16, i_bytes );
+ uint8_t *p_data = vlc_memalign( 16, i_bytes );
if( !p_data )
{
p_pic->i_planes = 0;
return VLC_EGENERIC;
}
+ p_pic->p_data_orig = p_data; /* TODO: get rid of this */
/* Fill the p_pixels field for each plane */
p_pic->p[0].p_pixels = p_data;
assert( p_picture->p_release_sys == NULL );
free( p_picture->p_q );
- free( p_picture->p_data_orig );
+ vlc_free( p_picture->p_data_orig );
free( p_picture->p_sys );
free( p_picture );
}